From dd49b46c46fa90eac989b077057c8e30c8ff20fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Fri, 1 Mar 2024 11:09:17 +0100 Subject: [PATCH] fix value undefined --- ...ction-view-layout-configuration.element.ts | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/collection-view/config/layout-configuration/property-editor-ui-collection-view-layout-configuration.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/collection-view/config/layout-configuration/property-editor-ui-collection-view-layout-configuration.element.ts index ea49184b4a..b20d40cee9 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/collection-view/config/layout-configuration/property-editor-ui-collection-view-layout-configuration.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/collection-view/config/layout-configuration/property-editor-ui-collection-view-layout-configuration.element.ts @@ -26,7 +26,7 @@ export class UmbPropertyEditorUICollectionViewLayoutConfigurationElement implements UmbPropertyEditorUiElement { @property({ type: Array }) - value: Array = []; + value?: Array; @property({ type: Object, attribute: false }) public config?: UmbPropertyEditorConfigCollection; @@ -41,47 +41,47 @@ export class UmbPropertyEditorUICollectionViewLayoutConfigurationElement } #onAdd() { - this.value = [...this.value, { isSystem: false, icon: 'icon-stop', selected: true }]; + this.value = [...(this.value ?? []), { isSystem: false, icon: 'icon-stop', selected: true }]; this.dispatchEvent(new UmbPropertyValueChangeEvent()); } #onRemove(unique: number) { - const values = [...this.value]; + const values = [...(this.value ?? [])]; values.splice(unique, 1); this.value = values; this.dispatchEvent(new UmbPropertyValueChangeEvent()); } #onChangePath(e: UUIInputEvent, index: number) { - const values = [...this.value]; + const values = [...(this.value ?? [])]; values[index] = { ...values[index], path: e.target.value as string }; this.value = values; this.dispatchEvent(new UmbPropertyValueChangeEvent()); } #onChangeName(e: UUIInputEvent, index: number) { - const values = [...this.value]; + const values = [...(this.value ?? [])]; values[index] = { ...values[index], name: e.target.value as string }; this.value = values; this.dispatchEvent(new UmbPropertyValueChangeEvent()); } #onChangeSelected(e: UUIBooleanInputEvent, index: number) { - const values = [...this.value]; + const values = [...(this.value ?? [])]; values[index] = { ...values[index], selected: e.target.checked }; this.value = values; this.dispatchEvent(new UmbPropertyValueChangeEvent()); } async #onIconChange(index: number) { - const icon = this.#iconReader(this.value[index].icon ?? ''); + const icon = this.#iconReader((this.value ? this.value[index].icon : undefined) ?? ''); // TODO: send icon data to modal const modalContext = this._modalContext?.open(UMB_ICON_PICKER_MODAL); const picked = await modalContext?.onSubmit(); if (!picked) return; - const values = [...this.value]; + const values = [...(this.value ?? [])]; values[index] = { ...values[index], icon: `${picked.icon} color-${picked.color}` }; this.value = values; this.dispatchEvent(new UmbPropertyValueChangeEvent()); @@ -89,16 +89,18 @@ export class UmbPropertyEditorUICollectionViewLayoutConfigurationElement render() { return html`
- ${repeat( - this.value, - (layout, index) => '' + layout.name + layout.icon, - (layout, index) => - html`
- ${layout.isSystem - ? this.renderSystemFieldRow(layout, index) - : this.renderCustomFieldRow(layout, index)} -
`, - )} + ${this.value + ? repeat( + this.value, + (layout, index) => '' + layout.name + layout.icon, + (layout, index) => + html`
+ ${layout.isSystem + ? this.renderSystemFieldRow(layout, index) + : this.renderCustomFieldRow(layout, index)} +
`, + ) + : ''}