minor restructure/clean up
This commit is contained in:
@@ -47,21 +47,21 @@ export class UmbDataTypeWorkspaceContext
|
||||
#properties = new UmbArrayState<PropertyEditorSettingsProperty>([], (x) => x.alias);
|
||||
readonly properties = this.#properties.asObservable();
|
||||
|
||||
private _propertyEditorSchemaConfigDefaultData: Array<PropertyEditorSettingsDefaultData> = [];
|
||||
private _propertyEditorUISettingsDefaultData: Array<PropertyEditorSettingsDefaultData> = [];
|
||||
|
||||
private _propertyEditorSchemaConfigProperties: Array<PropertyEditorSettingsProperty> = [];
|
||||
private _propertyEditorUISettingsProperties: Array<PropertyEditorSettingsProperty> = [];
|
||||
|
||||
private _propertyEditorSchemaConfigDefaultUIAlias: string | null = null;
|
||||
|
||||
private _configDefaultData?: Array<PropertyEditorSettingsDefaultData>;
|
||||
|
||||
private _propertyEditorUISettingsSchemaAlias?: string;
|
||||
|
||||
#defaults = new UmbArrayState<PropertyEditorSettingsDefaultData>([], (entry) => entry.alias);
|
||||
readonly defaults = this.#defaults.asObservable();
|
||||
|
||||
#propertyEditorSchemaSettingsDefaultData: Array<PropertyEditorSettingsDefaultData> = [];
|
||||
#propertyEditorUISettingsDefaultData: Array<PropertyEditorSettingsDefaultData> = [];
|
||||
|
||||
#propertyEditorSchemaSettingsProperties: Array<PropertyEditorSettingsProperty> = [];
|
||||
#propertyEditorUISettingsProperties: Array<PropertyEditorSettingsProperty> = [];
|
||||
|
||||
#propertyEditorSchemaConfigDefaultUIAlias: string | null = null;
|
||||
|
||||
#settingsDefaultData?: Array<PropertyEditorSettingsDefaultData>;
|
||||
|
||||
#propertyEditorUISettingsSchemaAlias?: string;
|
||||
|
||||
#propertyEditorUiIcon = new UmbStringState<string | null>(null);
|
||||
readonly propertyEditorUiIcon = this.#propertyEditorUiIcon.asObservable();
|
||||
|
||||
@@ -89,10 +89,10 @@ export class UmbDataTypeWorkspaceContext
|
||||
// if the property editor ui alias is not set, we use the default alias from the schema
|
||||
if (propertyEditorUiAlias === null) {
|
||||
await this.#observePropertyEditorSchemaAlias();
|
||||
this.setPropertyEditorUiAlias(this._propertyEditorSchemaConfigDefaultUIAlias!);
|
||||
this.setPropertyEditorUiAlias(this.#propertyEditorSchemaConfigDefaultUIAlias!);
|
||||
} else {
|
||||
await this.#setPropertyEditorUIConfig(propertyEditorUiAlias);
|
||||
this.setPropertyEditorSchemaAlias(this._propertyEditorUISettingsSchemaAlias!);
|
||||
this.setPropertyEditorSchemaAlias(this.#propertyEditorUISettingsSchemaAlias!);
|
||||
await this.#observePropertyEditorSchemaAlias();
|
||||
}
|
||||
|
||||
@@ -122,9 +122,9 @@ export class UmbDataTypeWorkspaceContext
|
||||
return this.observe(
|
||||
umbExtensionsRegistry.byTypeAndAlias('propertyEditorSchema', propertyEditorSchemaAlias),
|
||||
(manifest) => {
|
||||
this._propertyEditorSchemaConfigProperties = manifest?.meta.settings?.properties || [];
|
||||
this._propertyEditorSchemaConfigDefaultData = manifest?.meta.settings?.defaultData || [];
|
||||
this._propertyEditorSchemaConfigDefaultUIAlias = manifest?.meta.defaultPropertyEditorUiAlias || null;
|
||||
this.#propertyEditorSchemaSettingsProperties = manifest?.meta.settings?.properties || [];
|
||||
this.#propertyEditorSchemaSettingsDefaultData = manifest?.meta.settings?.defaultData || [];
|
||||
this.#propertyEditorSchemaConfigDefaultUIAlias = manifest?.meta.defaultPropertyEditorUiAlias || null;
|
||||
},
|
||||
'schema',
|
||||
).asPromise();
|
||||
@@ -137,35 +137,35 @@ export class UmbDataTypeWorkspaceContext
|
||||
this.#propertyEditorUiIcon.setValue(manifest?.meta.icon || null);
|
||||
this.#propertyEditorUiName.setValue(manifest?.name || null);
|
||||
|
||||
this._propertyEditorUISettingsSchemaAlias = manifest?.meta.propertyEditorSchemaAlias;
|
||||
this._propertyEditorUISettingsProperties = manifest?.meta.settings?.properties || [];
|
||||
this._propertyEditorUISettingsDefaultData = manifest?.meta.settings?.defaultData || [];
|
||||
this.#propertyEditorUISettingsSchemaAlias = manifest?.meta.propertyEditorSchemaAlias;
|
||||
this.#propertyEditorUISettingsProperties = manifest?.meta.settings?.properties || [];
|
||||
this.#propertyEditorUISettingsDefaultData = manifest?.meta.settings?.defaultData || [];
|
||||
},
|
||||
'editorUi',
|
||||
).asPromise();
|
||||
}
|
||||
|
||||
private _mergeConfigProperties() {
|
||||
if (this._propertyEditorSchemaConfigProperties && this._propertyEditorUISettingsProperties) {
|
||||
if (this.#propertyEditorSchemaSettingsProperties && this.#propertyEditorUISettingsProperties) {
|
||||
// Reset the value to this array, and then afterwards append:
|
||||
this.#properties.setValue(this._propertyEditorSchemaConfigProperties);
|
||||
this.#properties.setValue(this.#propertyEditorSchemaSettingsProperties);
|
||||
// Append the UI settings properties to the schema properties, so they can override the schema properties:
|
||||
this.#properties.append(this._propertyEditorUISettingsProperties);
|
||||
this.#properties.append(this.#propertyEditorUISettingsProperties);
|
||||
}
|
||||
}
|
||||
|
||||
private _mergeConfigDefaultData() {
|
||||
if (!this._propertyEditorSchemaConfigDefaultData || !this._propertyEditorUISettingsDefaultData) return;
|
||||
if (!this.#propertyEditorSchemaSettingsDefaultData || !this.#propertyEditorUISettingsDefaultData) return;
|
||||
|
||||
this._configDefaultData = [
|
||||
...this._propertyEditorSchemaConfigDefaultData,
|
||||
...this._propertyEditorUISettingsDefaultData,
|
||||
this.#settingsDefaultData = [
|
||||
...this.#propertyEditorSchemaSettingsDefaultData,
|
||||
...this.#propertyEditorUISettingsDefaultData,
|
||||
];
|
||||
this.#defaults.setValue(this._configDefaultData);
|
||||
this.#defaults.setValue(this.#settingsDefaultData);
|
||||
}
|
||||
|
||||
public getPropertyDefaultValue(alias: string) {
|
||||
return this._configDefaultData?.find((x) => x.alias === alias)?.value;
|
||||
return this.#settingsDefaultData?.find((x) => x.alias === alias)?.value;
|
||||
}
|
||||
|
||||
createPropertyDatasetContext(host: UmbControllerHost): UmbPropertyDatasetContext {
|
||||
@@ -174,8 +174,9 @@ export class UmbDataTypeWorkspaceContext
|
||||
|
||||
async load(unique: string) {
|
||||
this.resetState();
|
||||
this.#getDataPromise = this.repository.requestByUnique(unique);
|
||||
const { data } = await this.#getDataPromise;
|
||||
const request = this.repository.requestByUnique(unique);
|
||||
this.#getDataPromise = request;
|
||||
const { data } = await request;
|
||||
if (!data) return undefined;
|
||||
|
||||
this.setIsNew(false);
|
||||
@@ -185,8 +186,10 @@ export class UmbDataTypeWorkspaceContext
|
||||
|
||||
async create(parentUnique: string | null) {
|
||||
this.resetState();
|
||||
this.#getDataPromise = this.repository.createScaffold(parentUnique);
|
||||
let { data } = await this.#getDataPromise;
|
||||
const request = this.repository.createScaffold(parentUnique);
|
||||
this.#getDataPromise = request;
|
||||
let { data } = await request;
|
||||
if (!data) return undefined;
|
||||
if (this.modalContext) {
|
||||
data = { ...data, ...this.modalContext.data.preset };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user