From 75656b1ae1448f38675bd19f5f3506274d5c718b Mon Sep 17 00:00:00 2001 From: Grafikart Date: Thu, 10 Jul 2025 18:31:45 +0200 Subject: [PATCH] Add bulk mutation for Documents Signed-off-by: Sacha Al Himdani --- .../organizations/documents/DocumentsPage.tsx | 70 +++- .../DocumentsPagePublishMutation.graphql.ts | 303 ++++++++++++++++++ .../DocumentsPageSignatureMutation.graphql.ts | 128 ++++++++ 3 files changed, 498 insertions(+), 3 deletions(-) create mode 100644 apps/console/src/pages/organizations/documents/__generated__/DocumentsPagePublishMutation.graphql.ts create mode 100644 apps/console/src/pages/organizations/documents/__generated__/DocumentsPageSignatureMutation.graphql.ts diff --git a/apps/console/src/pages/organizations/documents/DocumentsPage.tsx b/apps/console/src/pages/organizations/documents/DocumentsPage.tsx index c83286ee5..263fc1253 100644 --- a/apps/console/src/pages/organizations/documents/DocumentsPage.tsx +++ b/apps/console/src/pages/organizations/documents/DocumentsPage.tsx @@ -39,6 +39,8 @@ import { sprintf, getDocumentTypeLabel } from "@probo/helpers"; import { CreateDocumentDialog } from "./dialogs/CreateDocumentDialog"; import type { DocumentsPageRowFragment$key } from "./__generated__/DocumentsPageRowFragment.graphql"; import { SortableTable, SortableTh } from "/components/SortableTable"; +import { useMutationWithToasts } from "/hooks/useMutationWithToasts.ts"; +import { usePeople } from "/hooks/graph/PeopleGraph.ts"; const documentsFragment = graphql` fragment DocumentsPageListFragment on Organization @@ -71,6 +73,36 @@ const documentsFragment = graphql` } `; +const documentsPublishMutation = graphql` + mutation DocumentsPagePublishMutation( + $input: BulkPublishDocumentVersionsInput! + ) { + bulkPublishDocumentVersions(input: $input) { + documentEdges { + node { + id + ...DocumentsPageRowFragment + } + } + } + } +`; + +const documentsSignatureMutation = graphql` + mutation DocumentsPageSignatureMutation( + $input: BulkRequestSignaturesInput! + ) { + bulkRequestSignatures(input: $input) { + documentVersionSignatureEdges { + node { + id + state + } + } + } + } +`; + type Props = { queryRef: PreloadedQuery; }; @@ -92,8 +124,16 @@ export default function DocumentsPage(props: Props) { const [sendSigningNotifications] = useSendSigningNotificationsMutation(); const { list: selection, toggle, clear, reset } = useList([]); - // TODO : Add mutation to handle publishing multiple documents and request multiple signatures + const [publishMutation, isPublishing] = useMutationWithToasts(documentsPublishMutation, { + successMessage: sprintf(__("%s documents published"), selection.length), + errorMessage: sprintf(__("Failed to publish %s documents"), selection.length), + }) + const [signatureMutation, isSigning] = useMutationWithToasts(documentsSignatureMutation, { + successMessage: __("Signature request send successfully"), + errorMessage: __("Failed to send signature requests"), + }) + const people = usePeople(organization.id); usePageTitle(__("Documents")); const handleSendSigningNotifications = () => { @@ -104,6 +144,30 @@ export default function DocumentsPage(props: Props) { }); }; + const publish = async () => { + await publishMutation({ + variables: { + input: { + documentIds: selection, + changelog: '', + } + } + }) + clear(); + } + + const requestSignatures = async () => { + await signatureMutation({ + variables: { + input: { + documentIds: selection, + signatoryIds: people.map(p => p.id), + } + } + }) + clear(); + } + return (
- - +
diff --git a/apps/console/src/pages/organizations/documents/__generated__/DocumentsPagePublishMutation.graphql.ts b/apps/console/src/pages/organizations/documents/__generated__/DocumentsPagePublishMutation.graphql.ts new file mode 100644 index 000000000..4663558d6 --- /dev/null +++ b/apps/console/src/pages/organizations/documents/__generated__/DocumentsPagePublishMutation.graphql.ts @@ -0,0 +1,303 @@ +/** + * @generated SignedSource<> + * @lightSyntaxTransform + * @nogrep + */ + +/* tslint:disable */ +/* eslint-disable */ +// @ts-nocheck + +import { ConcreteRequest } from 'relay-runtime'; +import { FragmentRefs } from "relay-runtime"; +export type BulkPublishDocumentVersionsInput = { + changelog: string; + documentIds: ReadonlyArray; +}; +export type DocumentsPagePublishMutation$variables = { + input: BulkPublishDocumentVersionsInput; +}; +export type DocumentsPagePublishMutation$data = { + readonly bulkPublishDocumentVersions: { + readonly documentEdges: ReadonlyArray<{ + readonly node: { + readonly id: string; + readonly " $fragmentSpreads": FragmentRefs<"DocumentsPageRowFragment">; + }; + }>; + }; +}; +export type DocumentsPagePublishMutation = { + response: DocumentsPagePublishMutation$data; + variables: DocumentsPagePublishMutation$variables; +}; + +const node: ConcreteRequest = (function(){ +var v0 = [ + { + "defaultValue": null, + "kind": "LocalArgument", + "name": "input" + } +], +v1 = [ + { + "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": "DocumentsPagePublishMutation", + "selections": [ + { + "alias": null, + "args": (v1/*: any*/), + "concreteType": "BulkPublishDocumentVersionsPayload", + "kind": "LinkedField", + "name": "bulkPublishDocumentVersions", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentEdge", + "kind": "LinkedField", + "name": "documentEdges", + "plural": true, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "Document", + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": [ + (v2/*: any*/), + { + "args": null, + "kind": "FragmentSpread", + "name": "DocumentsPageRowFragment" + } + ], + "storageKey": null + } + ], + "storageKey": null + } + ], + "storageKey": null + } + ], + "type": "Mutation", + "abstractKey": null + }, + "kind": "Request", + "operation": { + "argumentDefinitions": (v0/*: any*/), + "kind": "Operation", + "name": "DocumentsPagePublishMutation", + "selections": [ + { + "alias": null, + "args": (v1/*: any*/), + "concreteType": "BulkPublishDocumentVersionsPayload", + "kind": "LinkedField", + "name": "bulkPublishDocumentVersions", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentEdge", + "kind": "LinkedField", + "name": "documentEdges", + "plural": true, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "Document", + "kind": "LinkedField", + "name": "node", + "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 + } + ], + "storageKey": null + } + ] + }, + "params": { + "cacheID": "7cd29425535c6d30017201fee219447b", + "id": null, + "metadata": {}, + "name": "DocumentsPagePublishMutation", + "operationKind": "mutation", + "text": "mutation DocumentsPagePublishMutation(\n $input: BulkPublishDocumentVersionsInput!\n) {\n bulkPublishDocumentVersions(input: $input) {\n documentEdges {\n node {\n id\n ...DocumentsPageRowFragment\n }\n }\n }\n}\n\nfragment DocumentsPageRowFragment 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 = "baea3e7dce61a42bf5bf2caefda998ea"; + +export default node; diff --git a/apps/console/src/pages/organizations/documents/__generated__/DocumentsPageSignatureMutation.graphql.ts b/apps/console/src/pages/organizations/documents/__generated__/DocumentsPageSignatureMutation.graphql.ts new file mode 100644 index 000000000..f741a8b7b --- /dev/null +++ b/apps/console/src/pages/organizations/documents/__generated__/DocumentsPageSignatureMutation.graphql.ts @@ -0,0 +1,128 @@ +/** + * @generated SignedSource<<4c3514470041046f80f410ea5a3275d6>> + * @lightSyntaxTransform + * @nogrep + */ + +/* tslint:disable */ +/* eslint-disable */ +// @ts-nocheck + +import { ConcreteRequest } from 'relay-runtime'; +export type DocumentVersionSignatureState = "REQUESTED" | "SIGNED"; +export type BulkRequestSignaturesInput = { + documentIds: ReadonlyArray; + signatoryIds: ReadonlyArray; +}; +export type DocumentsPageSignatureMutation$variables = { + input: BulkRequestSignaturesInput; +}; +export type DocumentsPageSignatureMutation$data = { + readonly bulkRequestSignatures: { + readonly documentVersionSignatureEdges: ReadonlyArray<{ + readonly node: { + readonly id: string; + readonly state: DocumentVersionSignatureState; + }; + }>; + }; +}; +export type DocumentsPageSignatureMutation = { + response: DocumentsPageSignatureMutation$data; + variables: DocumentsPageSignatureMutation$variables; +}; + +const node: ConcreteRequest = (function(){ +var v0 = [ + { + "defaultValue": null, + "kind": "LocalArgument", + "name": "input" + } +], +v1 = [ + { + "alias": null, + "args": [ + { + "kind": "Variable", + "name": "input", + "variableName": "input" + } + ], + "concreteType": "BulkRequestSignaturesPayload", + "kind": "LinkedField", + "name": "bulkRequestSignatures", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersionSignatureEdge", + "kind": "LinkedField", + "name": "documentVersionSignatureEdges", + "plural": true, + "selections": [ + { + "alias": null, + "args": null, + "concreteType": "DocumentVersionSignature", + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "id", + "storageKey": null + }, + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "state", + "storageKey": null + } + ], + "storageKey": null + } + ], + "storageKey": null + } + ], + "storageKey": null + } +]; +return { + "fragment": { + "argumentDefinitions": (v0/*: any*/), + "kind": "Fragment", + "metadata": null, + "name": "DocumentsPageSignatureMutation", + "selections": (v1/*: any*/), + "type": "Mutation", + "abstractKey": null + }, + "kind": "Request", + "operation": { + "argumentDefinitions": (v0/*: any*/), + "kind": "Operation", + "name": "DocumentsPageSignatureMutation", + "selections": (v1/*: any*/) + }, + "params": { + "cacheID": "a61a828bc67d8b569c38f4826b42d00f", + "id": null, + "metadata": {}, + "name": "DocumentsPageSignatureMutation", + "operationKind": "mutation", + "text": "mutation DocumentsPageSignatureMutation(\n $input: BulkRequestSignaturesInput!\n) {\n bulkRequestSignatures(input: $input) {\n documentVersionSignatureEdges {\n node {\n id\n state\n }\n }\n }\n}\n" + } +}; +})(); + +(node as any).hash = "1cb2b7dfa938b35cf75b09b51cdd2dca"; + +export default node;