From 679c18c548739a7f44ae476d9ed7b8a13815275d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Wed, 1 Apr 2026 12:24:10 +0400 Subject: [PATCH] Fix create draft condition and delete draft connections handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Émile Ré --- .../_components/DocumentActionsDropdown.tsx | 21 +++++++++++++++---- .../DocumentVersionsDropdownMenu.tsx | 4 +++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/apps/console/src/pages/organizations/documents/_components/DocumentActionsDropdown.tsx b/apps/console/src/pages/organizations/documents/_components/DocumentActionsDropdown.tsx index a67235297..032f35c8d 100644 --- a/apps/console/src/pages/organizations/documents/_components/DocumentActionsDropdown.tsx +++ b/apps/console/src/pages/organizations/documents/_components/DocumentActionsDropdown.tsx @@ -41,8 +41,14 @@ const documentFragment = graphql` canArchive: permission(action: "core:document:archive") canUnarchive: permission(action: "core:document:unarchive") canDelete: permission(action: "core:document:delete") - versions(first: 20) { + versions(first: 1 orderBy: { field: CREATED_AT, direction: DESC }) { totalCount + edges { + node { + id + status + } + } } } `; @@ -151,6 +157,8 @@ export function DocumentActionsDropdownn(props: { const document = useFragment(documentFragment, documentFragmentRef); const version = useFragment(versionFragment, versionFragmentRef); + const lastVersion = document.versions.edges[0].node; + const hasDraft = lastVersion.status === "DRAFT"; const isDraft = version.status === "DRAFT"; const [createDraftDocumentVersion, isCreatingDraft] @@ -279,13 +287,18 @@ export function DocumentActionsDropdownn(props: { }; const handleDeleteDraft = () => { - const connectionId = ConnectionHandler.getConnectionID(document.id, "DocumentversionsDropdownMenu_versions"); + const versionsConnectionId = ConnectionHandler.getConnectionID(document.id, "DocumentversionsDropdownMenu_versions"); + const lastVersionConnectionId = ConnectionHandler.getConnectionID( + document.id, + "DocumentversionsDropdownMenu_lastVersion", + { orderBy: { field: "CREATED_AT", direction: "DESC" } }, + ); confirm( () => deleteDraftDocumentVersion({ variables: { input: { documentVersionId: version.id }, - connections: [connectionId], + connections: [versionsConnectionId, lastVersionConnectionId], }, onSuccess() { if (versionId) { @@ -348,7 +361,7 @@ export function DocumentActionsDropdownn(props: { defaultEmail={defaultEmail} /> - {document.canUpdate && !isDraft && ( + {document.canUpdate && !hasDraft && (