diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/collection-view/config/column-configuration/property-editor-ui-collection-view-column-configuration.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/collection-view/config/column-configuration/property-editor-ui-collection-view-column-configuration.element.ts index ac99056914..4445927e3e 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/collection-view/config/column-configuration/property-editor-ui-collection-view-column-configuration.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/property-editor/uis/collection-view/config/column-configuration/property-editor-ui-collection-view-column-configuration.element.ts @@ -1,7 +1,8 @@ import type { UmbCollectionColumnConfiguration } from '../../../../../collection/types.js'; -import { html, customElement, property, repeat, css, state } from '@umbraco-cms/backoffice/external/lit'; +import { html, customElement, property, repeat, css, state, nothing, when } from '@umbraco-cms/backoffice/external/lit'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; import { UmbPropertyValueChangeEvent } from '@umbraco-cms/backoffice/property-editor'; +import { UmbTextStyles } from '@umbraco-cms/backoffice/style'; import type { UmbInputContentTypePropertyElement } from '@umbraco-cms/backoffice/components'; import type { UmbPropertyEditorConfigCollection } from '@umbraco-cms/backoffice/property-editor'; import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry'; @@ -15,6 +16,9 @@ export class UmbPropertyEditorUICollectionViewColumnConfigurationElement extends UmbLitElement implements UmbPropertyEditorUiElement { + + // TODO: [LK] Add sorting. + @property({ type: Array }) value?: Array = []; @@ -24,7 +28,7 @@ export class UmbPropertyEditorUICollectionViewColumnConfigurationElement @state() private _field?: UmbInputContentTypePropertyElement['selectedProperty']; - #onChange(e: CustomEvent) { + #onAdd(e: CustomEvent) { const element = e.target as UmbInputContentTypePropertyElement; if (!element.selectedProperty) return; @@ -49,6 +53,15 @@ export class UmbPropertyEditorUICollectionViewColumnConfigurationElement this.dispatchEvent(new UmbPropertyValueChangeEvent()); } + #onChangeLabel(e: UUIInputEvent, configuration: UmbCollectionColumnConfiguration) { + this.value = this.value?.map( + (config): UmbCollectionColumnConfiguration => + config.alias === configuration.alias ? { ...config, header: e.target.value as string } : config, + ); + + this.dispatchEvent(new UmbPropertyValueChangeEvent()); + } + #onRemove(unique: string) { const newValue: Array = []; @@ -60,105 +73,86 @@ export class UmbPropertyEditorUICollectionViewColumnConfigurationElement this.dispatchEvent(new UmbPropertyValueChangeEvent()); } - #onHeaderChange(e: UUIInputEvent, configuration: UmbCollectionColumnConfiguration) { - this.value = this.value?.map( - (config): UmbCollectionColumnConfiguration => - config.alias === configuration.alias ? { ...config, header: e.target.value as string } : config, - ); - - this.dispatchEvent(new UmbPropertyValueChangeEvent()); - } - - #onTemplateChange(e: UUIInputEvent, configuration: UmbCollectionColumnConfiguration) { - this.value = this.value?.map( - (config): UmbCollectionColumnConfiguration => - config.alias === configuration.alias ? { ...config, nameTemplate: e.target.value as string } : config, - ); - - this.dispatchEvent(new UmbPropertyValueChangeEvent()); - } - render() { + if (!this.value) return nothing; return html` - ${this.#renderTable()} - +
+ ${repeat( + this.value, + (column) => column.alias, + (column) => this.#renderField(column), + )} +
+ @change=${this.#onAdd}> `; } - #renderTable() { - if (!this.value?.length) return; + #renderField(column: UmbCollectionColumnConfiguration) { return html` - - - - Alias - Header - Template - - - ${repeat( - this.value, - (configuration) => configuration.alias, - (configuration) => html` - - - ${configuration.isSystem === 1 - ? this.#renderSystemFieldRow(configuration) - : this.#renderCustomFieldRow(configuration)} - - this.#onRemove(configuration.alias)}> - - - `, - )} - - `; - } +
+ - #renderSystemFieldRow(configuration: UmbCollectionColumnConfiguration) { - return html` - ${configuration.alias} (system field) - ${configuration.header} - - `; - } - - #renderCustomFieldRow(configuration: UmbCollectionColumnConfiguration) { - return html` - ${configuration.alias} - this.#onHeaderChange(e, configuration)}> - - + label="label" + placeholder="Enter a label..." + .value=${column.header ?? ''} + @change=${(e: UUIInputEvent) => this.#onChangeLabel(e, column)}> + +
+ ${column.alias} +
+ this.#onTemplateChange(e, configuration)}> -
+ placeholder="Enter a name template..." + .value=${column.nameTemplate ?? ''}> + +
+ this.#onRemove(column.alias)}> +
+
`; } static styles = [ + UmbTextStyles, css` - :host { + #layout-wrapper { display: flex; flex-direction: column; - gap: var(--uui-size-space-1); + gap: 1px; + margin-bottom: var(--uui-size-1); } - uui-input { - width: 100%; + .layout-item { + background-color: var(--uui-color-surface-alt); + display: flex; + align-items: center; + gap: var(--uui-size-6); + padding: var(--uui-size-3) var(--uui-size-6); + } + + .layout-item > uui-icon { + flex: 0 0 var(--uui-size-6); + } + + .layout-item > uui-input, + .layout-item > .alias { + flex: 1; + } + + .layout-item > .actions { + flex: 0 0 auto; + display: flex; + justify-content: flex-end; } `, ];