From 6059289766d5720486e437f969d43aad95697054 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Thu, 12 Jun 2025 11:16:31 +0200 Subject: [PATCH 1/3] also show success/failed state when button have additional options --- .../workspace-action-default-kind.element.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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 5568fec2f188..11268a542eb5 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 @@ -115,16 +115,14 @@ export class UmbWorkspaceActionElement< try { if (!this.#api) throw new Error('No api defined'); await this.#api.execute(); - if (!this._additionalOptions) { - this._buttonState = 'success'; - } + this._buttonState = 'success'; + this.#initResetButtonState(); } catch (reason) { if (reason) { console.warn(reason); } - if (!this._additionalOptions) { - this._buttonState = 'failed'; - } + this._buttonState = 'failed'; + this.#initResetButtonState(); } } this.dispatchEvent(new UmbActionExecutedEvent()); @@ -140,6 +138,14 @@ export class UmbWorkspaceActionElement< ); } + #initResetButtonState() { + /* When the button have additional option we do not show the waiting state. + Therefore we need to ensure the button state is reset, so we are able to show the success state again. */ + setTimeout(() => { + this._buttonState = undefined; + }, 2000); + } + #observeExtensions(aliases: string[]): void { this.#extensionsController?.destroy(); this.#extensionsController = new UmbExtensionsElementAndApiInitializer< From 15653e85271093fb2158c0132dec73afa5fd996a Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Thu, 12 Jun 2025 11:18:14 +0200 Subject: [PATCH 2/3] rename method --- .../default/workspace-action-default-kind.element.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 11268a542eb5..06fc529d581c 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 @@ -116,13 +116,13 @@ export class UmbWorkspaceActionElement< if (!this.#api) throw new Error('No api defined'); await this.#api.execute(); this._buttonState = 'success'; - this.#initResetButtonState(); + this.#initButtonStateReset(); } catch (reason) { if (reason) { console.warn(reason); } this._buttonState = 'failed'; - this.#initResetButtonState(); + this.#initButtonStateReset(); } } this.dispatchEvent(new UmbActionExecutedEvent()); @@ -138,7 +138,7 @@ export class UmbWorkspaceActionElement< ); } - #initResetButtonState() { + #initButtonStateReset() { /* When the button have additional option we do not show the waiting state. Therefore we need to ensure the button state is reset, so we are able to show the success state again. */ setTimeout(() => { From 95115fcc94bc9ba46573cb2726988509f4709a4f Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Thu, 12 Jun 2025 12:43:28 +0200 Subject: [PATCH 3/3] clear timeout --- .../workspace-action-default-kind.element.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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 06fc529d581c..019657e5d7a5 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 @@ -78,6 +78,8 @@ export class UmbWorkspaceActionElement< @state() private _items: Array> = []; + #buttonStateResetTimeoutId: number | null = null; + /** * Create a list of original and overwritten aliases of workspace actions for the action. */ @@ -139,13 +141,22 @@ export class UmbWorkspaceActionElement< } #initButtonStateReset() { - /* When the button have additional option we do not show the waiting state. - Therefore we need to ensure the button state is reset, so we are able to show the success state again. */ - setTimeout(() => { + /* When the button has additional options, we do not show the waiting state. + Therefore, we need to ensure the button state is reset, so we are able to show the success state again. */ + this.#clearButtonStateResetTimeout(); + + this.#buttonStateResetTimeoutId = window.setTimeout(() => { this._buttonState = undefined; }, 2000); } + #clearButtonStateResetTimeout() { + if (this.#buttonStateResetTimeoutId !== null) { + clearTimeout(this.#buttonStateResetTimeoutId); + this.#buttonStateResetTimeoutId = null; + } + } + #observeExtensions(aliases: string[]): void { this.#extensionsController?.destroy(); this.#extensionsController = new UmbExtensionsElementAndApiInitializer< @@ -198,6 +209,11 @@ export class UmbWorkspaceActionElement< () => this.#renderButton(), ); } + + override disconnectedCallback(): void { + super.disconnectedCallback(); + this.#clearButtonStateResetTimeout(); + } } export default UmbWorkspaceActionElement;