Fix duplicate view field creation (#2677)

This commit is contained in:
Lucas Bordeau 2023-11-23 16:25:32 +01:00 committed by GitHub
parent 72421a39ea
commit 4b42ed42dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 };