[COMMAND MENU ITEMS] Sync object metadata with navigation command menu items (#19456)
When an object is created or enabled we create a navigation command menu item to that object. And when the object is disabled or deleted, we remove this command menu item.
This commit is contained in:
+26
-11
@@ -2,6 +2,7 @@ import { useApolloClient, useMutation } from '@apollo/client/react';
|
||||
import {
|
||||
type CreateObjectInput,
|
||||
CreateOneObjectMetadataItemDocument,
|
||||
FindManyCommandMenuItemsDocument,
|
||||
FindManyNavigationMenuItemsDocument,
|
||||
FindManyViewsDocument,
|
||||
} from '~/generated-metadata/graphql';
|
||||
@@ -13,6 +14,7 @@ import { type FlatObjectMetadataItem } from '@/metadata-store/types/FlatObjectMe
|
||||
import { splitViewWithRelated } from '@/metadata-store/utils/splitViewWithRelated';
|
||||
import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useLoadCurrentUser } from '@/users/hooks/useLoadCurrentUser';
|
||||
import { CombinedGraphQLErrors } from '@apollo/client/errors';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { CrudOperationType } from 'twenty-shared/types';
|
||||
@@ -28,6 +30,7 @@ export const useCreateOneObjectMetadataItem = () => {
|
||||
const { enqueueErrorSnackBar } = useSnackBar();
|
||||
const { addToDraft, replaceDraft, applyChanges } =
|
||||
useUpdateMetadataStoreDraft();
|
||||
const { loadCurrentUser } = useLoadCurrentUser();
|
||||
|
||||
const createOneObjectMetadataItem = async (
|
||||
input: CreateObjectInput,
|
||||
@@ -70,17 +73,22 @@ export const useCreateOneObjectMetadataItem = () => {
|
||||
|
||||
applyChanges();
|
||||
|
||||
const [viewsResult, navItemsResult] = await Promise.all([
|
||||
client.query({
|
||||
query: FindManyViewsDocument,
|
||||
variables: { objectMetadataId: createdObject.id },
|
||||
fetchPolicy: 'network-only',
|
||||
}),
|
||||
client.query({
|
||||
query: FindManyNavigationMenuItemsDocument,
|
||||
fetchPolicy: 'network-only',
|
||||
}),
|
||||
]);
|
||||
const [viewsResult, navItemsResult, commandMenuItemsResult] =
|
||||
await Promise.all([
|
||||
client.query({
|
||||
query: FindManyViewsDocument,
|
||||
variables: { objectMetadataId: createdObject.id },
|
||||
fetchPolicy: 'network-only',
|
||||
}),
|
||||
client.query({
|
||||
query: FindManyNavigationMenuItemsDocument,
|
||||
fetchPolicy: 'network-only',
|
||||
}),
|
||||
client.query({
|
||||
query: FindManyCommandMenuItemsDocument,
|
||||
fetchPolicy: 'network-only',
|
||||
}),
|
||||
]);
|
||||
|
||||
const fetchedViews = viewsResult.data?.getViews ?? [];
|
||||
|
||||
@@ -107,7 +115,14 @@ export const useCreateOneObjectMetadataItem = () => {
|
||||
navItemsResult.data?.navigationMenuItems ?? [],
|
||||
);
|
||||
|
||||
replaceDraft(
|
||||
'commandMenuItems',
|
||||
commandMenuItemsResult.data?.commandMenuItems ?? [],
|
||||
);
|
||||
|
||||
applyChanges();
|
||||
|
||||
await loadCurrentUser();
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user