diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/media/media/repository/media.repository.ts b/src/Umbraco.Web.UI.Client/src/backoffice/media/media/repository/media.repository.ts index cacafa2709..ab2d992be6 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/media/media/repository/media.repository.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/media/media/repository/media.repository.ts @@ -14,8 +14,6 @@ import type { UmbTreeRepository } from 'libs/repository/tree-repository.interfac type ItemDetailType = MediaDetails; export class UmbMediaRepository implements UmbTreeRepository, UmbDetailRepository { - #init!: Promise; - #host: UmbControllerHostInterface; #treeSource: UmbTreeDataSource; @@ -26,6 +24,9 @@ export class UmbMediaRepository implements UmbTreeRepository, UmbDetailRepositor #notificationContext?: UmbNotificationContext; + #initResolver?: () => void; + #initialized = false; + constructor(host: UmbControllerHostInterface) { this.#host = host; @@ -33,19 +34,32 @@ export class UmbMediaRepository implements UmbTreeRepository, UmbDetailRepositor this.#treeSource = new MediaTreeServerDataSource(this.#host); this.#detailDataSource = new UmbMediaDetailServerDataSource(this.#host); - this.#init = Promise.all([ - new UmbContextConsumerController(this.#host, UMB_MEDIA_TREE_STORE_CONTEXT_TOKEN, (instance) => { - this.#treeStore = instance; - }), + new UmbContextConsumerController(this.#host, UMB_MEDIA_TREE_STORE_CONTEXT_TOKEN, (instance) => { + this.#treeStore = instance; + this.#checkIfInitialized(); + }); - new UmbContextConsumerController(this.#host, UMB_MEDIA_STORE_CONTEXT_TOKEN, (instance) => { - this.#store = instance; - }), + new UmbContextConsumerController(this.#host, UMB_MEDIA_STORE_CONTEXT_TOKEN, (instance) => { + this.#store = instance; + this.#checkIfInitialized(); + }); - new UmbContextConsumerController(this.#host, UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => { - this.#notificationContext = instance; - }), - ]); + new UmbContextConsumerController(this.#host, UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => { + this.#notificationContext = instance; + this.#checkIfInitialized(); + }); + } + + // TODO: make a generic way to wait for initialization + #init = new Promise((resolve) => { + this.#initialized ? resolve() : (this.#initResolver = resolve); + }); + + #checkIfInitialized() { + if (this.#treeStore && this.#store && this.#notificationContext) { + this.#initialized = true; + this.#initResolver?.(); + } } async requestRootTreeItems() { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/tree/tree-item-base/tree-item-base.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/tree/tree-item-base/tree-item-base.context.ts index 25c3a500cb..7216fb0683 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/tree/tree-item-base/tree-item-base.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/tree/tree-item-base/tree-item-base.context.ts @@ -15,6 +15,7 @@ import { } from '@umbraco-cms/backoffice/context-api'; import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extensions-api'; import type { TreeItemPresentationModel } from '@umbraco-cms/backoffice/backend-api'; +import { ManifestEntityAction } from 'libs/extensions-registry/entity-action.models'; // add type for unique function export type UmbTreeItemUniqueFunction = (x: T) => string | null | undefined; @@ -54,11 +55,11 @@ export class UmbTreeItemContextBase; + #actionObserver?: UmbObserverController; constructor(host: UmbControllerHostInterface, getUniqueFunction: UmbTreeItemUniqueFunction) { this.host = host; this.#getUniqueFunction = getUniqueFunction; - this.#observeTreeItemActions(); this.#consumeContexts(); new UmbContextProviderController(host, UMB_TREE_ITEM_CONTEXT_TOKEN, this); } @@ -77,6 +78,7 @@ export class UmbTreeItemContextBase