This commit is contained in:
Niels Lyngsø
2022-12-20 14:28:16 +01:00
parent 2953e07577
commit 1ef67b9418
6 changed files with 34 additions and 26 deletions

View File

@@ -14,8 +14,8 @@ const DefaultDocumentTypeData = ({
export class UmbWorkspaceDocumentTypeContext extends UmbWorkspaceNodeContext<UmbDocumentTypeStoreItemType, UmbDocumentTypeStore> {
constructor(target:HTMLElement, entityType: string, entityKey: string) {
super(target, DefaultDocumentTypeData, 'umbDocumentTypeStore', entityType, entityKey);
constructor(target:HTMLElement, entityKey: string) {
super(target, DefaultDocumentTypeData, 'umbDocumentTypeStore', entityKey);
}
}

View File

@@ -88,7 +88,7 @@ export class UmbWorkspaceDocumentTypeElement extends UmbContextProviderMixin(
protected _provideWorkspace() {
if(this._entityType && this._entityKey) {
this._workspaceContext = new UmbWorkspaceDocumentTypeContext(this, this._entityType, this._entityKey);
this._workspaceContext = new UmbWorkspaceDocumentTypeContext(this, this._entityKey);
this.provideContext('umbWorkspaceContext', this._workspaceContext);
this._observeWorkspace()
}

View File

@@ -33,8 +33,8 @@ const DefaultDocumentData = ({
export class UmbWorkspaceDocumentContext extends UmbWorkspaceNodeContext<UmbDocumentStoreItemType, UmbDocumentStore> {
constructor(target:HTMLElement, entityType: string, entityKey: string) {
super(target, DefaultDocumentData, 'umbDocumentStore', entityType, entityKey);
constructor(target:HTMLElement, entityKey: string) {
super(target, DefaultDocumentData, 'umbDocumentStore', entityKey);
}
}

View File

@@ -68,7 +68,7 @@ export class UmbWorkspaceDocumentElement extends UmbObserverMixin(UmbContextCons
protected _provideWorkspace() {
if(this._entityType && this._entityKey) {
this._workspaceContext = new UmbWorkspaceDocumentContext(this, this._entityType, this._entityKey);
this._workspaceContext = new UmbWorkspaceDocumentContext(this, this._entityKey);
this.provideContext('umbWorkspaceContext', this._workspaceContext);
}
}

View File

@@ -1,13 +1,37 @@
import { UmbWorkspaceWithStoreContext } from "./workspace-with-store.context";
import { UmbNodeStoreBase } from "@umbraco-cms/stores/store";
import { UmbNotificationDefaultData } from "@umbraco-cms/services";
import { UmbNotificationDefaultData, UmbNotificationService } from "@umbraco-cms/services";
import { ContentTreeItem } from "@umbraco-cms/backend-api";
import { UmbContextConsumer } from "@umbraco-cms/context-api";
// TODO: Consider if its right to have this many WorkspaceContext
export class UmbWorkspaceNodeContext<ContentTypeType extends ContentTreeItem, StoreType extends UmbNodeStoreBase<ContentTypeType>> extends UmbWorkspaceWithStoreContext<ContentTypeType, StoreType> {
constructor(target:HTMLElement, defaultData:ContentTypeType, storeAlias:string, entityType: string, entityKey: string) {
super(target, defaultData, storeAlias, entityType, entityKey);
protected _notificationService?: UmbNotificationService;
protected _notificationConsumer!:UmbContextConsumer;
public entityKey:string;
constructor(target:HTMLElement, defaultData:ContentTypeType, storeAlias:string, entityKey: string) {
super(target, defaultData, storeAlias);
this._notificationConsumer = new UmbContextConsumer(this._target, 'umbNotificationService', (_instance: UmbNotificationService) => {
this._notificationService = _instance;
});
this.entityKey = entityKey;
}
connectedCallback() {
super.connectedCallback();
this._notificationConsumer.attach();
}
disconnectedCallback() {
super.connectedCallback();
this._notificationConsumer.detach();
}
@@ -29,8 +53,6 @@ export class UmbWorkspaceNodeContext<ContentTypeType extends ContentTreeItem, St
this._notificationService?.peek('danger', { data });
});
}
// TODO: trash?
}

View File

@@ -1,33 +1,21 @@
import { Subscription } from "rxjs";
import { UmbWorkspaceContext } from "./workspace.context";
import { UmbContextConsumer } from "@umbraco-cms/context-api";
import { UmbNotificationService } from "@umbraco-cms/services";
import { UmbDataStoreBase } from "@umbraco-cms/stores/store";
import { ContentTreeItem } from "@umbraco-cms/backend-api";
export abstract class UmbWorkspaceWithStoreContext<DataType extends ContentTreeItem, StoreType extends UmbDataStoreBase<DataType>> extends UmbWorkspaceContext<DataType> {
protected _notificationConsumer!:UmbContextConsumer;
protected _notificationService?: UmbNotificationService;
protected _storeConsumer!:UmbContextConsumer;
protected _store!: StoreType; // TODO: Double check its right to assume it here, at least from a type perspective?
protected _dataObserver?:Subscription;
public entityType:string;
public entityKey:string;
constructor(target:HTMLElement, defaultData:DataType, storeAlias:string, entityType: string, entityKey: string) {
constructor(target:HTMLElement, defaultData:DataType, storeAlias:string) {
super(target, defaultData)
this.entityType = entityType;
this.entityKey = entityKey;
this._notificationConsumer = new UmbContextConsumer(this._target, 'umbNotificationService', (_instance: UmbNotificationService) => {
this._notificationService = _instance;
});
// TODO: consider if store alias should be configurable of manifest:
this._storeConsumer = new UmbContextConsumer(this._target, storeAlias, (_instance: StoreType) => {
@@ -41,12 +29,10 @@ export abstract class UmbWorkspaceWithStoreContext<DataType extends ContentTreeI
}
connectedCallback() {
this._notificationConsumer.attach();
this._storeConsumer.attach();
}
disconnectedCallback() {
this._notificationConsumer.detach();
this._storeConsumer.detach();
}