Fix create draft condition and delete draft connections handling
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -41,8 +41,14 @@ const documentFragment = graphql`
|
|||||||
canArchive: permission(action: "core:document:archive")
|
canArchive: permission(action: "core:document:archive")
|
||||||
canUnarchive: permission(action: "core:document:unarchive")
|
canUnarchive: permission(action: "core:document:unarchive")
|
||||||
canDelete: permission(action: "core:document:delete")
|
canDelete: permission(action: "core:document:delete")
|
||||||
versions(first: 20) {
|
versions(first: 1 orderBy: { field: CREATED_AT, direction: DESC }) {
|
||||||
totalCount
|
totalCount
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
id
|
||||||
|
status
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
@@ -151,6 +157,8 @@ export function DocumentActionsDropdownn(props: {
|
|||||||
const document = useFragment<DocumentActionsDropdown_documentFragment$key>(documentFragment, documentFragmentRef);
|
const document = useFragment<DocumentActionsDropdown_documentFragment$key>(documentFragment, documentFragmentRef);
|
||||||
const version = useFragment<DocumentActionsDropdown_versionFragment$key>(versionFragment, versionFragmentRef);
|
const version = useFragment<DocumentActionsDropdown_versionFragment$key>(versionFragment, versionFragmentRef);
|
||||||
|
|
||||||
|
const lastVersion = document.versions.edges[0].node;
|
||||||
|
const hasDraft = lastVersion.status === "DRAFT";
|
||||||
const isDraft = version.status === "DRAFT";
|
const isDraft = version.status === "DRAFT";
|
||||||
|
|
||||||
const [createDraftDocumentVersion, isCreatingDraft]
|
const [createDraftDocumentVersion, isCreatingDraft]
|
||||||
@@ -279,13 +287,18 @@ export function DocumentActionsDropdownn(props: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteDraft = () => {
|
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(
|
confirm(
|
||||||
() =>
|
() =>
|
||||||
deleteDraftDocumentVersion({
|
deleteDraftDocumentVersion({
|
||||||
variables: {
|
variables: {
|
||||||
input: { documentVersionId: version.id },
|
input: { documentVersionId: version.id },
|
||||||
connections: [connectionId],
|
connections: [versionsConnectionId, lastVersionConnectionId],
|
||||||
},
|
},
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
if (versionId) {
|
if (versionId) {
|
||||||
@@ -348,7 +361,7 @@ export function DocumentActionsDropdownn(props: {
|
|||||||
defaultEmail={defaultEmail}
|
defaultEmail={defaultEmail}
|
||||||
/>
|
/>
|
||||||
<ActionDropdown variant="secondary">
|
<ActionDropdown variant="secondary">
|
||||||
{document.canUpdate && !isDraft && (
|
{document.canUpdate && !hasDraft && (
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
onClick={handleCreateDraft}
|
onClick={handleCreateDraft}
|
||||||
icon={IconPencil}
|
icon={IconPencil}
|
||||||
|
|||||||
@@ -33,7 +33,9 @@ export const documentVersionsDropdownMenuQuery = graphql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
# We use this on /documents/:documentId
|
# We use this on /documents/:documentId
|
||||||
lastVersion: versions(first: 1 orderBy: { field: CREATED_AT, direction: DESC }) @skip(if: $versionSpecified) {
|
lastVersion: versions(first: 1 orderBy: { field: CREATED_AT, direction: DESC })
|
||||||
|
@skip(if: $versionSpecified)
|
||||||
|
@connection(key: "DocumentversionsDropdownMenu_lastVersion" filters: ["orderBy"]) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
id
|
id
|
||||||
|
|||||||
Reference in New Issue
Block a user