Skip to content

Commit 8ba49bc

Browse files
committed
introduce umb-content-workspace-property to improve dx
1 parent 0442b9e commit 8ba49bc

File tree

5 files changed

+85
-6
lines changed

5 files changed

+85
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { UMB_CONTENT_WORKSPACE_CONTEXT } from '../constants.js';
2+
import { html, customElement, property, state, nothing } from '@umbraco-cms/backoffice/external/lit';
3+
import type { UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type';
4+
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
5+
import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property';
6+
import type { UmbVariantId } from '@umbraco-cms/backoffice/variant';
7+
8+
import '../workspace/views/edit/content-editor-property.element.js';
9+
10+
@customElement('umb-content-workspace-property')
11+
export class UmbContentWorkspacePropertyElement extends UmbLitElement {
12+
private _alias?: string | undefined;
13+
14+
@property()
15+
public get alias(): string | undefined {
16+
return this._alias;
17+
}
18+
public set alias(value: string | undefined) {
19+
this._alias = value;
20+
this.#observePropertyType();
21+
}
22+
23+
@state()
24+
_datasetVariantId?: UmbVariantId;
25+
26+
@state()
27+
_dataPath?: string;
28+
29+
@state()
30+
_writeable?: boolean;
31+
32+
@state()
33+
_workspaceContext?: typeof UMB_CONTENT_WORKSPACE_CONTEXT.TYPE;
34+
35+
@state()
36+
_propertyType?: UmbPropertyTypeModel;
37+
38+
constructor() {
39+
super();
40+
41+
// The Property Dataset is local to the active variant, we use this to retrieve the variant we like to gather the value from.
42+
this.consumeContext(UMB_PROPERTY_DATASET_CONTEXT, (datasetContext) => {
43+
this._datasetVariantId = datasetContext?.getVariantId();
44+
});
45+
46+
// The Content Workspace Context is used to retrieve the property type we like to observe.
47+
// This gives us the configuration from the property type as part of the data type.
48+
this.consumeContext(UMB_CONTENT_WORKSPACE_CONTEXT, async (workspaceContext) => {
49+
this._workspaceContext = workspaceContext;
50+
this.#observePropertyType();
51+
});
52+
}
53+
54+
async #observePropertyType() {
55+
if (!this._alias || !this._workspaceContext) return;
56+
57+
this.observe(await this._workspaceContext?.structure.propertyStructureByAlias(this._alias), (propertyType) => {
58+
this._propertyType = propertyType;
59+
});
60+
}
61+
62+
override render() {
63+
if (!this._datasetVariantId && !this._propertyType) return nothing;
64+
65+
return html`<umb-content-workspace-view-edit-property
66+
class="property"
67+
.variantId=${this._datasetVariantId}
68+
.property=${this._propertyType}></umb-content-workspace-view-edit-property>`;
69+
}
70+
}
71+
72+
export default UmbContentWorkspacePropertyElement;
73+
74+
declare global {
75+
interface HTMLElementTagNameMap {
76+
'umb-content-workspace-property': UmbContentWorkspacePropertyElement;
77+
}
78+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import './content-workspace-property.element.js';
2+
export * from './content-workspace-property.element.js';

src/Umbraco.Web.UI.Client/src/packages/content/content/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ export * from './collection/index.js';
22
export * from './components/index.js';
33
export * from './constants.js';
44
export * from './controller/merge-content-variant-data.controller.js';
5+
export * from './global-components/index.js';
56
export * from './manager/index.js';
67
export * from './property-dataset-context/index.js';
78
export * from './workspace/index.js';
9+
810
export type * from './repository/index.js';
911
export type * from './types.js';
1012
export type * from './variant-picker/index.js';

src/Umbraco.Web.UI.Client/src/packages/content/content/workspace/views/edit/content-editor-properties.element.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';
1111
import { UmbVariantId } from '@umbraco-cms/backoffice/variant';
1212
import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property';
1313

14-
import './content-editor-property.element.js';
15-
1614
@customElement('umb-content-workspace-view-edit-properties')
1715
export class UmbContentWorkspaceViewEditPropertiesElement extends UmbLitElement {
1816
#workspaceContext?: typeof UMB_CONTENT_WORKSPACE_CONTEXT.TYPE;
@@ -103,10 +101,9 @@ export class UmbContentWorkspaceViewEditPropertiesElement extends UmbLitElement
103101
this._visibleProperties,
104102
(property) => property.alias,
105103
(property) =>
106-
html`<umb-content-workspace-view-edit-property
104+
html`<umb-content-workspace-property
107105
class="property"
108-
.variantId=${this._datasetVariantId}
109-
.property=${property}></umb-content-workspace-view-edit-property>`,
106+
alias=${property.alias}></umb-content-workspace-property>`,
110107
)
111108
: nothing;
112109
}

src/Umbraco.Web.UI.Client/src/packages/content/content/workspace/views/edit/content-editor-property.element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class UmbContentWorkspaceViewEditPropertyElement extends UmbLitElement {
3333

3434
override willUpdate(changedProperties: Map<string, any>) {
3535
super.willUpdate(changedProperties);
36-
if (changedProperties.has('type') || changedProperties.has('variantId') || changedProperties.has('_context')) {
36+
if (changedProperties.has('property') || changedProperties.has('variantId') || changedProperties.has('_context')) {
3737
if (this.variantId && this.property && this._context) {
3838
const propertyVariantId = new UmbVariantId(
3939
this.property.variesByCulture ? this.variantId.culture : null,

0 commit comments

Comments
 (0)