From 9f477129e23b907c31412505fd9319f200d8a859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Bosi?= <71827178+bosiraphael@users.noreply.github.com> Date: Fri, 27 Sep 2024 16:42:35 +0200 Subject: [PATCH] Fix use object metadata item (#7297) Fixes a bug which happened during workspace creation and remove duplicated code --- .../ObjectMetadataItemsLoadEffect.tsx | 8 ++------ .../hooks/useObjectMetadataItem.ts | 18 ++---------------- .../src/testing/decorators/PageDecorator.tsx | 9 +++------ 3 files changed, 7 insertions(+), 28 deletions(-) diff --git a/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataItemsLoadEffect.tsx b/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataItemsLoadEffect.tsx index cd3f0e2c2b..ecc0772b85 100644 --- a/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataItemsLoadEffect.tsx +++ b/packages/twenty-front/src/modules/object-metadata/components/ObjectMetadataItemsLoadEffect.tsx @@ -16,7 +16,7 @@ export const ObjectMetadataItemsLoadEffect = () => { const currentWorkspace = useRecoilValue(currentWorkspaceState); const isLoggedIn = useIsLogged(); - const { objectMetadataItems: newObjectMetadataItems, loading } = + const { objectMetadataItems: newObjectMetadataItems } = useFindManyObjectMetadataItems({ skip: !isLoggedIn, }); @@ -31,16 +31,12 @@ export const ObjectMetadataItemsLoadEffect = () => { currentWorkspace?.activationStatus !== WorkspaceActivationStatus.Active ? generatedMockObjectMetadataItems : newObjectMetadataItems; - if ( - !loading && - !isDeeplyEqual(objectMetadataItems, toSetObjectMetadataItems) - ) { + if (!isDeeplyEqual(objectMetadataItems, toSetObjectMetadataItems)) { setObjectMetadataItems(toSetObjectMetadataItems); } }, [ currentUser, currentWorkspace?.activationStatus, - loading, newObjectMetadataItems, objectMetadataItems, setObjectMetadataItems, diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useObjectMetadataItem.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useObjectMetadataItem.ts index fb08e4c96a..0a8d3e8600 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/useObjectMetadataItem.ts +++ b/packages/twenty-front/src/modules/object-metadata/hooks/useObjectMetadataItem.ts @@ -1,37 +1,23 @@ import { useRecoilValue } from 'recoil'; -import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState'; import { ObjectMetadataItemNotFoundError } from '@/object-metadata/errors/ObjectMetadataNotFoundError'; import { objectMetadataItemFamilySelector } from '@/object-metadata/states/objectMetadataItemFamilySelector'; import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState'; import { isDefined } from '~/utils/isDefined'; -import { WorkspaceActivationStatus } from '~/generated/graphql'; -import { generatedMockObjectMetadataItems } from '~/testing/mock-data/objectMetadataItems'; import { ObjectMetadataItemIdentifier } from '../types/ObjectMetadataItemIdentifier'; export const useObjectMetadataItem = ({ objectNameSingular, }: ObjectMetadataItemIdentifier) => { - const currentWorkspace = useRecoilValue(currentWorkspaceState); - - let objectMetadataItem = useRecoilValue( + const objectMetadataItem = useRecoilValue( objectMetadataItemFamilySelector({ objectName: objectNameSingular, objectNameType: 'singular', }), ); - let objectMetadataItems = useRecoilValue(objectMetadataItemsState); - - if (currentWorkspace?.activationStatus !== WorkspaceActivationStatus.Active) { - objectMetadataItem = - generatedMockObjectMetadataItems.find( - (objectMetadataItem) => - objectMetadataItem.nameSingular === objectNameSingular, - ) ?? null; - objectMetadataItems = generatedMockObjectMetadataItems; - } + const objectMetadataItems = useRecoilValue(objectMetadataItemsState); if (!isDefined(objectMetadataItem)) { throw new ObjectMetadataItemNotFoundError( diff --git a/packages/twenty-front/src/testing/decorators/PageDecorator.tsx b/packages/twenty-front/src/testing/decorators/PageDecorator.tsx index 2381241c4a..7125e4326d 100644 --- a/packages/twenty-front/src/testing/decorators/PageDecorator.tsx +++ b/packages/twenty-front/src/testing/decorators/PageDecorator.tsx @@ -12,7 +12,6 @@ import { import { RecoilRoot } from 'recoil'; import { ClientConfigProviderEffect } from '@/client-config/components/ClientConfigProviderEffect'; -import { ObjectMetadataItemsProvider } from '@/object-metadata/components/ObjectMetadataItemsProvider'; import { ApolloMetadataClientMockedProvider } from '@/object-metadata/hooks/__mocks__/ApolloMetadataClientProvider'; import { SnackBarProviderScope } from '@/ui/feedback/snack-bar-manager/scopes/SnackBarProviderScope'; import { UserProviderEffect } from '@/users/components/UserProviderEffect'; @@ -77,11 +76,9 @@ const Providers = () => { - - - - - + + +