mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Add text when no statistics found (#9642)
* Add text when no statistics found * Update src/components/entity/ha-statistic-picker.ts Co-authored-by: Paulus Schoutsen <balloob@gmail.com> * fix typos * Update src/components/entity/ha-statistic-picker.ts * Prettier Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
1531e99528
commit
1bd6392a4c
@ -131,6 +131,9 @@ class HaEntitiesPickerLight extends LitElement {
|
|||||||
private async _addEntity(event: PolymerChangedEvent<string>) {
|
private async _addEntity(event: PolymerChangedEvent<string>) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const toAdd = event.detail.value;
|
const toAdd = event.detail.value;
|
||||||
|
if (!toAdd) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
(event.currentTarget as any).value = "";
|
(event.currentTarget as any).value = "";
|
||||||
if (!toAdd) {
|
if (!toAdd) {
|
||||||
return;
|
return;
|
||||||
|
@ -22,46 +22,12 @@ import { compare } from "../../common/string/compare";
|
|||||||
import { getStatisticIds, StatisticsMetaData } from "../../data/history";
|
import { getStatisticIds, StatisticsMetaData } from "../../data/history";
|
||||||
import { PolymerChangedEvent } from "../../polymer-types";
|
import { PolymerChangedEvent } from "../../polymer-types";
|
||||||
import { HomeAssistant } from "../../types";
|
import { HomeAssistant } from "../../types";
|
||||||
|
import { documentationUrl } from "../../util/documentation-url";
|
||||||
import "../ha-combo-box";
|
import "../ha-combo-box";
|
||||||
import type { HaComboBox } from "../ha-combo-box";
|
import type { HaComboBox } from "../ha-combo-box";
|
||||||
import "../ha-svg-icon";
|
import "../ha-svg-icon";
|
||||||
import "./state-badge";
|
import "./state-badge";
|
||||||
|
|
||||||
// vaadin-combo-box-item
|
|
||||||
|
|
||||||
const rowRenderer: ComboBoxLitRenderer<{
|
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
state?: HassEntity;
|
|
||||||
}> = (item) => html`<style>
|
|
||||||
paper-icon-item {
|
|
||||||
padding: 0;
|
|
||||||
margin: -8px;
|
|
||||||
}
|
|
||||||
#content {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
ha-svg-icon {
|
|
||||||
padding-left: 2px;
|
|
||||||
color: var(--secondary-text-color);
|
|
||||||
}
|
|
||||||
:host(:not([selected])) ha-svg-icon {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
:host([selected]) paper-icon-item {
|
|
||||||
margin-left: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
<ha-svg-icon .path=${mdiCheck}></ha-svg-icon>
|
|
||||||
<paper-icon-item>
|
|
||||||
<state-badge slot="item-icon" .stateObj=${item.state}></state-badge>
|
|
||||||
<paper-item-body two-line="">
|
|
||||||
${item.name}
|
|
||||||
<span secondary>${item.id}</span>
|
|
||||||
</paper-item-body>
|
|
||||||
</paper-icon-item>`;
|
|
||||||
|
|
||||||
@customElement("ha-statistic-picker")
|
@customElement("ha-statistic-picker")
|
||||||
export class HaStatisticPicker extends LitElement {
|
export class HaStatisticPicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@ -99,6 +65,53 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
|
|
||||||
private _init = false;
|
private _init = false;
|
||||||
|
|
||||||
|
private _rowRenderer: ComboBoxLitRenderer<{
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
state?: HassEntity;
|
||||||
|
}> = (item) => html`<style>
|
||||||
|
paper-icon-item {
|
||||||
|
padding: 0;
|
||||||
|
margin: -8px;
|
||||||
|
}
|
||||||
|
#content {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
ha-svg-icon {
|
||||||
|
padding-left: 2px;
|
||||||
|
color: var(--secondary-text-color);
|
||||||
|
}
|
||||||
|
:host(:not([selected])) ha-svg-icon {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
:host([selected]) paper-icon-item {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
a {
|
||||||
|
color: var(--primary-color);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<ha-svg-icon .path=${mdiCheck}></ha-svg-icon>
|
||||||
|
<paper-icon-item>
|
||||||
|
<state-badge slot="item-icon" .stateObj=${item.state}></state-badge>
|
||||||
|
<paper-item-body two-line="">
|
||||||
|
${item.name}
|
||||||
|
<span secondary
|
||||||
|
>${item.id === "" || item.id === "__missing"
|
||||||
|
? html`<a
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
href="${documentationUrl(this.hass, "/more-info/statistics/")}"
|
||||||
|
>${this.hass.localize(
|
||||||
|
"ui.components.statistic-picker.learn_more"
|
||||||
|
)}</a
|
||||||
|
>`
|
||||||
|
: item.id}</span
|
||||||
|
>
|
||||||
|
</paper-item-body>
|
||||||
|
</paper-icon-item>`;
|
||||||
|
|
||||||
private _getStatistics = memoizeOne(
|
private _getStatistics = memoizeOne(
|
||||||
(
|
(
|
||||||
statisticIds: StatisticsMetaData[],
|
statisticIds: StatisticsMetaData[],
|
||||||
@ -110,7 +123,7 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
{
|
{
|
||||||
id: "",
|
id: "",
|
||||||
name: this.hass.localize(
|
name: this.hass.localize(
|
||||||
"ui.components.statistics-picker.no_statistics"
|
"ui.components.statistic-picker.no_statistics"
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@ -142,10 +155,27 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (output.length === 1) {
|
if (!output.length) {
|
||||||
return output;
|
return [
|
||||||
|
{
|
||||||
|
id: "",
|
||||||
|
name: this.hass.localize("ui.components.statistic-picker.no_match"),
|
||||||
|
},
|
||||||
|
];
|
||||||
}
|
}
|
||||||
return output.sort((a, b) => compare(a.name || "", b.name || ""));
|
|
||||||
|
if (output.length > 1) {
|
||||||
|
output.sort((a, b) => compare(a.name || "", b.name || ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
output.push({
|
||||||
|
id: "__missing",
|
||||||
|
name: this.hass.localize(
|
||||||
|
"ui.components.statistic-picker.missing_entity"
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -195,7 +225,7 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
? this.hass.localize("ui.components.statistic-picker.statistic")
|
? this.hass.localize("ui.components.statistic-picker.statistic")
|
||||||
: this.label}
|
: this.label}
|
||||||
.value=${this._value}
|
.value=${this._value}
|
||||||
.renderer=${rowRenderer}
|
.renderer=${this._rowRenderer}
|
||||||
.disabled=${this.disabled}
|
.disabled=${this.disabled}
|
||||||
item-value-path="id"
|
item-value-path="id"
|
||||||
item-id-path="id"
|
item-id-path="id"
|
||||||
@ -216,7 +246,10 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
|
|
||||||
private _statisticChanged(ev: PolymerChangedEvent<string>) {
|
private _statisticChanged(ev: PolymerChangedEvent<string>) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const newValue = ev.detail.value;
|
let newValue = ev.detail.value;
|
||||||
|
if (newValue === "__missing") {
|
||||||
|
newValue = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (newValue !== this._value) {
|
if (newValue !== this._value) {
|
||||||
this._setValue(newValue);
|
this._setValue(newValue);
|
||||||
|
@ -90,6 +90,9 @@ class HaStatisticsPicker extends LitElement {
|
|||||||
private async _addStatistic(event: PolymerChangedEvent<string>) {
|
private async _addStatistic(event: PolymerChangedEvent<string>) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const toAdd = event.detail.value;
|
const toAdd = event.detail.value;
|
||||||
|
if (!toAdd) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
(event.currentTarget as any).value = "";
|
(event.currentTarget as any).value = "";
|
||||||
if (!toAdd) {
|
if (!toAdd) {
|
||||||
return;
|
return;
|
||||||
|
@ -155,7 +155,7 @@ class ConfigCoreForm extends LitElement {
|
|||||||
<a
|
<a
|
||||||
href="https://en.wikipedia.org/wiki/ISO_4217#Active_codes"
|
href="https://en.wikipedia.org/wiki/ISO_4217#Active_codes"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferer"
|
rel="noopener noreferrer"
|
||||||
>${this.hass.localize(
|
>${this.hass.localize(
|
||||||
"ui.panel.config.core.section.core.core_config.find_currency_value"
|
"ui.panel.config.core.section.core.core_config.find_currency_value"
|
||||||
)}</a
|
)}</a
|
||||||
|
@ -47,7 +47,7 @@ export class EnergyDeviceSettings extends LitElement {
|
|||||||
)}
|
)}
|
||||||
<a
|
<a
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferer"
|
rel="noopener noreferrer"
|
||||||
href="${documentationUrl(
|
href="${documentationUrl(
|
||||||
this.hass,
|
this.hass,
|
||||||
"/docs/energy/individual-devices/"
|
"/docs/energy/individual-devices/"
|
||||||
|
@ -73,7 +73,7 @@ export class EnergyGridSettings extends LitElement {
|
|||||||
${this.hass.localize("ui.panel.config.energy.grid.sub")}
|
${this.hass.localize("ui.panel.config.energy.grid.sub")}
|
||||||
<a
|
<a
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferer"
|
rel="noopener noreferrer"
|
||||||
href="${documentationUrl(
|
href="${documentationUrl(
|
||||||
this.hass,
|
this.hass,
|
||||||
"/docs/energy/electricity-grid/"
|
"/docs/energy/electricity-grid/"
|
||||||
|
@ -47,7 +47,7 @@ export class EnergySolarSettings extends LitElement {
|
|||||||
${this.hass.localize("ui.panel.config.energy.solar.sub")}
|
${this.hass.localize("ui.panel.config.energy.solar.sub")}
|
||||||
<a
|
<a
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferer"
|
rel="noopener noreferrer"
|
||||||
href="${documentationUrl(
|
href="${documentationUrl(
|
||||||
this.hass,
|
this.hass,
|
||||||
"/docs/energy/solar-panels/"
|
"/docs/energy/solar-panels/"
|
||||||
|
@ -390,6 +390,13 @@
|
|||||||
"failed_create_area": "Failed to create area."
|
"failed_create_area": "Failed to create area."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"statistic-picker": {
|
||||||
|
"statistic": "Statistic",
|
||||||
|
"no_statistics": "You don't have any statistics",
|
||||||
|
"no_match": "No matching statistics found",
|
||||||
|
"missing_entity": "Why is my entity not listed?",
|
||||||
|
"learn_more": "Learn more about statistics"
|
||||||
|
},
|
||||||
"addon-picker": {
|
"addon-picker": {
|
||||||
"addon": "Add-on",
|
"addon": "Add-on",
|
||||||
"error": {
|
"error": {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user