From c6f3f24995d00a6d27581d43751e5493898e281b Mon Sep 17 00:00:00 2001 From: leekelleher Date: Wed, 17 Jul 2024 11:48:10 +0100 Subject: [PATCH] Refactored Media Bulk MoveTo repository notification context --- .../move-to/repository/move-to.repository.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/media/media/entity-bulk-actions/move-to/repository/move-to.repository.ts b/src/Umbraco.Web.UI.Client/src/packages/media/media/entity-bulk-actions/move-to/repository/move-to.repository.ts index 016ff9c665..a8ea03a439 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/media/media/entity-bulk-actions/move-to/repository/move-to.repository.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/media/media/entity-bulk-actions/move-to/repository/move-to.repository.ts @@ -3,9 +3,19 @@ import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository'; import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification'; import type { UmbBulkMoveToRepository, UmbBulkMoveToRequestArgs } from '@umbraco-cms/backoffice/entity-bulk-action'; import type { UmbRepositoryErrorResponse } from '@umbraco-cms/backoffice/repository'; +import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; export class UmbBulkMoveToMediaRepository extends UmbRepositoryBase implements UmbBulkMoveToRepository { #moveSource = new UmbMoveMediaServerDataSource(this); + #notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE; + + constructor(host: UmbControllerHost) { + super(host); + + this.consumeContext(UMB_NOTIFICATION_CONTEXT, (notificationContext) => { + this.#notificationContext = notificationContext; + }); + } async requestBulkMoveTo(args: UmbBulkMoveToRequestArgs): Promise { let count = 0; @@ -15,18 +25,16 @@ export class UmbBulkMoveToMediaRepository extends UmbRepositoryBase implements U const { error } = await this.#moveSource.moveTo({ unique, destination }); if (error) { - const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT); const notification = { data: { message: error.message } }; - notificationContext.peek('danger', notification); + this.#notificationContext?.peek('danger', notification); } else { count++; } } if (count > 0) { - const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT); - const notification = { data: { message: `Moved ${count} media items` } }; - notificationContext.peek('positive', notification); + const notification = { data: { message: `Moved ${count} media ${count === 1 ? 'item' : 'items'}` } }; + this.#notificationContext?.peek('positive', notification); } return {};