diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/bulk-actions/collection-bulk-action-media-delete.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/bulk-actions/collection-bulk-action-media-delete.element.ts index 6cf38a66e0..31f7d08428 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/bulk-actions/collection-bulk-action-media-delete.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/bulk-actions/collection-bulk-action-media-delete.element.ts @@ -2,7 +2,7 @@ import { UUITextStyles } from '@umbraco-ui/uui-css'; import { css, html } from 'lit'; import { customElement } from 'lit/decorators.js'; import { ifDefined } from 'lit/directives/if-defined.js'; -import type { UmbCollectionContext } from '../collection.context'; +import { UmbCollectionContext, UMB_COLLECTION_CONTEXT_ALIAS } from '../collection.context'; import type { ManifestCollectionBulkAction } from '@umbraco-cms/models'; import { UmbLitElement } from '@umbraco-cms/element'; @@ -18,7 +18,7 @@ export class UmbCollectionBulkActionDeleteElement extends UmbLitElement { constructor() { super(); - this.consumeContext('umbCollectionContext', (context) => { + this.consumeContext(UMB_COLLECTION_CONTEXT_ALIAS, (context) => { this._collectionContext = context; }); } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection-selection-actions.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection-selection-actions.element.ts index 83121e2ee2..37c367f249 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection-selection-actions.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection-selection-actions.element.ts @@ -1,7 +1,7 @@ import { UUITextStyles } from '@umbraco-ui/uui-css'; import { css, html, nothing } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; -import type { UmbCollectionContext } from './collection.context'; +import { UmbCollectionContext, UMB_COLLECTION_CONTEXT_ALIAS } from './collection.context'; import type { MediaDetails } from '@umbraco-cms/models'; import { UmbLitElement } from '@umbraco-cms/element'; @@ -36,7 +36,7 @@ export class UmbCollectionSelectionActionsElement extends UmbLitElement { constructor() { super(); - this.consumeContext('umbCollectionContext', (instance) => { + this.consumeContext(UMB_COLLECTION_CONTEXT_ALIAS, (instance) => { this._collectionContext = instance; this._observeCollectionContext(); }); diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection.context.ts index a312ccadf0..a84ce349f9 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection.context.ts @@ -1,13 +1,12 @@ import { ContentTreeItem } from '@umbraco-cms/backend-api'; import { UmbTreeDataStore } from '@umbraco-cms/stores/store'; import { UmbControllerHostInterface } from '@umbraco-cms/controller'; -import { UmbContextConsumerController } from '@umbraco-cms/context-api'; +import { UmbContextAlias, UmbContextConsumerController } from '@umbraco-cms/context-api'; import { UniqueBehaviorSubject, UmbObserverController } from '@umbraco-cms/observable-api'; export class UmbCollectionContext< DataType extends ContentTreeItem, StoreType extends UmbTreeDataStore = UmbTreeDataStore > { - private _host: UmbControllerHostInterface; private _entityKey: string | null; @@ -60,14 +59,18 @@ export class UmbCollectionContext< this._dataObserver?.destroy(); if (this._entityKey) { - this._dataObserver = new UmbObserverController(this._host, this._store.getTreeItemChildren(this._entityKey), (nodes) => { - if(nodes) { - this.#data.next(nodes); + this._dataObserver = new UmbObserverController( + this._host, + this._store.getTreeItemChildren(this._entityKey), + (nodes) => { + if (nodes) { + this.#data.next(nodes); + } } - }); + ); } else { this._dataObserver = new UmbObserverController(this._host, this._store.getTreeRoot(), (nodes) => { - if(nodes) { + if (nodes) { this.#data.next(nodes); } }); @@ -107,3 +110,7 @@ export class UmbCollectionContext< this.#data.unsubscribe(); } } + +export const UMB_COLLECTION_CONTEXT_ALIAS = new UmbContextAlias>( + UmbCollectionContext.name +); diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection.element.ts index 20bf799c50..5c9f89572a 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/collection.element.ts @@ -4,7 +4,7 @@ import { customElement, state, property } from 'lit/decorators.js'; import { map } from 'rxjs'; import './collection-selection-actions.element'; import './collection-toolbar.element'; -import type { UmbCollectionContext } from './collection.context'; +import { UmbCollectionContext, UMB_COLLECTION_CONTEXT_ALIAS } from './collection.context'; import { createExtensionElement } from '@umbraco-cms/extensions-api'; import type { ManifestCollectionView, MediaDetails } from '@umbraco-cms/models'; import { umbExtensionsRegistry } from '@umbraco-cms/extensions-registry'; @@ -53,7 +53,7 @@ export class UmbCollectionElement extends UmbLitElement { constructor() { super(); - this.consumeContext('umbCollectionContext', (instance) => { + this.consumeContext(UMB_COLLECTION_CONTEXT_ALIAS, (instance) => { this._collectionContext = instance; this._observeCollectionContext(); }); @@ -85,7 +85,7 @@ export class UmbCollectionElement extends UmbLitElement { private _createRoutes(views: ManifestCollectionView[] | null) { this._routes = []; - if(views) { + if (views) { this._routes = views.map((view) => { return { path: `${view.meta.pathName}`, diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/dashboards/dashboard-collection.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/dashboards/dashboard-collection.element.ts index 697fa88192..772b8b22d9 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/dashboards/dashboard-collection.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/dashboards/dashboard-collection.element.ts @@ -4,7 +4,10 @@ import { customElement, state } from 'lit/decorators.js'; import '../collection.element'; import { ifDefined } from 'lit-html/directives/if-defined.js'; import { UmbMediaStore, UmbMediaStoreItemType } from 'src/backoffice/media/media/media.store'; -import { UmbCollectionContext } from 'src/backoffice/shared/collection/collection.context'; +import { + UmbCollectionContext, + UMB_COLLECTION_CONTEXT_ALIAS, +} from 'src/backoffice/shared/collection/collection.context'; import type { ManifestDashboardCollection } from '@umbraco-cms/models'; import { UmbLitElement } from '@umbraco-cms/element'; @@ -37,7 +40,7 @@ export class UmbDashboardCollectionElement extends UmbLitElement { const manifestMeta = this.manifest.meta as any; this._entityType = manifestMeta.entityType as string; this._collectionContext = new UmbCollectionContext(this, null, manifestMeta.storeAlias); - this.provideContext('umbCollectionContext', this._collectionContext); + this.provideContext(UMB_COLLECTION_CONTEXT_ALIAS, this._collectionContext); } } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/views/collection-view-media-grid.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/views/collection-view-media-grid.element.ts index 52d943758a..f0cd85277a 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/views/collection-view-media-grid.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/views/collection-view-media-grid.element.ts @@ -2,7 +2,7 @@ import { UUITextStyles } from '@umbraco-ui/uui-css'; import { css, html } from 'lit'; import { customElement, state } from 'lit/decorators.js'; import { repeat } from 'lit/directives/repeat.js'; -import type { UmbCollectionContext } from '../collection.context'; +import { UmbCollectionContext, UMB_COLLECTION_CONTEXT_ALIAS } from '../collection.context'; import type { MediaDetails } from '@umbraco-cms/models'; import { UmbLitElement } from '@umbraco-cms/element'; @@ -77,8 +77,7 @@ export class UmbCollectionViewsMediaGridElement extends UmbLitElement { document.addEventListener('dragenter', this._handleDragEnter.bind(this)); document.addEventListener('dragleave', this._handleDragLeave.bind(this)); document.addEventListener('drop', this._handleDrop.bind(this)); - this.consumeContext('umbCollectionContext', (instance) => { - console.log('umbCollectionContext', instance); + this.consumeContext(UMB_COLLECTION_CONTEXT_ALIAS, (instance) => { this._collectionContext = instance; this._observeCollectionContext(); }); diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/views/collection-view-media-table.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/views/collection-view-media-table.element.ts index 069e3c8c9e..3de3932012 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/views/collection-view-media-table.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/collection/views/collection-view-media-table.element.ts @@ -1,7 +1,7 @@ import { UUITextStyles } from '@umbraco-ui/uui-css'; import { css, html } from 'lit'; import { customElement, state } from 'lit/decorators.js'; -import type { UmbCollectionContext } from '../collection.context'; +import { UmbCollectionContext, UMB_COLLECTION_CONTEXT_ALIAS } from '../collection.context'; import type { MediaDetails } from '@umbraco-cms/models'; import { UmbLitElement } from '@umbraco-cms/element'; @@ -19,7 +19,7 @@ export class UmbCollectionViewMediaTableElement extends UmbLitElement { constructor() { super(); - this.consumeContext('umbCollectionContext', (instance) => { + this.consumeContext(UMB_COLLECTION_CONTEXT_ALIAS, (instance) => { this._collectionContext = instance; this._observeCollectionContext(); }); diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-content/views/collection/workspace-view-collection.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-content/views/collection/workspace-view-collection.element.ts index 3ea12bc01c..75bc9db40e 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-content/views/collection/workspace-view-collection.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-content/views/collection/workspace-view-collection.element.ts @@ -3,7 +3,10 @@ import { UUITextStyles } from '@umbraco-ui/uui-css/lib'; import { customElement } from 'lit/decorators.js'; import { ifDefined } from 'lit-html/directives/if-defined.js'; import type { UmbWorkspaceContentContext } from '../../workspace-content.context'; -import { UmbCollectionContext } from 'src/backoffice/shared/collection/collection.context'; +import { + UmbCollectionContext, + UMB_COLLECTION_CONTEXT_ALIAS, +} from 'src/backoffice/shared/collection/collection.context'; import { UmbMediaStore, UmbMediaStoreItemType } from 'src/backoffice/media/media/media.store'; import '../../../../../../shared/components/content-property/content-property.element'; @@ -42,7 +45,7 @@ export class UmbWorkspaceViewCollectionElement extends UmbLitElement { this._workspaceContext.entityKey, this._workspaceContext.getStore()?.storeAlias || '' // The store is available when the context is available. ); - this.provideContext('umbCollectionContext', this._collectionContext); + this.provideContext(UMB_COLLECTION_CONTEXT_ALIAS, this._collectionContext); } }