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 f74e69c54125..d1c2fad1d71b 100644 --- a/packages/twenty-front/src/pages/settings/data-model/SettingsObjectFieldEdit.tsx +++ b/packages/twenty-front/src/pages/settings/data-model/SettingsObjectFieldEdit.tsx @@ -1,6 +1,7 @@ import { useEffect } from 'react'; import { FormProvider, useForm } from 'react-hook-form'; import { useNavigate, useParams } from 'react-router-dom'; +import { useApolloClient } from '@apollo/client'; import styled from '@emotion/styled'; import { zodResolver } from '@hookform/resolvers/zod'; import omit from 'lodash.omit'; @@ -16,6 +17,7 @@ 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'; +import { useFindManyRecordsQuery } from '@/object-record/hooks/useFindManyRecordsQuery'; import { SaveAndCancelButtons } from '@/settings/components/SaveAndCancelButtons/SaveAndCancelButtons'; import { SettingsHeaderContainer } from '@/settings/components/SettingsHeaderContainer'; import { SettingsPageContainer } from '@/settings/components/SettingsPageContainer'; @@ -73,6 +75,20 @@ export const SettingsObjectFieldEdit = () => { const getRelationMetadata = useGetRelationMetadata(); const { updateOneFieldMetadataItem } = useUpdateOneFieldMetadataItem(); + const apolloClient = useApolloClient(); + + const { findManyRecordsQuery } = useFindManyRecordsQuery({ + objectNameSingular: activeObjectMetadataItem?.nameSingular || '', + }); + + const refetchRecords = async () => { + if (!activeObjectMetadataItem) return; + await apolloClient.query({ + query: findManyRecordsQuery, + fetchPolicy: 'network-only', + }); + }; + const formConfig = useForm({ mode: 'onTouched', resolver: zodResolver(settingsFieldFormSchema), @@ -135,6 +151,8 @@ export const SettingsObjectFieldEdit = () => { } navigate(`/settings/objects/${objectSlug}`); + + refetchRecords(); } catch (error) { enqueueSnackBar((error as Error).message, { variant: SnackBarVariant.Error, diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-migration-runner/services/workspace-migration-enum.service.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-migration-runner/services/workspace-migration-enum.service.ts index 35aa5eb95bdb..05ebc0370482 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-migration-runner/services/workspace-migration-enum.service.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-migration-runner/services/workspace-migration-enum.service.ts @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common'; import { QueryRunner, TableColumn } from 'typeorm'; import { v4 } from 'uuid'; +import { isDefined } from 'class-validator'; import { WorkspaceMigrationColumnAlter, @@ -117,10 +118,17 @@ export class WorkspaceMigrationEnumService { private migrateEnumValue( value: string, renamedEnumValues?: WorkspaceMigrationRenamedEnum[], + allEnumValues?: string[], ) { - return ( - renamedEnumValues?.find((enumVal) => enumVal?.from === value)?.to || value - ); + if (renamedEnumValues?.find((enumVal) => enumVal?.from === value)?.to) { + return renamedEnumValues?.find((enumVal) => enumVal?.from === value)?.to; + } + + if (allEnumValues?.includes(value)) { + return value; + } + + return null; } private async migrateEnumValues( @@ -147,11 +155,19 @@ export class WorkspaceMigrationEnumService { .slice(1, -1) .split(',') .map((v: string) => v.trim()) - .map((v: string) => this.migrateEnumValue(v, renamedEnumValues)) - .filter((v: string) => enumValues.includes(v)), + .map((v: string) => + this.migrateEnumValue(v, renamedEnumValues, enumValues), + ) + .filter((v: string | null) => isDefined(v)), ); } else if (typeof val === 'string') { - val = `'${this.migrateEnumValue(val, renamedEnumValues)}'`; + const migratedValue = this.migrateEnumValue( + val, + renamedEnumValues, + enumValues, + ); + + val = isDefined(migratedValue) ? `'${migratedValue}'` : null; } await queryRunner.query(`