Fix config update handling for map card editor (#8115)

This commit is contained in:
Philip Allgaier 2021-01-14 12:52:58 +01:00 committed by GitHub
parent 1aa40cb6df
commit ef7d2aea8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 40 deletions

View File

@ -31,17 +31,17 @@ export class HuiInputListEditor extends LitElement {
return html`
<paper-input
label="${this.inputLabel}"
.value="${listEntry}"
.configValue="${"entry"}"
.index="${index}"
@value-changed="${this._valueChanged}"
@blur="${this._consolidateEntries}"
.value=${listEntry}
.configValue=${"entry"}
.index=${index}
@value-changed=${this._valueChanged}
@blur=${this._consolidateEntries}
><ha-icon-button
slot="suffix"
class="clear-button"
icon="hass:close"
no-ripple
@click="${this._removeEntry}"
@click=${this._removeEntry}
>Clear</ha-icon-button
></paper-input
>
@ -49,7 +49,7 @@ export class HuiInputListEditor extends LitElement {
})}
<paper-input
label="${this.inputLabel}"
@change="${this._addEntry}"
@change=${this._addEntry}
></paper-input>
`;
}

View File

@ -96,36 +96,39 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
return html`
<div class="card-config">
<paper-input
.label="${this.hass.localize(
.label=${this.hass.localize(
"ui.panel.lovelace.editor.card.generic.title"
)} (${this.hass.localize(
)}
(${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional"
)})"
.value="${this._title}"
.configValue="${"title"}"
@value-changed="${this._valueChanged}"
)})
.value=${this._title}
.configValue=${"title"}
@value-changed=${this._valueChanged}
></paper-input>
<div class="side-by-side">
<paper-input
.label="${this.hass.localize(
.label=${this.hass.localize(
"ui.panel.lovelace.editor.card.generic.aspect_ratio"
)} (${this.hass.localize(
)}
(${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional"
)})"
.value="${this._aspect_ratio}"
.configValue="${"aspect_ratio"}"
@value-changed="${this._valueChanged}"
)})
.value=${this._aspect_ratio}
.configValue=${"aspect_ratio"}
@value-changed=${this._valueChanged}
></paper-input>
<paper-input
.label="${this.hass.localize(
.label=${this.hass.localize(
"ui.panel.lovelace.editor.card.map.default_zoom"
)} (${this.hass.localize(
)}
(${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional"
)})"
)})
type="number"
.value="${this._default_zoom}"
.configValue="${"default_zoom"}"
@value-changed="${this._valueChanged}"
.configValue=${"default_zoom"}
@value-changed=${this._valueChanged}
></paper-input>
</div>
<div class="side-by-side">
@ -136,27 +139,28 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
.dir=${computeRTLDirection(this.hass)}
>
<ha-switch
.checked="${this._dark_mode}"
.configValue="${"dark_mode"}"
@change="${this._valueChanged}"
.checked=${this._dark_mode}
.configValue=${"dark_mode"}
@change=${this._valueChanged}
></ha-switch
></ha-formfield>
<paper-input
.label="${this.hass.localize(
.label=${this.hass.localize(
"ui.panel.lovelace.editor.card.map.hours_to_show"
)} (${this.hass.localize(
)}
(${this.hass.localize(
"ui.panel.lovelace.editor.card.config.optional"
)})"
)})
type="number"
.value="${this._hours_to_show}"
.configValue="${"hours_to_show"}"
@value-changed="${this._valueChanged}"
.configValue=${"hours_to_show"}
@value-changed=${this._valueChanged}
></paper-input>
</div>
<hui-entity-editor
.hass=${this.hass}
.entities="${this._configEntities}"
@entities-changed="${this._entitiesValueChanged}"
.entities=${this._configEntities}
@entities-changed=${this._entitiesValueChanged}
></hui-entity-editor>
<h3>
${this.hass.localize(
@ -169,9 +173,9 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
"ui.panel.lovelace.editor.card.map.source"
)}
.hass=${this.hass}
.value="${this._geo_location_sources}"
.configValue="${"geo_location_sources"}"
@value-changed="${this._valueChanged}"
.value=${this._geo_location_sources}
.configValue=${"geo_location_sources"}
@value-changed=${this._valueChanged}
></hui-input-list-editor>
</div>
</div>
@ -195,14 +199,15 @@ export class HuiMapCardEditor extends LitElement implements LovelaceCardEditor {
return;
}
const target = ev.target! as EditorTarget;
if (target.configValue && this[`_${target.configValue}`] === target.value) {
let value = ev.detail.value;
if (target.configValue && this[`_${target.configValue}`] === value) {
return;
}
let value: any = target.value;
if (target.type === "number") {
value = Number(value);
}
if (target.value === "" || (target.type === "number" && isNaN(value))) {
if (value === "" || (target.type === "number" && isNaN(value))) {
this._config = { ...this._config };
delete this._config[target.configValue!];
} else if (target.configValue) {