Skip to content

Show success/failed state for workspace buttons with additional options #19535

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
@state()
private _items: Array<UmbExtensionElementAndApiInitializer<ManifestWorkspaceActionMenuItem>> = [];

#buttonStateResetTimeoutId: number | null = null;

/**
* Create a list of original and overwritten aliases of workspace actions for the action.
*/
Expand Down Expand Up @@ -115,16 +117,14 @@
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();

Check notice on line 127 in src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action/default/workspace-action-default-kind.element.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ No longer an issue: Complex Method

UmbWorkspaceActionElement.onClick is no longer above the threshold for cyclomatic complexity
}
}
this.dispatchEvent(new UmbActionExecutedEvent());
Expand All @@ -140,6 +140,23 @@
);
}

#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<
Expand Down Expand Up @@ -192,6 +209,11 @@
() => this.#renderButton(),
);
}

override disconnectedCallback(): void {
super.disconnectedCallback();
this.#clearButtonStateResetTimeout();
}
}

export default UmbWorkspaceActionElement;
Expand Down
Loading