-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Migrate more-info configurator #11792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
88f9d05
Migrate more-info configurator
bramkragten d6f39c3
Update more-info-configurator.ts
bramkragten 89477d1
Update src/dialogs/more-info/controls/more-info-configurator.ts
zsarnett 29972c0
Update src/dialogs/more-info/controls/more-info-configurator.ts
bramkragten 176c77c
Import
bramkragten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
148 changes: 0 additions & 148 deletions
148
src/dialogs/more-info/controls/more-info-configurator.js
This file was deleted.
Oops, something went wrong.
128 changes: 128 additions & 0 deletions
128
src/dialogs/more-info/controls/more-info-configurator.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import "@material/mwc-button"; | ||
| import type { HassEntity } from "home-assistant-js-websocket"; | ||
| import { css, html, LitElement, TemplateResult } from "lit"; | ||
| import { customElement, property, state } from "lit/decorators"; | ||
| import "../../../components/ha-alert"; | ||
| import "../../../components/ha-circular-progress"; | ||
| import "../../../components/ha-markdown"; | ||
| import "../../../components/ha-textfield"; | ||
| import type { HomeAssistant } from "../../../types"; | ||
|
|
||
| @customElement("more-info-configurator") | ||
| export class MoreInfoConfigurator extends LitElement { | ||
| @property({ attribute: false }) public hass!: HomeAssistant; | ||
|
|
||
| @property({ attribute: false }) public stateObj?: HassEntity; | ||
|
|
||
| @state() private _isConfiguring = false; | ||
|
|
||
| private _fieldInput = {}; | ||
|
|
||
| protected render(): TemplateResult { | ||
| if (this.stateObj?.state !== "configure") { | ||
| return html``; | ||
| } | ||
|
|
||
| return html` | ||
| <div class="container"> | ||
| <ha-markdown | ||
| breaks | ||
| .content=${this.stateObj.attributes.description} | ||
| ></ha-markdown> | ||
|
|
||
| ${this.stateObj.attributes.errors | ||
| ? html`<ha-alert alert-type="error"> | ||
| ${this.stateObj.attributes.errors} | ||
| </ha-alert>` | ||
| : ""} | ||
| ${this.stateObj.attributes.fields.map( | ||
| (field) => html`<ha-textfield | ||
| .label=${field.name} | ||
| .name=${field.id} | ||
| .type=${field.type} | ||
| @change=${this._fieldChanged} | ||
| ></ha-textfield>` | ||
| )} | ||
| ${this.stateObj.attributes.submit_caption | ||
| ? html`<p class="submit"> | ||
| <mwc-button | ||
| raised | ||
| .disabled=${this._isConfiguring} | ||
| @click=${this._submitClicked} | ||
| > | ||
| ${this._isConfiguring | ||
| ? html`<ha-circular-progress | ||
| active | ||
| alt="Configuring" | ||
| ></ha-circular-progress>` | ||
| : ""} | ||
| ${this.stateObj.attributes.submit_caption} | ||
| </mwc-button> | ||
| </p>` | ||
| : ""} | ||
| </div> | ||
| `; | ||
| } | ||
|
|
||
| private _fieldChanged(ev) { | ||
| const el = ev.target; | ||
| this._fieldInput[el.name] = el.value; | ||
| } | ||
|
|
||
| private _submitClicked() { | ||
| const data = { | ||
| configure_id: this.stateObj!.attributes.configure_id, | ||
| fields: this._fieldInput, | ||
| }; | ||
|
|
||
| this._isConfiguring = true; | ||
|
|
||
| this.hass.callService("configurator", "configure", data).then( | ||
| () => { | ||
| this._isConfiguring = false; | ||
| }, | ||
| () => { | ||
| this._isConfiguring = false; | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| static styles = css` | ||
| .container { | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
| p { | ||
| margin: 8px 0; | ||
| } | ||
|
|
||
| a { | ||
| color: var(--primary-color); | ||
| } | ||
|
|
||
| p > img { | ||
| max-width: 100%; | ||
| } | ||
|
|
||
| p.center { | ||
| text-align: center; | ||
| } | ||
|
|
||
| p.submit { | ||
| text-align: center; | ||
| height: 41px; | ||
| } | ||
|
|
||
| ha-circular-progress { | ||
| width: 14px; | ||
| height: 14px; | ||
| margin-right: 20px; | ||
| } | ||
| `; | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| "more-info-configurator": MoreInfoConfigurator; | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be a paragraph element
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, could be a div, but 🤷♂️ (it is used to center the button)