Skip to content

Commit

Permalink
Add storage variables for application credentials config table (#21215)
Browse files Browse the repository at this point in the history
Implement storage variables
  • Loading branch information
silamon authored Jun 28, 2024
1 parent cbc95a5 commit 4a1087c
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 {
Expand All @@ -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<ApplicationCredential> = {
Expand Down Expand Up @@ -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}
>
<div class="header-btns" slot="selection-bar">
${!this.narrow
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 4a1087c

Please sign in to comment.