workspace-with-store context
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import { UmbWorkspaceContext } from "../shared/workspace-context/workspace.context";
|
||||
import type { DocumentDetails } from "@umbraco-cms/models";
|
||||
|
||||
const DefaultDocumentTypeData = ({
|
||||
key: '',
|
||||
name: '',
|
||||
icon: '',
|
||||
type: '',
|
||||
hasChildren: false,
|
||||
parentKey: '',
|
||||
isTrashed: false,
|
||||
properties: [
|
||||
/*{
|
||||
alias: '',
|
||||
label: '',
|
||||
description: '',
|
||||
dataTypeKey: '',
|
||||
},*/
|
||||
],
|
||||
data: [
|
||||
{
|
||||
alias: '',
|
||||
value: '',
|
||||
},
|
||||
],
|
||||
variants: [
|
||||
{
|
||||
name: '',
|
||||
},
|
||||
],
|
||||
}) as DocumentDetails;
|
||||
|
||||
|
||||
export class UmbWorkspaceDocumentContext extends UmbWorkspaceContext<DocumentDetails> {
|
||||
|
||||
constructor(target:HTMLElement, entityType: string, entityKey: string) {
|
||||
super(target, DefaultDocumentTypeData);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { UmbWorkspaceContentContext } from "../shared/workspace-content/workspace-content.context";
|
||||
import { UmbWorkspaceWithStoreContext } from "../shared/workspace-context/workspace-with-store.context";
|
||||
import type { DocumentDetails } from "@umbraco-cms/models";
|
||||
|
||||
const DefaultDocumentData = ({
|
||||
@@ -31,7 +31,7 @@ const DefaultDocumentData = ({
|
||||
}) as DocumentDetails;
|
||||
|
||||
|
||||
export class UmbWorkspaceDocumentContext extends UmbWorkspaceContentContext<DocumentDetails> {
|
||||
export class UmbWorkspaceDocumentContext extends UmbWorkspaceWithStoreContext<DocumentDetails> {
|
||||
|
||||
constructor(target:HTMLElement, entityType: string, entityKey: string) {
|
||||
super(target, DefaultDocumentData, 'umbDocumentStore', entityType, entityKey);
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
import { Subscription } from "rxjs";
|
||||
import { UmbWorkspaceContext } from "../workspace-context/workspace.context";
|
||||
import { UmbWorkspaceContext } from "./workspace.context";
|
||||
import { UmbContextConsumer } from "@umbraco-cms/context-api";
|
||||
import type { DocumentDetails } from "@umbraco-cms/models";
|
||||
import { UmbDocumentStore } from "@umbraco-cms/stores/document/document.store";
|
||||
import { UmbNotificationDefaultData, UmbNotificationService } from "@umbraco-cms/services";
|
||||
import { UmbNotificationService } from "@umbraco-cms/services";
|
||||
import { UmbDataStoreBase } from "@umbraco-cms/stores/store";
|
||||
|
||||
export class UmbWorkspaceContentContext<T extends DocumentDetails> extends UmbWorkspaceContext<T> {
|
||||
export abstract class UmbWorkspaceWithStoreContext<T extends DocumentDetails> extends UmbWorkspaceContext<T> {
|
||||
|
||||
|
||||
protected _notificationConsumer!:UmbContextConsumer;
|
||||
protected _notificationService?: UmbNotificationService;
|
||||
|
||||
protected _storeConsumer!:UmbContextConsumer;
|
||||
protected _store!: UmbDocumentStore; // TODO: Double check its right to assume it here, at least from a type perspective?
|
||||
protected _store!: UmbDataStoreBase<T>; // TODO: Double check its right to assume it here, at least from a type perspective?
|
||||
|
||||
protected _dataObserver?:Subscription;
|
||||
|
||||
@@ -30,8 +30,12 @@ export class UmbWorkspaceContentContext<T extends DocumentDetails> extends UmbWo
|
||||
});
|
||||
|
||||
// TODO: consider if store alias should be configurable of manifest:
|
||||
this._storeConsumer = new UmbContextConsumer(this._target, storeAlias, (_instance: UmbDocumentStore) => {
|
||||
this._storeConsumer = new UmbContextConsumer(this._target, storeAlias, (_instance: UmbDataStoreBase<T>) => {
|
||||
this._store = _instance;
|
||||
if(!this._store) {
|
||||
// TODO: if we keep the type assumption of _store existing, then we should here make sure to break the application in a good way.
|
||||
return;
|
||||
}
|
||||
this._observeStore();
|
||||
});
|
||||
}
|
||||
@@ -46,25 +50,22 @@ export class UmbWorkspaceContentContext<T extends DocumentDetails> extends UmbWo
|
||||
this._storeConsumer.detach();
|
||||
}
|
||||
|
||||
private _observeStore() {
|
||||
if(!this._store) {
|
||||
// TODO: if we keep the type assumption of _store existing, then we should here make sure to break the application in a good way.
|
||||
return;
|
||||
}
|
||||
|
||||
protected abstract _observeStore(): void
|
||||
/* {
|
||||
this._dataObserver = this._store.getByKey(this.entityKey).subscribe((content) => {
|
||||
if (!content) return; // TODO: Handle nicely if there is no content data.
|
||||
this.update(content as any);
|
||||
});
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
public getStore():UmbDocumentStore {
|
||||
public getStore():UmbDataStoreBase<T> {
|
||||
return this._store;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// Document Store:
|
||||
public save() {
|
||||
this._store.save([this.getData()]).then(() => {
|
||||
@@ -75,6 +76,7 @@ export class UmbWorkspaceContentContext<T extends DocumentDetails> extends UmbWo
|
||||
this._notificationService?.peek('danger', { data });
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { BehaviorSubject, Observable } from "rxjs";
|
||||
|
||||
|
||||
export class UmbWorkspaceContext<DataType> {
|
||||
export abstract class UmbWorkspaceContext<DataType> {
|
||||
|
||||
|
||||
protected _target!:HTMLElement;
|
||||
|
||||
Reference in New Issue
Block a user