From d5144540f73f0c59e40079e8a2f4871702403a1e Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 11 Dec 2024 12:09:17 +0100 Subject: [PATCH] prevent the block list editor from setting an empty value on startup --- .../property-editor-ui-block-list.element.ts | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-list/property-editors/block-list-editor/property-editor-ui-block-list.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-list/property-editors/block-list-editor/property-editor-ui-block-list.element.ts index 1559e4899a..d608e3c373 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-list/property-editors/block-list-editor/property-editor-ui-block-list.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-list/property-editors/block-list-editor/property-editor-ui-block-list.element.ts @@ -56,15 +56,19 @@ export class UmbPropertyEditorUIBlockListElement //#catalogueModal: UmbModalRouteRegistrationController; - private _value: UmbBlockListValueModel = { - layout: {}, - contentData: [], - settingsData: [], - expose: [], - }; + private _value: UmbBlockListValueModel | undefined = undefined; + + #lastValue: UmbBlockListValueModel | undefined = undefined; @property({ attribute: false }) public override set value(value: UmbBlockListValueModel | undefined) { + this.#lastValue = value; + + if (!value) { + this._value = undefined; + return; + } + const buildUpValue: Partial = value ? { ...value } : {}; buildUpValue.layout ??= {}; buildUpValue.contentData ??= []; @@ -188,13 +192,24 @@ export class UmbPropertyEditorUIBlockListElement this.#managerContext.exposes, ]).pipe(debounceTime(20)), ([layouts, contents, settings, exposes]) => { - this._value = { - ...this._value, - layout: { [UMB_BLOCK_LIST_PROPERTY_EDITOR_SCHEMA_ALIAS]: layouts }, - contentData: contents, - settingsData: settings, - expose: exposes, - }; + if (layouts.length === 0) { + this._value = undefined; + } else { + this._value = { + ...this._value, + layout: { [UMB_BLOCK_LIST_PROPERTY_EDITOR_SCHEMA_ALIAS]: layouts }, + contentData: contents, + settingsData: settings, + expose: exposes, + }; + } + + // If we don't have a value set from the outside or an internal value, we don't want to set the value. + // This is added to prevent the block list from setting an empty value on startup. + if (this.#lastValue === undefined && this._value === undefined) { + return; + } + context.setValue(this._value); }, 'motherObserver',