From f5c41fe1560b1af2e9eb650dc78164054b166efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Thu, 22 Dec 2022 10:57:16 +0100 Subject: [PATCH] split into dashboard / workspace view --- .../collection/collection.context.ts | 4 +- .../dashboard-media-management.element.ts | 21 ++------ ...workspace-view-media-collection.element.ts | 48 +++++++++++++------ 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/components/collection/collection.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/components/collection/collection.context.ts index ca5379d452..1e3800045c 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/components/collection/collection.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/components/collection/collection.context.ts @@ -7,7 +7,7 @@ export class UmbCollectionContext = this._search.asObservable(); */ - constructor(target:HTMLElement, entityKey: string, storeAlias:string) { + constructor(target:HTMLElement, entityKey: string|null, storeAlias:string) { this._target = target; this._entityKey = entityKey; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/media-management/dashboard-media-management.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/media-management/dashboard-media-management.element.ts index a1f73d1e94..b3749672dc 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/media-management/dashboard-media-management.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/dashboards/media-management/dashboard-media-management.element.ts @@ -27,20 +27,13 @@ export class UmbDashboardMediaManagementElement extends UmbContextProviderMixin( private _collectionContext?:UmbCollectionContext; - private _entityKey!: string; - @property() - public get entityKey(): string { - return this._entityKey; - } - public set entityKey(value: string) { - this._entityKey = value; - this._provideWorkspace(); - } - constructor() { super(); + + this._collectionContext = new UmbCollectionContext(this, null, 'umbMediaStore'); + this.provideContext('umbCollectionContext', this._collectionContext); // TODO: subscribe selection. } @@ -56,14 +49,6 @@ export class UmbDashboardMediaManagementElement extends UmbContextProviderMixin( this._collectionContext?.disconnectedCallback(); } - - protected _provideWorkspace() { - if(this._entityKey) { - this._collectionContext = new UmbCollectionContext(this, this._entityKey, 'umbMediaStore'); - this.provideContext('umbCollectionContext', this._collectionContext); - } - } - render() { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/workspaces/shared/workspace-content/views/collection/workspace-view-media-collection.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/workspaces/shared/workspace-content/views/collection/workspace-view-media-collection.element.ts index d7c9f19129..7d32eac1b1 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/workspaces/shared/workspace-content/views/collection/workspace-view-media-collection.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/workspaces/shared/workspace-content/views/collection/workspace-view-media-collection.element.ts @@ -3,15 +3,17 @@ import { UUITextStyles } from '@umbraco-ui/uui-css/lib'; import { customElement, state } from 'lit/decorators.js'; import { distinctUntilChanged } from 'rxjs'; import type { UmbWorkspaceNodeContext } from '../../../workspace-context/workspace-node.context'; -import { UmbContextConsumerMixin } from '@umbraco-cms/context-api'; +import { UmbContextConsumerMixin, UmbContextProviderMixin } from '@umbraco-cms/context-api'; import { UmbObserverMixin } from '@umbraco-cms/observable-api'; -import type { ContentProperty, ContentPropertyData, DocumentDetails, MediaDetails } from '@umbraco-cms/models'; +import type { DocumentDetails, MediaDetails } from '@umbraco-cms/models'; import 'src/backoffice/components/content-property/content-property.element'; import 'src/backoffice/dashboards/media-management/dashboard-media-management.element'; +import { UmbCollectionContext } from '@umbraco-cms/components/collection/collection.context'; +import { UmbMediaStore, UmbMediaStoreItemType } from '@umbraco-cms/stores/media/media.store'; @customElement('umb-workspace-view-collection-media') -export class UmbWorkspaceViewCollectionMediaElement extends UmbContextConsumerMixin(UmbObserverMixin(LitElement)) { +export class UmbWorkspaceViewCollectionMediaElement extends UmbContextProviderMixin(UmbContextConsumerMixin(UmbObserverMixin(LitElement))) { static styles = [ UUITextStyles, css` @@ -23,16 +25,12 @@ export class UmbWorkspaceViewCollectionMediaElement extends UmbContextConsumerMi ]; @state() - _properties: ContentProperty[] = []; - - @state() - _data: ContentPropertyData[] = []; - - @state() - private _key = ''; + private _entityKey = ''; private _workspaceContext?: UmbWorkspaceNodeContext; + private _collectionContext?:UmbCollectionContext; + constructor() { super(); @@ -42,19 +40,39 @@ export class UmbWorkspaceViewCollectionMediaElement extends UmbContextConsumerMi }); } + connectedCallback(): void { + super.connectedCallback(); + // TODO: avoid this connection, our own approach on Lit-Controller could be handling this case. + this._collectionContext?.connectedCallback(); + } + disconnectedCallback(): void { + super.connectedCallback() + // TODO: avoid this connection, our own approach on Lit-Controller could be handling this case. + this._collectionContext?.disconnectedCallback(); + } + private _observeContent() { if (!this._workspaceContext) return; this.observe(this._workspaceContext.data.pipe(distinctUntilChanged()), (content) => { - this._properties = content.properties; - this._data = content.data; - this._key = content.key; + this._entityKey = content.key; + this._provideWorkspace(); }); } + protected _provideWorkspace() { + // Notice this should accept an empty string, when we want to get root nodes. + if(this._entityKey != null) { + this._collectionContext = new UmbCollectionContext(this, this._entityKey, 'umbMediaStore'); + this._collectionContext.connectedCallback(); + this.provideContext('umbCollectionContext', this._collectionContext); + } + } + + + render() { - if (!this._key) return nothing; - return html``; + return html``; } }