Merge remote-tracking branch 'origin/main' into feature/create-language
This commit is contained in:
@@ -14,8 +14,6 @@ import type { UmbTreeRepository } from 'libs/repository/tree-repository.interfac
|
|||||||
type ItemDetailType = MediaDetails;
|
type ItemDetailType = MediaDetails;
|
||||||
|
|
||||||
export class UmbMediaRepository implements UmbTreeRepository, UmbDetailRepository<ItemDetailType> {
|
export class UmbMediaRepository implements UmbTreeRepository, UmbDetailRepository<ItemDetailType> {
|
||||||
#init!: Promise<unknown>;
|
|
||||||
|
|
||||||
#host: UmbControllerHostInterface;
|
#host: UmbControllerHostInterface;
|
||||||
|
|
||||||
#treeSource: UmbTreeDataSource;
|
#treeSource: UmbTreeDataSource;
|
||||||
@@ -26,6 +24,9 @@ export class UmbMediaRepository implements UmbTreeRepository, UmbDetailRepositor
|
|||||||
|
|
||||||
#notificationContext?: UmbNotificationContext;
|
#notificationContext?: UmbNotificationContext;
|
||||||
|
|
||||||
|
#initResolver?: () => void;
|
||||||
|
#initialized = false;
|
||||||
|
|
||||||
constructor(host: UmbControllerHostInterface) {
|
constructor(host: UmbControllerHostInterface) {
|
||||||
this.#host = host;
|
this.#host = host;
|
||||||
|
|
||||||
@@ -33,19 +34,32 @@ export class UmbMediaRepository implements UmbTreeRepository, UmbDetailRepositor
|
|||||||
this.#treeSource = new MediaTreeServerDataSource(this.#host);
|
this.#treeSource = new MediaTreeServerDataSource(this.#host);
|
||||||
this.#detailDataSource = new UmbMediaDetailServerDataSource(this.#host);
|
this.#detailDataSource = new UmbMediaDetailServerDataSource(this.#host);
|
||||||
|
|
||||||
this.#init = Promise.all([
|
new UmbContextConsumerController(this.#host, UMB_MEDIA_TREE_STORE_CONTEXT_TOKEN, (instance) => {
|
||||||
new UmbContextConsumerController(this.#host, UMB_MEDIA_TREE_STORE_CONTEXT_TOKEN, (instance) => {
|
this.#treeStore = instance;
|
||||||
this.#treeStore = instance;
|
this.#checkIfInitialized();
|
||||||
}),
|
});
|
||||||
|
|
||||||
new UmbContextConsumerController(this.#host, UMB_MEDIA_STORE_CONTEXT_TOKEN, (instance) => {
|
new UmbContextConsumerController(this.#host, UMB_MEDIA_STORE_CONTEXT_TOKEN, (instance) => {
|
||||||
this.#store = instance;
|
this.#store = instance;
|
||||||
}),
|
this.#checkIfInitialized();
|
||||||
|
});
|
||||||
|
|
||||||
new UmbContextConsumerController(this.#host, UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => {
|
new UmbContextConsumerController(this.#host, UMB_NOTIFICATION_CONTEXT_TOKEN, (instance) => {
|
||||||
this.#notificationContext = 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() {
|
async requestRootTreeItems() {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
} from '@umbraco-cms/backoffice/context-api';
|
} from '@umbraco-cms/backoffice/context-api';
|
||||||
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extensions-api';
|
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extensions-api';
|
||||||
import type { TreeItemPresentationModel } from '@umbraco-cms/backoffice/backend-api';
|
import type { TreeItemPresentationModel } from '@umbraco-cms/backoffice/backend-api';
|
||||||
|
import { ManifestEntityAction } from 'libs/extensions-registry/entity-action.models';
|
||||||
|
|
||||||
// add type for unique function
|
// add type for unique function
|
||||||
export type UmbTreeItemUniqueFunction<T extends TreeItemPresentationModel> = (x: T) => string | null | undefined;
|
export type UmbTreeItemUniqueFunction<T extends TreeItemPresentationModel> = (x: T) => string | null | undefined;
|
||||||
@@ -54,11 +55,11 @@ export class UmbTreeItemContextBase<T extends TreeItemPresentationModel = TreeIt
|
|||||||
#sectionContext?: UmbSectionContext;
|
#sectionContext?: UmbSectionContext;
|
||||||
#sectionSidebarContext?: UmbSectionSidebarContext;
|
#sectionSidebarContext?: UmbSectionSidebarContext;
|
||||||
#getUniqueFunction: UmbTreeItemUniqueFunction<T>;
|
#getUniqueFunction: UmbTreeItemUniqueFunction<T>;
|
||||||
|
#actionObserver?: UmbObserverController<ManifestEntityAction[]>;
|
||||||
|
|
||||||
constructor(host: UmbControllerHostInterface, getUniqueFunction: UmbTreeItemUniqueFunction<T>) {
|
constructor(host: UmbControllerHostInterface, getUniqueFunction: UmbTreeItemUniqueFunction<T>) {
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.#getUniqueFunction = getUniqueFunction;
|
this.#getUniqueFunction = getUniqueFunction;
|
||||||
this.#observeTreeItemActions();
|
|
||||||
this.#consumeContexts();
|
this.#consumeContexts();
|
||||||
new UmbContextProviderController(host, UMB_TREE_ITEM_CONTEXT_TOKEN, this);
|
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.type = treeItem.type;
|
||||||
|
|
||||||
this.#hasChildren.next(treeItem.hasChildren || false);
|
this.#hasChildren.next(treeItem.hasChildren || false);
|
||||||
|
this.#observeActions();
|
||||||
this.#treeItem.next(treeItem);
|
this.#treeItem.next(treeItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,8 +162,10 @@ export class UmbTreeItemContextBase<T extends TreeItemPresentationModel = TreeIt
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#observeTreeItemActions() {
|
#observeActions() {
|
||||||
new UmbObserverController(
|
if (this.#actionObserver) this.#actionObserver.destroy();
|
||||||
|
|
||||||
|
this.#actionObserver = new UmbObserverController(
|
||||||
this.host,
|
this.host,
|
||||||
umbExtensionsRegistry
|
umbExtensionsRegistry
|
||||||
.extensionsOfType('entityAction')
|
.extensionsOfType('entityAction')
|
||||||
|
|||||||
Reference in New Issue
Block a user