From 9be4a5d53166b6bc264f3fdba10973f2661ccdbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Tue, 30 Jan 2024 16:00:45 +0100 Subject: [PATCH] adapt UmbPropertyContainerTypes and related --- ...-workspace-view-edit-properties.element.ts | 6 +-- ...t-type-container-structure-helper.class.ts | 15 +++---- ...nt-type-property-structure-helper.class.ts | 11 ++--- .../content-type-structure-manager.class.ts | 42 ++++++++++--------- .../src/packages/core/content-type/types.ts | 13 +++++- ...-workspace-view-edit-properties.element.ts | 6 +-- ...-workspace-view-edit-properties.element.ts | 6 +-- ...-workspace-view-edit-properties.element.ts | 6 +-- 8 files changed, 55 insertions(+), 50 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/views/edit/block-workspace-view-edit-properties.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/views/edit/block-workspace-view-edit-properties.element.ts index fb85953276..4095d6167a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/views/edit/block-workspace-view-edit-properties.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block/workspace/views/edit/block-workspace-view-edit-properties.element.ts @@ -2,7 +2,7 @@ import { UMB_BLOCK_WORKSPACE_CONTEXT } from '../../block-workspace.context-token import { css, html, customElement, property, state, repeat } from '@umbraco-cms/backoffice/external/lit'; import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import type { - PropertyContainerTypes, + UmbPropertyContainerTypes, UmbContentTypeModel, UmbPropertyTypeModel, } from '@umbraco-cms/backoffice/content-type'; @@ -20,10 +20,10 @@ export class UmbBlockWorkspaceViewEditPropertiesElement extends UmbLitElement { } @property({ type: String, attribute: 'container-type', reflect: false }) - public get containerType(): PropertyContainerTypes | undefined { + public get containerType(): UmbPropertyContainerTypes | undefined { return this._propertyStructureHelper.getContainerType(); } - public set containerType(value: PropertyContainerTypes | undefined) { + public set containerType(value: UmbPropertyContainerTypes | undefined) { this._propertyStructureHelper.setContainerType(value); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/content-type-container-structure-helper.class.ts b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/content-type-container-structure-helper.class.ts index 9dbda290e9..cc662c5d20 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/content-type-container-structure-helper.class.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/content-type-container-structure-helper.class.ts @@ -1,8 +1,5 @@ -import type { - PropertyContainerTypes, - UmbContentTypePropertyStructureManager, -} from './content-type-structure-manager.class.js'; -import type { UmbContentTypeModel } from './types.js'; +import type { UmbContentTypePropertyStructureManager } from './content-type-structure-manager.class.js'; +import type { UmbContentTypeModel, UmbPropertyContainerTypes } from './types.js'; import type { PropertyTypeContainerModelBaseModel } from '@umbraco-cms/backoffice/backend-api'; import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; import { UmbArrayState, UmbBooleanState, UmbObserverController } from '@umbraco-cms/backoffice/observable-api'; @@ -14,8 +11,8 @@ export class UmbContentTypeContainerStructureHelper; - private _ownerType?: PropertyContainerTypes = 'Tab'; - private _childType?: PropertyContainerTypes = 'Group'; + private _ownerType?: UmbPropertyContainerTypes = 'Tab'; + private _childType?: UmbPropertyContainerTypes = 'Group'; private _isRoot = false; /** * The owner id is the owning container (The container that is begin presented, the container is the parent of the child containers) @@ -53,7 +50,7 @@ export class UmbContentTypeContainerStructureHelper; - private _containerType?: PropertyContainerTypes; + private _containerType?: UmbPropertyContainerTypes; private _isRoot?: boolean; private _containerName?: string; @@ -40,7 +37,7 @@ export class UmbContentTypePropertyStructureHelper extends UmbBaseController { #init!: Promise; @@ -30,8 +30,10 @@ export class UmbContentTypePropertyStructureManager x.containers ?? []), ); - #containers: UmbArrayState = - new UmbArrayState([], (x) => x.id); + #containers: UmbArrayState = new UmbArrayState( + [], + (x) => x.id, + ); constructor(host: UmbControllerHost, typeRepository: UmbDetailRepository) { super(host); @@ -178,13 +180,13 @@ export class UmbContentTypePropertyStructureManager, + partialUpdate: Partial, ) { await this.#init; contentTypeUnique = contentTypeUnique ?? this.#ownerContentTypeUnique!; @@ -448,27 +450,27 @@ export class UmbContentTypePropertyStructureManager { return data.filter((x) => x.parent === null && x.type === containerType); }); } - getRootContainers(containerType: PropertyContainerTypes) { + getRootContainers(containerType: UmbPropertyContainerTypes) { return this.#containers.getValue().filter((x) => x.parent === null && x.type === containerType); } - hasRootContainers(containerType: PropertyContainerTypes) { + hasRootContainers(containerType: UmbPropertyContainerTypes) { return this.#containers.asObservablePart((data) => { return data.filter((x) => x.parent === null && x.type === containerType).length > 0; }); } - ownerContainersOf(containerType: PropertyContainerTypes) { + ownerContainersOf(containerType: UmbPropertyContainerTypes) { return this.ownerContentTypeObservablePart((x) => x.containers?.filter((x) => x.type === containerType) ?? []); } - getOwnerContainers(containerType: PropertyContainerTypes, parentId: string | null = null) { + getOwnerContainers(containerType: UmbPropertyContainerTypes, parentId: string | null = null) { return this.getOwnerContentType()?.containers?.filter((x) => parentId ? x.parent?.id === parentId : x.parent === null && x.type === containerType, ); @@ -478,14 +480,14 @@ export class UmbContentTypePropertyStructureManager x.id === containerId); } - containersOfParentKey(parentId: string, containerType: PropertyContainerTypes) { + containersOfParentKey(parentId: string, containerType: UmbPropertyContainerTypes) { return this.#containers.asObservablePart((data) => { return data.filter((x) => x.parent?.id === parentId && x.type === containerType); }); } // In future this might need to take parentName(parentId lookup) into account as well? otherwise containers that share same name and type will always be merged, but their position might be different and they should not be merged. - containersByNameAndType(name: string, containerType: PropertyContainerTypes) { + containersByNameAndType(name: string, containerType: UmbPropertyContainerTypes) { return this.#containers.asObservablePart((data) => { return data.filter((x) => x.name === name && x.type === containerType); }); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/types.ts b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/types.ts index a52488720e..14b63f4a6d 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/types.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/types.ts @@ -1,9 +1,18 @@ import type { - PropertyTypeContainerModelBaseModel, CompositionTypeModel, PropertyTypeModelBaseModel, + ReferenceByIdModel, } from '@umbraco-cms/backoffice/backend-api'; +export type UmbPropertyContainerTypes = 'Group' | 'Tab'; +export interface UmbPropertyTypeContainerModel { + id: string; + parent?: ReferenceByIdModel | null; + name?: string | null; + type: UmbPropertyContainerTypes; + sortOrder: number; +} + export interface UmbContentTypeModel { unique: string; parentUnique: string | null; @@ -17,7 +26,7 @@ export interface UmbContentTypeModel { isElement: boolean; // TODO: investigate if we need our own model for these properties: Array; - containers: Array; + containers: Array; allowedContentTypes: Array; compositions: Array; } diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/views/design/document-type-workspace-view-edit-properties.element.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/views/design/document-type-workspace-view-edit-properties.element.ts index dec6391e3c..aad0855107 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/views/design/document-type-workspace-view-edit-properties.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/workspace/views/design/document-type-workspace-view-edit-properties.element.ts @@ -3,7 +3,7 @@ import './document-type-workspace-view-edit-property.element.js'; import type { UmbDocumentTypeDetailModel } from '../../../types.js'; import { css, html, customElement, property, state, repeat, ifDefined } from '@umbraco-cms/backoffice/external/lit'; import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; -import type { PropertyContainerTypes, UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type'; +import type { UmbPropertyContainerTypes, UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type'; import { UmbContentTypePropertyStructureHelper } from '@umbraco-cms/backoffice/content-type'; import type { UmbSorterConfig } from '@umbraco-cms/backoffice/sorter'; import { UmbSorterController } from '@umbraco-cms/backoffice/sorter'; @@ -80,10 +80,10 @@ export class UmbDocumentTypeWorkspaceViewEditPropertiesElement extends UmbLitEle } @property({ type: String, attribute: 'container-type', reflect: false }) - public get containerType(): PropertyContainerTypes | undefined { + public get containerType(): UmbPropertyContainerTypes | undefined { return this._propertyStructureHelper.getContainerType(); } - public set containerType(value: PropertyContainerTypes | undefined) { + public set containerType(value: UmbPropertyContainerTypes | undefined) { this._propertyStructureHelper.setContainerType(value); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/views/edit/document-workspace-view-edit-properties.element.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/views/edit/document-workspace-view-edit-properties.element.ts index a4dd018e79..5862165faf 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/views/edit/document-workspace-view-edit-properties.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/views/edit/document-workspace-view-edit-properties.element.ts @@ -1,7 +1,7 @@ import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '../../document-workspace.context-token.js'; import { css, html, customElement, property, state, repeat } from '@umbraco-cms/backoffice/external/lit'; import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; -import type { PropertyContainerTypes, UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type'; +import type { UmbPropertyContainerTypes, UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type'; import { UmbContentTypePropertyStructureHelper } from '@umbraco-cms/backoffice/content-type'; import { UmbLitElement } from '@umbraco-cms/internal/lit-element'; @@ -16,10 +16,10 @@ export class UmbDocumentWorkspaceViewEditPropertiesElement extends UmbLitElement } @property({ type: String, attribute: 'container-type', reflect: false }) - public get containerType(): PropertyContainerTypes | undefined { + public get containerType(): UmbPropertyContainerTypes | undefined { return this._propertyStructureHelper.getContainerType(); } - public set containerType(value: PropertyContainerTypes | undefined) { + public set containerType(value: UmbPropertyContainerTypes | undefined) { this._propertyStructureHelper.setContainerType(value); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/media/media-types/workspace/views/design/media-type-workspace-view-edit-properties.element.ts b/src/Umbraco.Web.UI.Client/src/packages/media/media-types/workspace/views/design/media-type-workspace-view-edit-properties.element.ts index 9213ec0e76..1208510994 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/media/media-types/workspace/views/design/media-type-workspace-view-edit-properties.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/media/media-types/workspace/views/design/media-type-workspace-view-edit-properties.element.ts @@ -3,7 +3,7 @@ import './media-type-workspace-view-edit-property.element.js'; import type { UmbMediaTypeDetailModel } from '../../../types.js'; import { css, html, customElement, property, state, repeat, ifDefined } from '@umbraco-cms/backoffice/external/lit'; import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; -import type { PropertyContainerTypes, UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type'; +import type { UmbPropertyContainerTypes, UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type'; import { UmbContentTypePropertyStructureHelper } from '@umbraco-cms/backoffice/content-type'; import type { UmbSorterConfig } from '@umbraco-cms/backoffice/sorter'; import { UmbSorterController } from '@umbraco-cms/backoffice/sorter'; @@ -80,10 +80,10 @@ export class UmbMediaTypeWorkspaceViewEditPropertiesElement extends UmbLitElemen } @property({ type: String, attribute: 'container-type', reflect: false }) - public get containerType(): PropertyContainerTypes | undefined { + public get containerType(): UmbPropertyContainerTypes | undefined { return this._propertyStructureHelper.getContainerType(); } - public set containerType(value: PropertyContainerTypes | undefined) { + public set containerType(value: UmbPropertyContainerTypes | undefined) { this._propertyStructureHelper.setContainerType(value); }