mirror of
https://github.com/home-assistant/frontend.git
synced 2026-04-02 00:27:49 +01:00
Remove hass property in ha-data-table (#51304)
This commit is contained in:
@@ -422,7 +422,6 @@ export class DemoEntityState extends LitElement {
|
|||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-data-table
|
<ha-data-table
|
||||||
.hass=${this.hass}
|
|
||||||
.columns=${this._columns(this.hass)}
|
.columns=${this._columns(this.hass)}
|
||||||
.data=${this._rows()}
|
.data=${this._rows()}
|
||||||
auto-height
|
auto-height
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { consume, type ContextType } from "@lit/context";
|
||||||
import { mdiArrowDown, mdiArrowUp, mdiChevronUp } from "@mdi/js";
|
import { mdiArrowDown, mdiArrowUp, mdiChevronUp } from "@mdi/js";
|
||||||
import deepClone from "deep-clone-simple";
|
import deepClone from "deep-clone-simple";
|
||||||
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
import type { CSSResultGroup, PropertyValues, TemplateResult } from "lit";
|
||||||
@@ -21,9 +22,10 @@ import type { LocalizeFunc } from "../../common/translations/localize";
|
|||||||
import { debounce } from "../../common/util/debounce";
|
import { debounce } from "../../common/util/debounce";
|
||||||
import { groupBy } from "../../common/util/group-by";
|
import { groupBy } from "../../common/util/group-by";
|
||||||
import { nextRender } from "../../common/util/render-status";
|
import { nextRender } from "../../common/util/render-status";
|
||||||
|
import { localeContext, localizeContext } from "../../data/context";
|
||||||
|
import type { FrontendLocaleData } from "../../data/translation";
|
||||||
import { haStyleScrollbar } from "../../resources/styles";
|
import { haStyleScrollbar } from "../../resources/styles";
|
||||||
import { loadVirtualizer } from "../../resources/virtualizer";
|
import { loadVirtualizer } from "../../resources/virtualizer";
|
||||||
import type { HomeAssistant } from "../../types";
|
|
||||||
import "../ha-checkbox";
|
import "../ha-checkbox";
|
||||||
import type { HaCheckbox } from "../ha-checkbox";
|
import type { HaCheckbox } from "../ha-checkbox";
|
||||||
import "../ha-svg-icon";
|
import "../ha-svg-icon";
|
||||||
@@ -104,9 +106,13 @@ const UNDEFINED_GROUP_KEY = "zzzzz_undefined";
|
|||||||
|
|
||||||
@customElement("ha-data-table")
|
@customElement("ha-data-table")
|
||||||
export class HaDataTable extends LitElement {
|
export class HaDataTable extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@state()
|
||||||
|
@consume({ context: localizeContext, subscribe: true })
|
||||||
|
private _localize?: ContextType<typeof localizeContext>;
|
||||||
|
|
||||||
@property({ attribute: false }) public localizeFunc?: LocalizeFunc;
|
@state()
|
||||||
|
@consume({ context: localeContext, subscribe: true })
|
||||||
|
private _locale?: ContextType<typeof localeContext>;
|
||||||
|
|
||||||
@property({ type: Boolean }) public narrow = false;
|
@property({ type: Boolean }) public narrow = false;
|
||||||
|
|
||||||
@@ -378,8 +384,6 @@ export class HaDataTable extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const localize = this.localizeFunc || this.hass.localize;
|
|
||||||
|
|
||||||
const columns = this._sortedColumns(this.columns, this.columnOrder);
|
const columns = this._sortedColumns(this.columns, this.columnOrder);
|
||||||
|
|
||||||
const renderRow = (row: DataTableRowData, index: number) =>
|
const renderRow = (row: DataTableRowData, index: number) =>
|
||||||
@@ -503,7 +507,8 @@ export class HaDataTable extends LitElement {
|
|||||||
<div class="mdc-data-table__row" role="row">
|
<div class="mdc-data-table__row" role="row">
|
||||||
<div class="mdc-data-table__cell grows center" role="cell">
|
<div class="mdc-data-table__cell grows center" role="cell">
|
||||||
${this.noDataText ||
|
${this.noDataText ||
|
||||||
localize("ui.components.data-table.no-data")}
|
this._localize?.("ui.components.data-table.no-data") ||
|
||||||
|
"No data"}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -515,7 +520,8 @@ export class HaDataTable extends LitElement {
|
|||||||
@scroll=${this._saveScrollPos}
|
@scroll=${this._saveScrollPos}
|
||||||
.items=${this._groupData(
|
.items=${this._groupData(
|
||||||
this._filteredData,
|
this._filteredData,
|
||||||
localize,
|
this._localize,
|
||||||
|
this._locale,
|
||||||
this.appendRow,
|
this.appendRow,
|
||||||
this.groupColumn,
|
this.groupColumn,
|
||||||
this.groupOrder,
|
this.groupOrder,
|
||||||
@@ -685,7 +691,7 @@ export class HaDataTable extends LitElement {
|
|||||||
this._sortColumns[this.sortColumn],
|
this._sortColumns[this.sortColumn],
|
||||||
this.sortDirection,
|
this.sortDirection,
|
||||||
this.sortColumn,
|
this.sortColumn,
|
||||||
this.hass.locale.language
|
this._locale?.language
|
||||||
)
|
)
|
||||||
: filteredData;
|
: filteredData;
|
||||||
|
|
||||||
@@ -711,7 +717,8 @@ export class HaDataTable extends LitElement {
|
|||||||
private _groupData = memoizeOne(
|
private _groupData = memoizeOne(
|
||||||
(
|
(
|
||||||
data: DataTableRowData[],
|
data: DataTableRowData[],
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc | undefined,
|
||||||
|
locale: FrontendLocaleData | undefined,
|
||||||
appendRow,
|
appendRow,
|
||||||
groupColumn: string | undefined,
|
groupColumn: string | undefined,
|
||||||
groupOrder: string[] | undefined,
|
groupOrder: string[] | undefined,
|
||||||
@@ -735,11 +742,7 @@ export class HaDataTable extends LitElement {
|
|||||||
)
|
)
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
if (!groupOrder && isGroupSortColumn) {
|
if (!groupOrder && isGroupSortColumn) {
|
||||||
const comparison = stringCompare(
|
const comparison = stringCompare(a, b, locale?.language);
|
||||||
a,
|
|
||||||
b,
|
|
||||||
this.hass.locale.language
|
|
||||||
);
|
|
||||||
if (sortDirection === "asc") {
|
if (sortDirection === "asc") {
|
||||||
return comparison;
|
return comparison;
|
||||||
}
|
}
|
||||||
@@ -760,7 +763,7 @@ export class HaDataTable extends LitElement {
|
|||||||
return stringCompare(
|
return stringCompare(
|
||||||
["", "-", "—"].includes(a) ? "zzz" : a,
|
["", "-", "—"].includes(a) ? "zzz" : a,
|
||||||
["", "-", "—"].includes(b) ? "zzz" : b,
|
["", "-", "—"].includes(b) ? "zzz" : b,
|
||||||
this.hass.locale.language
|
locale?.language
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.reduce(
|
.reduce(
|
||||||
@@ -787,14 +790,15 @@ export class HaDataTable extends LitElement {
|
|||||||
>
|
>
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
.path=${mdiChevronUp}
|
.path=${mdiChevronUp}
|
||||||
.label=${this.hass.localize(
|
.label=${localize?.(
|
||||||
`ui.components.data-table.${collapsed ? "expand" : "collapse"}`
|
`ui.components.data-table.${collapsed ? "expand" : "collapse"}`
|
||||||
)}
|
) || (collapsed ? "Expand" : "Collapse")}
|
||||||
class=${collapsed ? "collapsed" : ""}
|
class=${collapsed ? "collapsed" : ""}
|
||||||
>
|
>
|
||||||
</ha-icon-button>
|
</ha-icon-button>
|
||||||
${groupName === UNDEFINED_GROUP_KEY
|
${groupName === UNDEFINED_GROUP_KEY
|
||||||
? localize("ui.components.data-table.ungrouped")
|
? localize?.("ui.components.data-table.ungrouped") ||
|
||||||
|
"Ungrouped"
|
||||||
: groupName || ""}
|
: groupName || ""}
|
||||||
</div>`,
|
</div>`,
|
||||||
});
|
});
|
||||||
@@ -863,7 +867,8 @@ export class HaDataTable extends LitElement {
|
|||||||
|
|
||||||
const groupedData = this._groupData(
|
const groupedData = this._groupData(
|
||||||
this._filteredData,
|
this._filteredData,
|
||||||
this.localizeFunc || this.hass.localize,
|
this._localize,
|
||||||
|
this._locale,
|
||||||
this.appendRow,
|
this.appendRow,
|
||||||
this.groupColumn,
|
this.groupColumn,
|
||||||
this.groupOrder,
|
this.groupOrder,
|
||||||
|
|||||||
@@ -505,7 +505,6 @@ export class HaTabsSubpageDataTable extends KeyboardShortcutMixin(LitElement) {
|
|||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
<ha-data-table
|
<ha-data-table
|
||||||
.hass=${this.hass}
|
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.columns=${this.columns}
|
.columns=${this.columns}
|
||||||
.data=${this.data}
|
.data=${this.data}
|
||||||
|
|||||||
@@ -108,7 +108,6 @@ export class HaConfigAppsRegistries extends LitElement {
|
|||||||
.header=${this.hass.localize("ui.panel.config.apps.store.registries")}
|
.header=${this.hass.localize("ui.panel.config.apps.store.registries")}
|
||||||
>
|
>
|
||||||
<ha-data-table
|
<ha-data-table
|
||||||
.hass=${this.hass}
|
|
||||||
.columns=${this._columns(this.hass.localize)}
|
.columns=${this._columns(this.hass.localize)}
|
||||||
.data=${this._registries}
|
.data=${this._registries}
|
||||||
.noDataText=${this.hass.localize(
|
.noDataText=${this.hass.localize(
|
||||||
|
|||||||
@@ -187,7 +187,6 @@ export class HaConfigAppsRepositories extends LitElement {
|
|||||||
.header=${this.hass.localize("ui.panel.config.apps.store.repositories")}
|
.header=${this.hass.localize("ui.panel.config.apps.store.repositories")}
|
||||||
>
|
>
|
||||||
<ha-data-table
|
<ha-data-table
|
||||||
.hass=${this.hass}
|
|
||||||
.columns=${this._columns(this.hass.localize, usedRepositories)}
|
.columns=${this._columns(this.hass.localize, usedRepositories)}
|
||||||
.data=${this._data(repositories)}
|
.data=${this._data(repositories)}
|
||||||
.noDataText=${this.hass.localize(
|
.noDataText=${this.hass.localize(
|
||||||
|
|||||||
@@ -451,7 +451,6 @@ class HaPanelDevStatistics extends KeyboardShortcutMixin(LitElement) {
|
|||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
<ha-data-table
|
<ha-data-table
|
||||||
.hass=${this.hass}
|
|
||||||
.narrow=${this.narrow}
|
.narrow=${this.narrow}
|
||||||
.columns=${columns}
|
.columns=${columns}
|
||||||
.data=${this._displayData(this._data, this.hass.localize)}
|
.data=${this._displayData(this._data, this.hass.localize)}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { customElement, property, state } from "lit/decorators";
|
|||||||
import { until } from "lit/directives/until";
|
import { until } from "lit/directives/until";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import type { LocalizeFunc } from "../../../common/translations/localize";
|
import type { LocalizeFunc } from "../../../common/translations/localize";
|
||||||
import "../../../components/data-table/ha-data-table";
|
|
||||||
import type {
|
import type {
|
||||||
DataTableColumnContainer,
|
DataTableColumnContainer,
|
||||||
DataTableRowData,
|
DataTableRowData,
|
||||||
|
|||||||
@@ -74,7 +74,6 @@ export class ZHAClustersDataTable extends LitElement {
|
|||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<ha-data-table
|
<ha-data-table
|
||||||
.hass=${this.hass}
|
|
||||||
.columns=${this._columns(this.narrow)}
|
.columns=${this._columns(this.narrow)}
|
||||||
.data=${this._clusters(this.clusters)}
|
.data=${this._clusters(this.clusters)}
|
||||||
.id=${"cluster_id"}
|
.id=${"cluster_id"}
|
||||||
|
|||||||
@@ -158,7 +158,6 @@ export class ZHADeviceEndpointDataTable extends LitElement {
|
|||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<ha-data-table
|
<ha-data-table
|
||||||
.hass=${this.hass}
|
|
||||||
.columns=${this._columns(this.hass.localize, this.narrow)}
|
.columns=${this._columns(this.hass.localize, this.narrow)}
|
||||||
.data=${this._deviceEndpoints(this.deviceEndpoints, this.hass.areas)}
|
.data=${this._deviceEndpoints(this.deviceEndpoints, this.hass.areas)}
|
||||||
.selectable=${this.selectable}
|
.selectable=${this.selectable}
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ class ZHADeviceNeighbors extends LitElement {
|
|||||||
${!this._devices
|
${!this._devices
|
||||||
? html`<ha-spinner size="large"></ha-spinner>`
|
? html`<ha-spinner size="large"></ha-spinner>`
|
||||||
: html`<ha-data-table
|
: html`<ha-data-table
|
||||||
.hass=${this.hass}
|
|
||||||
.columns=${this._columns(this.narrow)}
|
.columns=${this._columns(this.narrow)}
|
||||||
.data=${this._deviceNeighbors(this.device, this._devices)}
|
.data=${this._deviceNeighbors(this.device, this._devices)}
|
||||||
auto-height
|
auto-height
|
||||||
|
|||||||
@@ -129,7 +129,6 @@ class AssistDevicesPage extends LitElement {
|
|||||||
<ha-data-table
|
<ha-data-table
|
||||||
clickable
|
clickable
|
||||||
id="device_id"
|
id="device_id"
|
||||||
.hass=${this.hass}
|
|
||||||
.columns=${this._columns(this.hass.localize)}
|
.columns=${this._columns(this.hass.localize)}
|
||||||
.data=${this._data(
|
.data=${this._data(
|
||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
|
|||||||
@@ -104,7 +104,6 @@ export class HuiEntityPickerTable extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-data-table
|
<ha-data-table
|
||||||
class=${showEntityId ? "show-entity-id" : ""}
|
class=${showEntityId ? "show-entity-id" : ""}
|
||||||
.hass=${this.hass}
|
|
||||||
selectable
|
selectable
|
||||||
.id=${"entity_id"}
|
.id=${"entity_id"}
|
||||||
.columns=${columns}
|
.columns=${columns}
|
||||||
|
|||||||
Reference in New Issue
Block a user