implement validation context (#18808)

This commit is contained in:
Niels Lyngsø
2025-03-26 10:12:25 +01:00
committed by GitHub
parent 619e025e7a
commit 76dd141d86
3 changed files with 26 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
export * from './constants.js';
export * from './utils/index.js';
export * from './workspace/index.js';
export type * from './types.js';

View File

@@ -0,0 +1,11 @@
import type { UmbPropertyTypeData } from '../types.js';
/**
* Validation Data Path Query generator for Property Type.
* write a JSON-Path filter similar to `?(@.id == '1234-1224-1244')`
* @param {UmbPropertyTypeData} value - the object holding Property Type.
* @returns {string} - a JSON-path query
*/
export function UmbDataPathPropertyTypeQuery(value: Pick<UmbPropertyTypeData, 'id'>): string {
return `?(@.id == '${value.id}')`;
}

View File

@@ -19,6 +19,8 @@ import type { UmbPropertyTypeModel } from '@umbraco-cms/backoffice/content-type'
import { UMB_CONTENT_TYPE_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/content-type';
import { UmbId } from '@umbraco-cms/backoffice/id';
import { firstValueFrom } from '@umbraco-cms/backoffice/external/rxjs';
import { UmbValidationContext } from '@umbraco-cms/backoffice/validation';
import { UmbDataPathPropertyTypeQuery } from '../utils/index.js';
export class UmbPropertyTypeWorkspaceContext<PropertyTypeData extends UmbPropertyTypeModel = UmbPropertyTypeModel>
extends UmbSubmittableWorkspaceContextBase<PropertyTypeData>
@@ -32,6 +34,8 @@ export class UmbPropertyTypeWorkspaceContext<PropertyTypeData extends UmbPropert
#entityType: string;
validationgContext: UmbValidationContext;
// #persistedData
// #currentData
#data = new UmbObjectState<PropertyTypeData | undefined>(undefined);
@@ -53,6 +57,15 @@ export class UmbPropertyTypeWorkspaceContext<PropertyTypeData extends UmbPropert
const manifest = args.manifest;
this.#entityType = manifest.meta?.entityType;
this.validationgContext = new UmbValidationContext(this);
this.addValidationContext(this.validationgContext);
this.observe(this.unique, (unique) => {
if (unique) {
this.validationgContext.setDataPath(UmbDataPathPropertyTypeQuery({ id: unique }));
}
});
this.#init = this.consumeContext(UMB_CONTENT_TYPE_WORKSPACE_CONTEXT, (context) => {
this.#contentTypeContext = context;
})
@@ -217,6 +230,7 @@ export class UmbPropertyTypeWorkspaceContext<PropertyTypeData extends UmbPropert
await this.#init;
if (this.#contentTypeContext) {
this.validationgContext.report();
await this.#contentTypeContext.structure.insertProperty(contentTypeUnique, data);
this.setIsNew(false);