Skip to content

Commit 75ee1e6

Browse files
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
1 parent b7be95b commit 75ee1e6

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

src/Umbraco.Web.UI.Client/src/packages/core/workspace/components/workspace-action/default/workspace-action-default-kind.element.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export class UmbWorkspaceActionElement<
7878
@state()
7979
private _items: Array<UmbExtensionElementAndApiInitializer<ManifestWorkspaceActionMenuItem>> = [];
8080

81+
#buttonStateResetTimeoutId: number | null = null;
82+
8183
/**
8284
* Create a list of original and overwritten aliases of workspace actions for the action.
8385
*/
@@ -115,16 +117,14 @@ export class UmbWorkspaceActionElement<
115117
try {
116118
if (!this.#api) throw new Error('No api defined');
117119
await this.#api.execute();
118-
if (!this._additionalOptions) {
119-
this._buttonState = 'success';
120-
}
120+
this._buttonState = 'success';
121+
this.#initButtonStateReset();
121122
} catch (reason) {
122123
if (reason) {
123124
console.warn(reason);
124125
}
125-
if (!this._additionalOptions) {
126-
this._buttonState = 'failed';
127-
}
126+
this._buttonState = 'failed';
127+
this.#initButtonStateReset();
128128
}
129129
}
130130
this.dispatchEvent(new UmbActionExecutedEvent());
@@ -140,6 +140,23 @@ export class UmbWorkspaceActionElement<
140140
);
141141
}
142142

143+
#initButtonStateReset() {
144+
/* When the button has additional options, we do not show the waiting state.
145+
Therefore, we need to ensure the button state is reset, so we are able to show the success state again. */
146+
this.#clearButtonStateResetTimeout();
147+
148+
this.#buttonStateResetTimeoutId = window.setTimeout(() => {
149+
this._buttonState = undefined;
150+
}, 2000);
151+
}
152+
153+
#clearButtonStateResetTimeout() {
154+
if (this.#buttonStateResetTimeoutId !== null) {
155+
clearTimeout(this.#buttonStateResetTimeoutId);
156+
this.#buttonStateResetTimeoutId = null;
157+
}
158+
}
159+
143160
#observeExtensions(aliases: string[]): void {
144161
this.#extensionsController?.destroy();
145162
this.#extensionsController = new UmbExtensionsElementAndApiInitializer<
@@ -192,6 +209,11 @@ export class UmbWorkspaceActionElement<
192209
() => this.#renderButton(),
193210
);
194211
}
212+
213+
override disconnectedCallback(): void {
214+
super.disconnectedCallback();
215+
this.#clearButtonStateResetTimeout();
216+
}
195217
}
196218

197219
export default UmbWorkspaceActionElement;

0 commit comments

Comments
 (0)