Skip to content

Commit

Permalink
Merge pull request #17774 from umbraco/15.1/hotfix/block-editors-disc…
Browse files Browse the repository at this point in the history
…ard-changes-on-startup

* prevent the block list editor from setting an empty value on startup
* prevent block grid from setting and initial empty block object value
* fix import

---------

Co-authored-by: Niels Lyngsø <niels.lyngso@gmail.com>
Co-authored-by: Niels Lyngsø <nsl@umbraco.dk>
  • Loading branch information
nielslyngsoe and nielslyngsoe authored Dec 11, 2024
2 parents 9b56201 + 5cffe11 commit 5322e38
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property';
import { UmbModalRouteRegistrationController } from '@umbraco-cms/backoffice/router';
import { incrementString } from '@umbraco-cms/backoffice/utils';

import '../../components/block-grid-area-config-entry/index.js';
@customElement('umb-property-editor-ui-block-grid-areas-config')
export class UmbPropertyEditorUIBlockGridAreasConfigElement
extends UmbLitElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@ export class UmbPropertyEditorUIBlockGridElement
#settingsDataPathTranslator?: UmbBlockElementDataValidationPathTranslator;
#managerContext = new UmbBlockGridManagerContext(this);
//
private _value: UmbBlockGridValueModel = {
layout: {},
contentData: [],
settingsData: [],
expose: [],
};
private _value: UmbBlockGridValueModel | undefined = undefined;

#lastValue: UmbBlockGridValueModel | undefined = undefined;

public set config(config: UmbPropertyEditorConfigCollection | undefined) {
if (!config) return;
Expand All @@ -68,6 +65,13 @@ export class UmbPropertyEditorUIBlockGridElement

@property({ attribute: false })
public override set value(value: UmbBlockGridValueModel | undefined) {
this.#lastValue = value;

if (!value) {
this._value = undefined;
return;
}

const buildUpValue: Partial<UmbBlockGridValueModel> = value ? { ...value } : {};
buildUpValue.layout ??= {};
buildUpValue.contentData ??= [];
Expand All @@ -80,7 +84,7 @@ export class UmbPropertyEditorUIBlockGridElement
this.#managerContext.setSettings(this._value.settingsData);
this.#managerContext.setExposes(this._value.expose);
}
public override get value(): UmbBlockGridValueModel {
public override get value(): UmbBlockGridValueModel | undefined {
return this._value;
}

Expand Down Expand Up @@ -116,13 +120,24 @@ export class UmbPropertyEditorUIBlockGridElement
this.#managerContext.exposes,
]).pipe(debounceTime(20)),
([layouts, contents, settings, exposes]) => {
this._value = {
...this._value,
layout: { [UMB_BLOCK_GRID_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_GRID_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 grid from setting an empty value on startup.
if (this.#lastValue === undefined && this._value === undefined) {
return;
}

propertyContext.setValue(this._value);
},
'motherObserver',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,19 @@ export class UmbPropertyEditorUIBlockListElement

//#catalogueModal: UmbModalRouteRegistrationController<typeof UMB_BLOCK_CATALOGUE_MODAL.DATA, undefined>;

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<UmbBlockListValueModel> = value ? { ...value } : {};
buildUpValue.layout ??= {};
buildUpValue.contentData ??= [];
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 5322e38

Please sign in to comment.