Compare commits

...
7 Commits
2 changed files with 30 additions and 23 deletions
@@ -23,7 +23,6 @@ import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository';
export abstract class UmbRecycleBinRepositoryBase extends UmbRepositoryBase implements UmbRecycleBinRepository {
#recycleBinSource: UmbRecycleBinDataSource;
#notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE;
#requestTrashSuccessNotification?: UmbNotificationHandler;
#requestRestoreSuccessNotification?: UmbNotificationHandler;
/**
@@ -48,15 +47,7 @@ export abstract class UmbRecycleBinRepositoryBase extends UmbRepositoryBase impl
* @memberof UmbRecycleBinRepositoryBase
*/
async requestTrash(args: UmbRecycleBinTrashRequestArgs) {
const { error } = await this.#recycleBinSource.trash(args);
if (!error) {
this.#requestTrashSuccessNotification?.close();
const notification = { data: { message: `Trashed` } };
this.#requestTrashSuccessNotification = this.#notificationContext?.peek('positive', notification);
}
return { error };
return this.#recycleBinSource.trash(args);
}
/**
@@ -69,6 +60,7 @@ export abstract class UmbRecycleBinRepositoryBase extends UmbRepositoryBase impl
const { error } = await this.#recycleBinSource.restore(args);
if (!error) {
// TODO: keep this notification until we refresh the tree/structure correctly after the action
this.#requestRestoreSuccessNotification?.close();
const notification = { data: { message: `Restored` } };
this.#requestRestoreSuccessNotification = this.#notificationContext?.peek('positive', notification);
@@ -83,13 +75,6 @@ export abstract class UmbRecycleBinRepositoryBase extends UmbRepositoryBase impl
* @memberof UmbRecycleBinRepositoryBase
*/
async requestEmpty() {
const { error } = await this.#recycleBinSource.empty();
if (!error) {
const notification = { data: { message: `Recycle Bin Emptied` } };
this.#notificationContext?.peek('positive', notification);
}
return this.#recycleBinSource.empty();
}
@@ -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;