From 987995636fdf5190a38525e9301221ca5b25d048 Mon Sep 17 00:00:00 2001 From: Paul Rastoin <45004772+prastoin@users.noreply.github.com> Date: Wed, 22 Jul 2026 19:05:22 +0200 Subject: [PATCH] Sync metadata store after view child entity mutations server response (#23150) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - View persist hooks (`usePerformView(Sort|Field|Filter|Group|FieldGroup|FilterGroup|)APIPersist`) now write successful mutation results back to the metadata store (`addToDraft` / `updateInDraft` / `removeFromDraft` + `applyChanges`), following the existing pattern from `usePerformViewAPIUpdate`. - Previously the store only updated via SSE, so until that landed, save flows diffed against stale view data and re-sent creates with the same id — failing server-side with a duplicate key error. Fixes TWENTY-SERVER-HQM --- .../src/generated-metadata/graphql.ts | 24 -- .../mutations/createManyViewFieldGroups.ts | 11 - .../graphql/mutations/deleteViewFieldGroup.ts | 11 - .../graphql/mutations/updateViewFieldGroup.ts | 11 - .../internal/usePerformViewAPIPersist.ts | 150 ++++++------ ...usePerformViewEntityAPIPersistOperation.ts | 165 +++++++++++++ .../internal/usePerformViewFieldAPIPersist.ts | 210 +++++----------- .../usePerformViewFieldGroupAPIPersist.ts | 197 --------------- .../usePerformViewFilterAPIPersist.ts | 229 ++++++------------ .../usePerformViewFilterGroupAPIPersist.ts | 150 +++++++----- .../internal/usePerformViewGroupAPIPersist.ts | 90 +++---- .../internal/usePerformViewSortAPIPersist.ts | 216 +++++------------ .../hooks/useCreateViewFromCurrentView.ts | 13 +- ...roupFiltersToViewFiltersAndGroupFilters.ts | 20 +- 14 files changed, 584 insertions(+), 913 deletions(-) delete mode 100644 packages/twenty-front/src/modules/views/graphql/mutations/createManyViewFieldGroups.ts delete mode 100644 packages/twenty-front/src/modules/views/graphql/mutations/deleteViewFieldGroup.ts delete mode 100644 packages/twenty-front/src/modules/views/graphql/mutations/updateViewFieldGroup.ts create mode 100644 packages/twenty-front/src/modules/views/hooks/internal/usePerformViewEntityAPIPersistOperation.ts delete mode 100644 packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFieldGroupAPIPersist.ts diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts index a2f4a5c668..ade4d9fa83 100644 --- a/packages/twenty-front/src/generated-metadata/graphql.ts +++ b/packages/twenty-front/src/generated-metadata/graphql.ts @@ -8517,13 +8517,6 @@ export type ViewGroupFragmentFragment = { __typename?: 'ViewGroup', id: string, export type ViewSortFragmentFragment = { __typename?: 'ViewSort', id: string, fieldMetadataId: string, direction: ViewSortDirection, subFieldName?: string | null, viewId: string, createdAt: string, deletedAt?: string | null, updatedAt: string }; -export type CreateManyViewFieldGroupsMutationVariables = Exact<{ - inputs: Array | CreateViewFieldGroupInput; -}>; - - -export type CreateManyViewFieldGroupsMutation = { __typename?: 'Mutation', createManyViewFieldGroups: Array<{ __typename?: 'ViewFieldGroup', id: string, name: string, position: number, isVisible: boolean, viewId: string, isActive: boolean, createdAt: string, updatedAt: string, deletedAt?: string | null, viewFields: Array<{ __typename?: 'ViewField', id: string, fieldMetadataId: string, viewId: string, isVisible: boolean, position: number, size: number, aggregateOperation?: AggregateOperations | null, viewFieldGroupId?: string | null, isActive: boolean, createdAt: string, updatedAt: string, deletedAt?: string | null }> }> }; - export type CreateManyViewFieldsMutationVariables = Exact<{ inputs: Array | CreateViewFieldInput; }>; @@ -8601,13 +8594,6 @@ export type DeleteViewFieldMutationVariables = Exact<{ export type DeleteViewFieldMutation = { __typename?: 'Mutation', deleteViewField: { __typename?: 'ViewField', id: string, fieldMetadataId: string, viewId: string, isVisible: boolean, position: number, size: number, aggregateOperation?: AggregateOperations | null, viewFieldGroupId?: string | null, isActive: boolean, createdAt: string, updatedAt: string, deletedAt?: string | null } }; -export type DeleteViewFieldGroupMutationVariables = Exact<{ - input: DeleteViewFieldGroupInput; -}>; - - -export type DeleteViewFieldGroupMutation = { __typename?: 'Mutation', deleteViewFieldGroup: { __typename?: 'ViewFieldGroup', id: string, name: string, position: number, isVisible: boolean, viewId: string, isActive: boolean, createdAt: string, updatedAt: string, deletedAt?: string | null, viewFields: Array<{ __typename?: 'ViewField', id: string, fieldMetadataId: string, viewId: string, isVisible: boolean, position: number, size: number, aggregateOperation?: AggregateOperations | null, viewFieldGroupId?: string | null, isActive: boolean, createdAt: string, updatedAt: string, deletedAt?: string | null }> } }; - export type DeleteViewFilterMutationVariables = Exact<{ input: DeleteViewFilterInput; }>; @@ -8700,13 +8686,6 @@ export type UpdateViewFieldMutationVariables = Exact<{ export type UpdateViewFieldMutation = { __typename?: 'Mutation', updateViewField: { __typename?: 'ViewField', id: string, fieldMetadataId: string, viewId: string, isVisible: boolean, position: number, size: number, aggregateOperation?: AggregateOperations | null, viewFieldGroupId?: string | null, isActive: boolean, createdAt: string, updatedAt: string, deletedAt?: string | null } }; -export type UpdateViewFieldGroupMutationVariables = Exact<{ - input: UpdateViewFieldGroupInput; -}>; - - -export type UpdateViewFieldGroupMutation = { __typename?: 'Mutation', updateViewFieldGroup: { __typename?: 'ViewFieldGroup', id: string, name: string, position: number, isVisible: boolean, viewId: string, isActive: boolean, createdAt: string, updatedAt: string, deletedAt?: string | null, viewFields: Array<{ __typename?: 'ViewField', id: string, fieldMetadataId: string, viewId: string, isVisible: boolean, position: number, size: number, aggregateOperation?: AggregateOperations | null, viewFieldGroupId?: string | null, isActive: boolean, createdAt: string, updatedAt: string, deletedAt?: string | null }> } }; - export type UpdateViewFilterMutationVariables = Exact<{ input: UpdateViewFilterInput; }>; @@ -9206,7 +9185,6 @@ export const GetUsageAnalyticsDocument = {"kind":"Document","definitions":[{"kin export const DeleteUserAccountDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteUserAccount"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteUser"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode; export const DeleteUserWorkspaceDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteUserWorkspace"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"workspaceMemberIdToDelete"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteUserFromWorkspace"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"workspaceMemberIdToDelete"},"value":{"kind":"Variable","name":{"kind":"Name","value":"workspaceMemberIdToDelete"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}}]}}]} as unknown as DocumentNode; export const GetCurrentUserDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GetCurrentUser"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"currentUser"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"UserQueryFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"WorkspaceMemberQueryFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"WorkspaceMember"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"firstName"}},{"kind":"Field","name":{"kind":"Name","value":"lastName"}}]}},{"kind":"Field","name":{"kind":"Name","value":"colorScheme"}},{"kind":"Field","name":{"kind":"Name","value":"avatarUrl"}},{"kind":"Field","name":{"kind":"Name","value":"locale"}},{"kind":"Field","name":{"kind":"Name","value":"userEmail"}},{"kind":"Field","name":{"kind":"Name","value":"userWorkspaceId"}},{"kind":"Field","name":{"kind":"Name","value":"timeZone"}},{"kind":"Field","name":{"kind":"Name","value":"dateFormat"}},{"kind":"Field","name":{"kind":"Name","value":"timeFormat"}},{"kind":"Field","name":{"kind":"Name","value":"calendarStartDay"}},{"kind":"Field","name":{"kind":"Name","value":"numberFormat"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"PartialWorkspaceMemberQueryFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"WorkspaceMember"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"firstName"}},{"kind":"Field","name":{"kind":"Name","value":"lastName"}}]}},{"kind":"Field","name":{"kind":"Name","value":"avatarUrl"}},{"kind":"Field","name":{"kind":"Name","value":"userEmail"}},{"kind":"Field","name":{"kind":"Name","value":"userWorkspaceId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"DeletedWorkspaceMemberQueryFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"DeletedWorkspaceMember"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"firstName"}},{"kind":"Field","name":{"kind":"Name","value":"lastName"}}]}},{"kind":"Field","name":{"kind":"Name","value":"avatarUrl"}},{"kind":"Field","name":{"kind":"Name","value":"userEmail"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"RowLevelPermissionPredicateFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"RowLevelPermissionPredicate"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"objectMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"operand"}},{"kind":"Field","name":{"kind":"Name","value":"subFieldName"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceMemberFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceMemberSubFieldName"}},{"kind":"Field","name":{"kind":"Name","value":"rowLevelPermissionPredicateGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"positionInRowLevelPermissionPredicateGroup"}},{"kind":"Field","name":{"kind":"Name","value":"roleId"}},{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"RowLevelPermissionPredicateGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"RowLevelPermissionPredicateGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"parentRowLevelPermissionPredicateGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"logicalOperator"}},{"kind":"Field","name":{"kind":"Name","value":"positionInRowLevelPermissionPredicateGroup"}},{"kind":"Field","name":{"kind":"Name","value":"roleId"}},{"kind":"Field","name":{"kind":"Name","value":"objectMetadataId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ObjectPermissionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ObjectPermission"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"objectMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"canReadObjectRecords"}},{"kind":"Field","name":{"kind":"Name","value":"canUpdateObjectRecords"}},{"kind":"Field","name":{"kind":"Name","value":"canSoftDeleteObjectRecords"}},{"kind":"Field","name":{"kind":"Name","value":"canDestroyObjectRecords"}},{"kind":"Field","name":{"kind":"Name","value":"restrictedFields"}},{"kind":"Field","name":{"kind":"Name","value":"rowLevelPermissionPredicates"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"RowLevelPermissionPredicateFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"rowLevelPermissionPredicateGroups"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"RowLevelPermissionPredicateGroupFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"WorkspaceUrlsFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"WorkspaceUrls"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"subdomainUrl"}},{"kind":"Field","name":{"kind":"Name","value":"customUrl"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"price"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhase"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"start_date"}},{"kind":"Field","name":{"kind":"Name","value":"end_date"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseItemFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"interval"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"currentPeriodEnd"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptionItems"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasReachedCurrentPeriodCap"}},{"kind":"Field","name":{"kind":"Name","value":"quantity"}},{"kind":"Field","name":{"kind":"Name","value":"stripePriceId"}},{"kind":"Field","name":{"kind":"Name","value":"billingProduct"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"images"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"productKey"}},{"kind":"Field","name":{"kind":"Name","value":"planKey"}},{"kind":"Field","name":{"kind":"Name","value":"priceUsageBased"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"BillingSubscriptionFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"BillingSubscription"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"metadata"}},{"kind":"Field","name":{"kind":"Name","value":"cancelAt"}},{"kind":"Field","name":{"kind":"Name","value":"phases"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionSchedulePhaseFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"RoleFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"Role"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"label"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"canUpdateAllSettings"}},{"kind":"Field","name":{"kind":"Name","value":"canAccessAllTools"}},{"kind":"Field","name":{"kind":"Name","value":"isEditable"}},{"kind":"Field","name":{"kind":"Name","value":"canReadAllObjectRecords"}},{"kind":"Field","name":{"kind":"Name","value":"canUpdateAllObjectRecords"}},{"kind":"Field","name":{"kind":"Name","value":"canSoftDeleteAllObjectRecords"}},{"kind":"Field","name":{"kind":"Name","value":"canDestroyAllObjectRecords"}},{"kind":"Field","name":{"kind":"Name","value":"canBeAssignedToUsers"}},{"kind":"Field","name":{"kind":"Name","value":"canBeAssignedToAgents"}},{"kind":"Field","name":{"kind":"Name","value":"canBeAssignedToApiKeys"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AvailableWorkspaceFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"AvailableWorkspace"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"loginToken"}},{"kind":"Field","name":{"kind":"Name","value":"inviteHash"}},{"kind":"Field","name":{"kind":"Name","value":"personalInviteToken"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceUrls"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"subdomainUrl"}},{"kind":"Field","name":{"kind":"Name","value":"customUrl"}}]}},{"kind":"Field","name":{"kind":"Name","value":"logo"}},{"kind":"Field","name":{"kind":"Name","value":"sso"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"issuer"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"status"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"AvailableWorkspacesFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"AvailableWorkspaces"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"availableWorkspacesForSignIn"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AvailableWorkspaceFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"availableWorkspacesForSignUp"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AvailableWorkspaceFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"UserQueryFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"User"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"firstName"}},{"kind":"Field","name":{"kind":"Name","value":"lastName"}},{"kind":"Field","name":{"kind":"Name","value":"email"}},{"kind":"Field","name":{"kind":"Name","value":"hasPassword"}},{"kind":"Field","name":{"kind":"Name","value":"canAccessFullAdminPanel"}},{"kind":"Field","name":{"kind":"Name","value":"canImpersonate"}},{"kind":"Field","name":{"kind":"Name","value":"supportUserHash"}},{"kind":"Field","name":{"kind":"Name","value":"onboardingStatus"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceMember"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"WorkspaceMemberQueryFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"workspaceMembers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"PartialWorkspaceMemberQueryFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"deletedWorkspaceMembers"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"DeletedWorkspaceMemberQueryFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"currentUserWorkspace"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"permissionFlags"}},{"kind":"Field","name":{"kind":"Name","value":"objectsPermissions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ObjectPermissionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"twoFactorAuthenticationMethodSummary"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"twoFactorAuthenticationMethodId"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"strategy"}}]}}]}},{"kind":"Field","name":{"kind":"Name","value":"currentWorkspace"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"displayName"}},{"kind":"Field","name":{"kind":"Name","value":"logo"}},{"kind":"Field","name":{"kind":"Name","value":"inviteHash"}},{"kind":"Field","name":{"kind":"Name","value":"allowImpersonation"}},{"kind":"Field","name":{"kind":"Name","value":"activationStatus"}},{"kind":"Field","name":{"kind":"Name","value":"isPublicInviteLinkEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceDiscoverability"}},{"kind":"Field","name":{"kind":"Name","value":"isGoogleAuthEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"isMicrosoftAuthEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"isPasswordAuthEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"isGoogleAuthBypassEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"isMicrosoftAuthBypassEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"isPasswordAuthBypassEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"subdomain"}},{"kind":"Field","name":{"kind":"Name","value":"customDomain"}},{"kind":"Field","name":{"kind":"Name","value":"hasValidSignedEnterpriseKey"}},{"kind":"Field","name":{"kind":"Name","value":"hasValidEnterpriseValidityToken"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceCustomApplication"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}}]}},{"kind":"Field","name":{"kind":"Name","value":"installedApplications"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"universalIdentifier"}},{"kind":"Field","name":{"kind":"Name","value":"logo"}},{"kind":"Field","name":{"kind":"Name","value":"logoUrl"}}]}},{"kind":"Field","name":{"kind":"Name","value":"isCustomDomainEnabled"}},{"kind":"Field","name":{"kind":"Name","value":"workspaceUrls"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"WorkspaceUrlsFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"featureFlags"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"Field","name":{"kind":"Name","value":"metadataVersion"}},{"kind":"Field","name":{"kind":"Name","value":"currentBillingSubscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"CurrentBillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingCustomer"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"hasPaymentMethod"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingSubscriptions"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"BillingSubscriptionFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"billingEntitlements"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"value"}}]}},{"kind":"Field","name":{"kind":"Name","value":"workspaceMembersCount"}},{"kind":"Field","name":{"kind":"Name","value":"defaultRole"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"RoleFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"fastModel"}},{"kind":"Field","name":{"kind":"Name","value":"smartModel"}},{"kind":"Field","name":{"kind":"Name","value":"aiAdditionalInstructions"}},{"kind":"Field","name":{"kind":"Name","value":"enabledAiModelIds"}},{"kind":"Field","name":{"kind":"Name","value":"useRecommendedModels"}},{"kind":"Field","name":{"kind":"Name","value":"isTwoFactorAuthenticationEnforced"}},{"kind":"Field","name":{"kind":"Name","value":"trashRetentionDays"}},{"kind":"Field","name":{"kind":"Name","value":"eventLogRetentionDays"}},{"kind":"Field","name":{"kind":"Name","value":"editableProfileFields"}},{"kind":"Field","name":{"kind":"Name","value":"isInternalMessagesImportEnabled"}}]}},{"kind":"Field","name":{"kind":"Name","value":"availableWorkspaces"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"AvailableWorkspacesFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"userVars"}}]}}]} as unknown as DocumentNode; -export const CreateManyViewFieldGroupsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateManyViewFieldGroups"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"inputs"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateViewFieldGroupInput"}}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createManyViewFieldGroups"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"inputs"},"value":{"kind":"Variable","name":{"kind":"Name","value":"inputs"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldGroupFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewField"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"aggregateOperation"}},{"kind":"Field","name":{"kind":"Name","value":"viewFieldGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFieldGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}},{"kind":"Field","name":{"kind":"Name","value":"viewFields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldFragment"}}]}}]}}]} as unknown as DocumentNode; export const CreateManyViewFieldsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateManyViewFields"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"inputs"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateViewFieldInput"}}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createManyViewFields"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"inputs"},"value":{"kind":"Variable","name":{"kind":"Name","value":"inputs"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewField"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"aggregateOperation"}},{"kind":"Field","name":{"kind":"Name","value":"viewFieldGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}}]} as unknown as DocumentNode; export const CreateManyViewGroupsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateManyViewGroups"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"inputs"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateViewGroupInput"}}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createManyViewGroups"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"inputs"},"value":{"kind":"Variable","name":{"kind":"Name","value":"inputs"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewGroupFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"fieldValue"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}}]} as unknown as DocumentNode; export const CreateViewDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateView"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateViewInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createView"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewField"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"aggregateOperation"}},{"kind":"Field","name":{"kind":"Name","value":"viewFieldGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFieldGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}},{"kind":"Field","name":{"kind":"Name","value":"viewFields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFilterFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFilter"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"operand"}},{"kind":"Field","name":{"kind":"Name","value":"value"}},{"kind":"Field","name":{"kind":"Name","value":"viewFilterGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"positionInViewFilterGroup"}},{"kind":"Field","name":{"kind":"Name","value":"subFieldName"}},{"kind":"Field","name":{"kind":"Name","value":"relationTargetFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFilterGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFilterGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"parentViewFilterGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"logicalOperator"}},{"kind":"Field","name":{"kind":"Name","value":"positionInViewFilterGroup"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewSortFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewSort"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"direction"}},{"kind":"Field","name":{"kind":"Name","value":"subFieldName"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"fieldValue"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"View"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"objectMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"isCompact"}},{"kind":"Field","name":{"kind":"Name","value":"openRecordIn"}},{"kind":"Field","name":{"kind":"Name","value":"kanbanAggregateOperation"}},{"kind":"Field","name":{"kind":"Name","value":"kanbanAggregateOperationFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"mainGroupByFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"shouldHideEmptyGroups"}},{"kind":"Field","name":{"kind":"Name","value":"kanbanColumnWidth"}},{"kind":"Field","name":{"kind":"Name","value":"anyFieldFilterValue"}},{"kind":"Field","name":{"kind":"Name","value":"calendarFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"calendarEndFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"calendarLayout"}},{"kind":"Field","name":{"kind":"Name","value":"visibility"}},{"kind":"Field","name":{"kind":"Name","value":"createdByUserWorkspaceId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"viewFields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"viewFieldGroups"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldGroupFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"viewFilters"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFilterFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"viewFilterGroups"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFilterGroupFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"viewSorts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewSortFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"viewGroups"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewGroupFragment"}}]}}]}}]} as unknown as DocumentNode; @@ -9218,7 +9196,6 @@ export const CreateViewGroupDocument = {"kind":"Document","definitions":[{"kind" export const CreateViewSortDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateViewSort"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateViewSortInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createViewSort"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewSortFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewSortFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewSort"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"direction"}},{"kind":"Field","name":{"kind":"Name","value":"subFieldName"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}}]} as unknown as DocumentNode; export const DeleteViewDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteView"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteView"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}]}}]} as unknown as DocumentNode; export const DeleteViewFieldDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteViewField"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"DeleteViewFieldInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteViewField"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewField"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"aggregateOperation"}},{"kind":"Field","name":{"kind":"Name","value":"viewFieldGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}}]} as unknown as DocumentNode; -export const DeleteViewFieldGroupDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteViewFieldGroup"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"DeleteViewFieldGroupInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteViewFieldGroup"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldGroupFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewField"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"aggregateOperation"}},{"kind":"Field","name":{"kind":"Name","value":"viewFieldGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFieldGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}},{"kind":"Field","name":{"kind":"Name","value":"viewFields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldFragment"}}]}}]}}]} as unknown as DocumentNode; export const DeleteViewFilterDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteViewFilter"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"DeleteViewFilterInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteViewFilter"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFilterFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFilterFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFilter"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"operand"}},{"kind":"Field","name":{"kind":"Name","value":"value"}},{"kind":"Field","name":{"kind":"Name","value":"viewFilterGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"positionInViewFilterGroup"}},{"kind":"Field","name":{"kind":"Name","value":"subFieldName"}},{"kind":"Field","name":{"kind":"Name","value":"relationTargetFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}}]} as unknown as DocumentNode; export const DeleteViewFilterGroupDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteViewFilterGroup"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteViewFilterGroup"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}}]}]}}]} as unknown as DocumentNode; export const DeleteViewGroupDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"DeleteViewGroup"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"DeleteViewGroupInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"deleteViewGroup"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewGroupFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"fieldValue"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}}]} as unknown as DocumentNode; @@ -9232,7 +9209,6 @@ export const DestroyViewSortDocument = {"kind":"Document","definitions":[{"kind" export const UpdateManyViewGroupsDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateManyViewGroups"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"inputs"}},"type":{"kind":"NonNullType","type":{"kind":"ListType","type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateViewGroupInput"}}}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateManyViewGroups"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"inputs"},"value":{"kind":"Variable","name":{"kind":"Name","value":"inputs"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewGroupFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"fieldValue"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}}]} as unknown as DocumentNode; export const UpdateViewDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateView"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateViewInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateView"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}},{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewField"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"aggregateOperation"}},{"kind":"Field","name":{"kind":"Name","value":"viewFieldGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFieldGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}},{"kind":"Field","name":{"kind":"Name","value":"viewFields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFilterFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFilter"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"operand"}},{"kind":"Field","name":{"kind":"Name","value":"value"}},{"kind":"Field","name":{"kind":"Name","value":"viewFilterGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"positionInViewFilterGroup"}},{"kind":"Field","name":{"kind":"Name","value":"subFieldName"}},{"kind":"Field","name":{"kind":"Name","value":"relationTargetFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFilterGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFilterGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"parentViewFilterGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"logicalOperator"}},{"kind":"Field","name":{"kind":"Name","value":"positionInViewFilterGroup"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewSortFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewSort"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"direction"}},{"kind":"Field","name":{"kind":"Name","value":"subFieldName"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"fieldValue"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"View"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"objectMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"type"}},{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"icon"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"isCompact"}},{"kind":"Field","name":{"kind":"Name","value":"openRecordIn"}},{"kind":"Field","name":{"kind":"Name","value":"kanbanAggregateOperation"}},{"kind":"Field","name":{"kind":"Name","value":"kanbanAggregateOperationFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"mainGroupByFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"shouldHideEmptyGroups"}},{"kind":"Field","name":{"kind":"Name","value":"kanbanColumnWidth"}},{"kind":"Field","name":{"kind":"Name","value":"anyFieldFilterValue"}},{"kind":"Field","name":{"kind":"Name","value":"calendarFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"calendarEndFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"calendarLayout"}},{"kind":"Field","name":{"kind":"Name","value":"visibility"}},{"kind":"Field","name":{"kind":"Name","value":"createdByUserWorkspaceId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"viewFields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"viewFieldGroups"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldGroupFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"viewFilters"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFilterFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"viewFilterGroups"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFilterGroupFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"viewSorts"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewSortFragment"}}]}},{"kind":"Field","name":{"kind":"Name","value":"viewGroups"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewGroupFragment"}}]}}]}}]} as unknown as DocumentNode; export const UpdateViewFieldDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateViewField"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateViewFieldInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateViewField"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewField"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"aggregateOperation"}},{"kind":"Field","name":{"kind":"Name","value":"viewFieldGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}}]} as unknown as DocumentNode; -export const UpdateViewFieldGroupDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateViewFieldGroup"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateViewFieldGroupInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateViewFieldGroup"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldGroupFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewField"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"size"}},{"kind":"Field","name":{"kind":"Name","value":"aggregateOperation"}},{"kind":"Field","name":{"kind":"Name","value":"viewFieldGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFieldGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFieldGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"isActive"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}},{"kind":"Field","name":{"kind":"Name","value":"viewFields"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFieldFragment"}}]}}]}}]} as unknown as DocumentNode; export const UpdateViewFilterDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateViewFilter"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateViewFilterInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateViewFilter"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFilterFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFilterFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFilter"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"fieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"operand"}},{"kind":"Field","name":{"kind":"Name","value":"value"}},{"kind":"Field","name":{"kind":"Name","value":"viewFilterGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"positionInViewFilterGroup"}},{"kind":"Field","name":{"kind":"Name","value":"subFieldName"}},{"kind":"Field","name":{"kind":"Name","value":"relationTargetFieldMetadataId"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}}]} as unknown as DocumentNode; export const UpdateViewFilterGroupDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateViewFilterGroup"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateViewFilterGroupInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateViewFilterGroup"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}},{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewFilterGroupFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewFilterGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewFilterGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"parentViewFilterGroupId"}},{"kind":"Field","name":{"kind":"Name","value":"logicalOperator"}},{"kind":"Field","name":{"kind":"Name","value":"positionInViewFilterGroup"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}}]}}]} as unknown as DocumentNode; export const UpdateViewGroupDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateViewGroup"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateViewGroupInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"updateViewGroup"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"FragmentSpread","name":{"kind":"Name","value":"ViewGroupFragment"}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"ViewGroupFragment"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ViewGroup"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"isVisible"}},{"kind":"Field","name":{"kind":"Name","value":"fieldValue"}},{"kind":"Field","name":{"kind":"Name","value":"position"}},{"kind":"Field","name":{"kind":"Name","value":"viewId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"deletedAt"}}]}}]} as unknown as DocumentNode; diff --git a/packages/twenty-front/src/modules/views/graphql/mutations/createManyViewFieldGroups.ts b/packages/twenty-front/src/modules/views/graphql/mutations/createManyViewFieldGroups.ts deleted file mode 100644 index 22823bd637..0000000000 --- a/packages/twenty-front/src/modules/views/graphql/mutations/createManyViewFieldGroups.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { VIEW_FIELD_GROUP_FRAGMENT } from '@/views/graphql/fragments/viewFieldGroupFragment'; -import { gql } from '@apollo/client'; - -export const CREATE_MANY_VIEW_FIELD_GROUPS = gql` - ${VIEW_FIELD_GROUP_FRAGMENT} - mutation CreateManyViewFieldGroups($inputs: [CreateViewFieldGroupInput!]!) { - createManyViewFieldGroups(inputs: $inputs) { - ...ViewFieldGroupFragment - } - } -`; diff --git a/packages/twenty-front/src/modules/views/graphql/mutations/deleteViewFieldGroup.ts b/packages/twenty-front/src/modules/views/graphql/mutations/deleteViewFieldGroup.ts deleted file mode 100644 index aab965d4d4..0000000000 --- a/packages/twenty-front/src/modules/views/graphql/mutations/deleteViewFieldGroup.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { VIEW_FIELD_GROUP_FRAGMENT } from '@/views/graphql/fragments/viewFieldGroupFragment'; -import { gql } from '@apollo/client'; - -export const DELETE_VIEW_FIELD_GROUP = gql` - ${VIEW_FIELD_GROUP_FRAGMENT} - mutation DeleteViewFieldGroup($input: DeleteViewFieldGroupInput!) { - deleteViewFieldGroup(input: $input) { - ...ViewFieldGroupFragment - } - } -`; diff --git a/packages/twenty-front/src/modules/views/graphql/mutations/updateViewFieldGroup.ts b/packages/twenty-front/src/modules/views/graphql/mutations/updateViewFieldGroup.ts deleted file mode 100644 index 645445b3e7..0000000000 --- a/packages/twenty-front/src/modules/views/graphql/mutations/updateViewFieldGroup.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { VIEW_FIELD_GROUP_FRAGMENT } from '@/views/graphql/fragments/viewFieldGroupFragment'; -import { gql } from '@apollo/client'; - -export const UPDATE_VIEW_FIELD_GROUP = gql` - ${VIEW_FIELD_GROUP_FRAGMENT} - mutation UpdateViewFieldGroup($input: UpdateViewFieldGroupInput!) { - updateViewFieldGroup(input: $input) { - ...ViewFieldGroupFragment - } - } -`; diff --git a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewAPIPersist.ts b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewAPIPersist.ts index 1f44020860..f985086951 100644 --- a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewAPIPersist.ts +++ b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewAPIPersist.ts @@ -1,21 +1,20 @@ import { useCallback } from 'react'; -import { useMetadataErrorHandler } from '@/metadata-error-handler/hooks/useMetadataErrorHandler'; +import { type FlatView } from '@/metadata-store/types/FlatView'; +import { type FlatViewGroup } from '@/metadata-store/types/FlatViewGroup'; import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type'; -import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; +import { usePerformViewEntityAPIPersistOperation } from '@/views/hooks/internal/usePerformViewEntityAPIPersistOperation'; import { useViewsSideEffectsOnViewGroups } from '@/views/hooks/useViewsSideEffectsOnViewGroups'; -import { CombinedGraphQLErrors } from '@apollo/client/errors'; -import { t } from '@lingui/core/macro'; +import { useMutation } from '@apollo/client/react'; import { CrudOperationType } from 'twenty-shared/types'; import { isDefined } from 'twenty-shared/utils'; import { v4 } from 'uuid'; -import { useMutation } from '@apollo/client/react'; import { + CreateViewDocument, type CreateViewMutationVariables, + DestroyViewDocument, type DestroyViewMutationVariables, ViewType, - CreateViewDocument, - DestroyViewDocument, } from '~/generated-metadata/graphql'; export const usePerformViewAPIPersist = () => { @@ -24,8 +23,8 @@ export const usePerformViewAPIPersist = () => { const { triggerViewGroupOptimisticEffectAtViewCreation } = useViewsSideEffectsOnViewGroups(); - const { handleMetadataError } = useMetadataErrorHandler(); - const { enqueueErrorSnackBar } = useSnackBar(); + const { performViewEntityAPIPersistOperation } = + usePerformViewEntityAPIPersistOperation('view'); const performViewAPICreate = useCallback( async ( @@ -34,59 +33,64 @@ export const usePerformViewAPIPersist = () => { ): Promise< MetadataRequestResult>> > => { - try { - const newViewId = variables.input.id ?? v4(); - if (variables.input.type === ViewType.KANBAN) { - triggerViewGroupOptimisticEffectAtViewCreation({ - objectMetadataItemId: objectMetadataItemId, - mainGroupByFieldMetadataId: - variables.input.mainGroupByFieldMetadataId, - }); - } + const result = await performViewEntityAPIPersistOperation({ + persist: () => { + const newViewId = variables.input.id ?? v4(); + if (variables.input.type === ViewType.KANBAN) { + triggerViewGroupOptimisticEffectAtViewCreation({ + objectMetadataItemId: objectMetadataItemId, + mainGroupByFieldMetadataId: + variables.input.mainGroupByFieldMetadataId, + }); + } - const result = await createViewMutation({ - variables: { - input: { - ...variables.input, - id: newViewId, + return createViewMutation({ + variables: { + input: { + ...variables.input, + id: newViewId, + }, }, - }, - }); - - const newView = result.data?.createView; - - if (!isDefined(newView)) { - return { - status: 'failed', - error: new Error('Failed to create view'), - }; - } - - return { - status: 'successful', - response: result, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'view', - operationType: CrudOperationType.CREATE, }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } + }, + applyResultToDraft: (mutationResult, { addToDraft }) => { + const newView = mutationResult.data?.createView; - return { - status: 'failed', - error, - }; - } + if (!isDefined(newView)) { + throw new Error('Failed to create view'); + } + + const { + __typename, + viewFields: _viewFields, + viewFieldGroups: _viewFieldGroups, + viewFilters: _viewFilters, + viewFilterGroups: _viewFilterGroups, + viewSorts: _viewSorts, + viewGroups, + ...flatView + } = newView; + + addToDraft({ key: 'views', items: [flatView as FlatView] }); + + // The server auto-creates viewGroups for Kanban views (mainGroupByFieldMetadataId) + addToDraft({ + key: 'viewGroups', + items: viewGroups.map( + ({ __typename: _viewGroupTypename, ...viewGroup }) => + viewGroup as FlatViewGroup, + ), + }); + }, + operationType: CrudOperationType.CREATE, + }); + + return result; }, [ createViewMutation, triggerViewGroupOptimisticEffectAtViewCreation, - handleMetadataError, - enqueueErrorSnackBar, + performViewEntityAPIPersistOperation, ], ); @@ -95,33 +99,17 @@ export const usePerformViewAPIPersist = () => { variables: DestroyViewMutationVariables, ): Promise< MetadataRequestResult>> - > => { - try { - const result = await destroyViewMutation({ - variables, - }); - - return { - status: 'successful', - response: result, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'view', - operationType: CrudOperationType.DELETE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [destroyViewMutation, handleMetadataError, enqueueErrorSnackBar], + > => + performViewEntityAPIPersistOperation({ + persist: () => + destroyViewMutation({ + variables, + }), + applyResultToDraft: (_result, { removeFromDraft }) => + removeFromDraft({ key: 'views', itemIds: [variables.id] }), + operationType: CrudOperationType.DELETE, + }), + [destroyViewMutation, performViewEntityAPIPersistOperation], ); return { diff --git a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewEntityAPIPersistOperation.ts b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewEntityAPIPersistOperation.ts new file mode 100644 index 0000000000..892217d9c3 --- /dev/null +++ b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewEntityAPIPersistOperation.ts @@ -0,0 +1,165 @@ +import { useCallback } from 'react'; + +import { useMetadataErrorHandler } from '@/metadata-error-handler/hooks/useMetadataErrorHandler'; +import { useUpdateMetadataStoreDraft } from '@/metadata-store/hooks/useUpdateMetadataStoreDraft'; +import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type'; +import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; +import { CombinedGraphQLErrors } from '@apollo/client/errors'; +import { t } from '@lingui/core/macro'; +import { type AllMetadataName } from 'twenty-shared/metadata'; +import { type CrudOperationType } from 'twenty-shared/types'; +import { isDefined } from 'twenty-shared/utils'; + +type MetadataStoreDraftUtils = Pick< + ReturnType, + 'addToDraft' | 'updateInDraft' | 'removeFromDraft' +>; + +type PerformViewEntityAPIPersistOperationArgs = { + persist: () => Promise; + applyResultToDraft: ( + response: TResponse, + draftUtils: MetadataStoreDraftUtils, + ) => void; + operationType: CrudOperationType; +}; + +type PerformViewEntityAPIPersistBatchOperationArgs = { + inputs: TInput[]; + mutate: (input: TInput) => Promise; + applyResultToDraft: ( + fulfilledMutations: { input: TInput; result: TResult }[], + draftUtils: MetadataStoreDraftUtils, + ) => void; + operationType: CrudOperationType; +}; + +export const usePerformViewEntityAPIPersistOperation = ( + metadataName: AllMetadataName, +) => { + const { addToDraft, updateInDraft, removeFromDraft, applyChanges } = + useUpdateMetadataStoreDraft(); + + const { handleMetadataError } = useMetadataErrorHandler(); + const { enqueueErrorSnackBar } = useSnackBar(); + + const handlePersistError = useCallback( + (error: unknown, operationType: CrudOperationType) => { + if (CombinedGraphQLErrors.is(error)) { + handleMetadataError(error, { + primaryMetadataName: metadataName, + operationType, + }); + } else { + enqueueErrorSnackBar({ message: t`An error occurred.` }); + } + }, + [handleMetadataError, enqueueErrorSnackBar, metadataName], + ); + + const performViewEntityAPIPersistOperation = useCallback( + async ({ + persist, + applyResultToDraft, + operationType, + }: PerformViewEntityAPIPersistOperationArgs): Promise< + MetadataRequestResult + > => { + try { + const response = await persist(); + + applyResultToDraft(response, { + addToDraft, + updateInDraft, + removeFromDraft, + }); + applyChanges(); + + return { + status: 'successful', + response, + }; + } catch (error) { + handlePersistError(error, operationType); + + return { + status: 'failed', + error, + }; + } + }, + [ + addToDraft, + updateInDraft, + removeFromDraft, + applyChanges, + handlePersistError, + ], + ); + + const performViewEntityAPIPersistBatchOperation = useCallback( + async ({ + inputs, + mutate, + applyResultToDraft, + operationType, + }: PerformViewEntityAPIPersistBatchOperationArgs): Promise< + MetadataRequestResult + > => { + if (inputs.length === 0) { + return { + status: 'successful', + response: [], + }; + } + + const settledMutations = await Promise.allSettled(inputs.map(mutate)); + + const fulfilledMutations = settledMutations.flatMap( + (settledMutation, index) => + settledMutation.status === 'fulfilled' + ? [{ input: inputs[index], result: settledMutation.value }] + : [], + ); + + applyResultToDraft(fulfilledMutations, { + addToDraft, + updateInDraft, + removeFromDraft, + }); + applyChanges(); + + const firstRejectedMutation = settledMutations.find( + (settledMutation) => settledMutation.status === 'rejected', + ); + + if (isDefined(firstRejectedMutation)) { + const error = firstRejectedMutation.reason; + + handlePersistError(error, operationType); + + return { + status: 'failed', + error, + }; + } + + return { + status: 'successful', + response: fulfilledMutations.map(({ result }) => result), + }; + }, + [ + addToDraft, + updateInDraft, + removeFromDraft, + applyChanges, + handlePersistError, + ], + ); + + return { + performViewEntityAPIPersistOperation, + performViewEntityAPIPersistBatchOperation, + }; +}; diff --git a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFieldAPIPersist.ts b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFieldAPIPersist.ts index 728191dfee..f5bf1458df 100644 --- a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFieldAPIPersist.ts +++ b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFieldAPIPersist.ts @@ -1,12 +1,11 @@ import { useCallback } from 'react'; -import { useMetadataErrorHandler } from '@/metadata-error-handler/hooks/useMetadataErrorHandler'; +import { type FlatViewField } from '@/metadata-store/types/FlatViewField'; import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type'; -import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; -import { CombinedGraphQLErrors } from '@apollo/client/errors'; -import { t } from '@lingui/core/macro'; -import { CrudOperationType } from 'twenty-shared/types'; +import { usePerformViewEntityAPIPersistOperation } from '@/views/hooks/internal/usePerformViewEntityAPIPersistOperation'; import { useMutation } from '@apollo/client/react'; +import { CrudOperationType } from 'twenty-shared/types'; +import { isDefined } from 'twenty-shared/utils'; import { type CreateManyViewFieldsMutationVariables, type DeleteViewFieldMutationVariables, @@ -26,8 +25,10 @@ export const usePerformViewFieldAPIPersist = () => { const [deleteViewFieldMutation] = useMutation(DeleteViewFieldDocument); const [destroyViewFieldMutation] = useMutation(DestroyViewFieldDocument); - const { handleMetadataError } = useMetadataErrorHandler(); - const { enqueueErrorSnackBar } = useSnackBar(); + const { + performViewEntityAPIPersistOperation, + performViewEntityAPIPersistBatchOperation, + } = usePerformViewEntityAPIPersistOperation('viewField'); const performViewFieldAPICreate = useCallback( async ( @@ -47,79 +48,48 @@ export const usePerformViewFieldAPIPersist = () => { }; } - try { - const result = await createManyViewFieldsMutation({ - variables: createViewFieldInputs, - }); - - return { - status: 'successful', - response: result, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewField', - operationType: CrudOperationType.CREATE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } + return performViewEntityAPIPersistOperation({ + persist: () => + createManyViewFieldsMutation({ + variables: createViewFieldInputs, + }), + applyResultToDraft: (result, { addToDraft }) => + addToDraft({ + key: 'viewFields', + items: (result.data?.createManyViewFields ?? []).map( + ({ __typename, ...viewField }) => viewField as FlatViewField, + ), + }), + operationType: CrudOperationType.CREATE, + }); }, - [createManyViewFieldsMutation, handleMetadataError, enqueueErrorSnackBar], + [createManyViewFieldsMutation, performViewEntityAPIPersistOperation], ); const performViewFieldAPIUpdate = useCallback( async ( - createViewFieldInputs: UpdateViewFieldMutationVariables[], + updateViewFieldInputs: UpdateViewFieldMutationVariables[], ): Promise< MetadataRequestResult< Awaited>[] > - > => { - if (createViewFieldInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - createViewFieldInputs.map((variables) => - updateViewFieldMutation({ - variables, - }), + > => + performViewEntityAPIPersistBatchOperation({ + inputs: updateViewFieldInputs, + mutate: (variables) => updateViewFieldMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { updateInDraft }) => + updateInDraft( + 'viewFields', + fulfilledMutations + .map(({ result }) => result.data?.updateViewField) + .filter(isDefined) + .map( + ({ __typename, ...viewField }) => viewField as FlatViewField, + ), ), - ); - - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewField', - operationType: CrudOperationType.UPDATE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [updateViewFieldMutation, handleMetadataError, enqueueErrorSnackBar], + operationType: CrudOperationType.UPDATE, + }), + [updateViewFieldMutation, performViewEntityAPIPersistBatchOperation], ); const performViewFieldAPIDelete = useCallback( @@ -129,44 +99,18 @@ export const usePerformViewFieldAPIPersist = () => { MetadataRequestResult< Awaited>[] > - > => { - if (deleteViewFieldInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - deleteViewFieldInputs.map((variables) => - deleteViewFieldMutation({ - variables, - }), - ), - ); - - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewField', - operationType: CrudOperationType.DELETE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [deleteViewFieldMutation, handleMetadataError, enqueueErrorSnackBar], + > => + performViewEntityAPIPersistBatchOperation({ + inputs: deleteViewFieldInputs, + mutate: (variables) => deleteViewFieldMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { removeFromDraft }) => + removeFromDraft({ + key: 'viewFields', + itemIds: fulfilledMutations.map(({ input }) => input.input.id), + }), + operationType: CrudOperationType.DELETE, + }), + [deleteViewFieldMutation, performViewEntityAPIPersistBatchOperation], ); const performViewFieldAPIDestroy = useCallback( @@ -176,44 +120,18 @@ export const usePerformViewFieldAPIPersist = () => { MetadataRequestResult< Awaited>[] > - > => { - if (destroyViewFieldInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - destroyViewFieldInputs.map((variables) => - destroyViewFieldMutation({ - variables, - }), - ), - ); - - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewField', - operationType: CrudOperationType.DESTROY, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [destroyViewFieldMutation, handleMetadataError, enqueueErrorSnackBar], + > => + performViewEntityAPIPersistBatchOperation({ + inputs: destroyViewFieldInputs, + mutate: (variables) => destroyViewFieldMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { removeFromDraft }) => + removeFromDraft({ + key: 'viewFields', + itemIds: fulfilledMutations.map(({ input }) => input.input.id), + }), + operationType: CrudOperationType.DESTROY, + }), + [destroyViewFieldMutation, performViewEntityAPIPersistBatchOperation], ); return { diff --git a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFieldGroupAPIPersist.ts b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFieldGroupAPIPersist.ts deleted file mode 100644 index 4ff0c0d5db..0000000000 --- a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFieldGroupAPIPersist.ts +++ /dev/null @@ -1,197 +0,0 @@ -import { useCallback } from 'react'; - -import { useMetadataErrorHandler } from '@/metadata-error-handler/hooks/useMetadataErrorHandler'; -import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type'; -import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; -import { CREATE_MANY_VIEW_FIELD_GROUPS } from '@/views/graphql/mutations/createManyViewFieldGroups'; -import { DELETE_VIEW_FIELD_GROUP } from '@/views/graphql/mutations/deleteViewFieldGroup'; -import { UPDATE_VIEW_FIELD_GROUP } from '@/views/graphql/mutations/updateViewFieldGroup'; -import { useMutation } from '@apollo/client/react'; -import { CombinedGraphQLErrors } from '@apollo/client/errors'; -import { t } from '@lingui/core/macro'; -import { CrudOperationType } from 'twenty-shared/types'; -import { isDefined } from 'twenty-shared/utils'; -import { - type ViewFieldGroup, - type MutationCreateManyViewFieldGroupsArgs, - type MutationDeleteViewFieldGroupArgs, - type MutationUpdateViewFieldGroupArgs, -} from '~/generated-metadata/graphql'; - -type CreateManyViewFieldGroupsMutationResult = { - createManyViewFieldGroups: ViewFieldGroup[]; -}; - -type UpdateViewFieldGroupMutationResult = { - updateViewFieldGroup: ViewFieldGroup; -}; - -type DeleteViewFieldGroupMutationResult = { - deleteViewFieldGroup: ViewFieldGroup; -}; - -export const usePerformViewFieldGroupAPIPersist = () => { - const [createManyViewFieldGroupsMutation] = useMutation< - CreateManyViewFieldGroupsMutationResult, - MutationCreateManyViewFieldGroupsArgs - >(CREATE_MANY_VIEW_FIELD_GROUPS); - const [updateViewFieldGroupMutation] = useMutation< - UpdateViewFieldGroupMutationResult, - MutationUpdateViewFieldGroupArgs - >(UPDATE_VIEW_FIELD_GROUP); - const [deleteViewFieldGroupMutation] = useMutation< - DeleteViewFieldGroupMutationResult, - MutationDeleteViewFieldGroupArgs - >(DELETE_VIEW_FIELD_GROUP); - - const { handleMetadataError } = useMetadataErrorHandler(); - const { enqueueErrorSnackBar } = useSnackBar(); - - const performViewFieldGroupAPICreate = useCallback( - async ( - createViewFieldGroupInputs: MutationCreateManyViewFieldGroupsArgs, - ): Promise< - MetadataRequestResult - > => { - if ( - !Array.isArray(createViewFieldGroupInputs.inputs) || - createViewFieldGroupInputs.inputs.length === 0 - ) { - return { - status: 'successful', - response: null, - }; - } - - try { - const result = await createManyViewFieldGroupsMutation({ - variables: createViewFieldGroupInputs, - }); - - return { - status: 'successful', - response: result.data ?? null, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewFieldGroup', - operationType: CrudOperationType.CREATE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [ - createManyViewFieldGroupsMutation, - handleMetadataError, - enqueueErrorSnackBar, - ], - ); - - const performViewFieldGroupAPIUpdate = useCallback( - async ( - updateViewFieldGroupInputs: MutationUpdateViewFieldGroupArgs[], - ): Promise< - MetadataRequestResult - > => { - if (updateViewFieldGroupInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - updateViewFieldGroupInputs.map((variables) => - updateViewFieldGroupMutation({ - variables, - }), - ), - ); - - return { - status: 'successful', - response: results - .map((r) => r.data) - .filter(isDefined) as UpdateViewFieldGroupMutationResult[], - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewFieldGroup', - operationType: CrudOperationType.UPDATE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [updateViewFieldGroupMutation, handleMetadataError, enqueueErrorSnackBar], - ); - - const performViewFieldGroupAPIDelete = useCallback( - async ( - deleteViewFieldGroupInputs: MutationDeleteViewFieldGroupArgs[], - ): Promise< - MetadataRequestResult - > => { - if (deleteViewFieldGroupInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - deleteViewFieldGroupInputs.map((variables) => - deleteViewFieldGroupMutation({ - variables, - }), - ), - ); - - return { - status: 'successful', - response: results - .map((r) => r.data) - .filter(isDefined) as DeleteViewFieldGroupMutationResult[], - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewFieldGroup', - operationType: CrudOperationType.DELETE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [deleteViewFieldGroupMutation, handleMetadataError, enqueueErrorSnackBar], - ); - - return { - performViewFieldGroupAPICreate, - performViewFieldGroupAPIUpdate, - performViewFieldGroupAPIDelete, - }; -}; diff --git a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFilterAPIPersist.ts b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFilterAPIPersist.ts index e911ed53ec..79248eba01 100644 --- a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFilterAPIPersist.ts +++ b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFilterAPIPersist.ts @@ -1,31 +1,42 @@ import { useCallback } from 'react'; -import { useMetadataErrorHandler } from '@/metadata-error-handler/hooks/useMetadataErrorHandler'; +import { type FlatViewFilter } from '@/metadata-store/types/FlatViewFilter'; import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type'; -import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; -import { CombinedGraphQLErrors } from '@apollo/client/errors'; -import { t } from '@lingui/core/macro'; -import { CrudOperationType } from 'twenty-shared/types'; +import { usePerformViewEntityAPIPersistOperation } from '@/views/hooks/internal/usePerformViewEntityAPIPersistOperation'; import { useMutation } from '@apollo/client/react'; +import { CrudOperationType } from 'twenty-shared/types'; +import { convertViewFilterValueToString, isDefined } from 'twenty-shared/utils'; import { type CreateViewFilterMutationVariables, type DeleteViewFilterMutationVariables, type DestroyViewFilterMutationVariables, type UpdateViewFilterMutationVariables, + type ViewFilterFragmentFragment, CreateViewFilterDocument, DeleteViewFilterDocument, DestroyViewFilterDocument, UpdateViewFilterDocument, } from '~/generated-metadata/graphql'; +// Normalize value like the fetch path (splitViewWithRelated) so store +// comparisons against string-converted values stay consistent +const toFlatViewFilter = ({ + __typename, + ...viewFilter +}: ViewFilterFragmentFragment): FlatViewFilter => + ({ + ...viewFilter, + value: convertViewFilterValueToString(viewFilter.value), + }) as FlatViewFilter; + export const usePerformViewFilterAPIPersist = () => { const [createViewFilterMutation] = useMutation(CreateViewFilterDocument); const [updateViewFilterMutation] = useMutation(UpdateViewFilterDocument); const [deleteViewFilterMutation] = useMutation(DeleteViewFilterDocument); const [destroyViewFilterMutation] = useMutation(DestroyViewFilterDocument); - const { handleMetadataError } = useMetadataErrorHandler(); - const { enqueueErrorSnackBar } = useSnackBar(); + const { performViewEntityAPIPersistBatchOperation } = + usePerformViewEntityAPIPersistOperation('viewFilter'); const performViewFilterAPICreate = useCallback( async ( @@ -34,44 +45,21 @@ export const usePerformViewFilterAPIPersist = () => { MetadataRequestResult< Awaited>[] > - > => { - if (createViewFilterInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - createViewFilterInputs.map((variables) => - createViewFilterMutation({ - variables, - }), - ), - ); - - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewFilter', - operationType: CrudOperationType.CREATE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [createViewFilterMutation, handleMetadataError, enqueueErrorSnackBar], + > => + performViewEntityAPIPersistBatchOperation({ + inputs: createViewFilterInputs, + mutate: (variables) => createViewFilterMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { addToDraft }) => + addToDraft({ + key: 'viewFilters', + items: fulfilledMutations + .map(({ result }) => result.data?.createViewFilter) + .filter(isDefined) + .map(toFlatViewFilter), + }), + operationType: CrudOperationType.CREATE, + }), + [createViewFilterMutation, performViewEntityAPIPersistBatchOperation], ); const performViewFilterAPIUpdate = useCallback( @@ -81,44 +69,21 @@ export const usePerformViewFilterAPIPersist = () => { MetadataRequestResult< Awaited>[] > - > => { - if (updateViewFilterInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - updateViewFilterInputs.map((variables) => - updateViewFilterMutation({ - variables, - }), + > => + performViewEntityAPIPersistBatchOperation({ + inputs: updateViewFilterInputs, + mutate: (variables) => updateViewFilterMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { updateInDraft }) => + updateInDraft( + 'viewFilters', + fulfilledMutations + .map(({ result }) => result.data?.updateViewFilter) + .filter(isDefined) + .map(toFlatViewFilter), ), - ); - - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewFilter', - operationType: CrudOperationType.UPDATE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [updateViewFilterMutation, handleMetadataError, enqueueErrorSnackBar], + operationType: CrudOperationType.UPDATE, + }), + [updateViewFilterMutation, performViewEntityAPIPersistBatchOperation], ); const performViewFilterAPIDelete = useCallback( @@ -128,44 +93,18 @@ export const usePerformViewFilterAPIPersist = () => { MetadataRequestResult< Awaited>[] > - > => { - if (deleteViewFilterInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - deleteViewFilterInputs.map((variables) => - deleteViewFilterMutation({ - variables, - }), - ), - ); - - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewFilter', - operationType: CrudOperationType.DELETE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [deleteViewFilterMutation, handleMetadataError, enqueueErrorSnackBar], + > => + performViewEntityAPIPersistBatchOperation({ + inputs: deleteViewFilterInputs, + mutate: (variables) => deleteViewFilterMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { removeFromDraft }) => + removeFromDraft({ + key: 'viewFilters', + itemIds: fulfilledMutations.map(({ input }) => input.input.id), + }), + operationType: CrudOperationType.DELETE, + }), + [deleteViewFilterMutation, performViewEntityAPIPersistBatchOperation], ); const performViewFilterAPIDestroy = useCallback( @@ -175,44 +114,18 @@ export const usePerformViewFilterAPIPersist = () => { MetadataRequestResult< Awaited>[] > - > => { - if (destroyViewFilterInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - destroyViewFilterInputs.map((variables) => - destroyViewFilterMutation({ - variables, - }), - ), - ); - - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewFilter', - operationType: CrudOperationType.DESTROY, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [destroyViewFilterMutation, handleMetadataError, enqueueErrorSnackBar], + > => + performViewEntityAPIPersistBatchOperation({ + inputs: destroyViewFilterInputs, + mutate: (variables) => destroyViewFilterMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { removeFromDraft }) => + removeFromDraft({ + key: 'viewFilters', + itemIds: fulfilledMutations.map(({ input }) => input.input.id), + }), + operationType: CrudOperationType.DESTROY, + }), + [destroyViewFilterMutation, performViewEntityAPIPersistBatchOperation], ); return { diff --git a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFilterGroupAPIPersist.ts b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFilterGroupAPIPersist.ts index 9f60f5a791..19ea9d7c0b 100644 --- a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFilterGroupAPIPersist.ts +++ b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewFilterGroupAPIPersist.ts @@ -1,23 +1,38 @@ import { useCallback } from 'react'; -import { CREATE_VIEW_FILTER_GROUP } from '@/views/graphql/mutations/createViewFilterGroup'; -import { DESTROY_VIEW_FILTER_GROUP } from '@/views/graphql/mutations/destroyViewFilterGroup'; -import { UPDATE_VIEW_FILTER_GROUP } from '@/views/graphql/mutations/updateViewFilterGroup'; +import { type FlatViewFilterGroup } from '@/metadata-store/types/FlatViewFilterGroup'; +import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type'; +import { usePerformViewEntityAPIPersistOperation } from '@/views/hooks/internal/usePerformViewEntityAPIPersistOperation'; import { type GraphQLView } from '@/views/types/GraphQLView'; import { type ViewFilterGroup } from '@/views/types/ViewFilterGroup'; -import { useApolloClient } from '@apollo/client/react'; +import { useMutation } from '@apollo/client/react'; +import { CrudOperationType } from 'twenty-shared/types'; import { isDefined } from 'twenty-shared/utils'; -import { type ViewFilterGroup as GqlViewFilterGroup } from '~/generated-metadata/graphql'; +import { + CreateViewFilterGroupDocument, + DestroyViewFilterGroupDocument, + UpdateViewFilterGroupDocument, +} from '~/generated-metadata/graphql'; export const usePerformViewFilterGroupAPIPersist = () => { - const apolloClient = useApolloClient(); + const [createViewFilterGroupMutation] = useMutation( + CreateViewFilterGroupDocument, + ); + const [updateViewFilterGroupMutation] = useMutation( + UpdateViewFilterGroupDocument, + ); + const [destroyViewFilterGroupMutation] = useMutation( + DestroyViewFilterGroupDocument, + ); + + const { + performViewEntityAPIPersistOperation, + performViewEntityAPIPersistBatchOperation, + } = usePerformViewEntityAPIPersistOperation('viewFilterGroup'); const createViewFilterGroupRecord = useCallback( async (viewFilterGroup: ViewFilterGroup, view: Pick) => { - const result = await apolloClient.mutate<{ - createViewFilterGroup: ViewFilterGroup; - }>({ - mutation: CREATE_VIEW_FILTER_GROUP, + const result = await createViewFilterGroupMutation({ variables: { input: { id: viewFilterGroup.id, @@ -26,27 +41,26 @@ export const usePerformViewFilterGroupAPIPersist = () => { logicalOperator: viewFilterGroup.logicalOperator, positionInViewFilterGroup: viewFilterGroup.positionInViewFilterGroup, - } satisfies Partial, + }, }, }); - if (!result.data) { + if (!isDefined(result.data)) { throw new Error('Failed to create view filter group'); } - return { newRecordId: result.data.createViewFilterGroup.id }; + return { newRecord: result.data.createViewFilterGroup }; }, - [apolloClient], + [createViewFilterGroupMutation], ); const performViewFilterGroupAPICreate = useCallback( async ( viewFilterGroupsToCreate: ViewFilterGroup[], view: Pick, - ) => { - if (!viewFilterGroupsToCreate.length) return []; - + ): Promise> => { const oldToNewId = new Map(); + const newRecordIds: string[] = []; for (const viewFilterGroupToCreate of viewFilterGroupsToCreate) { const newParentViewFilterGroupId = isDefined( @@ -56,37 +70,50 @@ export const usePerformViewFilterGroupAPIPersist = () => { viewFilterGroupToCreate.parentViewFilterGroupId) : undefined; - const { newRecordId } = await createViewFilterGroupRecord( - { - ...viewFilterGroupToCreate, - parentViewFilterGroupId: newParentViewFilterGroupId, + const result = await performViewEntityAPIPersistOperation({ + persist: () => + createViewFilterGroupRecord( + { + ...viewFilterGroupToCreate, + parentViewFilterGroupId: newParentViewFilterGroupId, + }, + view, + ), + applyResultToDraft: ({ newRecord }, { addToDraft }) => { + const { __typename, ...viewFilterGroup } = newRecord; + return addToDraft({ + key: 'viewFilterGroups', + items: [viewFilterGroup as FlatViewFilterGroup], + }); }, - view, - ); + operationType: CrudOperationType.CREATE, + }); - oldToNewId.set(viewFilterGroupToCreate.id, newRecordId); + if (result.status === 'failed') { + return result; + } + + oldToNewId.set( + viewFilterGroupToCreate.id, + result.response.newRecord.id, + ); + newRecordIds.push(result.response.newRecord.id); } - const newRecordIds = viewFilterGroupsToCreate.map((viewFilterGroup) => { - const newId = oldToNewId.get(viewFilterGroup.id); - if (!newId) { - throw new Error('Failed to create view filter group'); - } - return newId; - }); - - return newRecordIds; + return { + status: 'successful', + response: newRecordIds, + }; }, - [createViewFilterGroupRecord], + [createViewFilterGroupRecord, performViewEntityAPIPersistOperation], ); const performViewFilterGroupAPIUpdate = useCallback( - (viewFilterGroupsToUpdate: ViewFilterGroup[]) => { - if (!viewFilterGroupsToUpdate.length) return; - return Promise.all( - viewFilterGroupsToUpdate.map((viewFilterGroup) => - apolloClient.mutate<{ updateViewFilterGroup: ViewFilterGroup }>({ - mutation: UPDATE_VIEW_FILTER_GROUP, + (viewFilterGroupsToUpdate: ViewFilterGroup[]) => + performViewEntityAPIPersistBatchOperation({ + inputs: viewFilterGroupsToUpdate, + mutate: (viewFilterGroup) => + updateViewFilterGroupMutation({ variables: { id: viewFilterGroup.id, input: { @@ -95,30 +122,43 @@ export const usePerformViewFilterGroupAPIPersist = () => { logicalOperator: viewFilterGroup.logicalOperator, positionInViewFilterGroup: viewFilterGroup.positionInViewFilterGroup, - } satisfies Partial, + }, }, }), - ), - ); - }, - [apolloClient], + applyResultToDraft: (fulfilledMutations, { updateInDraft }) => + updateInDraft( + 'viewFilterGroups', + fulfilledMutations + .map(({ result }) => result.data?.updateViewFilterGroup) + .filter(isDefined) + .map( + ({ __typename, ...viewFilterGroup }) => + viewFilterGroup as FlatViewFilterGroup, + ), + ), + operationType: CrudOperationType.UPDATE, + }), + [updateViewFilterGroupMutation, performViewEntityAPIPersistBatchOperation], ); const performViewFilterGroupAPIDestroy = useCallback( - (viewFilterGroupIdsToDestroy: string[]) => { - if (!viewFilterGroupIdsToDestroy.length) return; - return Promise.all( - viewFilterGroupIdsToDestroy.map((viewFilterGroupId) => - apolloClient.mutate<{ destroyViewFilterGroup: ViewFilterGroup }>({ - mutation: DESTROY_VIEW_FILTER_GROUP, + (viewFilterGroupIdsToDestroy: string[]) => + performViewEntityAPIPersistBatchOperation({ + inputs: viewFilterGroupIdsToDestroy, + mutate: (viewFilterGroupId) => + destroyViewFilterGroupMutation({ variables: { id: viewFilterGroupId, }, }), - ), - ); - }, - [apolloClient], + applyResultToDraft: (fulfilledMutations, { removeFromDraft }) => + removeFromDraft({ + key: 'viewFilterGroups', + itemIds: fulfilledMutations.map(({ input }) => input), + }), + operationType: CrudOperationType.DESTROY, + }), + [destroyViewFilterGroupMutation, performViewEntityAPIPersistBatchOperation], ); return { diff --git a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewGroupAPIPersist.ts b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewGroupAPIPersist.ts index f9564d05d0..6d26734eb5 100644 --- a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewGroupAPIPersist.ts +++ b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewGroupAPIPersist.ts @@ -1,11 +1,9 @@ import { useCallback } from 'react'; -import { useMetadataErrorHandler } from '@/metadata-error-handler/hooks/useMetadataErrorHandler'; +import { type FlatViewGroup } from '@/metadata-store/types/FlatViewGroup'; import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type'; -import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; -import { CombinedGraphQLErrors } from '@apollo/client/errors'; +import { usePerformViewEntityAPIPersistOperation } from '@/views/hooks/internal/usePerformViewEntityAPIPersistOperation'; import { useMutation } from '@apollo/client/react'; -import { t } from '@lingui/core/macro'; import { isNonEmptyArray } from '@sniptt/guards'; import { CrudOperationType } from 'twenty-shared/types'; import { @@ -24,8 +22,8 @@ export const usePerformViewGroupAPIPersist = () => { CreateManyViewGroupsDocument, ); - const { handleMetadataError } = useMetadataErrorHandler(); - const { enqueueErrorSnackBar } = useSnackBar(); + const { performViewEntityAPIPersistOperation } = + usePerformViewEntityAPIPersistOperation('viewGroup'); const performViewGroupAPIUpdate = useCallback( async ( @@ -42,32 +40,22 @@ export const usePerformViewGroupAPIPersist = () => { }; } - try { - const result = await updateManyViewGroupsMutation({ - variables: updateViewGroupInputs, - }); - - return { - status: 'successful', - response: result, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewGroup', - operationType: CrudOperationType.UPDATE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } + return performViewEntityAPIPersistOperation({ + persist: () => + updateManyViewGroupsMutation({ + variables: updateViewGroupInputs, + }), + applyResultToDraft: (result, { updateInDraft }) => + updateInDraft( + 'viewGroups', + (result.data?.updateManyViewGroups ?? []).map( + ({ __typename, ...viewGroup }) => viewGroup as FlatViewGroup, + ), + ), + operationType: CrudOperationType.UPDATE, + }); }, - [updateManyViewGroupsMutation, handleMetadataError, enqueueErrorSnackBar], + [updateManyViewGroupsMutation, performViewEntityAPIPersistOperation], ); const performViewGroupAPICreate = useCallback( @@ -85,32 +73,22 @@ export const usePerformViewGroupAPIPersist = () => { }; } - try { - const result = await createManyViewGroupsMutation({ - variables: createViewGroupInputs, - }); - - return { - status: 'successful', - response: result, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewGroup', - operationType: CrudOperationType.CREATE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } + return performViewEntityAPIPersistOperation({ + persist: () => + createManyViewGroupsMutation({ + variables: createViewGroupInputs, + }), + applyResultToDraft: (result, { addToDraft }) => + addToDraft({ + key: 'viewGroups', + items: (result.data?.createManyViewGroups ?? []).map( + ({ __typename, ...viewGroup }) => viewGroup as FlatViewGroup, + ), + }), + operationType: CrudOperationType.CREATE, + }); }, - [createManyViewGroupsMutation, handleMetadataError, enqueueErrorSnackBar], + [createManyViewGroupsMutation, performViewEntityAPIPersistOperation], ); return { diff --git a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewSortAPIPersist.ts b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewSortAPIPersist.ts index 71344dae96..cd08e445c9 100644 --- a/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewSortAPIPersist.ts +++ b/packages/twenty-front/src/modules/views/hooks/internal/usePerformViewSortAPIPersist.ts @@ -1,12 +1,11 @@ import { useCallback } from 'react'; -import { useMetadataErrorHandler } from '@/metadata-error-handler/hooks/useMetadataErrorHandler'; +import { type FlatViewSort } from '@/metadata-store/types/FlatViewSort'; import { type MetadataRequestResult } from '@/object-metadata/types/MetadataRequestResult.type'; -import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; -import { CombinedGraphQLErrors } from '@apollo/client/errors'; -import { t } from '@lingui/core/macro'; -import { CrudOperationType } from 'twenty-shared/types'; +import { usePerformViewEntityAPIPersistOperation } from '@/views/hooks/internal/usePerformViewEntityAPIPersistOperation'; import { useMutation } from '@apollo/client/react'; +import { CrudOperationType } from 'twenty-shared/types'; +import { isDefined } from 'twenty-shared/utils'; import { type CreateViewSortMutationVariables, type DeleteViewSortMutationVariables, @@ -24,8 +23,8 @@ export const usePerformViewSortAPIPersist = () => { const [deleteViewSortMutation] = useMutation(DeleteViewSortDocument); const [destroyViewSortMutation] = useMutation(DestroyViewSortDocument); - const { handleMetadataError } = useMetadataErrorHandler(); - const { enqueueErrorSnackBar } = useSnackBar(); + const { performViewEntityAPIPersistBatchOperation } = + usePerformViewEntityAPIPersistOperation('viewSort'); const performViewSortAPICreate = useCallback( async ( @@ -34,43 +33,21 @@ export const usePerformViewSortAPIPersist = () => { MetadataRequestResult< Awaited>[] > - > => { - if (createViewSortInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - createViewSortInputs.map((variables) => - createViewSortMutation({ - variables, - }), - ), - ); - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewSort', - operationType: CrudOperationType.CREATE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred.` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [createViewSortMutation, handleMetadataError, enqueueErrorSnackBar], + > => + performViewEntityAPIPersistBatchOperation({ + inputs: createViewSortInputs, + mutate: (variables) => createViewSortMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { addToDraft }) => + addToDraft({ + key: 'viewSorts', + items: fulfilledMutations + .map(({ result }) => result.data?.createViewSort) + .filter(isDefined) + .map(({ __typename, ...viewSort }) => viewSort as FlatViewSort), + }), + operationType: CrudOperationType.CREATE, + }), + [createViewSortMutation, performViewEntityAPIPersistBatchOperation], ); const performViewSortAPIUpdate = useCallback( @@ -80,44 +57,21 @@ export const usePerformViewSortAPIPersist = () => { MetadataRequestResult< Awaited>[] > - > => { - if (updateViewSortInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - updateViewSortInputs.map((variables) => - updateViewSortMutation({ - variables, - }), + > => + performViewEntityAPIPersistBatchOperation({ + inputs: updateViewSortInputs, + mutate: (variables) => updateViewSortMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { updateInDraft }) => + updateInDraft( + 'viewSorts', + fulfilledMutations + .map(({ result }) => result.data?.updateViewSort) + .filter(isDefined) + .map(({ __typename, ...viewSort }) => viewSort as FlatViewSort), ), - ); - - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewSort', - operationType: CrudOperationType.UPDATE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [updateViewSortMutation, handleMetadataError, enqueueErrorSnackBar], + operationType: CrudOperationType.UPDATE, + }), + [updateViewSortMutation, performViewEntityAPIPersistBatchOperation], ); const performViewSortAPIDelete = useCallback( @@ -127,44 +81,18 @@ export const usePerformViewSortAPIPersist = () => { MetadataRequestResult< Awaited>[] > - > => { - if (deleteViewSortInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - deleteViewSortInputs.map((variables) => - deleteViewSortMutation({ - variables, - }), - ), - ); - - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewSort', - operationType: CrudOperationType.DELETE, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [deleteViewSortMutation, handleMetadataError, enqueueErrorSnackBar], + > => + performViewEntityAPIPersistBatchOperation({ + inputs: deleteViewSortInputs, + mutate: (variables) => deleteViewSortMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { removeFromDraft }) => + removeFromDraft({ + key: 'viewSorts', + itemIds: fulfilledMutations.map(({ input }) => input.input.id), + }), + operationType: CrudOperationType.DELETE, + }), + [deleteViewSortMutation, performViewEntityAPIPersistBatchOperation], ); const performViewSortAPIDestroy = useCallback( @@ -174,44 +102,18 @@ export const usePerformViewSortAPIPersist = () => { MetadataRequestResult< Awaited>[] > - > => { - if (destroyViewSortInputs.length === 0) { - return { - status: 'successful', - response: [], - }; - } - - try { - const results = await Promise.all( - destroyViewSortInputs.map((variables) => - destroyViewSortMutation({ - variables, - }), - ), - ); - - return { - status: 'successful', - response: results, - }; - } catch (error) { - if (CombinedGraphQLErrors.is(error)) { - handleMetadataError(error, { - primaryMetadataName: 'viewSort', - operationType: CrudOperationType.DESTROY, - }); - } else { - enqueueErrorSnackBar({ message: t`An error occurred` }); - } - - return { - status: 'failed', - error, - }; - } - }, - [destroyViewSortMutation, handleMetadataError, enqueueErrorSnackBar], + > => + performViewEntityAPIPersistBatchOperation({ + inputs: destroyViewSortInputs, + mutate: (variables) => destroyViewSortMutation({ variables }), + applyResultToDraft: (fulfilledMutations, { removeFromDraft }) => + removeFromDraft({ + key: 'viewSorts', + itemIds: fulfilledMutations.map(({ input }) => input.input.id), + }), + operationType: CrudOperationType.DESTROY, + }), + [destroyViewSortMutation, performViewEntityAPIPersistBatchOperation], ); return { diff --git a/packages/twenty-front/src/modules/views/hooks/useCreateViewFromCurrentView.ts b/packages/twenty-front/src/modules/views/hooks/useCreateViewFromCurrentView.ts index ab56f8ab16..af7c95922c 100644 --- a/packages/twenty-front/src/modules/views/hooks/useCreateViewFromCurrentView.ts +++ b/packages/twenty-front/src/modules/views/hooks/useCreateViewFromCurrentView.ts @@ -207,9 +207,16 @@ export const useCreateViewFromCurrentView = (viewBarComponentId?: string) => { id: v4(), })); - await performViewFilterGroupAPICreate(viewFilterGroupsToCreate, { - id: newViewId, - }); + const filterGroupResult = await performViewFilterGroupAPICreate( + viewFilterGroupsToCreate, + { + id: newViewId, + }, + ); + + if (filterGroupResult.status === 'failed') { + return undefined; + } const createViewFilterInputs = viewFiltersToCreate.map( (viewFilter) => ({ diff --git a/packages/twenty-front/src/modules/views/hooks/useSaveRecordFiltersAndGroupFiltersToViewFiltersAndGroupFilters.ts b/packages/twenty-front/src/modules/views/hooks/useSaveRecordFiltersAndGroupFiltersToViewFiltersAndGroupFilters.ts index f3b9f67ada..6e98c0f0df 100644 --- a/packages/twenty-front/src/modules/views/hooks/useSaveRecordFiltersAndGroupFiltersToViewFiltersAndGroupFilters.ts +++ b/packages/twenty-front/src/modules/views/hooks/useSaveRecordFiltersAndGroupFiltersToViewFiltersAndGroupFilters.ts @@ -84,11 +84,20 @@ export const useSaveRecordFiltersAndGroupFiltersToViewFiltersAndGroupFilters = (viewFilterGroup) => viewFilterGroup.id, ); - await performViewFilterGroupAPICreate( + const createFilterGroupResult = await performViewFilterGroupAPICreate( viewFilterGroupsToCreate, currentView, ); - await performViewFilterGroupAPIUpdate(viewFilterGroupsToUpdate); + if (createFilterGroupResult.status === 'failed') { + return; + } + + const updateFilterGroupResult = await performViewFilterGroupAPIUpdate( + viewFilterGroupsToUpdate, + ); + if (updateFilterGroupResult.status === 'failed') { + return; + } const currentViewFilters = currentView.viewFilters ?? []; const currentRecordFilters = store.get( @@ -181,7 +190,12 @@ export const useSaveRecordFiltersAndGroupFiltersToViewFiltersAndGroupFilters = return; } - await performViewFilterGroupAPIDestroy(viewFilterGroupIdsToDestroy); + const destroyFilterGroupResult = await performViewFilterGroupAPIDestroy( + viewFilterGroupIdsToDestroy, + ); + if (destroyFilterGroupResult.status === 'failed') { + return; + } // Mirror the DB cascade: remove cascade-deleted viewFilters from the store if (viewFilterGroupIdsToDestroy.length > 0) {