Skip to content

Commit

Permalink
Merge pull request #2095 from umbraco/v14/feature/property-type-works…
Browse files Browse the repository at this point in the history
…pace

Feature: Property Type workspace
  • Loading branch information
nielslyngsoe authored Jul 5, 2024
2 parents f092989 + c0b8d98 commit 59118e5
Show file tree
Hide file tree
Showing 29 changed files with 624 additions and 406 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"./code-editor": "./dist-cms/packages/templating/code-editor/index.js",
"./collection": "./dist-cms/packages/core/collection/index.js",
"./components": "./dist-cms/packages/core/components/index.js",
"./content": "./dist-cms/packages/core/content/index.js",
"./content-type": "./dist-cms/packages/core/content-type/index.js",
"./content": "./dist-cms/packages/core/content/index.js",
"./culture": "./dist-cms/packages/core/culture/index.js",
"./current-user": "./dist-cms/packages/user/current-user/index.js",
"./data-type": "./dist-cms/packages/data-type/index.js",
Expand All @@ -35,9 +35,9 @@
"./document-blueprint": "./dist-cms/packages/documents/document-blueprints/index.js",
"./document-type": "./dist-cms/packages/documents/document-types/index.js",
"./document": "./dist-cms/packages/documents/documents/index.js",
"./entity": "./dist-cms/packages/core/entity/index.js",
"./entity-action": "./dist-cms/packages/core/entity-action/index.js",
"./entity-bulk-action": "./dist-cms/packages/core/entity-bulk-action/index.js",
"./entity": "./dist-cms/packages/core/entity/index.js",
"./event": "./dist-cms/packages/core/event/index.js",
"./extension-registry": "./dist-cms/packages/core/extension-registry/index.js",
"./icon": "./dist-cms/packages/core/icon-registry/index.js",
Expand All @@ -63,6 +63,7 @@
"./picker-input": "./dist-cms/packages/core/picker-input/index.js",
"./property-action": "./dist-cms/packages/core/property-action/index.js",
"./property-editor": "./dist-cms/packages/core/property-editor/index.js",
"./property-type": "./dist-cms/packages/core/property-type/index.js",
"./property": "./dist-cms/packages/core/property/index.js",
"./recycle-bin": "./dist-cms/packages/core/recycle-bin/index.js",
"./relation-type": "./dist-cms/packages/relations/relation-types/index.js",
Expand All @@ -73,8 +74,8 @@
"./script": "./dist-cms/packages/templating/scripts/index.js",
"./search": "./dist-cms/packages/search/index.js",
"./section": "./dist-cms/packages/core/section/index.js",
"./settings": "./dist-cms/packages/settings/index.js",
"./server-file-system": "./dist-cms/packages/core/server-file-system/index.js",
"./settings": "./dist-cms/packages/settings/index.js",
"./sorter": "./dist-cms/packages/core/sorter/index.js",
"./static-file": "./dist-cms/packages/static-file/index.js",
"./store": "./dist-cms/packages/core/store/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
UmbInvariantWorkspacePropertyDatasetContext,
UmbWorkspaceIsNewRedirectController,
} from '@umbraco-cms/backoffice/workspace';
import { UmbArrayState, UmbObjectState, appendToFrozenArray } from '@umbraco-cms/backoffice/observable-api';
import { UmbObjectState, appendToFrozenArray } from '@umbraco-cms/backoffice/observable-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
import type { ManifestWorkspace, PropertyEditorSettingsProperty } from '@umbraco-cms/backoffice/extension-registry';
import type { ManifestWorkspace } from '@umbraco-cms/backoffice/extension-registry';

export class UmbBlockTypeWorkspaceContext<BlockTypeData extends UmbBlockTypeWithGroupKey = UmbBlockTypeWithGroupKey>
extends UmbSubmittableWorkspaceContextBase<BlockTypeData>
Expand All @@ -30,9 +30,6 @@ export class UmbBlockTypeWorkspaceContext<BlockTypeData extends UmbBlockTypeWith
readonly name = this.#data.asObservablePart(() => 'block');
readonly unique = this.#data.asObservablePart((data) => data?.contentElementTypeKey);

#properties = new UmbArrayState<PropertyEditorSettingsProperty>([], (x) => x.alias);
readonly properties = this.#properties.asObservable();

constructor(host: UmbControllerHost, args: { manifest: ManifestWorkspace }) {
super(host, args.manifest.alias);
const manifest = args.manifest;
Expand Down Expand Up @@ -73,7 +70,7 @@ export class UmbBlockTypeWorkspaceContext<BlockTypeData extends UmbBlockTypeWith
protected override resetState() {
super.resetState();
this.#data.setValue(undefined);
this.#properties.setValue([]);
this.removeUmbControllerByAlias('isNewRedirectController');
}

createPropertyDatasetContext(host: UmbControllerHost): UmbPropertyDatasetContext {
Expand Down Expand Up @@ -171,7 +168,6 @@ export class UmbBlockTypeWorkspaceContext<BlockTypeData extends UmbBlockTypeWith

public override destroy(): void {
this.#data.destroy();
this.#properties.destroy();
super.destroy();
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/packages/block/block/workspace/block-element-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export class UmbBlockElementManager extends UmbControllerBase {
this.observe(this.contentTypeId, (id) => this.structure.loadType(id));
}

reset() {
this.#data.setValue(undefined);
}

setData(data: UmbBlockDataType | undefined) {
this.#data.setValue(data);
this.#getDataResolver();
Expand Down
13 changes: 12 additions & 1 deletion src/packages/block/block/workspace/block-workspace.context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,24 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
]);
}

protected override resetState() {
super.resetState();
this.#label.setValue(undefined);
this.#layout.setValue(undefined);
this.#initialLayout = undefined;
this.#initialContent = undefined;
this.#initialSettings = undefined;
this.content.reset();
this.settings.reset();
this.removeUmbControllerByAlias('isNewRedirectController');
}

async load(unique: string) {
await this.#retrieveBlockManager;
await this.#retrieveBlockEntries;
await this.#editorConfigPromise;
if (!this.#blockManager || !this.#blockEntries) {
throw new Error('Block manager not found');
return;
}

this.observe(
Expand Down
2 changes: 0 additions & 2 deletions src/packages/core/content-type/modals/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export * from './composition-picker/composition-picker-modal.token.js';
export * from './property-type-settings/property-type-settings-modal.token.js';
export * from './property-type-settings/property-type-settings-modal.context-token.js';
6 changes: 0 additions & 6 deletions src/packages/core/content-type/modals/manifests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ const modals: Array<ManifestModal> = [
name: 'ContentType Composition Picker Modal',
element: () => import('./composition-picker/composition-picker-modal.element.js'),
},
{
type: 'modal',
alias: 'Umb.Modal.PropertyTypeSettings',
name: 'Property Type Settings Modal',
element: () => import('./property-type-settings/property-type-settings-modal.element.js'),
},
];

export const manifests = modals;

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,6 @@ export class UmbContentTypePropertyStructureHelper<T extends UmbContentTypeModel
// TODO: consider moving this to another class, to separate 'viewer' from 'manipulator':
/** Manipulate methods: */

async createPropertyScaffold(ownerId?: string | null) {
await this.#init;
if (!this.#structure) return;

return await this.#structure.createPropertyScaffold(ownerId);
}
/*
Only used by legacy implementation:
@deprecated
*/
async addProperty(containerId?: string, sortOrder?: number) {
await this.#init;
if (!this.#structure) return;

return await this.#structure.createProperty(null, containerId, sortOrder);
}

async insertProperty(property: UmbPropertyTypeModel, sortOrder?: number) {
await this.#init;
if (!this.#structure) return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
UmbPropertyContainerTypes,
UmbPropertyTypeContainerModel,
UmbPropertyTypeModel,
UmbPropertyTypeScaffoldModel,
} from '../types.js';
import type { UmbDetailRepository } from '@umbraco-cms/backoffice/repository';
import { UmbId } from '@umbraco-cms/backoffice/id';
Expand Down Expand Up @@ -43,6 +42,7 @@ export class UmbContentTypeStructureManager<
readonly ownerContentType = this.#contentTypes.asObservablePart((x) =>
x.find((y) => y.unique === this.#ownerContentTypeUnique),
);

private readonly _contentTypeContainers = this.#contentTypes.asObservablePart((x) =>
x.flatMap((x) => x.containers ?? []),
);
Expand Down Expand Up @@ -449,61 +449,6 @@ export class UmbContentTypeStructureManager<
this.#contentTypes.updateOne(contentTypeUnique, { containers, properties });
}

createPropertyScaffold(containerId: string | null = null) {
const property: UmbPropertyTypeScaffoldModel = {
id: UmbId.new(),
container: containerId ? { id: containerId } : null,
alias: '',
name: '',
description: '',
variesByCulture: false,
variesBySegment: false,
validation: {
mandatory: false,
mandatoryMessage: null,
regEx: null,
regExMessage: null,
},
appearance: {
labelOnTop: false,
},
sortOrder: 0,
};

return property;
}

async createProperty(contentTypeUnique: string | null, containerId: string | null = null, sortOrder?: number) {
await this.#init;
contentTypeUnique = contentTypeUnique ?? this.#ownerContentTypeUnique!;

// If we have a container, we need to ensure it exists, and then update the container with the new parent id. [NL]
if (containerId) {
const container = await this.ensureContainerOf(containerId, contentTypeUnique);
if (!container) {
throw new Error('Container for inserting property could not be found or created');
}
// Correct containerId to the local one: [NL]
containerId = container.id;
}

const property = this.createPropertyScaffold(containerId);
property.sortOrder = sortOrder ?? 0;

const properties: Array<UmbPropertyTypeScaffoldModel | UmbPropertyTypeModel> = [
...(this.#contentTypes.getValue().find((x) => x.unique === contentTypeUnique)?.properties ?? []),
];

properties.push(property);

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// TODO: fix TS partial complaint
this.#contentTypes.updateOne(contentTypeUnique, { properties });

return property;
}

async insertProperty(contentTypeUnique: string | null, property: UmbPropertyTypeModel) {
await this.#init;
contentTypeUnique = contentTypeUnique ?? this.#ownerContentTypeUnique!;
Expand All @@ -518,6 +463,10 @@ export class UmbContentTypeStructureManager<
property = { ...property, container: { id: container.id } };
}

if (property.sortOrder === undefined) {
property.sortOrder = 0;
}

const frozenProperties =
this.#contentTypes.getValue().find((x) => x.unique === contentTypeUnique)?.properties ?? [];

Expand Down
Loading

0 comments on commit 59118e5

Please sign in to comment.