From 2e75fae3ad5a5fa4b2d26eb8897e6de2a44ef78e Mon Sep 17 00:00:00 2001 From: ad-elias Date: Tue, 26 Nov 2024 10:03:48 +0100 Subject: [PATCH] Allow standard field default value and settings editing (#7104) (#8559) Co-authored-by: Marie Stoppa --- .../SettingsDataModelFieldBooleanForm.tsx | 5 ---- ...SettingsDataModelFieldSettingsFormCard.tsx | 5 ---- .../data-model/SettingsObjectFieldEdit.tsx | 28 ++++--------------- .../SettingsObjectNewFieldConfigure.tsx | 1 - .../field-metadata/field-metadata.service.ts | 16 ++++++----- .../comparators/workspace-field.comparator.ts | 26 +++-------------- 6 files changed, 19 insertions(+), 62 deletions(-) diff --git a/packages/twenty-front/src/modules/settings/data-model/fields/forms/boolean/components/SettingsDataModelFieldBooleanForm.tsx b/packages/twenty-front/src/modules/settings/data-model/fields/forms/boolean/components/SettingsDataModelFieldBooleanForm.tsx index 4e50078d7b00..bd434b9ec4ee 100644 --- a/packages/twenty-front/src/modules/settings/data-model/fields/forms/boolean/components/SettingsDataModelFieldBooleanForm.tsx +++ b/packages/twenty-front/src/modules/settings/data-model/fields/forms/boolean/components/SettingsDataModelFieldBooleanForm.tsx @@ -5,7 +5,6 @@ import { z } from 'zod'; import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; import { SettingsOptionCardContentSelect } from '@/settings/components/SettingsOptions/SettingsOptionCardContentSelect'; import { useBooleanSettingsFormInitialValues } from '@/settings/data-model/fields/forms/boolean/hooks/useBooleanSettingsFormInitialValues'; -import { isDefined } from '~/utils/isDefined'; export const settingsDataModelFieldBooleanFormSchema = z.object({ defaultValue: z.boolean(), @@ -26,7 +25,6 @@ export const SettingsDataModelFieldBooleanForm = ({ }: SettingsDataModelFieldBooleanFormProps) => { const { control } = useFormContext(); - const isEditMode = isDefined(fieldMetadataItem?.defaultValue); const { initialDefaultValue } = useBooleanSettingsFormInitialValues({ fieldMetadataItem, }); @@ -44,9 +42,6 @@ export const SettingsDataModelFieldBooleanForm = ({ value={value} onChange={onChange} selectClassName={className} - // TODO: temporary fix - disabling edition because after editing the defaultValue, - // newly created records are not taking into account the updated defaultValue properly. - disabled={isEditMode} dropdownId="object-field-default-value-select-boolean" options={[ { diff --git a/packages/twenty-front/src/modules/settings/data-model/fields/forms/components/SettingsDataModelFieldSettingsFormCard.tsx b/packages/twenty-front/src/modules/settings/data-model/fields/forms/components/SettingsDataModelFieldSettingsFormCard.tsx index 281c2052286f..31f16b2ff5ea 100644 --- a/packages/twenty-front/src/modules/settings/data-model/fields/forms/components/SettingsDataModelFieldSettingsFormCard.tsx +++ b/packages/twenty-front/src/modules/settings/data-model/fields/forms/components/SettingsDataModelFieldSettingsFormCard.tsx @@ -99,7 +99,6 @@ export const settingsDataModelFieldSettingsFormSchema = z.discriminatedUnion( ); type SettingsDataModelFieldSettingsFormCardProps = { - isCreatingField?: boolean; fieldMetadataItem: Pick< FieldMetadataItem, 'icon' | 'label' | 'type' | 'isCustom' @@ -132,7 +131,6 @@ const previewableTypes = [ ]; export const SettingsDataModelFieldSettingsFormCard = ({ - isCreatingField, fieldMetadataItem, objectMetadataItem, }: SettingsDataModelFieldSettingsFormCardProps) => { @@ -152,7 +150,6 @@ export const SettingsDataModelFieldSettingsFormCard = ({ if (fieldMetadataItem.type === FieldMetadataType.Currency) { return ( @@ -165,7 +162,6 @@ export const SettingsDataModelFieldSettingsFormCard = ({ ) { return ( @@ -184,7 +180,6 @@ export const SettingsDataModelFieldSettingsFormCard = ({ if (fieldMetadataItem.type === FieldMetadataType.Number) { return ( diff --git a/packages/twenty-front/src/pages/settings/data-model/SettingsObjectFieldEdit.tsx b/packages/twenty-front/src/pages/settings/data-model/SettingsObjectFieldEdit.tsx index 6d677914579d..98dbfd779ed4 100644 --- a/packages/twenty-front/src/pages/settings/data-model/SettingsObjectFieldEdit.tsx +++ b/packages/twenty-front/src/pages/settings/data-model/SettingsObjectFieldEdit.tsx @@ -18,7 +18,6 @@ import { useFieldMetadataItem } from '@/object-metadata/hooks/useFieldMetadataIt import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems'; import { useGetRelationMetadata } from '@/object-metadata/hooks/useGetRelationMetadata'; import { useUpdateOneFieldMetadataItem } from '@/object-metadata/hooks/useUpdateOneFieldMetadataItem'; -import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem'; import { formatFieldMetadataItemInput } from '@/object-metadata/utils/formatFieldMetadataItemInput'; import { getFieldSlug } from '@/object-metadata/utils/getFieldSlug'; import { isLabelIdentifierField } from '@/object-metadata/utils/isLabelIdentifierField'; @@ -47,16 +46,6 @@ type SettingsDataModelFieldEditFormValues = z.infer< > & any; -const canPersistFieldMetadataItemUpdate = ( - fieldMetadataItem: FieldMetadataItem, -) => { - return ( - fieldMetadataItem.isCustom || - fieldMetadataItem.type === FieldMetadataType.Select || - fieldMetadataItem.type === FieldMetadataType.MultiSelect - ); -}; - export const SettingsObjectFieldEdit = () => { const navigate = useNavigate(); const { enqueueSnackBar } = useSnackBar(); @@ -179,9 +168,6 @@ export const SettingsObjectFieldEdit = () => { navigate(`/settings/objects/${objectSlug}`); }; - const shouldDisplaySaveAndCancel = - canPersistFieldMetadataItemUpdate(fieldMetadataItem); - return ( {/* eslint-disable-next-line react/jsx-props-no-spreading */} @@ -206,14 +192,12 @@ export const SettingsObjectFieldEdit = () => { }, ]} actionButton={ - shouldDisplaySaveAndCancel && ( - navigate(`/settings/objects/${objectSlug}`)} - onSave={formConfig.handleSubmit(handleSave)} - /> - ) + navigate(`/settings/objects/${objectSlug}`)} + onSave={formConfig.handleSubmit(handleSave)} + /> } > diff --git a/packages/twenty-front/src/pages/settings/data-model/SettingsObjectNewField/SettingsObjectNewFieldConfigure.tsx b/packages/twenty-front/src/pages/settings/data-model/SettingsObjectNewField/SettingsObjectNewFieldConfigure.tsx index 6470b77dd566..0ce1ba77e582 100644 --- a/packages/twenty-front/src/pages/settings/data-model/SettingsObjectNewField/SettingsObjectNewFieldConfigure.tsx +++ b/packages/twenty-front/src/pages/settings/data-model/SettingsObjectNewField/SettingsObjectNewFieldConfigure.tsx @@ -209,7 +209,6 @@ export const SettingsObjectNewFieldConfigure = () => {
{ + shouldIgnoreProperty: (property) => { if (commonFieldPropertiesToIgnore.includes(property)) { return true; } - if ( - originalMetadata && - property === 'defaultValue' && - originalMetadata.type === FieldMetadataType.SELECT - ) { - return true; - } - return false; }, propertiesToStringify: fieldPropertiesToStringify, @@ -82,19 +72,11 @@ export class WorkspaceFieldComparator { const standardFieldMetadataMap = transformMetadataForComparison( standardFieldMetadataCollection, { - shouldIgnoreProperty: (property, originalMetadata) => { + shouldIgnoreProperty: (property) => { if (commonFieldPropertiesToIgnore.includes(property)) { return true; } - if ( - originalMetadata && - property === 'defaultValue' && - originalMetadata.type === FieldMetadataType.SELECT - ) { - return true; - } - return false; }, propertiesToStringify: fieldPropertiesToStringify,