Merge remote-tracking branch 'origin/main' into feature/create-language

This commit is contained in:
Lone Iversen
2023-03-29 13:20:44 +02:00
2 changed files with 34 additions and 16 deletions

View File

@@ -14,8 +14,6 @@ import type { UmbTreeRepository } from 'libs/repository/tree-repository.interfac
type ItemDetailType = MediaDetails;
export class UmbMediaRepository implements UmbTreeRepository, UmbDetailRepository<ItemDetailType> {
#init!: Promise<unknown>;
#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<void>((resolve) => {
this.#initialized ? resolve() : (this.#initResolver = resolve);
});
#checkIfInitialized() {
if (this.#treeStore && this.#store && this.#notificationContext) {
this.#initialized = true;
this.#initResolver?.();
}
}
async requestRootTreeItems() {

View File

@@ -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<T extends TreeItemPresentationModel> = (x: T) => string | null | undefined;
@@ -54,11 +55,11 @@ export class UmbTreeItemContextBase<T extends TreeItemPresentationModel = TreeIt
#sectionContext?: UmbSectionContext;
#sectionSidebarContext?: UmbSectionSidebarContext;
#getUniqueFunction: UmbTreeItemUniqueFunction<T>;
#actionObserver?: UmbObserverController<ManifestEntityAction[]>;
constructor(host: UmbControllerHostInterface, getUniqueFunction: UmbTreeItemUniqueFunction<T>) {
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<T extends TreeItemPresentationModel = TreeIt
this.type = treeItem.type;
this.#hasChildren.next(treeItem.hasChildren || false);
this.#observeActions();
this.#treeItem.next(treeItem);
}
@@ -160,8 +162,10 @@ export class UmbTreeItemContextBase<T extends TreeItemPresentationModel = TreeIt
});
}
#observeTreeItemActions() {
new UmbObserverController(
#observeActions() {
if (this.#actionObserver) this.#actionObserver.destroy();
this.#actionObserver = new UmbObserverController(
this.host,
umbExtensionsRegistry
.extensionsOfType('entityAction')