From ec5a5dfa3e586d7e1d50d2ff6d4d04e1b0b10870 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Sun, 24 Mar 2024 19:32:18 +0100 Subject: [PATCH] render first entity action next to more button --- .../entity-actions-bundle.element.ts | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/components/entity-actions-bundle/entity-actions-bundle.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/components/entity-actions-bundle/entity-actions-bundle.element.ts index 01648402da..16da646483 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/components/entity-actions-bundle/entity-actions-bundle.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/components/entity-actions-bundle/entity-actions-bundle.element.ts @@ -1,9 +1,11 @@ +import type { UmbEntityAction } from '@umbraco-cms/backoffice/entity-action'; import { html, nothing, customElement, property, state } from '@umbraco-cms/backoffice/external/lit'; -import { map } from '@umbraco-cms/backoffice/external/rxjs'; import type { UmbSectionSidebarContext } from '@umbraco-cms/backoffice/section'; import { UMB_SECTION_SIDEBAR_CONTEXT } from '@umbraco-cms/backoffice/section'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; -import { ManifestEntityAction, umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'; +import type { ManifestEntityAction } from '@umbraco-cms/backoffice/extension-registry'; +import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'; +import { createExtensionApi } from '@umbraco-cms/backoffice/extension-api'; @customElement('umb-entity-actions-bundle') export class UmbEntityActionsBundleElement extends UmbLitElement { @@ -30,7 +32,10 @@ export class UmbEntityActionsBundleElement extends UmbLitElement { private _hasActions = false; @state() - private _firstAction?: ManifestEntityAction; + private _firstActionManifest?: ManifestEntityAction; + + @state() + private _firstActionApi?: UmbEntityAction; #sectionSidebarContext?: UmbSectionSidebarContext; @@ -45,35 +50,50 @@ export class UmbEntityActionsBundleElement extends UmbLitElement { #observeEntityActions() { this.observe( umbExtensionsRegistry.byType('entityAction'), - (manifests) => { + async (manifests) => { const actions = manifests.filter((manifest) => manifest.forEntityTypes.includes(this.entityType!)); this._hasActions = actions.length > 0; - this._firstAction = this._hasActions ? actions[0] : undefined; + this._firstActionManifest = this._hasActions ? actions[0] : undefined; + if (!this._firstActionManifest) return; + this._firstActionApi = await createExtensionApi(this, this._firstActionManifest, [ + { unique: this.unique, entityType: this.entityType }, + ]); }, 'umbEntityActionsObserver', ); } - private _openActions() { + #openContextMenu() { if (!this.entityType) throw new Error('Entity type is not defined'); if (this.unique === undefined) throw new Error('Unique is not defined'); this.#sectionSidebarContext?.toggleContextMenu(this.entityType, this.unique, this.label); } + async #onFirstActionClick(event: PointerEvent) { + event.stopPropagation(); + await this._firstActionApi?.execute(); + } + render() { return html` ${this._hasActions - ? html` - - - - - - - ` + ? html` ${this.#renderFirstAction()} ${this.#renderMore()} ` : nothing} `; } + + #renderMore() { + return html` + + `; + } + + #renderFirstAction() { + if (!this._firstActionApi) return nothing; + return html` + + `; + } } declare global {