only set defaults when creating new data-type
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { UmbDataTypeDetailRepository } from '../repository/detail/data-type-detail.repository.js';
|
||||
import type { UmbDataTypeDetailModel } from '../types.js';
|
||||
import type { UmbDataTypeDetailModel, UmbDataTypePropertyModel } from '../types.js';
|
||||
import { UmbDataTypeWorkspaceEditorElement } from './data-type-workspace-editor.element.js';
|
||||
import type { UmbPropertyDatasetContext } from '@umbraco-cms/backoffice/property';
|
||||
import type {
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
} from '@umbraco-cms/backoffice/workspace';
|
||||
import {
|
||||
appendToFrozenArray,
|
||||
mergeObservables,
|
||||
UmbArrayState,
|
||||
UmbObjectState,
|
||||
UmbStringState,
|
||||
@@ -25,7 +24,6 @@ import type {
|
||||
PropertyEditorSettingsProperty,
|
||||
} from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { UMB_PROPERTY_EDITOR_SCHEMA_ALIAS_DEFAULT } from '@umbraco-cms/backoffice/property-editor';
|
||||
import { UMB_ACTION_EVENT_CONTEXT } from '@umbraco-cms/backoffice/action';
|
||||
import {
|
||||
UmbRequestReloadChildrenOfEntityEvent,
|
||||
@@ -65,9 +63,6 @@ export class UmbDataTypeWorkspaceContext
|
||||
);
|
||||
readonly properties = this.#properties.asObservable();
|
||||
|
||||
#defaults = new UmbArrayState<PropertyEditorSettingsDefaultData>([], (entry) => entry.alias);
|
||||
readonly defaults = this.#defaults.asObservable();
|
||||
|
||||
#propertyEditorSchemaSettingsDefaultData: Array<PropertyEditorSettingsDefaultData> = [];
|
||||
#propertyEditorUISettingsDefaultData: Array<PropertyEditorSettingsDefaultData> = [];
|
||||
|
||||
@@ -123,6 +118,13 @@ export class UmbDataTypeWorkspaceContext
|
||||
super.resetState();
|
||||
this.#persistedData.setValue(undefined);
|
||||
this.#currentData.setValue(undefined);
|
||||
this.#propertyEditorSchemaSettingsProperties = [];
|
||||
this.#propertyEditorUISettingsProperties = [];
|
||||
this.#propertyEditorSchemaSettingsDefaultData = [];
|
||||
this.#propertyEditorUISettingsDefaultData = [];
|
||||
this.#settingsDefaultData = undefined;
|
||||
|
||||
this._mergeConfigProperties();
|
||||
}
|
||||
|
||||
#observePropertyEditorUIAlias() {
|
||||
@@ -142,8 +144,10 @@ export class UmbDataTypeWorkspaceContext
|
||||
await this.#observePropertyEditorSchemaAlias();
|
||||
}
|
||||
|
||||
if (this.getIsNew()) {
|
||||
this.#transferConfigDefaultData();
|
||||
}
|
||||
this._mergeConfigProperties();
|
||||
this._mergeConfigDefaultData();
|
||||
},
|
||||
'editorUiAlias',
|
||||
);
|
||||
@@ -152,21 +156,18 @@ export class UmbDataTypeWorkspaceContext
|
||||
#observePropertyEditorSchemaAlias() {
|
||||
return this.observe(
|
||||
this.propertyEditorSchemaAlias,
|
||||
async (propertyEditorSchemaAlias) => {
|
||||
if (!propertyEditorSchemaAlias) {
|
||||
this.setPropertyEditorSchemaAlias(UMB_PROPERTY_EDITOR_SCHEMA_ALIAS_DEFAULT);
|
||||
return;
|
||||
}
|
||||
|
||||
await this.#setPropertyEditorSchemaConfig(propertyEditorSchemaAlias);
|
||||
(propertyEditorSchemaAlias) => {
|
||||
this.#setPropertyEditorSchemaConfig(propertyEditorSchemaAlias);
|
||||
},
|
||||
'schemaAlias',
|
||||
).asPromise();
|
||||
}
|
||||
|
||||
#setPropertyEditorSchemaConfig(propertyEditorSchemaAlias: string) {
|
||||
return this.observe(
|
||||
umbExtensionsRegistry.byTypeAndAlias('propertyEditorSchema', propertyEditorSchemaAlias),
|
||||
#setPropertyEditorSchemaConfig(propertyEditorSchemaAlias?: string) {
|
||||
this.observe(
|
||||
propertyEditorSchemaAlias
|
||||
? umbExtensionsRegistry.byTypeAndAlias('propertyEditorSchema', propertyEditorSchemaAlias)
|
||||
: undefined,
|
||||
(manifest) => {
|
||||
// Maps properties to have a weight, so they can be sorted
|
||||
this.#propertyEditorSchemaSettingsProperties = (manifest?.meta.settings?.properties ?? []).map((x, i) => ({
|
||||
@@ -177,7 +178,7 @@ export class UmbDataTypeWorkspaceContext
|
||||
this.#propertyEditorSchemaConfigDefaultUIAlias = manifest?.meta.defaultPropertyEditorUiAlias || null;
|
||||
},
|
||||
'schema',
|
||||
).asPromise();
|
||||
);
|
||||
}
|
||||
|
||||
#setPropertyEditorUIConfig(propertyEditorUIAlias: string) {
|
||||
@@ -208,14 +209,20 @@ export class UmbDataTypeWorkspaceContext
|
||||
}
|
||||
}
|
||||
|
||||
private _mergeConfigDefaultData() {
|
||||
#transferConfigDefaultData() {
|
||||
if (!this.#propertyEditorSchemaSettingsDefaultData || !this.#propertyEditorUISettingsDefaultData) return;
|
||||
|
||||
const data = this.#currentData.getValue();
|
||||
if (!data) return;
|
||||
|
||||
this.#settingsDefaultData = [
|
||||
...this.#propertyEditorSchemaSettingsDefaultData,
|
||||
...this.#propertyEditorUISettingsDefaultData,
|
||||
];
|
||||
this.#defaults.setValue(this.#settingsDefaultData);
|
||||
] satisfies Array<UmbDataTypePropertyModel>;
|
||||
// We check for satisfied type, because we will be directly transferring them to become value. Future note, if they are not satisfied, we need to transfer alias and value. [NL]
|
||||
|
||||
this.#persistedData.update({ values: this.#settingsDefaultData });
|
||||
this.#currentData.update({ values: this.#settingsDefaultData });
|
||||
}
|
||||
|
||||
public getPropertyDefaultValue(alias: string) {
|
||||
@@ -258,6 +265,7 @@ export class UmbDataTypeWorkspaceContext
|
||||
this.#getDataPromise = request;
|
||||
let { data } = await request;
|
||||
if (!data) return undefined;
|
||||
|
||||
if (this.modalContext) {
|
||||
data = { ...data, ...this.modalContext.data.preset };
|
||||
}
|
||||
@@ -295,19 +303,8 @@ export class UmbDataTypeWorkspaceContext
|
||||
|
||||
async propertyValueByAlias<ReturnType = unknown>(propertyAlias: string) {
|
||||
await this.#getDataPromise;
|
||||
|
||||
return mergeObservables(
|
||||
[
|
||||
this.#currentData.asObservablePart(
|
||||
(data) => data?.values?.find((x) => x.alias === propertyAlias)?.value as ReturnType,
|
||||
),
|
||||
this.#defaults.asObservablePart(
|
||||
(defaults) => defaults?.find((x) => x.alias === propertyAlias)?.value as ReturnType,
|
||||
),
|
||||
],
|
||||
([value, defaultValue]) => {
|
||||
return value ?? defaultValue;
|
||||
},
|
||||
return this.#currentData.asObservablePart(
|
||||
(data) => data?.values?.find((x) => x.alias === propertyAlias)?.value as ReturnType,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -379,7 +376,6 @@ export class UmbDataTypeWorkspaceContext
|
||||
this.#persistedData.destroy();
|
||||
this.#currentData.destroy();
|
||||
this.#properties.destroy();
|
||||
this.#defaults.destroy();
|
||||
this.#propertyEditorUiIcon.destroy();
|
||||
this.#propertyEditorUiName.destroy();
|
||||
this.repository.destroy();
|
||||
|
||||
@@ -77,6 +77,13 @@ export class UmbDataTypeDetailsWorkspaceViewEditElement extends UmbLitElement im
|
||||
: this.#renderChooseButton()}
|
||||
</umb-property-layout>
|
||||
</uui-box>
|
||||
${this.#renderSettings()}
|
||||
`;
|
||||
}
|
||||
|
||||
#renderSettings() {
|
||||
if (!this._propertyEditorUiAlias || !this._propertyEditorSchemaAlias) return nothing;
|
||||
return html`
|
||||
<uui-box headline=${this.localize.term('general_settings')}>
|
||||
<umb-property-editor-config></umb-property-editor-config>
|
||||
</uui-box>
|
||||
|
||||
Reference in New Issue
Block a user