From a14ce2bc7482d8395d385fae636c0b08b85fda8c Mon Sep 17 00:00:00 2001 From: Nathan Woulfe Date: Wed, 22 Feb 2023 11:03:45 +1000 Subject: [PATCH] fix mocks for doc types fix handler for doc types update workspace context --- .../sources/document-type.server.data.ts | 14 ++-- .../document-type-workspace.context.ts | 77 ++++++++++++++----- .../document-type-workspace.element.ts | 6 +- ...space-view-document-type-design.element.ts | 12 ++- .../src/core/mocks/data/document-type.data.ts | 19 +++-- .../mocks/domains/document-type.handlers.ts | 5 +- .../modal-layout-icon-picker.element.ts | 2 +- 7 files changed, 94 insertions(+), 41 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/repository/sources/document-type.server.data.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/repository/sources/document-type.server.data.ts index 3bb0855410..c872af910c 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/repository/sources/document-type.server.data.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/repository/sources/document-type.server.data.ts @@ -80,7 +80,7 @@ export class UmbDocumentTypeServerDataSource implements RepositoryDetailDataSour // TODO: use resources when end point is ready: return tryExecuteAndNotify( this.#host, - fetch('/umbraco/management/api/v1/document/save', { + fetch('/umbraco/management/api/v1/document-type', { method: 'POST', body: body, headers: { @@ -116,8 +116,8 @@ export class UmbDocumentTypeServerDataSource implements RepositoryDetailDataSour // TODO: use resources when end point is ready: return tryExecuteAndNotify( this.#host, - fetch('/umbraco/management/api/v1/document-type/save', { - method: 'POST', + fetch(`/umbraco/management/api/v1/document-type/${document.key}`, { + method: 'PUT', body: body, headers: { 'Content-Type': 'application/json', @@ -141,8 +141,8 @@ export class UmbDocumentTypeServerDataSource implements RepositoryDetailDataSour // TODO: use resources when end point is ready: return tryExecuteAndNotify( this.#host, - fetch('/umbraco/management/api/v1/document-type/trash', { - method: 'POST', + fetch(`/umbraco/management/api/v1/document-type/${key}`, { + method: 'DELETE', body: JSON.stringify([key]), headers: { 'Content-Type': 'application/json', @@ -167,8 +167,8 @@ export class UmbDocumentTypeServerDataSource implements RepositoryDetailDataSour // TODO: use resources when end point is ready: return tryExecuteAndNotify( this.#host, - fetch('/umbraco/management/api/v1/document-type/trash', { - method: 'POST', + fetch(`/umbraco/management/api/v1/document-type/${key}`, { + method: 'DELETE', body: JSON.stringify([key]), headers: { 'Content-Type': 'application/json', 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 da36b169cb..69ebd21b08 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 @@ -1,35 +1,72 @@ -import { UmbEntityWorkspaceManager } from '../../../shared/components/workspace/workspace-context/entity-manager-controller'; import { UmbWorkspaceContext } from '../../../shared/components/workspace/workspace-context/workspace-context'; import { UmbWorkspaceEntityContextInterface } from '../../../shared/components/workspace/workspace-context/workspace-entity-context.interface'; -import { UMB_DOCUMENT_TYPE_STORE_CONTEXT_TOKEN } from '../repository/document-type.store'; +import { UmbDocumentTypeRepository } from '../repository/document-type.repository'; import type { DocumentTypeModel } from '@umbraco-cms/backend-api'; +import { UmbControllerHostInterface } from '@umbraco-cms/controller'; +import { ObjectState } from '@umbraco-cms/observable-api'; +type EntityType = DocumentTypeModel; export class UmbWorkspaceDocumentTypeContext extends UmbWorkspaceContext - implements UmbWorkspaceEntityContextInterface + implements UmbWorkspaceEntityContextInterface { - #manager = new UmbEntityWorkspaceManager(this._host, 'document-type', UMB_DOCUMENT_TYPE_STORE_CONTEXT_TOKEN); + #host: UmbControllerHostInterface; + #repo: UmbDocumentTypeRepository; - public readonly data = this.#manager.state.asObservable(); - public readonly name = this.#manager.state.getObservablePart((state) => state?.name); + #data = new ObjectState(undefined); + data = this.#data.asObservable(); + name = this.#data.getObservablePart((data) => data?.name); - setName(name: string) { - this.#manager.state.update({ name: name }); + constructor(host: UmbControllerHostInterface) { + super(host); + this.#host = host; + this.#repo = new UmbDocumentTypeRepository(this.#host); } - setIcon(icon: string) { - this.#manager.state.update({ icon: icon }); - } - getEntityType = this.#manager.getEntityType; - getUnique = this.#manager.getEntityKey; - getEntityKey = this.#manager.getEntityKey; - getStore = this.#manager.getStore; - getData = this.#manager.getData; - load = this.#manager.load; - create = this.#manager.create; - save = this.#manager.save; - destroy = this.#manager.destroy; public setPropertyValue(alias: string, value: unknown) { throw new Error('setPropertyValue is not implemented for UmbWorkspaceDocumentTypeContext'); } + + getData() { + return this.#data.getValue(); + } + + getEntityKey() { + return this.getData()?.key || ''; + } + + getEntityType() { + return 'document-type'; + } + + setName(name: string) { + this.#data.update({ name }); + } + + // TODO => manage setting icon color + setIcon(icon: string) { + this.#data.update({ icon }); + } + + async load(entityKey: string) { + const { data } = await this.#repo.requestByKey(entityKey); + if (data) { + this.#data.next(data); + } + } + + async createScaffold(parentKey: string | null) { + const { data } = await this.#repo.createDetailsScaffold(parentKey); + if (!data) return; + this.#data.next(data); + } + + async save() { + if (!this.#data.value) return; + this.#repo.saveDetail(this.#data.value); + } + + public destroy(): void { + this.#data.complete(); + } } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/document-type-workspace.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/document-type-workspace.element.ts index 460eecd5ac..bc9ff169a6 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/document-type-workspace.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/document-types/workspace/document-type-workspace.element.ts @@ -28,6 +28,7 @@ export class UmbDocumentTypeWorkspaceElement extends UmbLitElement implements Um #name { width: 100%; flex: 1 1 auto; + align-items: center; } #alias { @@ -70,7 +71,7 @@ export class UmbDocumentTypeWorkspaceElement extends UmbLitElement implements Um } public create(parentKey: string | null) { - this._workspaceContext.create(parentKey); + this._workspaceContext.createScaffold(parentKey); } // TODO. find a way where we don't have to do this for all workspaces. @@ -89,7 +90,6 @@ export class UmbDocumentTypeWorkspaceElement extends UmbLitElement implements Um modalHandler?.onClose().then((saved) => { if (saved) this._workspaceContext?.setIcon(saved.icon); - console.log(saved); // TODO save color ALIAS as well }); } @@ -100,7 +100,7 @@ export class UmbDocumentTypeWorkspaceElement extends UmbLitElement implements Um