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..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. */ @@ -115,16 +117,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.#initButtonStateReset(); } catch (reason) { if (reason) { console.warn(reason); } - if (!this._additionalOptions) { - this._buttonState = 'failed'; - } + this._buttonState = 'failed'; + this.#initButtonStateReset(); } } this.dispatchEvent(new UmbActionExecutedEvent()); @@ -140,6 +140,23 @@ export class UmbWorkspaceActionElement< ); } + #initButtonStateReset() { + /* 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< @@ -192,6 +209,11 @@ export class UmbWorkspaceActionElement< () => this.#renderButton(), ); } + + override disconnectedCallback(): void { + super.disconnectedCallback(); + this.#clearButtonStateResetTimeout(); + } } export default UmbWorkspaceActionElement;