From 4a1087c969d5fa2a42f30f0110d9c64a39d3ee09 Mon Sep 17 00:00:00 2001 From: Simon Lamon <32477463+silamon@users.noreply.github.com> Date: Fri, 28 Jun 2024 14:45:33 +0200 Subject: [PATCH] Add storage variables for application credentials config table (#21215) Implement storage variables --- .../ha-config-application-credentials.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/panels/config/application_credentials/ha-config-application-credentials.ts b/src/panels/config/application_credentials/ha-config-application-credentials.ts index 644759e148da..7c5fa5ae93dc 100644 --- a/src/panels/config/application_credentials/ha-config-application-credentials.ts +++ b/src/panels/config/application_credentials/ha-config-application-credentials.ts @@ -7,6 +7,7 @@ import { LocalizeFunc } from "../../../common/translations/localize"; import { DataTableColumnContainer, SelectionChangedEvent, + SortingChangedEvent, } from "../../../components/data-table/ha-data-table"; import "../../../components/ha-fab"; import "../../../components/ha-help-tooltip"; @@ -27,6 +28,7 @@ import type { HaTabsSubpageDataTable } from "../../../layouts/hass-tabs-subpage- import { HomeAssistant, Route } from "../../../types"; import { configSections } from "../ha-panel-config"; import { showAddApplicationCredentialDialog } from "./show-dialog-add-application-credential"; +import { storage } from "../../../common/decorators/storage"; @customElement("ha-config-application-credentials") export class HaConfigApplicationCredentials extends LitElement { @@ -45,6 +47,27 @@ export class HaConfigApplicationCredentials extends LitElement { @query("hass-tabs-subpage-data-table", true) private _dataTable!: HaTabsSubpageDataTable; + @storage({ + key: "application-credentials-table-sort", + state: false, + subscribe: false, + }) + private _activeSorting?: SortingChangedEvent; + + @storage({ + key: "application-credentials-table-column-order", + state: false, + subscribe: false, + }) + private _activeColumnOrder?: string[]; + + @storage({ + key: "application-credentials-table-hidden-columns", + state: false, + subscribe: false, + }) + private _activeHiddenColumns?: string[]; + private _columns = memoizeOne( (narrow: boolean, localize: LocalizeFunc): DataTableColumnContainer => { const columns: DataTableColumnContainer = { @@ -128,6 +151,11 @@ export class HaConfigApplicationCredentials extends LitElement { selectable .selected=${this._selected.length} @selection-changed=${this._handleSelectionChanged} + .initialSorting=${this._activeSorting} + .columnOrder=${this._activeColumnOrder} + .hiddenColumns=${this._activeHiddenColumns} + @columns-changed=${this._handleColumnsChanged} + @sorting-changed=${this._handleSortingChanged} >
${!this.narrow @@ -252,6 +280,15 @@ export class HaConfigApplicationCredentials extends LitElement { }); } + private _handleSortingChanged(ev: CustomEvent) { + this._activeSorting = ev.detail; + } + + private _handleColumnsChanged(ev: CustomEvent) { + this._activeColumnOrder = ev.detail.columnOrder; + this._activeHiddenColumns = ev.detail.hiddenColumns; + } + static get styles(): CSSResultGroup { return css` .table-header {