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:
Lucas Bordeau
2023-10-21 14:07:18 +02:00
committed by GitHub
parent 598fda8f45
commit f1670f0cf4
50 changed files with 1125 additions and 350 deletions

View File

@ -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) ?? ''],
});
};