From b54cb6d3fcc8801f769bc17c01e8fcaf2dd388a3 Mon Sep 17 00:00:00 2001 From: Sacha Al Himdani Date: Tue, 3 Jun 2025 14:55:54 -0700 Subject: [PATCH] Change document version Signed-off-by: Sacha Al Himdani --- .../documents/ShowDocumentView.tsx | 218 ++++++++- .../documents/VersionHistoryModal.tsx | 20 +- ...ntViewGenerateChangelogMutation.graphql.ts | 92 ++++ ...ShowDocumentViewPublishMutation.graphql.ts | 23 +- .../ShowDocumentViewQuery.graphql.ts | 102 ++-- ...umentViewUpdateDocumentMutation.graphql.ts | 16 +- ...onHistoryModal_documentVersions.graphql.ts | 52 +- pkg/agents/agents.go | 41 ++ pkg/agents/changelog_generator.go | 70 +++ pkg/agents/vendor_assessment.go | 32 +- pkg/coredata/document_version.go | 46 +- pkg/coredata/migrations/20250603T231005Z.sql | 35 ++ pkg/probo/document_service.go | 75 +++ pkg/probo/service.go | 48 +- pkg/probo/vendor_service.go | 2 +- pkg/probod/probod.go | 8 +- pkg/server/api/console/v1/schema.graphql | 14 + pkg/server/api/console/v1/schema/schema.go | 451 +++++++++++++++++- .../api/console/v1/types/document_version.go | 1 + pkg/server/api/console/v1/types/types.go | 11 + pkg/server/api/console/v1/v1_resolver.go | 34 +- pkg/server/server.go | 2 +- 22 files changed, 1247 insertions(+), 146 deletions(-) create mode 100644 apps/console/src/pages/organizations/documents/__generated__/ShowDocumentViewGenerateChangelogMutation.graphql.ts create mode 100644 pkg/agents/agents.go create mode 100644 pkg/agents/changelog_generator.go create mode 100644 pkg/coredata/migrations/20250603T231005Z.sql diff --git a/apps/console/src/pages/organizations/documents/ShowDocumentView.tsx b/apps/console/src/pages/organizations/documents/ShowDocumentView.tsx index be32e0c1a..edf0338e0 100644 --- a/apps/console/src/pages/organizations/documents/ShowDocumentView.tsx +++ b/apps/console/src/pages/organizations/documents/ShowDocumentView.tsx @@ -25,7 +25,7 @@ import type { ShowDocumentViewQuery } from "./__generated__/ShowDocumentViewQuer import { ShowDocumentViewPublishMutation } from "./__generated__/ShowDocumentViewPublishMutation.graphql"; import { ShowDocumentViewCreateDraftMutation } from "./__generated__/ShowDocumentViewCreateDraftMutation.graphql"; import { ShowDocumentViewUpdateDocumentMutation } from "./__generated__/ShowDocumentViewUpdateDocumentMutation.graphql"; -import { ShowDocumentViewUpdateDocumentTypeMutation } from "./__generated__/ShowDocumentViewUpdateDocumentTypeMutation.graphql"; +import { ShowDocumentViewGenerateChangelogMutation } from "./__generated__/ShowDocumentViewGenerateChangelogMutation.graphql"; import type { DocumentType } from "./__generated__/DocumentListViewCreateMutation.graphql"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; @@ -90,6 +90,10 @@ const documentViewQuery = graphql` content changelog publishedAt + title + owner { + fullName + } publishedBy { fullName } @@ -114,6 +118,7 @@ const publishDocumentVersionMutation = graphql` id status publishedAt + changelog publishedBy { fullName } @@ -144,6 +149,7 @@ const updateDocumentMutation = graphql` document { id documentType + title owner { id fullName @@ -154,6 +160,14 @@ const updateDocumentMutation = graphql` } `; +const generateChangelogMutation = graphql` + mutation ShowDocumentViewGenerateChangelogMutation($input: GenerateDocumentChangelogInput!) { + generateDocumentChangelog(input: $input) { + changelog + } + } +`; + function ShowDocumentContent({ queryRef, }: { @@ -176,8 +190,18 @@ function ShowDocumentContent({ const [isSignaturesModalOpen, setIsSignaturesModalOpen] = useState(false); const [isEditingOwner, setIsEditingOwner] = useState(false); const [isEditingType, setIsEditingType] = useState(false); + const [isEditingTitle, setIsEditingTitle] = useState(false); + const [editedTitle, setEditedTitle] = useState(documentValue.title || ''); + const [isPublishDialogOpen, setIsPublishDialogOpen] = useState(false); + const [publishChangelog, setPublishChangelog] = useState(''); + const [isGeneratingChangelog, setIsGeneratingChangelog] = useState(false); const printContentRef = useRef(null); + // Keep editedTitle in sync with documentValue.title + useEffect(() => { + setEditedTitle(documentValue.title || ''); + }, [documentValue.title]); + const [publishDraft, isPublishInFlight] = useMutation(publishDocumentVersionMutation); const [createDraft, isCreateDraftInFlight] = @@ -186,6 +210,7 @@ function ShowDocumentContent({ ); const [updateDocument, isUpdatingDocument] = useMutation(updateDocumentMutation); + const [generateChangelog] = useMutation(generateChangelogMutation); const latestVersionEdge = documentValue.latestVersion?.edges[0]; const latestVersionNode = latestVersionEdge?.node; @@ -300,12 +325,57 @@ function ShowDocumentContent({ // Navigate to publish flow const handlePublish = useCallback(() => { + setIsPublishDialogOpen(true); + setPublishChangelog(""); + + // Generate changelog + setIsGeneratingChangelog(true); + + generateChangelog({ + variables: { + input: { + documentId: documentValue.id, + }, + }, + onCompleted: (response, errors) => { + setIsGeneratingChangelog(false); + if (errors) { + toast({ + title: "Error", + description: errors[0]?.message || "An unknown error occurred", + variant: "destructive", + }); + return; + } + + const generatedChangelog = response.generateDocumentChangelog.changelog; + setPublishChangelog(prev => { + if (prev.trim()) { + return `${prev}\n${generatedChangelog}`; + } + return generatedChangelog; + }); + }, + onError: (error) => { + setIsGeneratingChangelog(false); + toast({ + title: "Error", + description: error.message || "An unknown error occurred", + variant: "destructive", + }); + }, + }); + }, [documentValue.id, generateChangelog, toast]); + + // Confirm publish + const confirmPublish = useCallback(() => { if (!documentValue.id) return; publishDraft({ variables: { input: { documentId: documentValue.id, + changelog: publishChangelog, }, }, onCompleted: (_, errors) => { @@ -323,6 +393,7 @@ function ShowDocumentContent({ description: `The document has been published successfully`, }); + setIsPublishDialogOpen(false); // Reload the query to refresh the data loadQuery({ documentId: documentValue.id, organizationId: organizationId! }); }, @@ -334,7 +405,7 @@ function ShowDocumentContent({ }); }, }); - }, [documentValue.id, publishDraft, toast, loadQuery]); + }, [documentValue.id, publishDraft, toast, loadQuery, publishChangelog, organizationId]); // Open version history modal const handleVersionHistoryClick = useCallback(() => { @@ -658,7 +729,84 @@ function ShowDocumentContent({
- Document Title: {documentValue.title} +
+ Document Title: + {isEditingTitle ? ( +
+ setEditedTitle(e.target.value)} + placeholder="Enter document title" + /> + + +
+ ) : ( +
+ {documentValue.title} + +
+ )} +
Version: {latestVersionNode.version || "N/A"} @@ -826,6 +974,50 @@ function ShowDocumentContent({ + + {/* Publish Confirmation Dialog */} + + + + Publish Document + + Please review and edit the changelog before publishing the document. + + +
+ +