In this PR, we implement the display and update of fields from fromManyObjects (e.g update Employees for a Company). Product requirement - update should be triggered at each box check/uncheck, not at lose of focus Left to do in upcoming PRs - add the column in the table views (e.g. column "Employees" on "Companies" table view) - add "Add new" possibility when there is no records (as is currently exists for "one" side of relations:) <img width="374" alt="Capture d’écran 2024-06-10 à 17 38 02" src="https://github.com/twentyhq/twenty/assets/51697796/6f0cc494-e44f-4620-a762-d7b438951eec"> - update cache after an update affecting other records (e.g "Listings" have one "Person"; if listing A belonged to Person A but then we attribute listing A to Person B, Person A is no longer owner of Listing A. For the moment that would not be reflected immediatly leading, to potential false information if information is accessed from cache) - try to get rid of the glitch - we also have it on the task page example. (probably) due to the fact that we are using a recoil state to read, update then re-read https://github.com/twentyhq/twenty/assets/51697796/54f71674-237a-4946-866e-b8d96353c458
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
|
import { parseFieldRelationType } from '@/object-metadata/utils/parseFieldRelationType';
|
|
import { FieldDefinition } from '@/object-record/record-field/types/FieldDefinition';
|
|
import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
|
|
import { getFieldButtonIcon } from '@/object-record/record-field/utils/getFieldButtonIcon';
|
|
|
|
import { FieldMetadataItem } from '../types/FieldMetadataItem';
|
|
|
|
export type FieldMetadataItemAsFieldDefinitionProps = {
|
|
field: FieldMetadataItem;
|
|
objectMetadataItem: ObjectMetadataItem;
|
|
showLabel?: boolean;
|
|
labelWidth?: number;
|
|
};
|
|
|
|
export const formatFieldMetadataItemAsFieldDefinition = ({
|
|
field,
|
|
objectMetadataItem,
|
|
showLabel,
|
|
labelWidth,
|
|
}: FieldMetadataItemAsFieldDefinitionProps): FieldDefinition<FieldMetadata> => {
|
|
const relationObjectMetadataItem =
|
|
field.toRelationMetadata?.fromObjectMetadata ||
|
|
field.fromRelationMetadata?.toObjectMetadata;
|
|
|
|
const relationFieldMetadataId =
|
|
field.toRelationMetadata?.fromFieldMetadataId ||
|
|
field.fromRelationMetadata?.toFieldMetadataId;
|
|
|
|
const fieldDefintionMetadata = {
|
|
fieldName: field.name,
|
|
placeHolder: field.label,
|
|
relationType: parseFieldRelationType(field),
|
|
relationFieldMetadataId,
|
|
relationObjectMetadataNameSingular:
|
|
relationObjectMetadataItem?.nameSingular ?? '',
|
|
relationObjectMetadataNamePlural:
|
|
relationObjectMetadataItem?.namePlural ?? '',
|
|
objectMetadataNameSingular: objectMetadataItem.nameSingular ?? '',
|
|
targetFieldMetadataName:
|
|
field.relationDefinition?.targetFieldMetadata?.name ?? '',
|
|
options: field.options,
|
|
};
|
|
|
|
return {
|
|
fieldMetadataId: field.id,
|
|
label: field.label,
|
|
showLabel,
|
|
labelWidth,
|
|
type: field.type,
|
|
metadata: fieldDefintionMetadata,
|
|
iconName: field.icon ?? 'Icon123',
|
|
defaultValue: field.defaultValue,
|
|
editButtonIcon: getFieldButtonIcon({
|
|
metadata: fieldDefintionMetadata,
|
|
type: field.type,
|
|
}),
|
|
};
|
|
};
|