From a4e75f40d0ed5cf77ba037645d63b4d71005439f Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 28 Oct 2024 11:41:45 +0100 Subject: [PATCH] Hotfix: Publish with decendants structure reload (#2486) * ensure we always have the latest variant data * use enum value * Update document-tree-item.element.ts * only dispatch event if there is no error * reload structure after publish with descendants * only request update if it succeeds * rename private method --- .../entity-actions/unpublish.action.ts | 16 ++++--- .../tree-item/document-tree-item.element.ts | 17 +++++-- .../workspace/document-workspace.context.ts | 47 ++++++++++++++----- 3 files changed, 56 insertions(+), 24 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/unpublish.action.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/unpublish.action.ts index ff9d645a17..46d3471ea3 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/unpublish.action.ts +++ b/src/Umbraco.Web.UI.Client/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); + } } } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts index 3c5c94c536..634f3d8bad 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/tree/tree-item/document-tree-item.element.ts @@ -1,4 +1,5 @@ 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'; @@ -31,7 +32,7 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase { this._currentCulture = value; - this._variant = this.#getVariant(value); + this._variant = this.#findVariant(value); }); } @@ -41,7 +42,7 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase x.culture === culture); } @@ -56,16 +57,22 @@ export class UmbDocumentTreeItemElement extends UmbTreeItemElementBase ({ 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() { @@ -832,6 +834,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); @@ -853,15 +861,30 @@ export class UmbDocumentWorkspaceContext if (!variantIds.length) return; - // TODO: Validate content & Save changes for the selected variants — This was how it worked in v.13 [NL] - - 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() {