mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-26 21:53:48 +03:00
Fix duplicate view field creation (#2677)
This commit is contained in:
parent
72421a39ea
commit
4b42ed42dc
@ -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 };
|
||||
|
Loading…
Reference in New Issue
Block a user