Introduce main identifier to power RelationFieldDisplay (#2577)
* Introduce main identifier to power RelationFieldDisplay, FilterDrodown, TableFirstColumn * Apply to RelationPicker
This commit is contained in:
@ -165,11 +165,11 @@ export const RecordShowPage = () => {
|
||||
value={{
|
||||
entityId: object.id,
|
||||
recoilScopeId: object.id + metadataField.id,
|
||||
isMainIdentifier: false,
|
||||
fieldDefinition:
|
||||
formatFieldMetadataItemAsColumnDefinition({
|
||||
field: metadataField,
|
||||
position: index,
|
||||
objectMetadataItem: foundObjectMetadataItem,
|
||||
}),
|
||||
useUpdateEntityMutation: useUpdateOneObjectMutation,
|
||||
hotkeyScope: InlineCellHotkeyScope.InlineCell,
|
||||
|
||||
@ -2,6 +2,7 @@ import { useEffect } from 'react';
|
||||
|
||||
import { useComputeDefinitionsFromFieldMetadata } from '@/object-metadata/hooks/useComputeDefinitionsFromFieldMetadata';
|
||||
import { useFindOneObjectMetadataItem } from '@/object-metadata/hooks/useFindOneObjectMetadataItem';
|
||||
import { useObjectMainIdentifier } from '@/object-metadata/hooks/useObjectMainIdentifier';
|
||||
import { useRecordTableContextMenuEntries } from '@/object-record/hooks/useRecordTableContextMenuEntries';
|
||||
import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns';
|
||||
import { useRecordTable } from '@/ui/object/record-table/hooks/useRecordTable';
|
||||
@ -13,12 +14,19 @@ export const RecordTableEffect = () => {
|
||||
scopeId: objectNamePlural,
|
||||
setAvailableTableColumns,
|
||||
setOnEntityCountChange,
|
||||
setObjectMetadataConfig,
|
||||
} = useRecordTable();
|
||||
|
||||
const { foundObjectMetadataItem } = useFindOneObjectMetadataItem({
|
||||
objectNamePlural,
|
||||
});
|
||||
|
||||
const {
|
||||
mainIdentifierMapper,
|
||||
basePathToShowPage,
|
||||
mainIdentifierFieldMetadataId,
|
||||
} = useObjectMainIdentifier(foundObjectMetadataItem);
|
||||
|
||||
const { columnDefinitions, filterDefinitions, sortDefinitions } =
|
||||
useComputeDefinitionsFromFieldMetadata(foundObjectMetadataItem);
|
||||
|
||||
@ -31,6 +39,26 @@ export const RecordTableEffect = () => {
|
||||
setEntityCountInCurrentView,
|
||||
} = useView();
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
mainIdentifierMapper &&
|
||||
basePathToShowPage &&
|
||||
mainIdentifierFieldMetadataId
|
||||
) {
|
||||
setObjectMetadataConfig?.({
|
||||
mainIdentifierMapper,
|
||||
basePathToShowPage,
|
||||
mainIdentifierFieldMetadataId,
|
||||
});
|
||||
}
|
||||
}, [
|
||||
basePathToShowPage,
|
||||
foundObjectMetadataItem,
|
||||
mainIdentifierFieldMetadataId,
|
||||
mainIdentifierMapper,
|
||||
setObjectMetadataConfig,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!foundObjectMetadataItem) {
|
||||
return;
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
import { FieldMetadata } from '@/ui/object/field/types/FieldMetadata';
|
||||
import { isFieldRelation } from '@/ui/object/field/types/guards/isFieldRelation';
|
||||
import { ColumnDefinition } from '@/ui/object/record-table/types/ColumnDefinition';
|
||||
|
||||
export const filterAvailableTableColumns = (
|
||||
columnDefinition: ColumnDefinition<FieldMetadata>,
|
||||
): boolean => {
|
||||
if (
|
||||
columnDefinition.type === 'RELATION' &&
|
||||
columnDefinition.relationType !== 'TO_ONE_OBJECT'
|
||||
isFieldRelation(columnDefinition) &&
|
||||
columnDefinition.metadata?.relationType !== 'TO_ONE_OBJECT'
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ export const mapPaginatedObjectsToObjects = <
|
||||
pagedObjects: ObjectTypeQuery | undefined;
|
||||
objectNamePlural: string;
|
||||
}) => {
|
||||
console.log(objectNamePlural);
|
||||
const formattedObjects: ObjectType[] =
|
||||
pagedObjects?.[objectNamePlural].edges.map((objectEdge: ObjectEdge) => ({
|
||||
...objectEdge.node,
|
||||
|
||||
Reference in New Issue
Block a user