From 20c483bb6f0bf775acf7a089ae44d025a9fbc3ef Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 17 Oct 2023 13:34:28 +0200 Subject: [PATCH] Update data-type-workspace.context.ts --- .../workspace/data-type-workspace.context.ts | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts index c39690c9c4..d9046b6ba6 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts @@ -50,6 +50,8 @@ export class UmbDataTypeWorkspaceContext private _configDefaultData?: Array; + private _propertyEditorUISettingsSchemaAlias?: string; + #defaults = new UmbArrayState([], (entry) => entry.alias); defaults = this.#defaults.asObservable(); @@ -61,33 +63,38 @@ export class UmbDataTypeWorkspaceContext constructor(host: UmbControllerHostElement) { super(host, 'Umb.Workspace.DataType', new UmbDataTypeRepository(host)); + this.#observePropertyEditorUIAlias(); + } - this.observe(this.propertyEditorSchemaAlias, async (propertyEditorSchemaAlias) => { + #observePropertyEditorUIAlias() { + this.observe(this.propertyEditorUiAlias, async (propertyEditorUiAlias) => { + // we only want to react on the change if the alias is set or null. When it is undefined something is still loading + if (propertyEditorUiAlias === undefined) return; + + // 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!); + } else { + await this.#setPropertyEditorUIConfig(propertyEditorUiAlias); + this.setPropertyEditorSchemaAlias(this._propertyEditorUISettingsSchemaAlias!); + await this.#setPropertyEditorSchemaConfig(this._propertyEditorUISettingsSchemaAlias!); + } + + this._mergeConfigProperties(); + this._mergeConfigDefaultData(); + }); + } + + #observePropertyEditorSchemaAlias() { + return this.observe(this.propertyEditorSchemaAlias, async (propertyEditorSchemaAlias) => { if (!propertyEditorSchemaAlias) { this.setPropertyEditorSchemaAlias(UMB_PROPERTY_EDITOR_SCHEMA_ALIAS_DEFAULT); return; } await this.#setPropertyEditorSchemaConfig(propertyEditorSchemaAlias); - this.#observePropertyEditorUIAlias(); - }); - } - - #observePropertyEditorUIAlias() { - this.observe(this.propertyEditorUiAlias, async (propertyEditorUiAlias) => { - // we only want to react on the change if the alias is set or null. When it is undefined something is still loading - if (propertyEditorUiAlias === undefined || !this._propertyEditorSchemaConfigDefaultUIAlias) return; - - // if the property editor ui alias is not set, we use the default alias from the schema - if (propertyEditorUiAlias === null) { - this.setPropertyEditorUiAlias(this._propertyEditorSchemaConfigDefaultUIAlias); - return; - } - - await this.#setPropertyEditorUIConfig(propertyEditorUiAlias); - this._mergeConfigProperties(); - this._mergeConfigDefaultData(); - }); + }).asPromise(); } #setPropertyEditorSchemaConfig(propertyEditorSchemaAlias: string) { @@ -108,6 +115,7 @@ export class UmbDataTypeWorkspaceContext this.#propertyEditorUiIcon.next(manifest?.meta.icon || null); this.#propertyEditorUiName.next(manifest?.name || null); + this._propertyEditorUISettingsSchemaAlias = manifest?.meta.propertyEditorSchemaAlias; this._propertyEditorUISettingsProperties = manifest?.meta.settings?.properties || []; this._propertyEditorUISettingsDefaultData = manifest?.meta.settings?.defaultData || []; },