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. + + +
+ +