From 242baeae8ded4ab0e9d3ee699167dbbe7e0a1e31 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Wed, 28 Feb 2024 15:01:33 +0100 Subject: [PATCH] modernize entity-action.element --- .../entity-action/entity-action.element.ts | 65 ++++++++++--------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/entity-action.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/entity-action.element.ts index 14cab2580b..f08dd18cd3 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/entity-action.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/entity-action.element.ts @@ -7,58 +7,61 @@ import { createExtensionApi } from '@umbraco-cms/backoffice/extension-api'; @customElement('umb-entity-action') export class UmbEntityActionElement extends UmbLitElement { - private _entityType?: string | null; + #entityType?: string | null; + @property({ type: String }) - public get entityType() { - return this._entityType; - } public set entityType(value: string | undefined | null) { - const oldValue = this._entityType; - this._entityType = value; - if (oldValue !== this._entityType) { + const oldValue = this.#entityType; + this.#entityType = value; + if (oldValue !== this.#entityType) { this.#createApi(); this.requestUpdate('entityType', oldValue); } } - - private _unique?: string | null; - @property({ type: String }) - public get unique() { - return this._unique; + public get entityType() { + return this.#entityType; } + + #unique?: string | null; + + @property({ type: String }) public set unique(value: string | undefined | null) { - const oldValue = this._unique; - this._unique = value; - if (oldValue !== this._unique) { + const oldValue = this.#unique; + this.#unique = value; + if (oldValue !== this.#unique) { this.#createApi(); this.requestUpdate('unique', oldValue); } } - - private _manifest?: ManifestEntityAction; - @property({ type: Object, attribute: false }) - public get manifest() { - return this._manifest; + public get unique() { + return this.#unique; } + + #manifest?: ManifestEntityAction; + + @property({ type: Object, attribute: false }) public set manifest(value: ManifestEntityAction | undefined) { if (!value) return; - const oldValue = this._manifest; - this._manifest = value; - if (oldValue !== this._manifest) { + const oldValue = this.#manifest; + this.#manifest = value; + if (oldValue !== this.#manifest) { this.#createApi(); this.requestUpdate('manifest', oldValue); } } + public get manifest() { + return this.#manifest; + } async #createApi() { // only create the api if we have all the required properties - if (!this._manifest) return; - if (this._unique === undefined) return; - if (!this._entityType) return; + if (!this.#manifest) return; + if (this.#unique === undefined) return; + if (!this.#entityType) return; - this.#api = await createExtensionApi(this._manifest, [ + this.#api = await createExtensionApi(this.#manifest, [ this, - this._manifest.meta.repositoryAlias, + this.#manifest.meta.repositoryAlias, this.unique, this.entityType, ]); @@ -89,12 +92,12 @@ export class UmbEntityActionElement extends UmbLitElement { render() { return html` - ${this._manifest?.meta.icon - ? html`` + ${this.manifest?.meta.icon + ? html`` : nothing} `;