mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix blueprint editor behavior for number and text with defaults (#17646)
This commit is contained in:
parent
693c77ce1c
commit
e764076b1a
@ -9,7 +9,6 @@ import "../../../components/ha-circular-progress";
|
|||||||
import "../../../components/ha-markdown";
|
import "../../../components/ha-markdown";
|
||||||
import "../../../components/ha-selector/ha-selector";
|
import "../../../components/ha-selector/ha-selector";
|
||||||
import "../../../components/ha-settings-row";
|
import "../../../components/ha-settings-row";
|
||||||
import "../../../components/ha-textfield";
|
|
||||||
import "../../../components/ha-alert";
|
import "../../../components/ha-alert";
|
||||||
import { BlueprintAutomationConfig } from "../../../data/automation";
|
import { BlueprintAutomationConfig } from "../../../data/automation";
|
||||||
import {
|
import {
|
||||||
@ -129,27 +128,19 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
breaks
|
breaks
|
||||||
.content=${value?.description}
|
.content=${value?.description}
|
||||||
></ha-markdown>
|
></ha-markdown>
|
||||||
${value?.selector
|
${html`<ha-selector
|
||||||
? html`<ha-selector
|
.hass=${this.hass}
|
||||||
.hass=${this.hass}
|
.selector=${value?.selector ?? { text: undefined }}
|
||||||
.selector=${value.selector}
|
.key=${key}
|
||||||
.key=${key}
|
.disabled=${this.disabled}
|
||||||
.value=${(this.config.use_blueprint.input &&
|
.required=${value?.default === undefined}
|
||||||
this.config.use_blueprint.input[key]) ??
|
.placeholder=${value?.default}
|
||||||
value?.default}
|
.value=${this.config.use_blueprint.input &&
|
||||||
.disabled=${this.disabled}
|
key in this.config.use_blueprint.input
|
||||||
.required=${value?.default === undefined}
|
? this.config.use_blueprint.input[key]
|
||||||
@value-changed=${this._inputChanged}
|
: value?.default}
|
||||||
></ha-selector>`
|
@value-changed=${this._inputChanged}
|
||||||
: html`<ha-textfield
|
></ha-selector>`}
|
||||||
.key=${key}
|
|
||||||
.required=${value?.default === undefined}
|
|
||||||
.value=${(this.config.use_blueprint.input &&
|
|
||||||
this.config.use_blueprint.input[key]) ??
|
|
||||||
value?.default}
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
@input=${this._inputChanged}
|
|
||||||
></ha-textfield>`}
|
|
||||||
</ha-settings-row>`
|
</ha-settings-row>`
|
||||||
)
|
)
|
||||||
: html`<p class="padding">
|
: html`<p class="padding">
|
||||||
@ -173,7 +164,7 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
}
|
}
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: {
|
value: {
|
||||||
...this.config!,
|
...this.config,
|
||||||
use_blueprint: {
|
use_blueprint: {
|
||||||
path: ev.detail.value,
|
path: ev.detail.value,
|
||||||
},
|
},
|
||||||
@ -195,20 +186,9 @@ export class HaBlueprintAutomationEditor extends LitElement {
|
|||||||
}
|
}
|
||||||
const input = { ...this.config.use_blueprint.input, [key]: value };
|
const input = { ...this.config.use_blueprint.input, [key]: value };
|
||||||
|
|
||||||
const blueprint = this._blueprint;
|
|
||||||
const metaValue =
|
|
||||||
!blueprint || "error" in blueprint
|
|
||||||
? undefined
|
|
||||||
: blueprint?.metadata.input && blueprint?.metadata?.input[key];
|
|
||||||
const keyDefault = metaValue && metaValue.default;
|
|
||||||
|
|
||||||
if ((value === "" && !keyDefault) || value === undefined) {
|
|
||||||
delete input[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: {
|
value: {
|
||||||
...this.config!,
|
...this.config,
|
||||||
use_blueprint: {
|
use_blueprint: {
|
||||||
...this.config.use_blueprint,
|
...this.config.use_blueprint,
|
||||||
input,
|
input,
|
||||||
|
@ -5,7 +5,6 @@ import "../../../components/ha-blueprint-picker";
|
|||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-circular-progress";
|
import "../../../components/ha-circular-progress";
|
||||||
import "../../../components/ha-markdown";
|
import "../../../components/ha-markdown";
|
||||||
import "../../../components/ha-textfield";
|
|
||||||
import "../../../components/ha-selector/ha-selector";
|
import "../../../components/ha-selector/ha-selector";
|
||||||
import "../../../components/ha-settings-row";
|
import "../../../components/ha-settings-row";
|
||||||
|
|
||||||
@ -108,27 +107,19 @@ export class HaBlueprintScriptEditor extends LitElement {
|
|||||||
breaks
|
breaks
|
||||||
.content=${value?.description}
|
.content=${value?.description}
|
||||||
></ha-markdown>
|
></ha-markdown>
|
||||||
${value?.selector
|
${html`<ha-selector
|
||||||
? html`<ha-selector
|
.hass=${this.hass}
|
||||||
.hass=${this.hass}
|
.selector=${value?.selector ?? { text: undefined }}
|
||||||
.selector=${value.selector}
|
.key=${key}
|
||||||
.key=${key}
|
.disabled=${this.disabled}
|
||||||
.disabled=${this.disabled}
|
.required=${value?.default === undefined}
|
||||||
.required=${value?.default === undefined}
|
.placeholder=${value?.default}
|
||||||
.value=${(this.config.use_blueprint.input &&
|
.value=${this.config.use_blueprint.input &&
|
||||||
this.config.use_blueprint.input[key]) ??
|
key in this.config.use_blueprint.input
|
||||||
value?.default}
|
? this.config.use_blueprint.input[key]
|
||||||
@value-changed=${this._inputChanged}
|
: value?.default}
|
||||||
></ha-selector>`
|
@value-changed=${this._inputChanged}
|
||||||
: html`<ha-textfield
|
></ha-selector>`}
|
||||||
.key=${key}
|
|
||||||
.required=${value?.default === undefined}
|
|
||||||
.disabled=${this.disabled}
|
|
||||||
.value=${(this.config.use_blueprint.input &&
|
|
||||||
this.config.use_blueprint.input[key]) ??
|
|
||||||
value?.default}
|
|
||||||
@change=${this._inputChanged}
|
|
||||||
></ha-textfield>`}
|
|
||||||
</ha-settings-row>`
|
</ha-settings-row>`
|
||||||
)
|
)
|
||||||
: html`<p class="padding">
|
: html`<p class="padding">
|
||||||
@ -174,17 +165,6 @@ export class HaBlueprintScriptEditor extends LitElement {
|
|||||||
}
|
}
|
||||||
const input = { ...this.config.use_blueprint.input, [key]: value };
|
const input = { ...this.config.use_blueprint.input, [key]: value };
|
||||||
|
|
||||||
const blueprint = this._blueprint;
|
|
||||||
const metaValue =
|
|
||||||
!blueprint || "error" in blueprint
|
|
||||||
? undefined
|
|
||||||
: blueprint?.metadata.input && blueprint?.metadata?.input[key];
|
|
||||||
const keyDefault = metaValue && metaValue.default;
|
|
||||||
|
|
||||||
if ((value === "" && !keyDefault) || value === undefined) {
|
|
||||||
delete input[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: {
|
value: {
|
||||||
...this.config,
|
...this.config,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user