Added a fallback default record chip generator (#5860)

The record chip generator context was missing a edge were a new field of
type relation is created and not yet in the metadata so no chip
generator function can be precomputed.

For now I added a fallback default chip generator, to prevent any bug,
but we might want to add a new chip generator function while creating
the new field ?
This commit is contained in:
Lucas Bordeau 2024-06-13 18:28:02 +02:00 committed by GitHub
parent 582653f9df
commit 65fc83a763
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 2 deletions

View File

@ -0,0 +1,15 @@
import { isFieldFullNameValue } from '@/object-record/record-field/types/guards/isFieldFullNameValue';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
export const generateDefaultRecordChipData = (record: ObjectRecord) => {
const name = isFieldFullNameValue(record.name)
? record.name.firstName + ' ' + record.name.lastName
: record.name ?? '';
return {
name,
avatarUrl: name,
avatarType: 'rounded',
linkToShowPage: false,
};
};

View File

@ -2,6 +2,7 @@ import { useContext } from 'react';
import { isNonEmptyString } from '@sniptt/guards';
import { PreComputedChipGeneratorsContext } from '@/object-metadata/context/PreComputedChipGeneratorsContext';
import { generateDefaultRecordChipData } from '@/object-metadata/utils/generateDefaultRecordChipData';
import { isFieldFullName } from '@/object-record/record-field/types/guards/isFieldFullName';
import { isFieldNumber } from '@/object-record/record-field/types/guards/isFieldNumber';
import { isFieldText } from '@/object-record/record-field/types/guards/isFieldText';
@ -37,7 +38,7 @@ export const useChipFieldDisplay = () => {
const generateRecordChipData =
chipGeneratorPerObjectPerField[
fieldDefinition.metadata.objectMetadataNameSingular
][fieldDefinition.metadata.fieldName];
]?.[fieldDefinition.metadata.fieldName] ?? generateDefaultRecordChipData;
return {
objectNameSingular,

View File

@ -2,6 +2,7 @@ import { useContext } from 'react';
import { isNonEmptyString } from '@sniptt/guards';
import { PreComputedChipGeneratorsContext } from '@/object-metadata/context/PreComputedChipGeneratorsContext';
import { generateDefaultRecordChipData } from '@/object-metadata/utils/generateDefaultRecordChipData';
import { useRecordFieldValue } from '@/object-record/record-store/contexts/RecordFieldValueSelectorContext';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
import { FIELD_EDIT_BUTTON_WIDTH } from '@/ui/field/display/constants/FieldEditButtonWidth';
@ -50,7 +51,7 @@ export const useRelationFieldDisplay = () => {
const generateRecordChipData =
chipGeneratorPerObjectPerField[
fieldDefinition.metadata.objectMetadataNameSingular
][fieldDefinition.metadata.fieldName];
]?.[fieldDefinition.metadata.fieldName] ?? generateDefaultRecordChipData;
return {
fieldDefinition,