From 58579ce610e2bfbee17f820f2067eaecb4b86f69 Mon Sep 17 00:00:00 2001 From: Sacha Al Himdani Date: Mon, 1 Sep 2025 16:23:38 +0200 Subject: [PATCH] Fix document deletion and update errors Signed-off-by: Sacha Al Himdani --- .../documents/DocumentDetailPage.tsx | 40 ++- .../organizations/documents/DocumentsPage.tsx | 17 +- ...cumentDetailPagePublishMutation.graphql.ts | 253 +++++++++++++++--- .../DocumentDetailPageRowFragment.graphql.ts | 213 +++++++++++++++ 4 files changed, 469 insertions(+), 54 deletions(-) create mode 100644 apps/console/src/pages/organizations/documents/__generated__/DocumentDetailPageRowFragment.graphql.ts diff --git a/apps/console/src/pages/organizations/documents/DocumentDetailPage.tsx b/apps/console/src/pages/organizations/documents/DocumentDetailPage.tsx index 8676b100e..6a20f8ff6 100644 --- a/apps/console/src/pages/organizations/documents/DocumentDetailPage.tsx +++ b/apps/console/src/pages/organizations/documents/DocumentDetailPage.tsx @@ -113,6 +113,36 @@ const documentFragment = graphql` } `; +graphql` + fragment DocumentDetailPageRowFragment on Document { + id + title + description + documentType + updatedAt + owner { + id + fullName + } + versions(first: 1) { + edges { + node { + id + status + signatures(first: 100) { + edges { + node { + id + state + } + } + } + } + } + } + } +`; + const publishDocumentVersionMutation = graphql` mutation DocumentDetailPagePublishMutation( $input: PublishDocumentVersionInput! @@ -120,6 +150,7 @@ const publishDocumentVersionMutation = graphql` publishDocumentVersion(input: $input) { document { id + ...DocumentDetailPageRowFragment } } } @@ -267,15 +298,6 @@ export default function DocumentDetailPage(props: Props) { variables: { input: { documentId: document.id }, }, - onSuccess: () => { - // Refresh the whole query to get the new version - loadQuery( - props.queryRef.environment, - documentNodeQuery, - props.queryRef.variables, - { fetchPolicy: "network-only" } - ); - }, }); }; diff --git a/apps/console/src/pages/organizations/documents/DocumentsPage.tsx b/apps/console/src/pages/organizations/documents/DocumentsPage.tsx index 4c1228097..768d93c7b 100644 --- a/apps/console/src/pages/organizations/documents/DocumentsPage.tsx +++ b/apps/console/src/pages/organizations/documents/DocumentsPage.tsx @@ -89,7 +89,9 @@ export default function DocumentsPage(props: Props) { organization as DocumentsPageListFragment$key ); - const documents = pagination.data.documents.edges.map((edge) => edge.node); + const documents = pagination.data.documents.edges + .map((edge) => edge.node) + .filter(Boolean); const connectionId = pagination.data.documents.__id; const [sendSigningNotifications] = useSendSigningNotificationsMutation(); const { list: selection, toggle, clear, reset } = useList([]); @@ -240,10 +242,15 @@ function DocumentRow({ rowFragment, documentKey ); - const lastVersion = document.versions.edges[0].node; + const lastVersion = document.versions.edges?.[0]?.node; + + if (!lastVersion) { + return null; + } + const isDraft = lastVersion.status === "DRAFT"; const { __, dateFormat } = useTranslate(); - const signatures = lastVersion.signatures?.edges?.map((edge) => edge.node) ?? []; + const signatures = lastVersion.signatures?.edges?.map((edge) => edge?.node)?.filter(Boolean) ?? []; const signedCount = signatures.filter( (signature) => signature.state === "SIGNED" ).length; @@ -294,8 +301,8 @@ function DocumentRow({ {getDocumentTypeLabel(__, document.documentType)}
- - {document.owner.fullName} + + {document.owner?.fullName}
diff --git a/apps/console/src/pages/organizations/documents/__generated__/DocumentDetailPagePublishMutation.graphql.ts b/apps/console/src/pages/organizations/documents/__generated__/DocumentDetailPagePublishMutation.graphql.ts index 429d5a4ad..efd18d894 100644 --- a/apps/console/src/pages/organizations/documents/__generated__/DocumentDetailPagePublishMutation.graphql.ts +++ b/apps/console/src/pages/organizations/documents/__generated__/DocumentDetailPagePublishMutation.graphql.ts @@ -1,5 +1,5 @@ /** - * @generated SignedSource<> + * @generated SignedSource<> * @lightSyntaxTransform * @nogrep */ @@ -9,6 +9,7 @@ // @ts-nocheck import { ConcreteRequest } from 'relay-runtime'; +import { FragmentRefs } from "relay-runtime"; export type PublishDocumentVersionInput = { changelog?: string | null | undefined; documentId: string; @@ -20,6 +21,7 @@ export type DocumentDetailPagePublishMutation$data = { readonly publishDocumentVersion: { readonly document: { readonly id: string; + readonly " $fragmentSpreads": FragmentRefs<"DocumentDetailPageRowFragment">; }; }; }; @@ -38,48 +40,54 @@ var v0 = [ ], v1 = [ { - "alias": null, - "args": [ - { - "kind": "Variable", - "name": "input", - "variableName": "input" - } - ], - "concreteType": "PublishDocumentVersionPayload", - "kind": "LinkedField", - "name": "publishDocumentVersion", - "plural": false, - "selections": [ - { - "alias": null, - "args": null, - "concreteType": "Document", - "kind": "LinkedField", - "name": "document", - "plural": false, - "selections": [ - { - "alias": null, - "args": null, - "kind": "ScalarField", - "name": "id", - "storageKey": null - } - ], - "storageKey": null - } - ], - "storageKey": null + "kind": "Variable", + "name": "input", + "variableName": "input" } -]; +], +v2 = { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "id", + "storageKey": null +}; return { "fragment": { "argumentDefinitions": (v0/*: any*/), "kind": "Fragment", "metadata": null, "name": "DocumentDetailPagePublishMutation", - "selections": (v1/*: any*/), + "selections": [ + { + "alias": null, + "args": (v1/*: any*/), + "concreteType": "PublishDocumentVersionPayload", + "kind": "LinkedField", + "name": "publishDocumentVersion", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "Document", + "kind": "LinkedField", + "name": "document", + "plural": false, + "selections": [ + (v2/*: any*/), + { + "args": null, + "kind": "FragmentSpread", + "name": "DocumentDetailPageRowFragment" + } + ], + "storageKey": null + } + ], + "storageKey": null + } + ], "type": "Mutation", "abstractKey": null }, @@ -88,19 +96,184 @@ return { "argumentDefinitions": (v0/*: any*/), "kind": "Operation", "name": "DocumentDetailPagePublishMutation", - "selections": (v1/*: any*/) + "selections": [ + { + "alias": null, + "args": (v1/*: any*/), + "concreteType": "PublishDocumentVersionPayload", + "kind": "LinkedField", + "name": "publishDocumentVersion", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "Document", + "kind": "LinkedField", + "name": "document", + "plural": false, + "selections": [ + (v2/*: any*/), + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "title", + "storageKey": null + }, + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "description", + "storageKey": null + }, + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "documentType", + "storageKey": null + }, + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "updatedAt", + "storageKey": null + }, + { + "alias": null, + "args": null, + "concreteType": "People", + "kind": "LinkedField", + "name": "owner", + "plural": false, + "selections": [ + (v2/*: any*/), + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "fullName", + "storageKey": null + } + ], + "storageKey": null + }, + { + "alias": null, + "args": [ + { + "kind": "Literal", + "name": "first", + "value": 1 + } + ], + "concreteType": "DocumentVersionConnection", + "kind": "LinkedField", + "name": "versions", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersionEdge", + "kind": "LinkedField", + "name": "edges", + "plural": true, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersion", + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": [ + (v2/*: any*/), + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "status", + "storageKey": null + }, + { + "alias": null, + "args": [ + { + "kind": "Literal", + "name": "first", + "value": 100 + } + ], + "concreteType": "DocumentVersionSignatureConnection", + "kind": "LinkedField", + "name": "signatures", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersionSignatureEdge", + "kind": "LinkedField", + "name": "edges", + "plural": true, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersionSignature", + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": [ + (v2/*: any*/), + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "state", + "storageKey": null + } + ], + "storageKey": null + } + ], + "storageKey": null + } + ], + "storageKey": "signatures(first:100)" + } + ], + "storageKey": null + } + ], + "storageKey": null + } + ], + "storageKey": "versions(first:1)" + } + ], + "storageKey": null + } + ], + "storageKey": null + } + ] }, "params": { - "cacheID": "bbee8d20f444cdc0dbb012e8fecfa9c1", + "cacheID": "e7734d4aece1b73c9bd85eddfbda2548", "id": null, "metadata": {}, "name": "DocumentDetailPagePublishMutation", "operationKind": "mutation", - "text": "mutation DocumentDetailPagePublishMutation(\n $input: PublishDocumentVersionInput!\n) {\n publishDocumentVersion(input: $input) {\n document {\n id\n }\n }\n}\n" + "text": "mutation DocumentDetailPagePublishMutation(\n $input: PublishDocumentVersionInput!\n) {\n publishDocumentVersion(input: $input) {\n document {\n id\n ...DocumentDetailPageRowFragment\n }\n }\n}\n\nfragment DocumentDetailPageRowFragment on Document {\n id\n title\n description\n documentType\n updatedAt\n owner {\n id\n fullName\n }\n versions(first: 1) {\n edges {\n node {\n id\n status\n signatures(first: 100) {\n edges {\n node {\n id\n state\n }\n }\n }\n }\n }\n }\n}\n" } }; })(); -(node as any).hash = "2f5cc9855133b614896a1ac3768e669f"; +(node as any).hash = "9a5706a103ffb1a6a1804e22055851d8"; export default node; diff --git a/apps/console/src/pages/organizations/documents/__generated__/DocumentDetailPageRowFragment.graphql.ts b/apps/console/src/pages/organizations/documents/__generated__/DocumentDetailPageRowFragment.graphql.ts new file mode 100644 index 000000000..b5140d279 --- /dev/null +++ b/apps/console/src/pages/organizations/documents/__generated__/DocumentDetailPageRowFragment.graphql.ts @@ -0,0 +1,213 @@ +/** + * @generated SignedSource<<4cf9e23d757753509bb695aab205ee46>> + * @lightSyntaxTransform + * @nogrep + */ + +/* tslint:disable */ +/* eslint-disable */ +// @ts-nocheck + +import { ReaderFragment } from 'relay-runtime'; +export type DocumentStatus = "DRAFT" | "PUBLISHED"; +export type DocumentType = "ISMS" | "OTHER" | "POLICY"; +export type DocumentVersionSignatureState = "REQUESTED" | "SIGNED"; +import { FragmentRefs } from "relay-runtime"; +export type DocumentDetailPageRowFragment$data = { + readonly description: string; + readonly documentType: DocumentType; + readonly id: string; + readonly owner: { + readonly fullName: string; + readonly id: string; + }; + readonly title: string; + readonly updatedAt: any; + readonly versions: { + readonly edges: ReadonlyArray<{ + readonly node: { + readonly id: string; + readonly signatures: { + readonly edges: ReadonlyArray<{ + readonly node: { + readonly id: string; + readonly state: DocumentVersionSignatureState; + }; + }>; + }; + readonly status: DocumentStatus; + }; + }>; + }; + readonly " $fragmentType": "DocumentDetailPageRowFragment"; +}; +export type DocumentDetailPageRowFragment$key = { + readonly " $data"?: DocumentDetailPageRowFragment$data; + readonly " $fragmentSpreads": FragmentRefs<"DocumentDetailPageRowFragment">; +}; + +const node: ReaderFragment = (function(){ +var v0 = { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "id", + "storageKey": null +}; +return { + "argumentDefinitions": [], + "kind": "Fragment", + "metadata": null, + "name": "DocumentDetailPageRowFragment", + "selections": [ + (v0/*: any*/), + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "title", + "storageKey": null + }, + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "description", + "storageKey": null + }, + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "documentType", + "storageKey": null + }, + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "updatedAt", + "storageKey": null + }, + { + "alias": null, + "args": null, + "concreteType": "People", + "kind": "LinkedField", + "name": "owner", + "plural": false, + "selections": [ + (v0/*: any*/), + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "fullName", + "storageKey": null + } + ], + "storageKey": null + }, + { + "alias": null, + "args": [ + { + "kind": "Literal", + "name": "first", + "value": 1 + } + ], + "concreteType": "DocumentVersionConnection", + "kind": "LinkedField", + "name": "versions", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersionEdge", + "kind": "LinkedField", + "name": "edges", + "plural": true, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersion", + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": [ + (v0/*: any*/), + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "status", + "storageKey": null + }, + { + "alias": null, + "args": [ + { + "kind": "Literal", + "name": "first", + "value": 100 + } + ], + "concreteType": "DocumentVersionSignatureConnection", + "kind": "LinkedField", + "name": "signatures", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersionSignatureEdge", + "kind": "LinkedField", + "name": "edges", + "plural": true, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersionSignature", + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": [ + (v0/*: any*/), + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "state", + "storageKey": null + } + ], + "storageKey": null + } + ], + "storageKey": null + } + ], + "storageKey": "signatures(first:100)" + } + ], + "storageKey": null + } + ], + "storageKey": null + } + ], + "storageKey": "versions(first:1)" + } + ], + "type": "Document", + "abstractKey": null +}; +})(); + +(node as any).hash = "2144e456e031960d8ceefd334741831e"; + +export default node;