Files
twenty/front/src/modules/settings/data-model/hooks/useRelationFieldPreview.ts
T
Charles Bochet 09533e286b Fix/opportunities board (#2610)
* WIP

* wip

* update pipelineStepId

* rename pipeline stage to pipeline step

* rename pipelineProgress to Opportunity

* fix UUID type not queried

* fix boardColumnTotal

* fix micros

* fixing filters, sorts and fields

* wip

* wip

* Fix opportunity board re-render

---------

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
Co-authored-by: bosiraphael <raphael.bosi@gmail.com>
2023-11-21 01:24:25 +01:00

38 lines
1.2 KiB
TypeScript

import { useObjectMainIdentifier } from '@/object-metadata/hooks/useObjectMainIdentifier';
import { useObjectMetadataItemForSettings } from '@/object-metadata/hooks/useObjectMetadataItemForSettings';
import { useFindManyObjectRecords } from '@/object-record/hooks/useFindManyObjectRecords';
export const useRelationFieldPreview = ({
relationObjectMetadataId,
skipDefaultValue,
}: {
relationObjectMetadataId?: string;
skipDefaultValue: boolean;
}) => {
const { findObjectMetadataItemById } = useObjectMetadataItemForSettings();
const relationObjectMetadataItem = relationObjectMetadataId
? findObjectMetadataItemById(relationObjectMetadataId)
: undefined;
const { objects: relationObjects } = useFindManyObjectRecords({
objectNamePlural: relationObjectMetadataItem?.namePlural,
skip: skipDefaultValue || !relationObjectMetadataItem,
});
const {
labelIdentifierFieldPaths,
imageIdentifierUrlField,
imageIdentifierUrlPrefix,
imageIdentifierFormat,
} = useObjectMainIdentifier(relationObjectMetadataItem);
return {
defaultValue: relationObjects?.[0],
labelIdentifierFieldPaths,
imageIdentifierUrlField,
imageIdentifierUrlPrefix,
imageIdentifierFormat,
};
};