From dabfde508b63c72bd0dda5c711a3c14e6960ef7c Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 21 Feb 2023 12:40:06 +0100 Subject: [PATCH] update workspace contexts --- .../document-type-workspace.context.ts | 1 - .../workspace/document-workspace.context.ts | 7 +++---- .../workspace/media-type-workspace.context.ts | 5 +++-- .../media/workspace/media-workspace.context.ts | 7 +++---- .../workspace/member-group-workspace.context.ts | 5 +++-- .../workspace/member-type-workspace.context.ts | 7 +++---- .../workspace/member-workspace.context.ts | 1 - .../workspace/data-type-workspace.context.ts | 7 +++---- .../language/language-workspace.context.ts | 17 +++-------------- .../workspace-context.interface.ts | 4 +--- .../workspace-context/workspace-context.ts | 12 ++++++++++++ .../workspace-entity-context.interface.ts | 5 ----- .../workspace/dictionary-workspace.context.ts | 6 ++++-- .../workspace/user-group-workspace.context.ts | 2 -- .../users/workspace/user-workspace.context.ts | 1 - 15 files changed, 38 insertions(+), 49 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/document-type-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/document-type-workspace.context.ts index efe6f99b1d..da36b169cb 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/document-type-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/document-type-workspace.context.ts @@ -8,7 +8,6 @@ export class UmbWorkspaceDocumentTypeContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; #manager = new UmbEntityWorkspaceManager(this._host, 'document-type', UMB_DOCUMENT_TYPE_STORE_CONTEXT_TOKEN); public readonly data = this.#manager.state.asObservable(); diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts index 1ace3a7c48..745deb59d7 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts @@ -19,7 +19,6 @@ export class UmbDocumentWorkspaceContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; #host: UmbControllerHostInterface; #documentRepository: UmbDocumentRepository; #documentTypeRepository: UmbDocumentTypeRepository; @@ -44,7 +43,7 @@ export class UmbDocumentWorkspaceContext async load(entityKey: string) { const { data } = await this.#documentRepository.requestByKey(entityKey); if (data) { - this.isNew = false; + this.setIsNew(false); this.#data.next(data); } } @@ -52,7 +51,7 @@ export class UmbDocumentWorkspaceContext async createScaffold(parentKey: string | null) { const { data } = await this.#documentRepository.createScaffold(parentKey); if (!data) return; - this.isNew = true; + this.setIsNew(true); this.#data.next(data); } @@ -180,7 +179,7 @@ export class UmbDocumentWorkspaceContext await this.#documentRepository.save(this.#data.value); } // If it went well, then its not new anymore?. - this.isNew = false; + this.setIsNew(false); } async delete(key: string) { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/media/media-types/workspace/media-type-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/media/media-types/workspace/media-type-workspace.context.ts index 871b1ef489..2445086e43 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/media/media-types/workspace/media-type-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/media/media-types/workspace/media-type-workspace.context.ts @@ -10,7 +10,6 @@ export class UmbWorkspaceMediaTypeContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; #host: UmbControllerHostInterface; #repo: UmbMediaTypeRepository; @@ -54,12 +53,14 @@ export class UmbWorkspaceMediaTypeContext async createScaffold() { const { data } = await this.#repo.createScaffold(); if (!data) return; + this.setIsNew(true); this.#data.next(data); } async save() { if (!this.#data.value) return; - this.#repo.save(this.#data.value); + await this.#repo.save(this.#data.value); + this.setIsNew(false); } public destroy(): void { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/media/media/workspace/media-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/media/media/workspace/media-workspace.context.ts index 4905458014..fe27ecb936 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/media/media/workspace/media-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/media/media/workspace/media-workspace.context.ts @@ -10,7 +10,6 @@ export class UmbMediaWorkspaceContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; #host: UmbControllerHostInterface; #detailRepository: UmbMediaRepository; @@ -54,7 +53,7 @@ export class UmbMediaWorkspaceContext async load(entityKey: string) { const { data } = await this.#detailRepository.requestByKey(entityKey); if (data) { - this.isNew = false; + this.setIsNew(false); this.#data.next(data); } } @@ -62,7 +61,7 @@ export class UmbMediaWorkspaceContext async createScaffold(parentKey: string | null) { const { data } = await this.#detailRepository.createScaffold(parentKey); if (!data) return; - this.isNew = true; + this.setIsNew(true); this.#data.next(data); } @@ -74,7 +73,7 @@ export class UmbMediaWorkspaceContext await this.#detailRepository.save(this.#data.value); } // If it went well, then its not new anymore?. - this.isNew = false; + this.setIsNew(false); } async delete(key: string) { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/members/member-groups/workspace/member-group-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/members/member-groups/workspace/member-group-workspace.context.ts index 335d2d8524..194e50c0ae 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/members/member-groups/workspace/member-group-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/members/member-groups/workspace/member-group-workspace.context.ts @@ -10,7 +10,6 @@ export class UmbWorkspaceMemberGroupContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; #host: UmbControllerHostInterface; #repo: UmbMemberGroupRepository; @@ -55,12 +54,14 @@ export class UmbWorkspaceMemberGroupContext async createScaffold() { const { data } = await this.#repo.createScaffold(); if (!data) return; + this.setIsNew(true); this.#data.next(data); } async save() { if (!this.#data.value) return; - this.#repo.save(this.#data.value); + await this.#repo.save(this.#data.value); + this.setIsNew(true); } public destroy(): void { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/members/member-types/workspace/member-type-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/members/member-types/workspace/member-type-workspace.context.ts index 00e0ef78ea..166d07c469 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/members/member-types/workspace/member-type-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/members/member-types/workspace/member-type-workspace.context.ts @@ -11,7 +11,6 @@ export class UmbWorkspaceMemberTypeContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; #host: UmbControllerHostInterface; #dataTypeRepository: UmbMemberTypeRepository; @@ -27,7 +26,7 @@ export class UmbWorkspaceMemberTypeContext async load(entityKey: string) { const { data } = await this.#dataTypeRepository.requestByKey(entityKey); if (data) { - this.isNew = false; + this.setIsNew(false); this.#data.next(data); } } @@ -35,7 +34,7 @@ export class UmbWorkspaceMemberTypeContext async createScaffold() { const { data } = await this.#dataTypeRepository.createScaffold(); if (!data) return; - this.isNew = true; + this.setIsNew(true); this.#data.next(data); } @@ -67,7 +66,7 @@ export class UmbWorkspaceMemberTypeContext await this.#dataTypeRepository.save(this.#data.value); } // If it went well, then its not new anymore?. - this.isNew = false; + this.setIsNew(false); } async delete(key: string) { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/members/members/workspace/member-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/members/members/workspace/member-workspace.context.ts index 0643082bba..e3ea0a4a1a 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/members/members/workspace/member-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/members/members/workspace/member-workspace.context.ts @@ -8,7 +8,6 @@ export class UmbWorkspaceMemberContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; #manager = new UmbEntityWorkspaceManager(this._host, 'member', UMB_MEMBER_DETAIL_STORE_CONTEXT_TOKEN); public readonly data = this.#manager.state.asObservable(); diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/workspace/data-type-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/workspace/data-type-workspace.context.ts index e8b10c2c24..e07767d67a 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/workspace/data-type-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/data-types/workspace/data-type-workspace.context.ts @@ -9,7 +9,6 @@ export class UmbDataTypeWorkspaceContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; #host: UmbControllerHostInterface; #dataTypeRepository: UmbDataTypeRepository; @@ -27,15 +26,15 @@ export class UmbDataTypeWorkspaceContext async load(key: string) { const { data } = await this.#dataTypeRepository.requestByKey(key); if (data) { - this.isNew = false; + this.setIsNew(false); this.#data.update(data); } } async createScaffold(parentKey: string | null) { - this.isNew = true; const { data } = await this.#dataTypeRepository.createScaffold(parentKey); if (!data) return; + this.setIsNew(true); this.#data.next(data); } @@ -82,7 +81,7 @@ export class UmbDataTypeWorkspaceContext await this.#dataTypeRepository.save(this.#data.value); } // If it went well, then its not new anymore?. - this.isNew = false; + this.setIsNew(false); } async delete(key: string) { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/language-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/language-workspace.context.ts index 860fa6eb69..8744f0c8f9 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/language-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/languages/workspace/language/language-workspace.context.ts @@ -1,16 +1,13 @@ import { UmbLanguageRepository } from '../../repository/language.repository'; import { UmbWorkspaceContext } from '../../../../shared/components/workspace/workspace-context/workspace-context'; import type { LanguageModel } from '@umbraco-cms/backend-api'; -import { DeepState, ObjectState } from '@umbraco-cms/observable-api'; +import { ObjectState } from '@umbraco-cms/observable-api'; import { UmbControllerHostInterface } from '@umbraco-cms/controller'; export class UmbLanguageWorkspaceContext extends UmbWorkspaceContext { #host: UmbControllerHostInterface; #languageRepository: UmbLanguageRepository; - #isNew = new DeepState(false); - isNew = this.#isNew.asObservable(); - #data = new ObjectState(undefined); data = this.#data.asObservable(); @@ -23,7 +20,7 @@ export class UmbLanguageWorkspaceContext extends UmbWorkspaceContext { async load(isoCode: string) { const { data } = await this.#languageRepository.requestByIsoCode(isoCode); if (data) { - this.#isNew.next(false); + this.setIsNew(false); this.#data.update(data); } } @@ -31,7 +28,7 @@ export class UmbLanguageWorkspaceContext extends UmbWorkspaceContext { async createScaffold() { const { data } = await this.#languageRepository.createScaffold(); if (!data) return; - this.#isNew.next(true); + this.setIsNew(true); this.#data.update(data); } @@ -43,14 +40,6 @@ export class UmbLanguageWorkspaceContext extends UmbWorkspaceContext { return 'language'; } - getIsNew() { - return this.#isNew.getValue(); - } - - setIsNew(isNew: boolean) { - this.#isNew.next(isNew); - } - setName(name: string) { this.#data.update({ name }); } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-context.interface.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-context.interface.ts index d3bb53e38b..6b6a0332a9 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-context.interface.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-context.interface.ts @@ -1,9 +1,7 @@ import { Observable } from 'rxjs'; export interface UmbWorkspaceContextInterface { - //readonly data: Observable; - //getUnique(): string | undefined; - isNew: Observable; + isNew: Observable; getIsNew(): boolean; setIsNew(value: boolean): void; getEntityType(): string; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-context.ts index d0df62f4e2..ca0407059d 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-context.ts @@ -1,5 +1,6 @@ import { UmbContextProviderController } from '@umbraco-cms/context-api'; import { UmbControllerHostInterface } from '@umbraco-cms/controller'; +import { DeepState } from '@umbraco-cms/observable-api'; /* @@ -9,8 +10,19 @@ If so we need to align on a interface that all of these implements. otherwise co export abstract class UmbWorkspaceContext { protected _host: UmbControllerHostInterface; + #isNew = new DeepState(false); + isNew = this.#isNew.asObservable(); + constructor(host: UmbControllerHostInterface) { this._host = host; new UmbContextProviderController(host, 'umbWorkspaceContext', this); } + + getIsNew() { + return this.#isNew.getValue(); + } + + setIsNew(isNew: boolean) { + this.#isNew.next(isNew); + } } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-entity-context.interface.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-entity-context.interface.ts index 87fd3e526e..6d15dead5d 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-entity-context.interface.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/workspace/workspace-context/workspace-entity-context.interface.ts @@ -1,14 +1,9 @@ import { UmbWorkspaceContextInterface } from './workspace-context.interface'; export interface UmbWorkspaceEntityContextInterface extends UmbWorkspaceContextInterface { - //readonly name: Observable; - getEntityKey(): string | undefined; // COnsider if this should go away now that we have getUnique() getEntityType(): string; - getData(): T; - setPropertyValue(alias: string, value: unknown): void; - save(): Promise; } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/translation/dictionary/workspace/dictionary-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/translation/dictionary/workspace/dictionary-workspace.context.ts index c926b618dc..d8d1080ead 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/translation/dictionary/workspace/dictionary-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/translation/dictionary/workspace/dictionary-workspace.context.ts @@ -10,7 +10,6 @@ export class UmbWorkspaceDictionaryContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; #host: UmbControllerHostInterface; #repo: UmbDictionaryRepository; @@ -64,6 +63,7 @@ export class UmbWorkspaceDictionaryContext async load(entityKey: string) { const { data } = await this.#repo.requestByKey(entityKey); if (data) { + this.setIsNew(false); this.#data.next(data); } } @@ -71,12 +71,14 @@ export class UmbWorkspaceDictionaryContext async createScaffold(parentKey: string | null) { const { data } = await this.#repo.createScaffold(parentKey); if (!data) return; + this.setIsNew(true); this.#data.next(data); } async save() { if (!this.#data.value) return; - this.#repo.save(this.#data.value); + await this.#repo.save(this.#data.value); + this.setIsNew(false); } public destroy(): void { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/workspace/user-group-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/workspace/user-group-workspace.context.ts index e7d36244a3..8f7d07ef24 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/workspace/user-group-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/users/user-groups/workspace/user-group-workspace.context.ts @@ -8,8 +8,6 @@ export class UmbWorkspaceUserGroupContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; - #manager = new UmbEntityWorkspaceManager(this._host, 'user-group', UMB_USER_GROUP_STORE_CONTEXT_TOKEN); public readonly data = this.#manager.state.asObservable(); diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/users/users/workspace/user-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/users/users/workspace/user-workspace.context.ts index 7f1dd39cb5..5552864df8 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/users/users/workspace/user-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/users/users/workspace/user-workspace.context.ts @@ -8,7 +8,6 @@ export class UmbWorkspaceUserContext extends UmbWorkspaceContext implements UmbWorkspaceEntityContextInterface { - isNew = false; #manager = new UmbEntityWorkspaceManager(this._host, 'user', UMB_USER_STORE_CONTEXT_TOKEN); public readonly data = this.#manager.state.asObservable();