From 2b24b40a755c1fe4d13848632726d18108cf52ca Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Tue, 4 Mar 2025 09:54:38 +0100 Subject: [PATCH] V15: Workspace buttons cannot be overwritten in all cases (#18525) * fix: consider that overwrites can be strings OR arrays * chore: formatting * chore(mock): use correct javascript for mock plugins * chore: uses intersection helper method to save on code * fix: should work without requesting extra update to the the extensions controller refreshing the state --- .../custom-bundle-package/index.js | 4 +- .../workspace-action-menu.element.ts | 54 +++++++++---------- .../workspace-action-default-kind.element.ts | 13 +++-- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/public-assets/App_Plugins/custom-bundle-package/index.js b/src/Umbraco.Web.UI.Client/public-assets/App_Plugins/custom-bundle-package/index.js index 79a68d028c..ba0e344d9b 100644 --- a/src/Umbraco.Web.UI.Client/public-assets/App_Plugins/custom-bundle-package/index.js +++ b/src/Umbraco.Web.UI.Client/public-assets/App_Plugins/custom-bundle-package/index.js @@ -1,9 +1,9 @@ -export const manifests: Array = [ +export const manifests = [ { type: 'section', alias: 'MyBundle.Section.Custom', name: 'Custom Section', - js: '/App_Plugins/section.js', + element: () => import('./section.js'), weight: 1, meta: { label: 'My Bundle Section', diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action-menu/workspace-action-menu.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action-menu/workspace-action-menu.element.ts index 9f1e456f55..5085ef7a3c 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action-menu/workspace-action-menu.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action-menu/workspace-action-menu.element.ts @@ -27,34 +27,32 @@ export class UmbWorkspaceActionMenuElement extends UmbLitElement { } override render() { - return this.items?.length - ? html` - - - - - - - ${repeat( - this.items, - (ext) => ext.alias, - (ext) => ext.component, - )} - - - - ` - : nothing; + if (!this.items?.length) return nothing; + + return html` + + + + + + ${repeat( + this.items, + (ext) => ext.alias, + (ext) => ext.component, + )} + + + `; } static override styles = [ diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action/default/workspace-action-default-kind.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action/default/workspace-action-default-kind.element.ts index 166a57e22f..54b4a164dd 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action/default/workspace-action-default-kind.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action/default/workspace-action-default-kind.element.ts @@ -13,6 +13,7 @@ import { type UmbExtensionElementAndApiInitializer, UmbExtensionsElementAndApiInitializer, } from '@umbraco-cms/backoffice/extension-api'; +import { stringOrStringArrayIntersects } from '@umbraco-cms/backoffice/utils'; import '../../workspace-action-menu/index.js'; @@ -38,7 +39,6 @@ export class UmbWorkspaceActionElement< this._href = value?.meta.href; this._additionalOptions = value?.meta.additionalOptions; this.#createAliases(); - this.requestUpdate('manifest', oldValue); } } public get manifest() { @@ -90,7 +90,10 @@ export class UmbWorkspaceActionElement< // TODO: This works on one level for now, which will be enough for the current use case. However, you can overwrite the overwrites, so we need to make this recursive. Perhaps we could move this to the extensions initializer. // Add overwrites so that we can show any previously registered actions on the original workspace action if (this.#manifest.overwrites) { - for (const alias of this.#manifest.overwrites) { + const overwrites = Array.isArray(this.#manifest.overwrites) + ? this.#manifest.overwrites + : [this.#manifest.overwrites]; + for (const alias of overwrites) { aliases.add(alias); } } @@ -145,11 +148,7 @@ export class UmbWorkspaceActionElement< umbExtensionsRegistry, 'workspaceActionMenuItem', ExtensionApiArgsMethod, - (action) => { - return Array.isArray(action.forWorkspaceActions) - ? action.forWorkspaceActions.some((alias) => aliases.includes(alias)) - : aliases.includes(action.forWorkspaceActions); - }, + (action) => stringOrStringArrayIntersects(action.forWorkspaceActions, aliases), (extensionControllers) => { this._items = extensionControllers; },