change config default data to array
This commit is contained in:
@@ -631,6 +631,16 @@ components:
|
||||
- label
|
||||
- alias
|
||||
- propertyEditorUI
|
||||
PropertyEditorConfigDefaultData:
|
||||
type: object
|
||||
properties:
|
||||
alias:
|
||||
type: string
|
||||
value:
|
||||
type: object
|
||||
required:
|
||||
- alias
|
||||
- value
|
||||
PropertyEditorConfig:
|
||||
type: object
|
||||
properties:
|
||||
@@ -639,7 +649,9 @@ components:
|
||||
items:
|
||||
$ref: '#/components/schemas/PropertyEditorConfigProperty'
|
||||
defaultData:
|
||||
type: object
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/PropertyEditorConfigDefaultData'
|
||||
required:
|
||||
- properties
|
||||
MetaPropertyEditorUI:
|
||||
@@ -996,7 +1008,9 @@ components:
|
||||
items:
|
||||
$ref: '#/components/schemas/PropertyEditorConfigProperty'
|
||||
defaultData:
|
||||
type: object
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/PropertyEditorConfigDefaultData'
|
||||
required:
|
||||
- properties
|
||||
ServerStatus:
|
||||
|
||||
@@ -188,9 +188,13 @@ export interface components {
|
||||
alias: string;
|
||||
propertyEditorUI: string;
|
||||
};
|
||||
PropertyEditorConfigDefaultData: {
|
||||
alias: string;
|
||||
value: { [key: string]: unknown };
|
||||
};
|
||||
PropertyEditorConfig: {
|
||||
properties: components["schemas"]["PropertyEditorConfigProperty"][];
|
||||
defaultData?: { [key: string]: unknown };
|
||||
defaultData?: components["schemas"]["PropertyEditorConfigDefaultData"][];
|
||||
};
|
||||
MetaPropertyEditorUI: {
|
||||
label: string;
|
||||
@@ -329,7 +333,7 @@ export interface components {
|
||||
};
|
||||
PropertyEditorConfigResponse: {
|
||||
properties: components["schemas"]["PropertyEditorConfigProperty"][];
|
||||
defaultData?: { [key: string]: unknown };
|
||||
defaultData?: components["schemas"]["PropertyEditorConfigDefaultData"][];
|
||||
};
|
||||
/** @enum {string} */
|
||||
ServerStatus: "running" | "must-install" | "must-upgrade";
|
||||
|
||||
@@ -7,7 +7,7 @@ import { UmbContextConsumerMixin } from '../../../../core/context';
|
||||
import { UmbExtensionRegistry } from '../../../../core/extension';
|
||||
import { UmbPropertyEditorConfigStore } from '../../../../core/stores/property-editor-config/property-editor-config.store';
|
||||
|
||||
import type { PropertyEditorConfigProperty } from '../../../../core/models';
|
||||
import type { PropertyEditorConfigDefaultData, PropertyEditorConfigProperty } from '../../../../core/models';
|
||||
|
||||
import '../../../components/entity-property/entity-property.element';
|
||||
|
||||
@@ -40,13 +40,15 @@ export class UmbPropertyEditorConfigElement extends UmbContextConsumerMixin(LitE
|
||||
}
|
||||
|
||||
@property({ type: Array })
|
||||
public data: Array<any> = [];
|
||||
public data: Array<{ alias: string; value: unknown }> = [];
|
||||
|
||||
@state()
|
||||
private _properties: Array<PropertyEditorConfigProperty> = [];
|
||||
|
||||
private _propertyEditorConfigDefaultData?: any;
|
||||
private _propertyEditorUIConfigDefaultData?: any;
|
||||
private _propertyEditorConfigDefaultData: Array<PropertyEditorConfigDefaultData> = [];
|
||||
private _propertyEditorUIConfigDefaultData: Array<PropertyEditorConfigDefaultData> = [];
|
||||
|
||||
private _configDefaultData?: Array<PropertyEditorConfigDefaultData>;
|
||||
|
||||
private _propertyEditorConfigProperties: Array<PropertyEditorConfigProperty> = [];
|
||||
private _propertyEditorUIConfigProperties: Array<PropertyEditorConfigProperty> = [];
|
||||
@@ -81,8 +83,9 @@ export class UmbPropertyEditorConfigElement extends UmbContextConsumerMixin(LitE
|
||||
.subscribe((propertyEditorConfig) => {
|
||||
if (!propertyEditorConfig) return;
|
||||
this._propertyEditorConfigProperties = propertyEditorConfig?.config?.properties || [];
|
||||
this._propertyEditorConfigDefaultData = propertyEditorConfig?.config?.defaultData || {};
|
||||
this._applyProperties();
|
||||
this._mergeProperties();
|
||||
this._propertyEditorConfigDefaultData = propertyEditorConfig?.config?.defaultData || [];
|
||||
this._mergeDefaultData();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -94,21 +97,24 @@ 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();
|
||||
this._mergeProperties();
|
||||
this._propertyEditorUIConfigDefaultData = manifest?.meta.config?.defaultData || [];
|
||||
this._mergeDefaultData();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private _applyProperties() {
|
||||
private _mergeProperties() {
|
||||
this._properties = [...this._propertyEditorConfigProperties, ...this._propertyEditorUIConfigProperties];
|
||||
}
|
||||
|
||||
private _mergeDefaultData() {
|
||||
this._configDefaultData = [...this._propertyEditorConfigDefaultData, ...this._propertyEditorUIConfigDefaultData];
|
||||
}
|
||||
|
||||
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];
|
||||
const defaultValue = this._configDefaultData?.find((data) => data.alias === property.alias)?.value;
|
||||
return value || defaultValue || null;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ export type PropertyEditorConfigResponse = components['schemas']['PropertyEditor
|
||||
export type PropertyEditorConfig = components['schemas']['PropertyEditorConfig'];
|
||||
export type PropertyEditor = components['schemas']['PropertyEditor'];
|
||||
export type PropertyEditorConfigProperty = components['schemas']['PropertyEditorConfigProperty'];
|
||||
export type PropertyEditorConfigDefaultData = components['schemas']['PropertyEditorConfigDefaultData'];
|
||||
|
||||
export type ManifestElementType =
|
||||
| ManifestSection
|
||||
|
||||
@@ -157,9 +157,12 @@ export const data: Array<PropertyEditor> = [
|
||||
propertyEditorUI: 'Umb.PropertyEditorUI.Textarea',
|
||||
},
|
||||
],
|
||||
defaultData: {
|
||||
maxChars: 512,
|
||||
},
|
||||
defaultData: [
|
||||
{
|
||||
alias: 'maxChars',
|
||||
value: '512',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -195,9 +195,12 @@ export const internalManifests: Array<ManifestTypes & { loader: () => Promise<ob
|
||||
propertyEditorUI: 'Umb.PropertyEditorUI.Text',
|
||||
},
|
||||
],
|
||||
defaultData: {
|
||||
someConfiguration: 'Hello Default World',
|
||||
},
|
||||
defaultData: [
|
||||
{
|
||||
alias: 'someConfiguration',
|
||||
value: 'Some default value',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -64,7 +64,7 @@ export interface PropertyEditor {
|
||||
|
||||
export interface PropertyEditorConfig {
|
||||
properties: PropertyEditorConfigProperty[];
|
||||
defaultData?: {};
|
||||
defaultData?: PropertyEditorConfigDefaultData[];
|
||||
}
|
||||
|
||||
export interface PropertyEditorConfigProperty {
|
||||
@@ -73,3 +73,8 @@ export interface PropertyEditorConfigProperty {
|
||||
alias: string;
|
||||
propertyEditorUI: string;
|
||||
}
|
||||
|
||||
export interface PropertyEditorConfigDefaultData {
|
||||
alias: string;
|
||||
value: {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user