From 4b42ed42dc80d5f52d969f440a61b838c991733e Mon Sep 17 00:00:00 2001 From: Lucas Bordeau Date: Thu, 23 Nov 2023 16:25:32 +0100 Subject: [PATCH] Fix duplicate view field creation (#2677) --- .../views/hooks/internal/useViewFields.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/front/src/modules/views/hooks/internal/useViewFields.ts b/front/src/modules/views/hooks/internal/useViewFields.ts index c0e6f0fcac..e967714773 100644 --- a/front/src/modules/views/hooks/internal/useViewFields.ts +++ b/front/src/modules/views/hooks/internal/useViewFields.ts @@ -1,4 +1,5 @@ import { useApolloClient } from '@apollo/client'; +import { getOperationName } from '@apollo/client/utilities'; import { useRecoilCallback } from 'recoil'; import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; @@ -11,6 +12,10 @@ export const useViewFields = (viewScopeId: string) => { objectNameSingular: 'viewField', }); + const { findManyQuery: findManyViewsQuery } = useObjectMetadataItem({ + objectNameSingular: 'view', + }); + const apolloClient = useApolloClient(); const persistViewFields = useRecoilCallback( @@ -53,6 +58,9 @@ export const useViewFields = (viewScopeId: string) => { position: viewField.position, }, }, + // TODO: implement optimistic response + refetchQueries: [getOperationName(findManyViewsQuery) ?? ''], + awaitRefetchQueries: true, }), ), ); @@ -75,6 +83,9 @@ export const useViewFields = (viewScopeId: string) => { position: viewField.position, }, }, + // TODO: implement optimistic response + refetchQueries: [getOperationName(findManyViewsQuery) ?? ''], + awaitRefetchQueries: true, }), ), ); @@ -96,12 +107,20 @@ export const useViewFields = (viewScopeId: string) => { ); set(isPersistingViewState, true); + await _createViewFields(viewFieldsToCreate); await _updateViewFields(viewFieldsToUpdate); + set(isPersistingViewState, false); }, - [apolloClient, createOneMutation, updateOneMutation, viewScopeId], + [ + apolloClient, + createOneMutation, + updateOneMutation, + viewScopeId, + findManyViewsQuery, + ], ); return { persistViewFields };