From 32f88ab2bb8f8c3ece500daeb2faca4b70ceaf31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Wed, 19 Jun 2024 14:13:33 +0200 Subject: [PATCH] clean settings data when unset --- .../block/block/context/block-entry.context.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block/context/block-entry.context.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block/context/block-entry.context.ts index 57d20682f7..3986d0ffff 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block/context/block-entry.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block/context/block-entry.context.ts @@ -191,16 +191,23 @@ export abstract class UmbBlockEntryContext< this.#observeBlockTypeLabel(); }); + // Correct settings data, accordingly to configuration of the BlockType: [NL] this.observe( observeMultiple([this.settingsElementTypeKey, this.settingsDataContentTypeKey]), ([settingsElementTypeKey, settingsDataContentTypeKey]) => { + // Notice the values are only undefined while we are missing the source of these observables. [NL] if (settingsElementTypeKey === undefined || settingsDataContentTypeKey === undefined) return; - if (settingsElementTypeKey !== null && settingsElementTypeKey !== settingsDataContentTypeKey) { - // Update the settings model with latest elementTypeKey, so data is up to date with configuration: [NL] - const currentSettings = this.#settings.getValue(); - if (currentSettings) { - this._manager?.setOneSettings({ ...currentSettings, contentTypeKey: settingsElementTypeKey }); + // Is there a difference between configuration and actual data udi: + if (settingsElementTypeKey !== settingsDataContentTypeKey) { + // We need to update our udi for the settings data [NL] + if (settingsElementTypeKey != null) { + // Update the settings model with latest elementTypeKey, so data is up to date with configuration: [NL] + const currentSettings = this.#settings.getValue(); + if (currentSettings) { + this._manager?.setOneSettings({ ...currentSettings, contentTypeKey: settingsElementTypeKey }); + } } + // We do not need to remove the settings if configuration is gone, cause another observation handles this. [NL] } }, );