@ -90,7 +90,10 @@ export const SettingsObjectFieldPreview = ({
|
|||||||
objectMetadataId,
|
objectMetadataId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { defaultValue: relationDefaultValue } = useRelationFieldPreview({
|
const {
|
||||||
|
defaultValue: relationDefaultValue,
|
||||||
|
recordMapper: mainIdentifierMapper,
|
||||||
|
} = useRelationFieldPreview({
|
||||||
relationObjectMetadataId,
|
relationObjectMetadataId,
|
||||||
skipDefaultValue:
|
skipDefaultValue:
|
||||||
fieldMetadata.type !== FieldMetadataType.Relation || hasValue,
|
fieldMetadata.type !== FieldMetadataType.Relation || hasValue,
|
||||||
@ -143,7 +146,7 @@ export const SettingsObjectFieldPreview = ({
|
|||||||
iconName: 'FieldIcon',
|
iconName: 'FieldIcon',
|
||||||
fieldMetadataId: fieldMetadata.id || '',
|
fieldMetadataId: fieldMetadata.id || '',
|
||||||
label: fieldMetadata.label,
|
label: fieldMetadata.label,
|
||||||
metadata: { fieldName },
|
metadata: { fieldName, mainIdentifierMapper },
|
||||||
},
|
},
|
||||||
hotkeyScope: 'field-preview',
|
hotkeyScope: 'field-preview',
|
||||||
}}
|
}}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
|
import { useObjectMainIdentifier } from '@/object-metadata/hooks/useObjectMainIdentifier';
|
||||||
import { useObjectMetadataItemForSettings } from '@/object-metadata/hooks/useObjectMetadataItemForSettings';
|
import { useObjectMetadataItemForSettings } from '@/object-metadata/hooks/useObjectMetadataItemForSettings';
|
||||||
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
|
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
|
||||||
|
import { MainIdentifierMapper } from '@/ui/object/field/types/MainIdentifierMapper';
|
||||||
|
|
||||||
export const useRelationFieldPreview = ({
|
export const useRelationFieldPreview = ({
|
||||||
relationObjectMetadataId,
|
relationObjectMetadataId,
|
||||||
@ -19,11 +21,24 @@ export const useRelationFieldPreview = ({
|
|||||||
skip: skipDefaultValue || !relationObjectMetadataItem,
|
skip: skipDefaultValue || !relationObjectMetadataItem,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { mainIdentifierMapper } = useObjectMainIdentifier(
|
||||||
|
relationObjectMetadataItem,
|
||||||
|
);
|
||||||
|
|
||||||
|
const recordMapper: MainIdentifierMapper | undefined =
|
||||||
|
relationObjectMetadataItem && mainIdentifierMapper
|
||||||
|
? (record: { id: string }) => {
|
||||||
|
const mappedRecord = mainIdentifierMapper(record);
|
||||||
|
|
||||||
|
return {
|
||||||
|
...mappedRecord,
|
||||||
|
name: mappedRecord.name || relationObjectMetadataItem.labelSingular,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
defaultValue: relationObjects?.[0],
|
defaultValue: relationObjects?.[0],
|
||||||
entityChipDisplayMapper: (fieldValue?: { id: string }) => ({
|
recordMapper,
|
||||||
name: fieldValue?.id || relationObjectMetadataItem?.labelSingular || '',
|
|
||||||
avatarType: 'squared' as const,
|
|
||||||
}),
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user