From e2d4f3e0de174e61da5e71d90a9576acb0fae735 Mon Sep 17 00:00:00 2001 From: leekelleher Date: Thu, 21 Nov 2024 12:56:39 +0000 Subject: [PATCH] Passes `entityType` to bulk actions --- .../collection-selection-actions.element.ts | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/collection/components/collection-selection-actions.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/collection/components/collection-selection-actions.element.ts index 8beb70b56c..389f1d22ac 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/collection/components/collection-selection-actions.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/collection/components/collection-selection-actions.element.ts @@ -1,20 +1,29 @@ import { UMB_COLLECTION_CONTEXT } from '../default/index.js'; -import type { UmbActionExecutedEvent } from '@umbraco-cms/backoffice/event'; -import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; -import { css, html, nothing, customElement, state } from '@umbraco-cms/backoffice/external/lit'; +import { css, customElement, html, nothing, state } from '@umbraco-cms/backoffice/external/lit'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; +import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; +import { UMB_ENTITY_CONTEXT } from '@umbraco-cms/backoffice/entity'; import type { ManifestEntityBulkAction, MetaEntityBulkAction } from '@umbraco-cms/backoffice/extension-registry'; +import type { UmbActionExecutedEvent } from '@umbraco-cms/backoffice/event'; /** - * - * @param manifest + * Generates API arguments for the given manifest. + * @param {string | null | undefined} entityType - The type of the entity. + * @param {ManifestEntityBulkAction} manifest - The manifest object from the extension. + * @returns {Array} An array with the meta object from the manifest. */ -function apiArgsMethod(manifest: ManifestEntityBulkAction) { - return [{ meta: manifest.meta }] as unknown[]; +function apiArgsMethod( + entityType: string | null | undefined, + manifest: ManifestEntityBulkAction, +): Array { + return [{ entityType, meta: manifest.meta }] as Array; } @customElement('umb-collection-selection-actions') export class UmbCollectionSelectionActionsElement extends UmbLitElement { + @state() + private _entityType?: string | null; + @state() private _totalItems = 0; @@ -34,6 +43,10 @@ export class UmbCollectionSelectionActionsElement extends UmbLitElement { this._collectionContext = instance; this._observeCollectionContext(); }); + + this.consumeContext(UMB_ENTITY_CONTEXT, (entityContext) => { + this._entityType = entityContext.getEntityType(); + }); } private _handleKeyDown(event: KeyboardEvent) { @@ -96,7 +109,7 @@ export class UmbCollectionSelectionActionsElement extends UmbLitElement { type="entityBulkAction" default-element="umb-entity-bulk-action" .apiProps=${this._apiProps} - .apiArgs=${apiArgsMethod} + .apiArgs=${(manifest: ManifestEntityBulkAction) => apiArgsMethod(this._entityType, manifest)} @action-executed=${this.#onActionExecuted}>