Feat/metadata datatable types (#2175)
* Handled new url v2 type * Fixed refetch queries * wip * Ok delete but views bug * Fix lint --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -10,14 +10,11 @@ import { UPDATE_ONE_METADATA_OBJECT } from '../graphql/mutations';
|
||||
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
|
||||
|
||||
import { useApolloMetadataClient } from './useApolloMetadataClient';
|
||||
import { useFindManyMetadataObjects } from './useFindManyMetadataObjects';
|
||||
|
||||
// TODO: Slice the Apollo store synchronously in the update function instead of subscribing, so we can use update after read in the same function call
|
||||
export const useUpdateOneMetadataObject = () => {
|
||||
const apolloClientMetadata = useApolloMetadataClient();
|
||||
|
||||
const { getMetadataObjectsFromCache } = useFindManyMetadataObjects();
|
||||
|
||||
const [mutate] = useMutation<
|
||||
UpdateOneMetadataObjectMutation,
|
||||
UpdateOneMetadataObjectMutationVariables
|
||||
@ -25,41 +22,22 @@ export const useUpdateOneMetadataObject = () => {
|
||||
client: apolloClientMetadata ?? undefined,
|
||||
});
|
||||
|
||||
const updateOneMetadataObject = ({
|
||||
const updateOneMetadataObject = async ({
|
||||
idToUpdate,
|
||||
updatePayload,
|
||||
}: {
|
||||
idToUpdate: UpdateOneMetadataObjectMutationVariables['idToUpdate'];
|
||||
updatePayload: Partial<
|
||||
Pick<
|
||||
UpdateOneMetadataObjectMutationVariables['updatePayload'],
|
||||
'description' | 'icon' | 'isActive' | 'labelPlural' | 'labelSingular'
|
||||
>
|
||||
updatePayload: Pick<
|
||||
UpdateOneMetadataObjectMutationVariables['updatePayload'],
|
||||
'description' | 'icon' | 'isActive' | 'labelPlural' | 'labelSingular'
|
||||
>;
|
||||
}) => {
|
||||
const metadataObjects = getMetadataObjectsFromCache();
|
||||
|
||||
const foundMetadataObject = metadataObjects.find(
|
||||
(metadataObject) => metadataObject.id === idToUpdate,
|
||||
);
|
||||
|
||||
if (!foundMetadataObject)
|
||||
throw new Error(`Metadata object with id ${idToUpdate} not found`);
|
||||
|
||||
return mutate({
|
||||
return await mutate({
|
||||
variables: {
|
||||
idToUpdate,
|
||||
updatePayload: {
|
||||
namePlural: foundMetadataObject.namePlural,
|
||||
nameSingular: foundMetadataObject.nameSingular,
|
||||
description: foundMetadataObject.description,
|
||||
icon: foundMetadataObject.icon,
|
||||
isActive: foundMetadataObject.isActive,
|
||||
labelPlural: foundMetadataObject.labelPlural,
|
||||
labelSingular: foundMetadataObject.labelSingular,
|
||||
...updatePayload,
|
||||
},
|
||||
updatePayload,
|
||||
},
|
||||
awaitRefetchQueries: true,
|
||||
refetchQueries: [getOperationName(FIND_MANY_METADATA_OBJECTS) ?? ''],
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user