Show success/failed state for workspace buttons with additional options (#19535)
* also show success/failed state when button have additional options * rename method * clear timeout
This commit is contained in:
@@ -78,6 +78,8 @@ export class UmbWorkspaceActionElement<
|
||||
@state()
|
||||
private _items: Array<UmbExtensionElementAndApiInitializer<ManifestWorkspaceActionMenuItem>> = [];
|
||||
|
||||
#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;
|
||||
|
||||
Reference in New Issue
Block a user