From 7fa05bf5397303d57b7c22fd4c240074f0e1d8b8 Mon Sep 17 00:00:00 2001 From: Pacifique LINJANJA Date: Mon, 3 Jun 2024 12:12:04 +0200 Subject: [PATCH] feat (improvement): update the createOneObjectMetaItem (#5673) # This PR - Fix #5278 - Updates the implementation of the `createOneObjectMataItem` hook to reduce the number of api calls - Users can now navigate to the newly created object first and the graphql api calls to cache data are happening in the background - this will improve the user experience and reduce the create object api call time by >2 Screenshot 2024-05-30 at 12 00 15 In the issue description, it also suggested to have a loading indicator while creating the object, it seems like on #5352 we adopted to disable it while creating the object - which looks good to me and it works, let me know if we still need the loading indicator instead @Bonapara Looking forward to getting your feedback cc: @charlesBochet --------- Co-authored-by: Thomas Trompette --- .../hooks/useCreateOneObjectMetadataItem.ts | 7 +++++-- .../src/pages/settings/data-model/SettingsNewObject.tsx | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneObjectMetadataItem.ts b/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneObjectMetadataItem.ts index 19df20de7..6cbb5e02a 100644 --- a/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneObjectMetadataItem.ts +++ b/packages/twenty-front/src/modules/object-metadata/hooks/useCreateOneObjectMetadataItem.ts @@ -38,15 +38,18 @@ export const useCreateOneObjectMetadataItem = () => { refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''], }); + return createdObjectMetadata; + }; + + const findManyRecordsCache = async () => { await apolloClient.query({ query: findManyRecordsQuery, fetchPolicy: 'network-only', }); - - return createdObjectMetadata; }; return { createOneObjectMetadataItem, + findManyRecordsCache, }; }; diff --git a/packages/twenty-front/src/pages/settings/data-model/SettingsNewObject.tsx b/packages/twenty-front/src/pages/settings/data-model/SettingsNewObject.tsx index f6a338810..cfb6f203b 100644 --- a/packages/twenty-front/src/pages/settings/data-model/SettingsNewObject.tsx +++ b/packages/twenty-front/src/pages/settings/data-model/SettingsNewObject.tsx @@ -30,7 +30,8 @@ export const SettingsNewObject = () => { const navigate = useNavigate(); const { enqueueSnackBar } = useSnackBar(); - const { createOneObjectMetadataItem } = useCreateOneObjectMetadataItem(); + const { createOneObjectMetadataItem, findManyRecordsCache } = + useCreateOneObjectMetadataItem(); const settingsObjectsPagePath = getSettingsPagePath(SettingsPath.Objects); @@ -57,6 +58,8 @@ export const SettingsNewObject = () => { )}` : settingsObjectsPagePath, ); + + await findManyRecordsCache(); } catch (error) { enqueueSnackBar((error as Error).message, { variant: SnackBarVariant.Error,