Skip to content

Commit 59118e5

Browse files
authored
Merge pull request #2095 from umbraco/v14/feature/property-type-workspace
Feature: Property Type workspace
2 parents f092989 + c0b8d98 commit 59118e5

29 files changed

+624
-406
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"./code-editor": "./dist-cms/packages/templating/code-editor/index.js",
2626
"./collection": "./dist-cms/packages/core/collection/index.js",
2727
"./components": "./dist-cms/packages/core/components/index.js",
28-
"./content": "./dist-cms/packages/core/content/index.js",
2928
"./content-type": "./dist-cms/packages/core/content-type/index.js",
29+
"./content": "./dist-cms/packages/core/content/index.js",
3030
"./culture": "./dist-cms/packages/core/culture/index.js",
3131
"./current-user": "./dist-cms/packages/user/current-user/index.js",
3232
"./data-type": "./dist-cms/packages/data-type/index.js",
@@ -35,9 +35,9 @@
3535
"./document-blueprint": "./dist-cms/packages/documents/document-blueprints/index.js",
3636
"./document-type": "./dist-cms/packages/documents/document-types/index.js",
3737
"./document": "./dist-cms/packages/documents/documents/index.js",
38-
"./entity": "./dist-cms/packages/core/entity/index.js",
3938
"./entity-action": "./dist-cms/packages/core/entity-action/index.js",
4039
"./entity-bulk-action": "./dist-cms/packages/core/entity-bulk-action/index.js",
40+
"./entity": "./dist-cms/packages/core/entity/index.js",
4141
"./event": "./dist-cms/packages/core/event/index.js",
4242
"./extension-registry": "./dist-cms/packages/core/extension-registry/index.js",
4343
"./icon": "./dist-cms/packages/core/icon-registry/index.js",
@@ -63,6 +63,7 @@
6363
"./picker-input": "./dist-cms/packages/core/picker-input/index.js",
6464
"./property-action": "./dist-cms/packages/core/property-action/index.js",
6565
"./property-editor": "./dist-cms/packages/core/property-editor/index.js",
66+
"./property-type": "./dist-cms/packages/core/property-type/index.js",
6667
"./property": "./dist-cms/packages/core/property/index.js",
6768
"./recycle-bin": "./dist-cms/packages/core/recycle-bin/index.js",
6869
"./relation-type": "./dist-cms/packages/relations/relation-types/index.js",
@@ -73,8 +74,8 @@
7374
"./script": "./dist-cms/packages/templating/scripts/index.js",
7475
"./search": "./dist-cms/packages/search/index.js",
7576
"./section": "./dist-cms/packages/core/section/index.js",
76-
"./settings": "./dist-cms/packages/settings/index.js",
7777
"./server-file-system": "./dist-cms/packages/core/server-file-system/index.js",
78+
"./settings": "./dist-cms/packages/settings/index.js",
7879
"./sorter": "./dist-cms/packages/core/sorter/index.js",
7980
"./static-file": "./dist-cms/packages/static-file/index.js",
8081
"./store": "./dist-cms/packages/core/store/index.js",

src/packages/block/block-type/workspace/block-type-workspace.context.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111
UmbInvariantWorkspacePropertyDatasetContext,
1212
UmbWorkspaceIsNewRedirectController,
1313
} from '@umbraco-cms/backoffice/workspace';
14-
import { UmbArrayState, UmbObjectState, appendToFrozenArray } from '@umbraco-cms/backoffice/observable-api';
14+
import { UmbObjectState, appendToFrozenArray } from '@umbraco-cms/backoffice/observable-api';
1515
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
16-
import type { ManifestWorkspace, PropertyEditorSettingsProperty } from '@umbraco-cms/backoffice/extension-registry';
16+
import type { ManifestWorkspace } from '@umbraco-cms/backoffice/extension-registry';
1717

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

33-
#properties = new UmbArrayState<PropertyEditorSettingsProperty>([], (x) => x.alias);
34-
readonly properties = this.#properties.asObservable();
35-
3633
constructor(host: UmbControllerHost, args: { manifest: ManifestWorkspace }) {
3734
super(host, args.manifest.alias);
3835
const manifest = args.manifest;
@@ -73,7 +70,7 @@ export class UmbBlockTypeWorkspaceContext<BlockTypeData extends UmbBlockTypeWith
7370
protected override resetState() {
7471
super.resetState();
7572
this.#data.setValue(undefined);
76-
this.#properties.setValue([]);
73+
this.removeUmbControllerByAlias('isNewRedirectController');
7774
}
7875

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

172169
public override destroy(): void {
173170
this.#data.destroy();
174-
this.#properties.destroy();
175171
super.destroy();
176172
}
177173
}

src/packages/block/block/workspace/block-element-manager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export class UmbBlockElementManager extends UmbControllerBase {
3131
this.observe(this.contentTypeId, (id) => this.structure.loadType(id));
3232
}
3333

34+
reset() {
35+
this.#data.setValue(undefined);
36+
}
37+
3438
setData(data: UmbBlockDataType | undefined) {
3539
this.#data.setValue(data);
3640
this.#getDataResolver();

src/packages/block/block/workspace/block-workspace.context.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,24 @@ export class UmbBlockWorkspaceContext<LayoutDataType extends UmbBlockLayoutBaseM
112112
]);
113113
}
114114

115+
protected override resetState() {
116+
super.resetState();
117+
this.#label.setValue(undefined);
118+
this.#layout.setValue(undefined);
119+
this.#initialLayout = undefined;
120+
this.#initialContent = undefined;
121+
this.#initialSettings = undefined;
122+
this.content.reset();
123+
this.settings.reset();
124+
this.removeUmbControllerByAlias('isNewRedirectController');
125+
}
126+
115127
async load(unique: string) {
116128
await this.#retrieveBlockManager;
117129
await this.#retrieveBlockEntries;
118130
await this.#editorConfigPromise;
119131
if (!this.#blockManager || !this.#blockEntries) {
120132
throw new Error('Block manager not found');
121-
return;
122133
}
123134

124135
this.observe(
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
11
export * from './composition-picker/composition-picker-modal.token.js';
2-
export * from './property-type-settings/property-type-settings-modal.token.js';
3-
export * from './property-type-settings/property-type-settings-modal.context-token.js';

src/packages/core/content-type/modals/manifests.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ const modals: Array<ManifestModal> = [
77
name: 'ContentType Composition Picker Modal',
88
element: () => import('./composition-picker/composition-picker-modal.element.js'),
99
},
10-
{
11-
type: 'modal',
12-
alias: 'Umb.Modal.PropertyTypeSettings',
13-
name: 'Property Type Settings Modal',
14-
element: () => import('./property-type-settings/property-type-settings-modal.element.js'),
15-
},
1610
];
1711

1812
export const manifests = modals;

src/packages/core/content-type/modals/property-type-settings/property-type-settings-modal.context.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/packages/core/content-type/modals/property-type-settings/property-type-settings-modal.token.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/packages/core/content-type/structure/content-type-property-structure-helper.class.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -181,23 +181,6 @@ export class UmbContentTypePropertyStructureHelper<T extends UmbContentTypeModel
181181
// TODO: consider moving this to another class, to separate 'viewer' from 'manipulator':
182182
/** Manipulate methods: */
183183

184-
async createPropertyScaffold(ownerId?: string | null) {
185-
await this.#init;
186-
if (!this.#structure) return;
187-
188-
return await this.#structure.createPropertyScaffold(ownerId);
189-
}
190-
/*
191-
Only used by legacy implementation:
192-
@deprecated
193-
*/
194-
async addProperty(containerId?: string, sortOrder?: number) {
195-
await this.#init;
196-
if (!this.#structure) return;
197-
198-
return await this.#structure.createProperty(null, containerId, sortOrder);
199-
}
200-
201184
async insertProperty(property: UmbPropertyTypeModel, sortOrder?: number) {
202185
await this.#init;
203186
if (!this.#structure) return false;

src/packages/core/content-type/structure/content-type-structure-manager.class.ts

Lines changed: 5 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type {
33
UmbPropertyContainerTypes,
44
UmbPropertyTypeContainerModel,
55
UmbPropertyTypeModel,
6-
UmbPropertyTypeScaffoldModel,
76
} from '../types.js';
87
import type { UmbDetailRepository } from '@umbraco-cms/backoffice/repository';
98
import { UmbId } from '@umbraco-cms/backoffice/id';
@@ -43,6 +42,7 @@ export class UmbContentTypeStructureManager<
4342
readonly ownerContentType = this.#contentTypes.asObservablePart((x) =>
4443
x.find((y) => y.unique === this.#ownerContentTypeUnique),
4544
);
45+
4646
private readonly _contentTypeContainers = this.#contentTypes.asObservablePart((x) =>
4747
x.flatMap((x) => x.containers ?? []),
4848
);
@@ -449,61 +449,6 @@ export class UmbContentTypeStructureManager<
449449
this.#contentTypes.updateOne(contentTypeUnique, { containers, properties });
450450
}
451451

452-
createPropertyScaffold(containerId: string | null = null) {
453-
const property: UmbPropertyTypeScaffoldModel = {
454-
id: UmbId.new(),
455-
container: containerId ? { id: containerId } : null,
456-
alias: '',
457-
name: '',
458-
description: '',
459-
variesByCulture: false,
460-
variesBySegment: false,
461-
validation: {
462-
mandatory: false,
463-
mandatoryMessage: null,
464-
regEx: null,
465-
regExMessage: null,
466-
},
467-
appearance: {
468-
labelOnTop: false,
469-
},
470-
sortOrder: 0,
471-
};
472-
473-
return property;
474-
}
475-
476-
async createProperty(contentTypeUnique: string | null, containerId: string | null = null, sortOrder?: number) {
477-
await this.#init;
478-
contentTypeUnique = contentTypeUnique ?? this.#ownerContentTypeUnique!;
479-
480-
// If we have a container, we need to ensure it exists, and then update the container with the new parent id. [NL]
481-
if (containerId) {
482-
const container = await this.ensureContainerOf(containerId, contentTypeUnique);
483-
if (!container) {
484-
throw new Error('Container for inserting property could not be found or created');
485-
}
486-
// Correct containerId to the local one: [NL]
487-
containerId = container.id;
488-
}
489-
490-
const property = this.createPropertyScaffold(containerId);
491-
property.sortOrder = sortOrder ?? 0;
492-
493-
const properties: Array<UmbPropertyTypeScaffoldModel | UmbPropertyTypeModel> = [
494-
...(this.#contentTypes.getValue().find((x) => x.unique === contentTypeUnique)?.properties ?? []),
495-
];
496-
497-
properties.push(property);
498-
499-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
500-
// @ts-ignore
501-
// TODO: fix TS partial complaint
502-
this.#contentTypes.updateOne(contentTypeUnique, { properties });
503-
504-
return property;
505-
}
506-
507452
async insertProperty(contentTypeUnique: string | null, property: UmbPropertyTypeModel) {
508453
await this.#init;
509454
contentTypeUnique = contentTypeUnique ?? this.#ownerContentTypeUnique!;
@@ -518,6 +463,10 @@ export class UmbContentTypeStructureManager<
518463
property = { ...property, container: { id: container.id } };
519464
}
520465

466+
if (property.sortOrder === undefined) {
467+
property.sortOrder = 0;
468+
}
469+
521470
const frozenProperties =
522471
this.#contentTypes.getValue().find((x) => x.unique === contentTypeUnique)?.properties ?? [];
523472

0 commit comments

Comments
 (0)