add defaultData to property editor config

This commit is contained in:
Mads Rasmussen
2022-09-27 14:25:14 +02:00
parent cfa3bc2f96
commit 46a0343263
6 changed files with 26 additions and 7 deletions

View File

@@ -609,7 +609,7 @@ components:
type: array
items:
$ref: '#/components/schemas/PropertyEditorConfigProperty'
defaultConfig:
defaultData:
type: object
required:
- properties
@@ -966,7 +966,7 @@ components:
type: array
items:
$ref: '#/components/schemas/PropertyEditorConfigProperty'
defaultConfig:
defaultData:
type: object
required:
- properties

View File

@@ -184,7 +184,7 @@ export interface components {
};
PropertyEditorConfig: {
properties: components["schemas"]["PropertyEditorConfigProperty"][];
defaultConfig?: { [key: string]: unknown };
defaultData?: { [key: string]: unknown };
};
MetaPropertyEditorUI: {
label: string;
@@ -323,7 +323,7 @@ export interface components {
};
PropertyEditorConfigResponse: {
properties: components["schemas"]["PropertyEditorConfigProperty"][];
defaultConfig?: { [key: string]: unknown };
defaultData?: { [key: string]: unknown };
};
/** @enum {string} */
ServerStatus: "running" | "must-install" | "must-upgrade";

View File

@@ -45,6 +45,9 @@ export class UmbPropertyEditorConfigElement extends UmbContextConsumerMixin(LitE
@state()
private _properties: Array<PropertyEditorConfigProperty> = [];
private _propertyEditorConfigDefaultData?: any;
private _propertyEditorUIConfigDefaultData?: any;
private _propertyEditorConfigProperties: Array<PropertyEditorConfigProperty> = [];
private _propertyEditorUIConfigProperties: Array<PropertyEditorConfigProperty> = [];
@@ -78,6 +81,7 @@ export class UmbPropertyEditorConfigElement extends UmbContextConsumerMixin(LitE
.subscribe((propertyEditorConfig) => {
if (!propertyEditorConfig) return;
this._propertyEditorConfigProperties = propertyEditorConfig?.config?.properties || [];
this._propertyEditorConfigDefaultData = propertyEditorConfig?.config?.defaultData || {};
this._applyProperties();
});
}
@@ -90,6 +94,7 @@ export class UmbPropertyEditorConfigElement extends UmbContextConsumerMixin(LitE
this._extensionRegistry?.getByAlias(this.propertyEditorUIAlias).subscribe((manifest) => {
if (manifest?.type === 'propertyEditorUI') {
this._propertyEditorUIConfigProperties = manifest?.meta.config?.properties || [];
this._propertyEditorUIConfigDefaultData = manifest?.meta.config?.defaultData || {};
this._applyProperties();
}
});
@@ -99,6 +104,14 @@ export class UmbPropertyEditorConfigElement extends UmbContextConsumerMixin(LitE
this._properties = [...this._propertyEditorConfigProperties, ...this._propertyEditorUIConfigProperties];
}
private _getValue(property: PropertyEditorConfigProperty) {
const value = this.data.find((data) => data.alias === property.alias)?.value;
const defaultValue =
this._propertyEditorConfigDefaultData?.[property.alias] ||
this._propertyEditorUIConfigDefaultData?.[property.alias];
return value || defaultValue || null;
}
disconnectedCallback(): void {
super.disconnectedCallback();
this._propertyEditorConfigSubscription?.unsubscribe();
@@ -116,7 +129,7 @@ export class UmbPropertyEditorConfigElement extends UmbContextConsumerMixin(LitE
description="${ifDefined(property.description)}"
alias="${property.alias}"
property-editor-ui-alias="${property.propertyEditorUI}"
.value=${this.data.find((data) => data.alias === property.alias)?.value}></umb-entity-property>
.value=${this._getValue(property)}></umb-entity-property>
`
)}
`

View File

@@ -157,6 +157,9 @@ export const data: Array<PropertyEditor> = [
propertyEditorUI: 'Umb.PropertyEditorUI.Textarea',
},
],
defaultData: {
maxChars: 512,
},
},
},
{

View File

@@ -179,10 +179,13 @@ export const internalManifests: Array<ManifestTypes & { loader: () => Promise<ob
properties: [
{
label: 'Some Configuration',
alias: 'someConfiruation',
alias: 'someConfiguration',
propertyEditorUI: 'Umb.PropertyEditorUI.Text',
},
],
defaultData: {
someConfiguration: 'Hello Default World',
},
},
},
},

View File

@@ -64,7 +64,7 @@ export interface PropertyEditor {
export interface PropertyEditorConfig {
properties: PropertyEditorConfigProperty[];
defaultConfig?: {};
defaultData?: {};
}
export interface PropertyEditorConfigProperty {