Fix use object metadata item (#7297)

Fixes a bug which happened during workspace creation and remove
duplicated code
This commit is contained in:
Raphaël Bosi 2024-09-27 16:42:35 +02:00 committed by GitHub
parent 9d36493cf0
commit 9f477129e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 28 deletions

View File

@ -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,

View File

@ -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(

View File

@ -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 = () => {
<HelmetProvider>
<SnackBarProviderScope snackBarManagerScopeId="snack-bar-manager">
<IconsProvider>
<ObjectMetadataItemsProvider>
<PrefetchDataProvider>
<Outlet />
</PrefetchDataProvider>
</ObjectMetadataItemsProvider>
</IconsProvider>
</SnackBarProviderScope>
</HelmetProvider>