Compare commits

...
Author SHA1 Message Date
Aidan Timson 559775af9d Flatten the Status filter on the entities page 2026-11-24 14:53:54 +00:00
3 changed files with 54 additions and 156 deletions

No files matched your search

+28 -101
View File
@@ -20,7 +20,6 @@ import "./ha-expansion-panel";
import "./ha-icon";
import "./ha-icon-button";
import "./ha-svg-icon";
import "./ha-tree-indicator";
import "./item/ha-list-item-option";
import type { HaListItemOption } from "./item/ha-list-item-option";
import "./list/ha-list-selectable";
@@ -35,23 +34,6 @@ export interface FilterStateOption {
iconPath?: string;
}
/**
* Two opposite options, like available and unavailable, listed under a row
* that ticks or unticks both. The row is partly ticked when one of the two is.
*/
export interface FilterStatePair {
/** Identifies the row, apart from the values of its options */
value: string;
label: string;
iconPath?: string;
options: [FilterStateOption, FilterStateOption];
}
export type FilterStateItem = FilterStateOption | FilterStatePair;
const isPair = (item: FilterStateItem): item is FilterStatePair =>
"options" in item;
@customElement("ha-filter-states")
export class HaFilterStates extends LitElement {
@state()
@@ -62,7 +44,7 @@ export class HaFilterStates extends LitElement {
@property({ attribute: false }) public value?: string[];
@property({ attribute: false }) public states?: FilterStateItem[];
@property({ attribute: false }) public states?: FilterStateOption[];
@property({ type: Boolean }) public narrow = false;
@@ -108,10 +90,29 @@ export class HaFilterStates extends LitElement {
@ha-list-item-selected=${this._handleItemToggled}
@ha-list-item-deselected=${this._handleItemToggled}
>
${this.states.map((item) =>
isPair(item)
? this._renderPair(item)
: this._renderOption(item)
${this.states.map(
(item) =>
html`<ha-list-item-option
appearance="checkbox"
selection-position="end"
.value=${item.value}
.selected=${this.value?.includes(item.value) ?? false}
>
${
item.iconPath
? html`<ha-svg-icon
slot="start"
.path=${item.iconPath}
></ha-svg-icon>`
: item.icon
? html`<ha-icon
slot="start"
.icon=${item.icon}
></ha-icon>`
: nothing
}
<span slot="headline">${item.label}</span>
</ha-list-item-option>`
)}
</ha-list-selectable>
</div>
@@ -121,56 +122,6 @@ export class HaFilterStates extends LitElement {
`;
}
private _renderOption(item: FilterStateOption, nested?: { last: boolean }) {
return html`<ha-list-item-option
appearance="checkbox"
selection-position="end"
class=${nested ? "nested" : ""}
.value=${item.value}
.selected=${this.value?.includes(item.value) ?? false}
>
${
nested
? html`<ha-tree-indicator
slot="start"
.end=${nested.last}
></ha-tree-indicator>`
: nothing
}
${this._renderIcon(item)}
<span slot="headline">${item.label}</span>
</ha-list-item-option>`;
}
private _renderPair(pair: FilterStatePair) {
const picked = pair.options.filter((option) =>
this.value?.includes(option.value)
).length;
return html`<ha-list-item-option
appearance="checkbox"
selection-position="end"
.value=${pair.value}
.selected=${picked === pair.options.length}
.indeterminate=${picked > 0 && picked < pair.options.length}
>
${this._renderIcon(pair)}
<span slot="headline">${pair.label}</span>
</ha-list-item-option>
${pair.options.map((option, index) =>
this._renderOption(option, {
last: index === pair.options.length - 1,
})
)}`;
}
private _renderIcon(item: { icon?: string; iconPath?: string }) {
return item.iconPath
? html`<ha-svg-icon slot="start" .path=${item.iconPath}></ha-svg-icon>`
: item.icon
? html`<ha-icon slot="start" .icon=${item.icon}></ha-icon>`
: nothing;
}
private _expandedChanged(ev) {
this.expanded = ev.detail.expanded;
}
@@ -185,21 +136,10 @@ export class HaFilterStates extends LitElement {
return;
}
const selected = ev.type === "ha-list-item-selected";
// A pair row ticks or unticks both of its options
const pair = this.states?.find(
(item): item is FilterStatePair =>
isPair(item) && item.value === itemValue
);
const values = pair
? pair.options.map((option) => option.value)
: [itemValue];
this.value = values.reduce(
(value, val) =>
selected ? arrayWith(value, val) : arrayWithout(value, val),
this.value
);
this.value =
ev.type === "ha-list-item-selected"
? arrayWith(this.value, itemValue)
: arrayWithout(this.value, itemValue);
fireEvent(this, "data-table-filter-changed", {
value: this.value,
@@ -229,19 +169,6 @@ export class HaFilterStates extends LitElement {
flex: 1;
min-height: 0;
}
/* Options of a pair sit under it, like areas under their floor */
.nested::part(base) {
padding-inline-start: 48px;
}
ha-tree-indicator {
width: 56px;
position: absolute;
top: 0px;
inset-inline-start: 0px;
}
ha-tree-indicator:dir(rtl) {
transform: scaleX(-1);
}
.header {
display: flex;
align-items: center;
@@ -7,14 +7,11 @@ import {
mdiDotsVertical,
mdiEye,
mdiEyeOff,
mdiEyeOutline,
mdiMenuDown,
mdiMicrophoneMessage,
mdiMicrophoneMessageOff,
mdiPencilOff,
mdiPlus,
mdiPower,
mdiPulse,
mdiRestore,
mdiRestoreAlert,
mdiToggleSwitch,
@@ -78,7 +75,7 @@ import "../../../components/ha-filter-floor-areas";
import "../../../components/ha-filter-integrations";
import "../../../components/ha-filter-labels";
import "../../../components/ha-filter-states";
import type { FilterStateItem } from "../../../components/ha-filter-states";
import type { FilterStateOption } from "../../../components/ha-filter-states";
import "../../../components/ha-filter-voice-assistants";
import "../../../components/ha-icon";
import "../../../components/ha-icon-button";
@@ -324,59 +321,36 @@ export class HaConfigEntities extends LitElement {
// The icons of the options match the ones of the status column and of the
// actions for the selected entities
private _states = memoize((localize: LocalizeFunc): FilterStateItem[] => [
private _states = memoize((localize: LocalizeFunc): FilterStateOption[] => [
{
value: "availability",
label: localize("ui.panel.config.entities.picker.headers.availability"),
iconPath: mdiPulse,
options: [
{
value: "available",
label: localize("ui.panel.config.entities.picker.status.available"),
iconPath: mdiCheckCircle,
},
{
value: "unavailable",
label: localize("ui.panel.config.entities.picker.status.unavailable"),
iconPath: mdiAlertCircle,
},
],
value: "available",
label: localize("ui.panel.config.entities.picker.status.available"),
iconPath: mdiCheckCircle,
},
{
value: "activation",
label: localize(
"ui.panel.config.entities.picker.status_pairs.activation"
),
iconPath: mdiPower,
options: [
{
value: "enabled",
label: localize("ui.panel.config.entities.picker.status.enabled"),
iconPath: mdiToggleSwitch,
},
{
value: "disabled",
label: localize("ui.panel.config.entities.picker.status.disabled"),
iconPath: mdiToggleSwitchOffOutline,
},
],
value: "unavailable",
label: localize("ui.panel.config.entities.picker.status.unavailable"),
iconPath: mdiAlertCircle,
},
{
value: "visibility",
label: localize("ui.panel.config.entities.picker.headers.visibility"),
iconPath: mdiEyeOutline,
options: [
{
value: "visible",
label: localize("ui.panel.config.entities.picker.status.visible"),
iconPath: mdiEye,
},
{
value: "hidden",
label: localize("ui.panel.config.entities.picker.status.hidden"),
iconPath: mdiEyeOff,
},
],
value: "enabled",
label: localize("ui.panel.config.entities.picker.status.enabled"),
iconPath: mdiToggleSwitch,
},
{
value: "disabled",
label: localize("ui.panel.config.entities.picker.status.disabled"),
iconPath: mdiToggleSwitchOffOutline,
},
{
value: "visible",
label: localize("ui.panel.config.entities.picker.status.visible"),
iconPath: mdiEye,
},
{
value: "hidden",
label: localize("ui.panel.config.entities.picker.status.hidden"),
iconPath: mdiEyeOff,
},
{
value: "readonly",
-3
View File
@@ -7904,9 +7904,6 @@
"not_provided": "Not provided",
"unmanageable": "Unmanageable"
},
"status_pairs": {
"activation": "Activation"
},
"headers": {
"state_icon": "State icon",
"entity": "Entity",