Skip to content

Consolidate document draft management and add delete draft#1000

Open
SachaProbo wants to merge 1 commit intomainfrom
SachaProbo/document-draft-versions
Open

Consolidate document draft management and add delete draft#1000
SachaProbo wants to merge 1 commit intomainfrom
SachaProbo/document-draft-versions

Conversation

@SachaProbo
Copy link
Copy Markdown
Contributor

@SachaProbo SachaProbo commented Apr 7, 2026

Merge createDraftDocumentVersion, updateDocumentVersion, and deleteDraftDocumentVersion into the existing updateDocument mutation. The backend auto-creates a draft when title, content, classification, or type changes, updates an existing draft, and auto-deletes it when all fields revert to match the published version.

Add a new deleteDocumentDraft mutation (GraphQL, MCP) that takes a document ID and deletes the latest version if it is a draft (excluding the initial v0.1). Exposed in the actions dropdown before archive.


Summary by cubic

Consolidates all draft logic into updateDocument and adds deleteDocumentDraft by document ID. The console edits the latest version; drafts are auto-created/updated/removed and the UI refreshes on version changes.

  • New Features

    • updateDocument now accepts title, content, classification, and documentType. It auto-creates/updates a draft on change and auto-deletes it when values match the published version. The payload includes documentVersion when a draft exists or is created.
    • Title, content, classification, and type editors now call updateDocument. The description editor is enabled only on the latest version when the document isn’t archived and you have core:document:update; historical versions are read-only. The layout uses store-and-network and refetches when a draft is created/deleted or the version changes.
    • Actions dropdown removes “Create draft”. It shows “Delete draft” only when the latest is a deletable draft (not v0.1) and you have core:document:delete-draft. It calls deleteDocumentDraft, refetches, and navigates to the description on success.
  • Migration

    • Remove createDraftDocumentVersion, updateDocumentVersion, and deleteDraftDocumentVersion (GraphQL and MCP). Use updateDocument for title/content/classification/type and deleteDocumentDraft with documentId. Permissions: use core:document:update and core:document:delete-draft (version-level update/delete-draft actions are removed).
    • CLI: remove probo document create-draft and probo document update-version. Use probo document update --title/--content/--document-type/--classification and probo document delete-draft <document-id>.

Written for commit bb21ffb. Summary will update on new commits.

@SachaProbo SachaProbo marked this pull request as draft April 7, 2026 13:42
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 15 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="e2e/console/document_version_test.go">

<violation number="1" location="e2e/console/document_version_test.go:550">
P1: Parallel subtests share and mutate one `result` variable, causing a data race and flaky tests.</violation>
</file>

<file name="apps/console/src/pages/organizations/documents/_components/DocumentActionsDropdown.tsx">

<violation number="1" location="apps/console/src/pages/organizations/documents/_components/DocumentActionsDropdown.tsx:208">
P1: After deleting a draft, the code no longer navigates away from a draft-version route, which can leave users on a URL referencing a deleted version.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@SachaProbo SachaProbo force-pushed the SachaProbo/document-draft-versions branch 6 times, most recently from 546d010 to e92c0fc Compare April 7, 2026 14:31
@SachaProbo SachaProbo marked this pull request as ready for review April 7, 2026 14:34
@SachaProbo
Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai please review

@cubic-dev-ai
Copy link
Copy Markdown

cubic-dev-ai bot commented Apr 7, 2026

@cubic-dev-ai please review

@SachaProbo I have started the AI code review. It will take a few minutes to complete.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 15 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="pkg/probo/document_service.go">

<violation number="1" location="pkg/probo/document_service.go:1611">
P2: Missing auto-delete check after creating a new draft. When the latest version is published and a new draft is created, the code does not verify whether the draft actually differs from the published version. If all non-nil request fields match the published values, an identical draft is left behind. The draft-exists branch handles this correctly—consider applying the same comparison logic here, or checking for actual field changes before creating the draft.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@SachaProbo SachaProbo requested a review from a team April 8, 2026 06:56
@SachaProbo SachaProbo force-pushed the SachaProbo/document-draft-versions branch 7 times, most recently from 446e6f5 to 625d167 Compare April 9, 2026 20:38
}

// Refetch layout when draft status changes (created or deleted)
// so the drawer and header reflect the current version.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if I start writing again during this call, do I lose this content after the refetch?

Copy link
Copy Markdown
Contributor Author

@SachaProbo SachaProbo Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refetch is there only for the edge case where the connection membership changes (draft created or deleted), not on every save. In those situation the page refetch and it is not really possible to writes during the refetch.

// so the drawer and header reflect the current version.
const draftReturned = !!data.updateDocument.documentVersion;
if (wasDraft !== draftReturned) {
onRefetch();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should we refetch instead of just updating the store?
If the mutation sends back needed data then the store should update itself without the need for refetch.

});

useEffect(() => {
if (draftDeletedAt > 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the use of this? Why do we need to refetch here, when a draft is deleted then we should navigate to the last available version if we were on the draft page. This should be enough without refetch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version is not in the url.

@SachaProbo SachaProbo force-pushed the SachaProbo/document-draft-versions branch 7 times, most recently from 9616ea4 to 1469d70 Compare April 13, 2026 14:41
@SachaProbo SachaProbo force-pushed the SachaProbo/document-draft-versions branch 4 times, most recently from df70de8 to a9393cd Compare April 13, 2026 16:33
Merge createDraftDocumentVersion, updateDocumentVersion, and
deleteDraftDocumentVersion into the existing updateDocument mutation.
The backend auto-creates a draft when title, content, classification,
or type changes, updates an existing draft, and auto-deletes it when
all fields revert to match the published version.

Add a new deleteDocumentDraft mutation (GraphQL, MCP) that takes a
document ID and deletes the latest version if it is a draft (excluding
the initial v0.1). Exposed in the actions dropdown before archive.

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
@SachaProbo SachaProbo force-pushed the SachaProbo/document-draft-versions branch from a9393cd to bb21ffb Compare April 13, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants