Skip to content

Commit 773a155

Browse files
committed
Adds validation to the Property Context
1 parent 773346c commit 773a155

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/packages/core/property/property/property.context.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,39 @@ import type { UmbVariantId } from '@umbraco-cms/backoffice/variant';
1414
import type { UmbPropertyEditorConfigProperty } from '@umbraco-cms/backoffice/property-editor';
1515
import { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor';
1616
import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry';
17-
import type { UmbPropertyTypeAppearanceModel } from '@umbraco-cms/backoffice/content-type';
17+
import type {
18+
UmbPropertyTypeAppearanceModel,
19+
UmbPropertyTypeValidationModel,
20+
} from '@umbraco-cms/backoffice/content-type';
1821

1922
export class UmbPropertyContext<ValueType = any> extends UmbContextBase<UmbPropertyContext<ValueType>> {
2023
#alias = new UmbStringState(undefined);
2124
public readonly alias = this.#alias.asObservable();
25+
2226
#label = new UmbStringState(undefined);
2327
public readonly label = this.#label.asObservable();
28+
2429
#description = new UmbStringState(undefined);
2530
public readonly description = this.#description.asObservable();
31+
2632
#appearance = new UmbObjectState<UmbPropertyTypeAppearanceModel | undefined>(undefined);
2733
public readonly appearance = this.#appearance.asObservable();
34+
2835
#value = new UmbDeepState<ValueType | undefined>(undefined);
2936
public readonly value = this.#value.asObservable();
37+
3038
#configValues = new UmbArrayState<UmbPropertyEditorConfigProperty>([], (x) => x.alias);
3139
public readonly configValues = this.#configValues.asObservable();
3240

3341
#config = new UmbClassState<UmbPropertyEditorConfigCollection | undefined>(undefined);
3442
public readonly config = this.#config.asObservable();
3543

44+
#validation = new UmbObjectState<UmbPropertyTypeValidationModel | undefined>(undefined);
45+
public readonly validation = this.#validation.asObservable();
46+
3647
private _editor = new UmbBasicState<UmbPropertyEditorUiElement | undefined>(undefined);
3748
public readonly editor = this._editor.asObservable();
49+
3850
setEditor(editor: UmbPropertyEditorUiElement | undefined) {
3951
this._editor.setValue(editor ?? undefined);
4052
}
@@ -108,24 +120,28 @@ export class UmbPropertyContext<ValueType = any> extends UmbContextBase<UmbPrope
108120
public getAlias(): string | undefined {
109121
return this.#alias.getValue();
110122
}
123+
111124
public setLabel(label: string | undefined): void {
112125
this.#label.setValue(label);
113126
}
114127
public getLabel(): string | undefined {
115128
return this.#label.getValue();
116129
}
130+
117131
public setDescription(description: string | undefined): void {
118132
this.#description.setValue(description);
119133
}
120134
public getDescription(): string | undefined {
121135
return this.#description.getValue();
122136
}
137+
123138
public setAppearance(appearance: UmbPropertyTypeAppearanceModel | undefined): void {
124139
this.#appearance.setValue(appearance);
125140
}
126141
public getAppearance(): UmbPropertyTypeAppearanceModel | undefined {
127142
return this.#appearance.getValue();
128143
}
144+
129145
/**
130146
* Set the value of this property.
131147
* @param value {ValueType} the whole value to be set
@@ -143,19 +159,28 @@ export class UmbPropertyContext<ValueType = any> extends UmbContextBase<UmbPrope
143159
public getValue(): ValueType | undefined {
144160
return this.#value.getValue();
145161
}
162+
146163
public setConfig(config: Array<UmbPropertyEditorConfigProperty> | undefined): void {
147164
this.#configValues.setValue(config ?? []);
148165
}
149166
public getConfig(): Array<UmbPropertyEditorConfigProperty> | undefined {
150167
return this.#configValues.getValue();
151168
}
169+
152170
public setVariantId(variantId: UmbVariantId | undefined): void {
153171
this.#variantId.setValue(variantId);
154172
}
155173
public getVariantId(): UmbVariantId | undefined {
156174
return this.#variantId.getValue();
157175
}
158176

177+
public setValidation(validation: UmbPropertyTypeValidationModel | undefined): void {
178+
this.#validation.setValue(validation);
179+
}
180+
public getValidation(): UmbPropertyTypeValidationModel | undefined {
181+
return this.#validation.getValue();
182+
}
183+
159184
public resetValue(): void {
160185
this.setValue(undefined); // TODO: We should get the value from the server aka. the value from the persisted data. (Most workspaces holds this data, via dataset) [NL]
161186
}

0 commit comments

Comments
 (0)