From 0eb6a160174cedf66e8179be855e0ca06fe5d6a7 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Thu, 9 Jan 2025 14:24:33 +0100 Subject: [PATCH] Reload children of destination after duplicate of content (#17878) * Reload children of destination after duplicate of content. * Revert changes to generic duplicate to action. * Don't assume entity type of duplicated item is the same as the destination. Instead treat as "document" unless destination unique is null, when it will be "document-root". * add todo back * remove console log --------- Co-authored-by: Mads Rasmussen --- .../duplicate/duplicate-document.action.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/duplicate/duplicate-document.action.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/duplicate/duplicate-document.action.ts index a0d46d1456..6b2872c074 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/duplicate/duplicate-document.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/entity-actions/duplicate/duplicate-document.action.ts @@ -1,8 +1,9 @@ +import { UMB_DOCUMENT_ENTITY_TYPE, UMB_DOCUMENT_ROOT_ENTITY_TYPE } from '../../entity.js'; import { UMB_DUPLICATE_DOCUMENT_MODAL } from './modal/index.js'; import { UmbDuplicateDocumentRepository } from './repository/index.js'; import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action'; -import { UmbEntityActionBase, UmbRequestReloadStructureForEntityEvent } from '@umbraco-cms/backoffice/entity-action'; +import { UmbEntityActionBase, UmbRequestReloadChildrenOfEntityEvent } from '@umbraco-cms/backoffice/entity-action'; export class UmbDuplicateDocumentEntityAction extends UmbEntityActionBase { override async execute() { @@ -32,22 +33,28 @@ export class UmbDuplicateDocumentEntityAction extends UmbEntityActionBase }); if (!error) { - this.#reloadMenu(); + this.#reloadMenu(destinationUnique); } } catch (error) { console.log(error); } } - async #reloadMenu() { + async #reloadMenu(destinationUnique: string | null) { const actionEventContext = await this.getContext(UMB_ACTION_EVENT_CONTEXT); - const event = new UmbRequestReloadStructureForEntityEvent({ - unique: this.args.unique, - entityType: this.args.entityType, + + // When duplicating, the destination entity type may or may not be the same as that of + // the item selected for duplication (that is available in this.args). + // For documents though, we know the entity type will be "document", unless we are duplicating + // to the root (when the destinationUnique will be null). + const destinationEntityType = destinationUnique === null ? UMB_DOCUMENT_ROOT_ENTITY_TYPE : UMB_DOCUMENT_ENTITY_TYPE; + + const event = new UmbRequestReloadChildrenOfEntityEvent({ + unique: destinationUnique, + entityType: destinationEntityType, }); actionEventContext.dispatchEvent(event); - // TODO: Reload destination } }