diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/rename/rename-repository-base.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/rename/rename-repository-base.ts index aa242fbc3a..39a0a75d0c 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/rename/rename-repository-base.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/rename/rename-repository-base.ts @@ -1,6 +1,5 @@ import { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import { UMB_NOTIFICATION_CONTEXT_TOKEN, UmbNotificationContext } from '@umbraco-cms/backoffice/notification'; -import { UMB_ACTION_EVENT_CONTEXT, UmbActionEvent, UmbActionEventContext } from '@umbraco-cms/backoffice/action'; import { UmbRepositoryBase } from '@umbraco-cms/backoffice/repository'; import { UmbRenameDataSource, UmbRenameDataSourceConstructor } from '@umbraco-cms/backoffice/entity-action'; import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'; @@ -10,7 +9,6 @@ export abstract class UmbRenameRepositoryBase; #renameSource: UmbRenameDataSource; #notificationContext?: UmbNotificationContext; - #actionEventContext?: UmbActionEventContext; #init: Promise; constructor( @@ -29,10 +27,6 @@ export abstract class UmbRenameRepositoryBase { this.#notificationContext = instance; }).asPromise(), - - this.consumeContext(UMB_ACTION_EVENT_CONTEXT, (instance) => { - this.#actionEventContext = instance; - }).asPromise(), ]); } @@ -48,9 +42,6 @@ export abstract class UmbRenameRepositoryBase { - this.#actionEventContext = instance; - this.#listen(); - }); + new UmbStoreConnector( + host, + this, + UMB_STYLESHEET_DETAIL_STORE_CONTEXT, + (item) => this.#createTreeItemMapper(item), + (item) => this.#updateTreeItemMapper(item), + ); } - #listen() { - // TODO: add event class to remove the magic strings - this.#actionEventContext?.addEventListener('detail-create-success', this.#onCreated as EventListener); - this.#actionEventContext?.addEventListener('detail-save-success', this.#onSaved as EventListener); - this.#actionEventContext?.addEventListener('detail-delete-success', this.#onDeleted as EventListener); - } + // TODO: revisit this when we have decided on detail model sizes + #createTreeItemMapper = (item: UmbStylesheetDetailModel) => { + const treeItem: UmbStylesheetTreeItemModel = { + unique: item.unique, + parentUnique: item.parentUnique, + entityType: UMB_STYLESHEET_ENTITY_TYPE, + name: item.name, + hasChildren: false, + isContainer: false, + isFolder: false, + }; - #stopListening() { - this.#actionEventContext?.removeEventListener('detail-create-success', this.#onCreated as EventListener); - this.#actionEventContext?.removeEventListener('detail-save-success', this.#onSaved as EventListener); - this.#actionEventContext?.removeEventListener('detail-delete-success', this.#onDeleted as EventListener); - } - - #onCreated = (event: UmbActionEvent) => { - // the item doesn't exist yet, so we reload the parent - const eventParentUnique = event.getParentUnique(); - this.#treeRepository.requestTreeItemsOf(eventParentUnique); + return treeItem; }; - #onSaved = (event: UmbActionEvent) => { - // only reload the parent if the item is already in the store - const eventUnique = event.getUnique(); - const storeItem = this.getItems([eventUnique])?.[0]; - - /* we need to remove the store because the unique (path) can have changed. - and it will therefore not update the correct item but append a new. */ - if (storeItem) { - this.removeItem(eventUnique); - this.#treeRepository.requestTreeItemsOf(storeItem.parentUnique); - } + // TODO: revisit this when we have decided on detail model sizes + #updateTreeItemMapper = (item: UmbStylesheetDetailModel) => { + return { + name: item.name, + }; }; - - #onDeleted = (event: UmbActionEvent) => { - this.removeItem(event.getUnique()); - }; - - onDestroy() { - this.#stopListening(); - } } export const UMB_STYLESHEET_TREE_STORE_CONTEXT = new UmbContextToken('UmbStylesheetTreeStore');