From 1e5d751d59ffcc91b05ec5b5787a7cf4e7e8e7bb Mon Sep 17 00:00:00 2001 From: Lone Iversen <108085781+loivsen@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:42:21 +0100 Subject: [PATCH] save grouping --- ...ui-block-grid-type-configuration.element.ts | 18 ++++++++++++------ .../input-block-type.element.ts | 4 +++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-editors/block-grid-type-configuration/property-editor-ui-block-grid-type-configuration.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-editors/block-grid-type-configuration/property-editor-ui-block-grid-type-configuration.element.ts index 32e9dc2de4..f63568ff1e 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-editors/block-grid-type-configuration/property-editor-ui-block-grid-type-configuration.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-grid/property-editors/block-grid-type-configuration/property-editor-ui-block-grid-type-configuration.element.ts @@ -19,8 +19,14 @@ export class UmbPropertyEditorUIBlockGridTypeConfigurationElement { #datasetContext?: UmbPropertyDatasetContext; + private _value: Array = []; @property({ attribute: false }) - value: UmbBlockTypeWithGroupKey[] = []; + get value() { + return this._value; + } + set value(value: Array) { + this._value = value ?? []; + } @property({ type: Object, attribute: false }) public config?: UmbPropertyEditorConfigCollection; @@ -43,7 +49,7 @@ export class UmbPropertyEditorUIBlockGridTypeConfigurationElement if (!this.#datasetContext) return; this.observe(await this.#datasetContext.propertyValueByAlias('blockGroups'), (value) => { - this._blockGroups = value as Array; + this._blockGroups = (value as Array) ?? []; this.#mapValuesToBlockGroups(); }); this.observe(await this.#datasetContext.propertyValueByAlias('blocks'), () => { @@ -53,10 +59,10 @@ export class UmbPropertyEditorUIBlockGridTypeConfigurationElement #mapValuesToBlockGroups() { // What if a block is in a group that does not exist in the block groups? Should it be removed? (Right now they will never be rendered) - const valuesWithNoGroup = this.value.filter((value) => !value.groupKey); + const valuesWithNoGroup = this._value.filter((value) => !value.groupKey); const valuesWithGroup = this._blockGroups.map((group) => { - return { name: group.name, key: group.key, blocks: this.value.filter((value) => value.groupKey === group.key) }; + return { name: group.name, key: group.key, blocks: this._value.filter((value) => value.groupKey === group.key) }; }); this._mappedValuesAndGroups = [{ blocks: valuesWithNoGroup }, ...valuesWithGroup]; @@ -76,7 +82,7 @@ export class UmbPropertyEditorUIBlockGridTypeConfigurationElement const groupName = e.target.value as string; this.#datasetContext?.setPropertyValue( 'blockGroups', - this._blockGroups.map((group) => ({ ...group, groupName: groupKey === group.key ? groupName : group.name })), + this._blockGroups.map((group) => (group.key === groupKey ? { ...group, name: groupName } : group)), ); } @@ -87,7 +93,7 @@ export class UmbPropertyEditorUIBlockGridTypeConfigurationElement ); // Should blocks that belonged to the removed group be deleted as well? - this.value = this.value.filter((block) => block.groupKey !== groupKey); + this.value = this._value.filter((block) => block.groupKey !== groupKey); } #renderGroupInput(groupKey: string, groupName?: string) { diff --git a/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/input-block-type/input-block-type.element.ts b/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/input-block-type/input-block-type.element.ts index 2a3721f41a..186f9b8079 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/input-block-type/input-block-type.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/block/block-type/components/input-block-type/input-block-type.element.ts @@ -59,6 +59,7 @@ export class UmbInputBlockTypeElement< typeof UMB_WORKSPACE_MODAL.VALUE >; + /* #datasetContext?: UmbPropertyDatasetContext; #filter: Array = []; @@ -71,6 +72,7 @@ export class UmbInputBlockTypeElement< }); }); } + */ create() { this.consumeContext(UMB_MODAL_MANAGER_CONTEXT_TOKEN, async (modalManager) => { @@ -84,7 +86,7 @@ export class UmbInputBlockTypeElement< // Only pick elements: docType.isElement && // Prevent picking the an already used element type: - this.#filter.find((x) => x.contentElementTypeKey === docType.unique) === undefined, + this._items.find((x) => x.contentElementTypeKey === docType.unique) === undefined, }, });