mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 01:36:49 +00:00
Hide columns in unused entities on mobile (#3719)
* Hide columns in unused entities on mobile * Update hui-unused-entities.ts * Fix * Update hui-unused-entities.ts
This commit is contained in:
parent
065e42c8fd
commit
722e9bcda7
@ -10,6 +10,9 @@ import {
|
|||||||
} from "lit-element";
|
} from "lit-element";
|
||||||
|
|
||||||
import { classMap } from "lit-html/directives/class-map";
|
import { classMap } from "lit-html/directives/class-map";
|
||||||
|
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
|
|
||||||
import "../../../../components/ha-fab";
|
import "../../../../components/ha-fab";
|
||||||
import "../../../../components/entity/state-badge";
|
import "../../../../components/entity/state-badge";
|
||||||
import "../../../../components/ha-relative-time";
|
import "../../../../components/ha-relative-time";
|
||||||
@ -17,7 +20,10 @@ import "../../../../components/ha-icon";
|
|||||||
|
|
||||||
import "../../../../components/ha-data-table";
|
import "../../../../components/ha-data-table";
|
||||||
// tslint:disable-next-line
|
// tslint:disable-next-line
|
||||||
import { SelectionChangedEvent } from "../../../../components/ha-data-table";
|
import {
|
||||||
|
SelectionChangedEvent,
|
||||||
|
DataTabelColumnContainer,
|
||||||
|
} from "../../../../components/ha-data-table";
|
||||||
|
|
||||||
import computeStateName from "../../../../common/entity/compute_state_name";
|
import computeStateName from "../../../../common/entity/compute_state_name";
|
||||||
import computeDomain from "../../../../common/entity/compute_domain";
|
import computeDomain from "../../../../common/entity/compute_domain";
|
||||||
@ -38,6 +44,8 @@ export class HuiUnusedEntities extends LitElement {
|
|||||||
|
|
||||||
@property() public hass?: HomeAssistant;
|
@property() public hass?: HomeAssistant;
|
||||||
|
|
||||||
|
@property() public narrow?: boolean;
|
||||||
|
|
||||||
@property() private _unusedEntities: string[] = [];
|
@property() private _unusedEntities: string[] = [];
|
||||||
|
|
||||||
private _selectedEntities: string[] = [];
|
private _selectedEntities: string[] = [];
|
||||||
@ -46,31 +54,41 @@ export class HuiUnusedEntities extends LitElement {
|
|||||||
return this.lovelace!.config;
|
return this.lovelace!.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _columns = {
|
private _columns = memoizeOne((narrow: boolean) => {
|
||||||
entity: {
|
const columns: DataTabelColumnContainer = {
|
||||||
title: "Entity",
|
entity: {
|
||||||
sortable: true,
|
title: "Entity",
|
||||||
filterable: true,
|
sortable: true,
|
||||||
filterKey: "friendly_name",
|
filterable: true,
|
||||||
direction: "asc",
|
filterKey: "friendly_name",
|
||||||
template: (stateObj) => html`
|
direction: "asc",
|
||||||
<div @click=${this._handleEntityClicked} style="cursor: pointer;">
|
template: (stateObj) => html`
|
||||||
<state-badge .hass=${this.hass!} .stateObj=${stateObj}></state-badge>
|
<div @click=${this._handleEntityClicked} style="cursor: pointer;">
|
||||||
${stateObj.friendly_name}
|
<state-badge
|
||||||
</div>
|
.hass=${this.hass!}
|
||||||
`,
|
.stateObj=${stateObj}
|
||||||
},
|
></state-badge>
|
||||||
entity_id: {
|
${stateObj.friendly_name}
|
||||||
|
</div>
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (narrow) {
|
||||||
|
return columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
columns.entity_id = {
|
||||||
title: "Entity id",
|
title: "Entity id",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
},
|
};
|
||||||
domain: {
|
columns.domain = {
|
||||||
title: "Domain",
|
title: "Domain",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
filterable: true,
|
filterable: true,
|
||||||
},
|
};
|
||||||
last_changed: {
|
columns.last_changed = {
|
||||||
title: "Last Changed",
|
title: "Last Changed",
|
||||||
type: "numeric",
|
type: "numeric",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
@ -80,8 +98,10 @@ export class HuiUnusedEntities extends LitElement {
|
|||||||
.datetime=${lastChanged}
|
.datetime=${lastChanged}
|
||||||
></ha-relative-time>
|
></ha-relative-time>
|
||||||
`,
|
`,
|
||||||
},
|
};
|
||||||
};
|
|
||||||
|
return columns;
|
||||||
|
});
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues): void {
|
protected updated(changedProperties: PropertyValues): void {
|
||||||
super.updated(changedProperties);
|
super.updated(changedProperties);
|
||||||
@ -114,7 +134,7 @@ export class HuiUnusedEntities extends LitElement {
|
|||||||
</div>
|
</div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
<ha-data-table
|
<ha-data-table
|
||||||
.columns=${this._columns}
|
.columns=${this._columns(this.narrow!)}
|
||||||
.data=${this._unusedEntities.map((entity) => {
|
.data=${this._unusedEntities.map((entity) => {
|
||||||
const stateObj = this.hass!.states[entity];
|
const stateObj = this.hass!.states[entity];
|
||||||
return {
|
return {
|
||||||
|
@ -602,6 +602,7 @@ class HUIRoot extends LitElement {
|
|||||||
() => {
|
() => {
|
||||||
unusedEntities.hass = this.hass!;
|
unusedEntities.hass = this.hass!;
|
||||||
unusedEntities.lovelace = this.lovelace!;
|
unusedEntities.lovelace = this.lovelace!;
|
||||||
|
unusedEntities.narrow = this.narrow;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (this.config.background) {
|
if (this.config.background) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user