Skip to content

Commit

Permalink
Input conversion in dev tools (home-assistant#11795)
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten authored Feb 23, 2022
1 parent 6e2e80a commit 0010bf5
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This is the repository for the official [Home Assistant](https://home-assistant.io) frontend.

[![Screenshot of the frontend](https://raw.githubusercontent.com/home-assistant/home-assistant-polymer/master/docs/screenshot.png)](https://demo.home-assistant.io/)
[![Screenshot of the frontend](https://raw.githubusercontent.com/home-assistant/frontend/master/docs/screenshot.png)](https://demo.home-assistant.io/)

- [View demo of Home Assistant](https://demo.home-assistant.io/)
- [More information about Home Assistant](https://home-assistant.io)
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/generic/dialog-box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class DialogBox extends LitElement {
? html`
<ha-textfield
dialogInitialFocus
.value=${this._value}
.value=${this._value || ""}
@keyup=${this._handleKeyUp}
@change=${this._valueChanged}
.label=${this._params.inputLabel
Expand Down
17 changes: 13 additions & 4 deletions src/panels/developer-tools/event/developer-tools-event.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import "@material/mwc-button";
import "@polymer/iron-flex-layout/iron-flex-layout-classes";
import "@polymer/paper-input/paper-input";
import { html } from "@polymer/polymer/lib/utils/html-tag";
/* eslint-plugin-disable lit */
import { PolymerElement } from "@polymer/polymer/polymer-element";
import { load } from "js-yaml";
import "../../../components/ha-code-editor";
import "../../../components/ha-textfield";
import { showAlertDialog } from "../../../dialogs/generic/show-dialog-box";
import { EventsMixin } from "../../../mixins/events-mixin";
import LocalizeMixin from "../../../mixins/localize-mixin";
Expand Down Expand Up @@ -46,6 +46,10 @@ class HaPanelDevEvent extends EventsMixin(LocalizeMixin(PolymerElement)) {
margin-top: 8px;
}
ha-textfield {
display: block;
}
.code-editor {
margin-right: 16px;
}
Expand Down Expand Up @@ -78,14 +82,15 @@ class HaPanelDevEvent extends EventsMixin(LocalizeMixin(PolymerElement)) {
</a>
</p>
<div class="inputs">
<paper-input
<ha-textfield
label="[[localize(
'ui.panel.developer-tools.tabs.events.type'
)]]"
autofocus
required
value="{{eventType}}"
></paper-input>
value="[[eventType]]"
on-change="eventTypeChanged"
></ha-textfield>
<p>[[localize( 'ui.panel.developer-tools.tabs.events.data' )]]</p>
</div>
<div class="code-editor">
Expand Down Expand Up @@ -150,6 +155,10 @@ class HaPanelDevEvent extends EventsMixin(LocalizeMixin(PolymerElement)) {
this.eventType = ev.detail.eventType;
}

eventTypeChanged(ev) {
this.eventType = ev.target.value;
}

_computeParsedEventData(eventData) {
try {
return eventData.trim() ? load(eventData) : {};
Expand Down
18 changes: 8 additions & 10 deletions src/panels/developer-tools/event/event-subscribe-card.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import "@material/mwc-button";
import "@polymer/paper-input/paper-input";
import { HassEvent } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { formatTime } from "../../../common/datetime/format_time";
import "../../../components/ha-card";
import { PolymerChangedEvent } from "../../../polymer-types";
import "../../../components/ha-textfield";
import { HomeAssistant } from "../../../types";

@customElement("event-subscribe-card")
Expand Down Expand Up @@ -39,7 +38,7 @@ class EventSubscribeCard extends LitElement {
)}
>
<form>
<paper-input
<ha-textfield
.label=${this._subscribed
? this.hass!.localize(
"ui.panel.developer-tools.tabs.events.listening_to"
Expand All @@ -49,8 +48,8 @@ class EventSubscribeCard extends LitElement {
)}
.disabled=${this._subscribed !== undefined}
.value=${this._eventType}
@value-changed=${this._valueChanged}
></paper-input>
@input=${this._valueChanged}
></ha-textfield>
<mwc-button
.disabled=${this._eventType === ""}
@click=${this._handleSubmit}
Expand Down Expand Up @@ -84,8 +83,8 @@ class EventSubscribeCard extends LitElement {
`;
}

private _valueChanged(ev: PolymerChangedEvent<string>): void {
this._eventType = ev.detail.value;
private _valueChanged(ev): void {
this._eventType = ev.target.value;
}

private async _handleSubmit(): Promise<void> {
Expand Down Expand Up @@ -116,9 +115,8 @@ class EventSubscribeCard extends LitElement {
display: block;
padding: 0 0 16px 16px;
}
paper-input {
display: inline-block;
width: 200px;
ha-textfield {
width: 300px;
}
mwc-button {
vertical-align: middle;
Expand Down
63 changes: 49 additions & 14 deletions src/panels/developer-tools/state/developer-tools-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
mdiInformationOutline,
mdiRefresh,
} from "@mdi/js";
import "@polymer/paper-input/paper-input";
import { html } from "@polymer/polymer/lib/utils/html-tag";
/* eslint-plugin-disable lit */
import { PolymerElement } from "@polymer/polymer/polymer-element";
Expand Down Expand Up @@ -42,6 +41,14 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
padding: 16px;
}
ha-textfield {
display: block;
}
.state-input {
margin-top: 16px;
}
ha-expansion-panel {
margin: 0 8px 16px;
}
Expand Down Expand Up @@ -74,6 +81,14 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
);
}
.filters th {
padding: 0;
}
.filters ha-textfield {
--mdc-text-field-fill-color: transparent;
}
th.attributes {
position: relative;
}
Expand Down Expand Up @@ -164,16 +179,17 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
on-change="entityIdChanged"
allow-custom-entity
></ha-entity-picker>
<paper-input
<ha-textfield
label="[[localize('ui.panel.developer-tools.tabs.states.state')]]"
required
autocapitalize="none"
autocomplete="off"
autocorrect="off"
spellcheck="false"
value="{{_state}}"
value="[[_state]]"
on-change="stateChanged"
class="state-input"
></paper-input>
></ha-textfield>
<p>
[[localize('ui.panel.developer-tools.tabs.states.state_attributes')]]
</p>
Expand Down Expand Up @@ -234,27 +250,30 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
></ha-checkbox>
</th>
</tr>
<tr>
<tr class="filters">
<th>
<paper-input
<ha-textfield
label="[[localize('ui.panel.developer-tools.tabs.states.filter_entities')]]"
type="search"
value="{{_entityFilter}}"
></paper-input>
value="[[_entityFilter]]"
on-input="_entityFilterChanged"
></ha-textfield>
</th>
<th>
<paper-input
<ha-textfield
label="[[localize('ui.panel.developer-tools.tabs.states.filter_states')]]"
type="search"
value="{{_stateFilter}}"
></paper-input>
value="[[_stateFilter]]"
on-input="_stateFilterChanged"
></ha-textfield>
</th>
<th hidden$="[[!computeShowAttributes(narrow, _showAttributes)]]">
<paper-input
<ha-textfield
label="[[localize('ui.panel.developer-tools.tabs.states.filter_attributes')]]"
type="search"
value="{{_attributeFilter}}"
></paper-input>
value="[[_attributeFilter]]"
on-input="_attributeFilterChanged"
></ha-textfield>
</th>
</tr>
<tr hidden$="[[!computeShowEntitiesPlaceholder(_entities)]]">
Expand Down Expand Up @@ -416,6 +435,22 @@ class HaPanelDevState extends EventsMixin(LocalizeMixin(PolymerElement)) {
this._expanded = true;
}

stateChanged(ev) {
this._state = ev.target.value;
}

_entityFilterChanged(ev) {
this._entityFilter = ev.target.value;
}

_stateFilterChanged(ev) {
this._stateFilter = ev.target.value;
}

_attributeFilterChanged(ev) {
this._attributeFilter = ev.target.value;
}

_getHistoryURL(entityId, inputDate) {
const date = new Date(inputDate);
const hourBefore = addHours(date, -1).toISOString();
Expand Down
1 change: 0 additions & 1 deletion src/panels/lovelace/editor/card-editor/hui-card-preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import "@polymer/paper-input/paper-textarea";
import { PropertyValues, ReactiveElement } from "lit";
import { property } from "lit/decorators";
import { computeRTL } from "../../../../common/util/compute_rtl";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export class HuiConditionalCardEditor
.condition .state mwc-select {
margin-right: 16px;
}
.condition .state paper-input {
.condition .state ha-textfield {
flex-grow: 1;
}
Expand Down
1 change: 0 additions & 1 deletion src/panels/mailbox/ha-panel-mailbox.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "@material/mwc-button";
import "@polymer/app-layout/app-header/app-header";
import "@polymer/app-layout/app-toolbar/app-toolbar";
import "@polymer/paper-input/paper-textarea";
import "@polymer/paper-item/paper-item";
import "@polymer/paper-item/paper-item-body";
import "@polymer/paper-tabs/paper-tab";
Expand Down
10 changes: 7 additions & 3 deletions src/panels/profile/ha-long-lived-access-token-dialog.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import "@material/mwc-button";
import "@polymer/paper-input/paper-input";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event";
import { createCloseHeading } from "../../components/ha-dialog";
import { haStyleDialog } from "../../resources/styles";
import type { HomeAssistant } from "../../types";
import { LongLivedAccessTokenDialogParams } from "./show-long-lived-access-token-dialog";
import "../../components/ha-textfield";

const QR_LOGO_URL = "/static/icons/favicon-192x192.png";

Expand Down Expand Up @@ -41,14 +41,15 @@ export class HaLongLivedAccessTokenDialog extends LitElement {
@closed=${this.closeDialog}
>
<div>
<paper-input
<ha-textfield
dialogInitialFocus
.value=${this._params.token}
.label=${this.hass.localize(
"ui.panel.profile.long_lived_access_tokens.prompt_copy_token"
)}
type="text"
></paper-input>
readOnly
></ha-textfield>
<div id="qr">
${this._qrCode
? this._qrCode
Expand Down Expand Up @@ -94,6 +95,9 @@ export class HaLongLivedAccessTokenDialog extends LitElement {
#qr {
text-align: center;
}
ha-textfield {
display: block;
}
`,
];
}
Expand Down

0 comments on commit 0010bf5

Please sign in to comment.