From 11cd1426b1b393c482a01b254dff7954c6fa68e3 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 25 Oct 2024 11:29:10 +0200 Subject: [PATCH 1/7] ensure we always have the latest variant data --- .../documents/tree/tree-item/document-tree-item.element.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts b/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts index 3c5c94c536..79070a0341 100644 --- a/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts +++ b/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts @@ -56,6 +56,9 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase Date: Fri, 25 Oct 2024 11:35:12 +0200 Subject: [PATCH 2/7] use enum value --- .../documents/tree/tree-item/document-tree-item.element.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts b/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts index 79070a0341..949cc7a358 100644 --- a/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts +++ b/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts @@ -1,3 +1,4 @@ +import { DocumentVariantStateModel } from '@umbraco-cms/backoffice/external/backend-api'; import type { UmbDocumentTreeItemModel, UmbDocumentTreeItemVariantModel } from '../types.js'; import { css, html, nothing, customElement, state, classMap } from '@umbraco-cms/backoffice/external/lit'; import type { UmbAppLanguageContext } from '@umbraco-cms/backoffice/language'; @@ -65,13 +66,13 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase Date: Fri, 25 Oct 2024 11:35:32 +0200 Subject: [PATCH 3/7] Update document-tree-item.element.ts --- .../documents/tree/tree-item/document-tree-item.element.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts b/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts index 949cc7a358..a73e55b78e 100644 --- a/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts +++ b/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts @@ -1,5 +1,5 @@ -import { DocumentVariantStateModel } from '@umbraco-cms/backoffice/external/backend-api'; import type { UmbDocumentTreeItemModel, UmbDocumentTreeItemVariantModel } from '../types.js'; +import { DocumentVariantStateModel } from '@umbraco-cms/backoffice/external/backend-api'; import { css, html, nothing, customElement, state, classMap } from '@umbraco-cms/backoffice/external/lit'; import type { UmbAppLanguageContext } from '@umbraco-cms/backoffice/language'; import { UMB_APP_LANGUAGE_CONTEXT } from '@umbraco-cms/backoffice/language'; From 982a405e92aa72dbbd77a745ff75b7a9ff3497b5 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 25 Oct 2024 11:37:34 +0200 Subject: [PATCH 4/7] only dispatch event if there is no error --- .../documents/entity-actions/unpublish.action.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/packages/documents/documents/entity-actions/unpublish.action.ts b/src/packages/documents/documents/entity-actions/unpublish.action.ts index ff9d645a17..46d3471ea3 100644 --- a/src/packages/documents/documents/entity-actions/unpublish.action.ts +++ b/src/packages/documents/documents/entity-actions/unpublish.action.ts @@ -77,15 +77,17 @@ export class UmbUnpublishDocumentEntityAction extends UmbEntityActionBase if (variantIds.length) { const publishingRepository = new UmbDocumentPublishingRepository(this._host); - await publishingRepository.unpublish(this.args.unique, variantIds); + const { error } = await publishingRepository.unpublish(this.args.unique, variantIds); - const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT); - const event = new UmbRequestReloadStructureForEntityEvent({ - unique: this.args.unique, - entityType: this.args.entityType, - }); + if (!error) { + const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT); + const event = new UmbRequestReloadStructureForEntityEvent({ + unique: this.args.unique, + entityType: this.args.entityType, + }); - actionEventContext.dispatchEvent(event); + actionEventContext.dispatchEvent(event); + } } } } From 4372e2bdba1b8967b9144666636ce5ae4946c464 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 25 Oct 2024 12:10:33 +0200 Subject: [PATCH 5/7] reload structure after publish with descendants --- .../workspace/document-workspace.context.ts | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/packages/documents/documents/workspace/document-workspace.context.ts b/src/packages/documents/documents/workspace/document-workspace.context.ts index 6d4cbb73b6..270c5bd9f2 100644 --- a/src/packages/documents/documents/workspace/document-workspace.context.ts +++ b/src/packages/documents/documents/workspace/document-workspace.context.ts @@ -826,6 +826,12 @@ export class UmbDocumentWorkspaceContext } public async publishWithDescendants() { + const unique = this.getUnique(); + if (!unique) throw new Error('Unique is missing'); + + const entityType = this.getEntityType(); + if (!entityType) throw new Error('Entity type is missing'); + const { options, selected } = await this.#determineVariantOptions(); const modalManagerContext = await this.getContext(UMB_MODAL_MANAGER_CONTEXT); @@ -847,13 +853,30 @@ export class UmbDocumentWorkspaceContext if (!variantIds.length) return; - const unique = this.getUnique(); - if (!unique) throw new Error('Unique is missing'); - await this.publishingRepository.publishWithDescendants( + const { error } = await this.publishingRepository.publishWithDescendants( unique, variantIds, result.includeUnpublishedDescendants ?? false, ); + + if (!error) { + const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT); + + // request reload of this entity + const structureEvent = new UmbRequestReloadStructureForEntityEvent({ + entityType, + unique, + }); + + // request reload of the children + const childrenEvent = new UmbRequestReloadChildrenOfEntityEvent({ + entityType, + unique, + }); + + eventContext.dispatchEvent(structureEvent); + eventContext.dispatchEvent(childrenEvent); + } } async delete() { From 095163f1df4633e97a88d12be993f442123454ee Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 25 Oct 2024 12:19:41 +0200 Subject: [PATCH 6/7] only request update if it succeeds --- .../workspace/document-workspace.context.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/packages/documents/documents/workspace/document-workspace.context.ts b/src/packages/documents/documents/workspace/document-workspace.context.ts index 270c5bd9f2..79ebeffdcd 100644 --- a/src/packages/documents/documents/workspace/document-workspace.context.ts +++ b/src/packages/documents/documents/workspace/document-workspace.context.ts @@ -712,18 +712,20 @@ export class UmbDocumentWorkspaceContext await this.#performSaveOrCreate(variantIds, saveData); - await this.publishingRepository.publish( + const { error } = await this.publishingRepository.publish( unique, variantIds.map((variantId) => ({ variantId })), ); - const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT); - const event = new UmbRequestReloadStructureForEntityEvent({ - unique: this.getUnique()!, - entityType: this.getEntityType(), - }); + if (!error) { + const eventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT); + const event = new UmbRequestReloadStructureForEntityEvent({ + unique: this.getUnique()!, + entityType: this.getEntityType(), + }); - eventContext.dispatchEvent(event); + eventContext.dispatchEvent(event); + } } async #handleSave() { From 9dd78bfacbb1a3e8dd539e32d8ce298a121b4952 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 25 Oct 2024 12:27:11 +0200 Subject: [PATCH 7/7] rename private method --- .../tree/tree-item/document-tree-item.element.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts b/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts index a73e55b78e..634f3d8bad 100644 --- a/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts +++ b/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts @@ -32,7 +32,7 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase { this._currentCulture = value; - this._variant = this.#getVariant(value); + this._variant = this.#findVariant(value); }); } @@ -42,7 +42,7 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase x.culture === culture); } @@ -58,9 +58,9 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase