adapt UmbPropertyContainerTypes and related

This commit is contained in:
Niels Lyngsø
2024-01-30 16:00:45 +01:00
parent bc31ee3958
commit 9be4a5d531
8 changed files with 55 additions and 50 deletions

View File

@@ -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);
}

View File

@@ -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<T extends UmbContentTypeMode
#structure?: UmbContentTypePropertyStructureManager<T>;
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<T extends UmbContentTypeMode
this._observeOwnerAlikeContainers();
}
public setType(value?: PropertyContainerTypes) {
public setType(value?: UmbPropertyContainerTypes) {
if (this._ownerType === value) return;
this._ownerType = value;
this._observeOwnerAlikeContainers();
@@ -62,7 +59,7 @@ export class UmbContentTypeContainerStructureHelper<T extends UmbContentTypeMode
return this._ownerType;
}
public setContainerChildType(value?: PropertyContainerTypes) {
public setContainerChildType(value?: UmbPropertyContainerTypes) {
if (this._childType === value) return;
this._childType = value;
this._observeOwnerAlikeContainers();

View File

@@ -1,8 +1,5 @@
import type {
PropertyContainerTypes,
UmbContentTypePropertyStructureManager,
} from './content-type-structure-manager.class.js';
import type { UmbContentTypeModel, UmbPropertyTypeModel } from './types.js';
import type { UmbContentTypePropertyStructureManager } from './content-type-structure-manager.class.js';
import type { UmbContentTypeModel, UmbPropertyContainerTypes, UmbPropertyTypeModel } from './types.js';
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import { UmbArrayState, UmbObserverController } from '@umbraco-cms/backoffice/observable-api';
@@ -13,7 +10,7 @@ export class UmbContentTypePropertyStructureHelper<T extends UmbContentTypeModel
#structure?: UmbContentTypePropertyStructureManager<T>;
private _containerType?: PropertyContainerTypes;
private _containerType?: UmbPropertyContainerTypes;
private _isRoot?: boolean;
private _containerName?: string;
@@ -40,7 +37,7 @@ export class UmbContentTypePropertyStructureHelper<T extends UmbContentTypeModel
this._observeGroupContainers();
}
public setContainerType(value?: PropertyContainerTypes) {
public setContainerType(value?: UmbPropertyContainerTypes) {
if (this._containerType === value) return;
this._containerType = value;
this._observeGroupContainers();

View File

@@ -1,7 +1,11 @@
import type { UmbContentTypeModel, UmbPropertyTypeModel } from './types.js';
import type {
UmbContentTypeModel,
UmbPropertyContainerTypes,
UmbPropertyTypeContainerModel,
UmbPropertyTypeModel,
} from './types.js';
import type { UmbDetailRepository } from '@umbraco-cms/backoffice/repository';
import { UmbId } from '@umbraco-cms/backoffice/id';
import type { PropertyTypeContainerModelBaseModel } from '@umbraco-cms/backoffice/backend-api';
import type { UmbControllerHost, UmbController } from '@umbraco-cms/backoffice/controller-api';
import type { MappingFunction } from '@umbraco-cms/backoffice/observable-api';
import {
@@ -13,10 +17,6 @@ import {
import { incrementString } from '@umbraco-cms/backoffice/utils';
import { UmbBaseController } from '@umbraco-cms/backoffice/class-api';
export type PropertyContainerTypes = 'Group' | 'Tab';
// TODO: get this type from the repository, or use some generic type.
// TODO: Make this a controller on its own:
export class UmbContentTypePropertyStructureManager<T extends UmbContentTypeModel> extends UmbBaseController {
#init!: Promise<unknown>;
@@ -30,8 +30,10 @@ export class UmbContentTypePropertyStructureManager<T extends UmbContentTypeMode
x.flatMap((x) => x.containers ?? []),
);
#containers: UmbArrayState<PropertyTypeContainerModelBaseModel> =
new UmbArrayState<PropertyTypeContainerModelBaseModel>([], (x) => x.id);
#containers: UmbArrayState<UmbPropertyTypeContainerModel> = new UmbArrayState<UmbPropertyTypeContainerModel>(
[],
(x) => x.id,
);
constructor(host: UmbControllerHost, typeRepository: UmbDetailRepository<T>) {
super(host);
@@ -178,13 +180,13 @@ export class UmbContentTypePropertyStructureManager<T extends UmbContentTypeMode
async createContainer(
contentTypeUnique: string | null,
parentId: string | null = null,
type: PropertyContainerTypes = 'Group',
type: UmbPropertyContainerTypes = 'Group',
sortOrder?: number,
) {
await this.#init;
contentTypeUnique = contentTypeUnique ?? this.#ownerContentTypeUnique!;
const container: PropertyTypeContainerModelBaseModel = {
const container: UmbPropertyTypeContainerModel = {
id: UmbId.new(),
parent: parentId ? { id: parentId } : null,
name: '',
@@ -205,7 +207,7 @@ export class UmbContentTypePropertyStructureManager<T extends UmbContentTypeMode
return container;
}
async insertContainer(contentTypeUnique: string | null, container: PropertyTypeContainerModelBaseModel) {
async insertContainer(contentTypeUnique: string | null, container: UmbPropertyTypeContainerModel) {
await this.#init;
contentTypeUnique = contentTypeUnique ?? this.#ownerContentTypeUnique!;
@@ -223,7 +225,7 @@ export class UmbContentTypePropertyStructureManager<T extends UmbContentTypeMode
makeContainerNameUniqueForOwnerContentType(
newName: string,
containerType: PropertyContainerTypes = 'Tab',
containerType: UmbPropertyContainerTypes = 'Tab',
parentId: string | null = null,
) {
const ownerRootContainers = this.getOwnerContainers(containerType); //getRootContainers() can't differentiates between compositions and locals
@@ -242,7 +244,7 @@ export class UmbContentTypePropertyStructureManager<T extends UmbContentTypeMode
async updateContainer(
contentTypeUnique: string | null,
containerId: string,
partialUpdate: Partial<PropertyTypeContainerModelBaseModel>,
partialUpdate: Partial<UmbPropertyTypeContainerModel>,
) {
await this.#init;
contentTypeUnique = contentTypeUnique ?? this.#ownerContentTypeUnique!;
@@ -448,27 +450,27 @@ export class UmbContentTypePropertyStructureManager<T extends UmbContentTypeMode
});
}
rootContainers(containerType: PropertyContainerTypes) {
rootContainers(containerType: UmbPropertyContainerTypes) {
return this.#containers.asObservablePart((data) => {
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<T extends UmbContentTypeMode
return this.getOwnerContentType()?.containers?.filter((x) => 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);
});

View File

@@ -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<UmbPropertyTypeModel>;
containers: Array<PropertyTypeContainerModelBaseModel>;
containers: Array<UmbPropertyTypeContainerModel>;
allowedContentTypes: Array<UmbContentTypeSortModel>;
compositions: Array<UmbContentTypeCompositionModel>;
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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);
}