Skip to content

Commit aedca0d

Browse files
authored
Merge pull request #2273 from umbraco/v14/feature/property_dataset_properties_observable
V14/feature: Content Type Structure Manager properties observable
2 parents 3fdd55a + ab6768c commit aedca0d

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,20 @@ export class UmbContentTypeStructureManager<
4646
(x) => x.find((y) => y.unique === this.#ownerContentTypeUnique)?.compositions,
4747
);
4848

49-
readonly #contentTypeContainers = this.#contentTypes.asObservablePart(() => {
50-
return this.#contentTypes.getValue().flatMap((x) => x.containers ?? []);
49+
readonly #contentTypeContainers = this.#contentTypes.asObservablePart((contentTypes) => {
50+
// Notice this may need to use getValue to avoid resetting it self. [NL]
51+
return contentTypes.flatMap((x) => x.containers ?? []);
52+
});
53+
readonly contentTypeProperties = this.#contentTypes.asObservablePart((contentTypes) => {
54+
// Notice this may need to use getValue to avoid resetting it self. [NL]
55+
return contentTypes.flatMap((x) => x.properties ?? []);
56+
});
57+
readonly contentTypeHasProperties = this.#contentTypes.asObservablePart((contentTypes) => {
58+
// Notice this may need to use getValue to avoid resetting it self. [NL]
59+
return contentTypes.some((x) => x.properties.length > 0);
60+
});
61+
readonly contentTypePropertyAliases = this.#contentTypes.asObservablePart((contentTypes) => {
62+
return contentTypes.flatMap((x) => x.properties ?? []).map((x) => x.alias);
5163
});
5264
readonly contentTypeUniques = this.#contentTypes.asObservablePart((x) => x.map((y) => y.unique));
5365
readonly contentTypeAliases = this.#contentTypes.asObservablePart((x) => x.map((y) => y.alias));
@@ -77,7 +89,8 @@ export class UmbContentTypeStructureManager<
7789
/**
7890
* loadType will load the ContentType and all inherited and composed ContentTypes.
7991
* This will give us all the structure for properties and containers.
80-
* @param unique
92+
* @param {string} unique - The unique of the ContentType to load.
93+
* @returns {Promise} - Promise resolved
8194
*/
8295
public async loadType(unique?: string) {
8396
this._reset();
@@ -219,6 +232,14 @@ export class UmbContentTypeStructureManager<
219232
return this.#ownerContentTypeUnique;
220233
}
221234

235+
/**
236+
* Figure out if any of the Content Types has a Property.
237+
* @returns {boolean} - true if any of the Content Type in this composition has a Property.
238+
*/
239+
getHasProperties() {
240+
return this.#contentTypes.getValue().some((y) => y.properties.length > 0);
241+
}
242+
222243
updateOwnerContentType(entry: Partial<T>) {
223244
this.#contentTypes.updateOne(this.#ownerContentTypeUnique, entry);
224245
}

src/packages/core/content/workspace/views/edit/conditions/has-properties/content-has-properties.condition.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ export class UmbContentHasPropertiesWorkspaceCondition
1616

1717
this.consumeContext(UMB_CONTENT_WORKSPACE_CONTEXT, (context) => {
1818
this.observe(
19-
context.structure.contentTypes,
20-
(contentTypes) => {
21-
const hasProperties = contentTypes.some((contentType) => contentType.properties.length > 0);
19+
context.structure.contentTypeHasProperties,
20+
(hasProperties) => {
2221
this.permitted = hasProperties;
2322
},
24-
'contentTypesObserver',
23+
'hasPropertiesObserver',
2524
);
2625
});
2726
}

src/packages/core/property/property-dataset/property-dataset.element.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export class UmbPropertyDatasetElement extends UmbLitElement {
1616

1717
public readonly context: UmbPropertyDatasetContextBase;
1818

19+
@property({ attribute: false })
1920
/**
2021
* The value of the dataset.
21-
* @returns {Array<UmbPropertyValueData>}
22-
* @memberof UmbBasicVariantElement
22+
* @returns {Array<UmbPropertyValueData>} - The value of the dataset
2323
* @example
2424
* ```ts
2525
* const dataSet = [
@@ -46,7 +46,6 @@ export class UmbPropertyDatasetElement extends UmbLitElement {
4646
* `
4747
* ```
4848
*/
49-
@property({ attribute: false })
5049
public set value(value: Array<UmbPropertyValueData>) {
5150
this.#allowChangeEvent = false;
5251
this.context.setValues(value);
@@ -57,11 +56,12 @@ export class UmbPropertyDatasetElement extends UmbLitElement {
5756
return this.context.getValues();
5857
}
5958

59+
@property({ attribute: false })
6060
/**
6161
* The name of the dataset, this name varies depending on the use-case. But this is either
62+
* @property name
6263
* @type {string}
6364
* @returns {string}
64-
* @memberof UmbBasicVariantElement
6565
* @example
6666
* ```ts
6767
* html`
@@ -70,7 +70,6 @@ export class UmbPropertyDatasetElement extends UmbLitElement {
7070
* </umb-property-dataset>
7171
* `
7272
*/
73-
@property({ attribute: false })
7473
public set name(value: string | undefined) {
7574
this.#allowChangeEvent = false;
7675
this.context.setName(value);

src/packages/documents/documents/workspace/document-workspace.context.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
} from '../paths.js';
2626
import { UMB_DOCUMENTS_SECTION_PATH } from '../../section/paths.js';
2727
import { UmbDocumentPreviewRepository } from '../repository/preview/index.js';
28-
28+
import { sortVariants } from '../utils.js';
2929
import { UMB_DOCUMENT_WORKSPACE_ALIAS } from './manifests.js';
3030
import { UmbEntityContext } from '@umbraco-cms/backoffice/entity';
3131
import { UMB_INVARIANT_CULTURE, UmbVariantId } from '@umbraco-cms/backoffice/variant';
@@ -68,7 +68,6 @@ import type { UmbContentWorkspaceContext } from '@umbraco-cms/backoffice/content
6868
import type { UmbDocumentTypeDetailModel } from '@umbraco-cms/backoffice/document-type';
6969
import { UmbIsTrashedEntityContext } from '@umbraco-cms/backoffice/recycle-bin';
7070
import { UmbReadOnlyVariantStateManager } from '@umbraco-cms/backoffice/utils';
71-
import { sortVariants } from '../utils.js';
7271

7372
type EntityType = UmbDocumentDetailModel;
7473
export class UmbDocumentWorkspaceContext

0 commit comments

Comments
 (0)