Chore: Move workspace context (#675)

* move workspace context

* Update document-type-workspace.context.ts

* fix duplicate import
This commit is contained in:
Mads Rasmussen
2023-05-02 10:34:09 +02:00
committed by GitHub
parent 6b5a1a3185
commit 5a98aff39d
17 changed files with 20 additions and 36 deletions

View File

@@ -1,2 +1,3 @@
export * from './workspace-context.interface';
export * from './workspace-entity-context.interface';
export * from './workspace-context';

View File

@@ -0,0 +1,40 @@
import { UmbEntityWorkspaceContextInterface } from './workspace-entity-context.interface';
import { UmbContextProviderController, UMB_ENTITY_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/context-api';
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller';
import { UmbBooleanState } from '@umbraco-cms/backoffice/observable-api';
import type { BaseEntity } from '@umbraco-cms/backoffice/models';
/*
TODO: We need to figure out if we like to keep using same alias for all workspace contexts.
If so we need to align on a interface that all of these implements. otherwise consumers cant trust the workspace-context.
*/
export abstract class UmbWorkspaceContext<T, EntityType extends BaseEntity>
implements UmbEntityWorkspaceContextInterface<EntityType>
{
public host: UmbControllerHostElement;
public repository: T;
#isNew = new UmbBooleanState(undefined);
isNew = this.#isNew.asObservable();
constructor(host: UmbControllerHostElement, repository: T) {
this.host = host;
this.repository = repository;
new UmbContextProviderController(host, UMB_ENTITY_WORKSPACE_CONTEXT, this);
}
getIsNew() {
return this.#isNew.getValue();
}
setIsNew(isNew: boolean) {
this.#isNew.next(isNew);
}
abstract getEntityId(): string | undefined; // COnsider if this should go away now that we have getUnique()
abstract getEntityType(): string; // TODO: consider of this should be on the repository because a repo is responsible for one entity type
abstract getData(): EntityType | undefined;
abstract save(): Promise<void>;
abstract destroy(): void;
}