From 9e8c7e73f2efd26124b42089c71c910a9f0d418c Mon Sep 17 00:00:00 2001 From: Zack Date: Wed, 29 Jun 2022 16:03:13 -0500 Subject: [PATCH] History Panel Fixes for beta --- src/components/ha-target-picker.ts | 199 +++++++++++++------------ src/panels/history/ha-panel-history.ts | 56 ++++--- src/translations/en.json | 3 + 3 files changed, 135 insertions(+), 123 deletions(-) diff --git a/src/components/ha-target-picker.ts b/src/components/ha-target-picker.ts index 7545a19a36..b98d969d05 100644 --- a/src/components/ha-target-picker.ts +++ b/src/components/ha-target-picker.ts @@ -42,8 +42,8 @@ import "./entity/ha-entity-picker"; import type { HaEntityPickerEntityFilterFunc } from "./entity/ha-entity-picker"; import "./ha-area-picker"; import "./ha-icon-button"; -import "./ha-svg-icon"; import "./ha-input-helper-text"; +import "./ha-svg-icon"; @customElement("ha-target-picker") export class HaTargetPicker extends SubscribeMixin(LitElement) { @@ -119,55 +119,68 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) { if (!this._areas || !this._devices || !this._entities) { return html``; } - return html`
- ${this.horizontal ? this._renderChips() : this._renderItems()} - ${this._renderPicker()} - ${this.horizontal ? this._renderItems() : this._renderChips()} -
`; + return html` + ${this.horizontal + ? html` +
+ ${this._renderChips()} ${this._renderPicker()} +
+ ${this._renderItems()} + ` + : html` +
+ ${this._renderItems()} ${this._renderPicker()} + ${this._renderChips()} +
+ `} + `; } private _renderItems() { - return html`
- ${this.value?.area_id - ? ensureArray(this.value.area_id).map((area_id) => { - const area = this._areas![area_id]; - return this._renderChip( - "area_id", - area_id, - area?.name || area_id, - undefined, - mdiSofa - ); - }) - : ""} - ${this.value?.device_id - ? ensureArray(this.value.device_id).map((device_id) => { - const device = this._devices![device_id]; - return this._renderChip( - "device_id", - device_id, - device ? computeDeviceName(device, this.hass) : device_id, - undefined, - mdiDevices - ); - }) - : ""} - ${this.value?.entity_id - ? ensureArray(this.value.entity_id).map((entity_id) => { - const entity = this.hass.states[entity_id]; - return this._renderChip( - "entity_id", - entity_id, - entity ? computeStateName(entity) : entity_id, - entity - ); - }) - : ""} -
`; + return html` +
+ ${this.value?.area_id + ? ensureArray(this.value.area_id).map((area_id) => { + const area = this._areas![area_id]; + return this._renderChip( + "area_id", + area_id, + area?.name || area_id, + undefined, + mdiSofa + ); + }) + : ""} + ${this.value?.device_id + ? ensureArray(this.value.device_id).map((device_id) => { + const device = this._devices![device_id]; + return this._renderChip( + "device_id", + device_id, + device ? computeDeviceName(device, this.hass) : device_id, + undefined, + mdiDevices + ); + }) + : ""} + ${this.value?.entity_id + ? ensureArray(this.value.entity_id).map((entity_id) => { + const entity = this.hass.states[entity_id]; + return this._renderChip( + "entity_id", + entity_id, + entity ? computeStateName(entity) : entity_id, + entity + ); + }) + : ""} +
+ `; } private _renderChips() { - return html`
+ return html` +
${this.helper ? html`${this.helper}` - : ""} `; + : ""} + `; } private async _showPicker(ev) { @@ -320,51 +334,54 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) { private _renderPicker() { switch (this._addMode) { case "area_id": - return html``; + return html` + + `; case "device_id": - return html``; + return html` + + `; case "entity_id": - return html``; + return html` + + `; } return html``; } @@ -553,12 +570,6 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) { static get styles(): CSSResultGroup { return css` ${unsafeCSS(chipStyles)} - .hidden-picker { - height: 0px; - display: inline-block; - overflow: hidden; - position: absolute; - } .horizontal-container { display: flex; flex-wrap: wrap; diff --git a/src/panels/history/ha-panel-history.ts b/src/panels/history/ha-panel-history.ts index 9deb2cf1b1..c77fbc544c 100644 --- a/src/panels/history/ha-panel-history.ts +++ b/src/panels/history/ha-panel-history.ts @@ -10,9 +10,11 @@ import { startOfWeek, startOfYesterday, } from "date-fns/esm"; +import { UnsubscribeFunc } from "home-assistant-js-websocket/dist/types"; import { css, html, LitElement, PropertyValues } from "lit"; import { property, state } from "lit/decorators"; -import { UnsubscribeFunc } from "home-assistant-js-websocket/dist/types"; +import { computeDomain } from "../../common/entity/compute_domain"; +import { computeStateName } from "../../common/entity/compute_state_name"; import { navigate } from "../../common/navigate"; import { createSearchParam, @@ -20,23 +22,21 @@ import { } from "../../common/url/search-params"; import { computeRTL } from "../../common/util/compute_rtl"; import "../../components/chart/state-history-charts"; -import "../../components/ha-target-picker"; import "../../components/ha-circular-progress"; import "../../components/ha-date-range-picker"; import type { DateRangePickerRanges } from "../../components/ha-date-range-picker"; import "../../components/ha-icon-button"; import "../../components/ha-menu-button"; -import { computeHistory, fetchDateWS } from "../../data/history"; -import "../../layouts/ha-app-layout"; -import { haStyle } from "../../resources/styles"; -import { HomeAssistant } from "../../types"; +import "../../components/ha-target-picker"; import { EntityRegistryEntry, subscribeEntityRegistry, } from "../../data/entity_registry"; +import { computeHistory, fetchDateWS } from "../../data/history"; +import "../../layouts/ha-app-layout"; import { SubscribeMixin } from "../../mixins/subscribe-mixin"; -import { computeStateName } from "../../common/entity/compute_state_name"; -import { computeDomain } from "../../common/entity/compute_domain"; +import { haStyle } from "../../resources/styles"; +import { HomeAssistant } from "../../types"; class HaPanelHistory extends SubscribeMixin(LitElement) { @property() hass!: HomeAssistant; @@ -118,30 +118,22 @@ class HaPanelHistory extends SubscribeMixin(LitElement) { @value-changed=${this._entitiesChanged} >
- ${this._isLoading - ? html`
+
+ ${!this._targetPickerValue + ? html` + + ` + : this._isLoading + ? html` +
-
` - : html` - - - `} -
- ${this._isLoading - ? html`
- -
` +
+ ` : html`