mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-16 13:56:35 +00:00
Script change icon (#20885)
* Add icon to rename dialog * Check in entity registry * Only use icon for script
This commit is contained in:
parent
56cabeb497
commit
e059ca146b
@ -4,12 +4,18 @@ import { customElement, property, state } from "lit/decorators";
|
|||||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||||
import "../../../../components/ha-alert";
|
import "../../../../components/ha-alert";
|
||||||
import { createCloseHeading } from "../../../../components/ha-dialog";
|
import { createCloseHeading } from "../../../../components/ha-dialog";
|
||||||
|
import "../../../../components/ha-domain-icon";
|
||||||
|
import "../../../../components/ha-icon-picker";
|
||||||
import "../../../../components/ha-textarea";
|
import "../../../../components/ha-textarea";
|
||||||
import "../../../../components/ha-textfield";
|
import "../../../../components/ha-textfield";
|
||||||
|
|
||||||
import { HassDialog } from "../../../../dialogs/make-dialog-manager";
|
import { HassDialog } from "../../../../dialogs/make-dialog-manager";
|
||||||
import { haStyle, haStyleDialog } from "../../../../resources/styles";
|
import { haStyle, haStyleDialog } from "../../../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../../../types";
|
import type { HomeAssistant } from "../../../../types";
|
||||||
import type { AutomationRenameDialog } from "./show-dialog-automation-rename";
|
import type {
|
||||||
|
AutomationRenameDialogParams,
|
||||||
|
ScriptRenameDialogParams,
|
||||||
|
} from "./show-dialog-automation-rename";
|
||||||
|
|
||||||
@customElement("ha-dialog-automation-rename")
|
@customElement("ha-dialog-automation-rename")
|
||||||
class DialogAutomationRename extends LitElement implements HassDialog {
|
class DialogAutomationRename extends LitElement implements HassDialog {
|
||||||
@ -19,15 +25,20 @@ class DialogAutomationRename extends LitElement implements HassDialog {
|
|||||||
|
|
||||||
@state() private _error?: string;
|
@state() private _error?: string;
|
||||||
|
|
||||||
private _params!: AutomationRenameDialog;
|
private _params!: AutomationRenameDialogParams | ScriptRenameDialogParams;
|
||||||
|
|
||||||
private _newName?: string;
|
private _newName?: string;
|
||||||
|
|
||||||
|
private _newIcon?: string;
|
||||||
|
|
||||||
private _newDescription?: string;
|
private _newDescription?: string;
|
||||||
|
|
||||||
public showDialog(params: AutomationRenameDialog): void {
|
public showDialog(
|
||||||
|
params: AutomationRenameDialogParams | ScriptRenameDialogParams
|
||||||
|
): void {
|
||||||
this._opened = true;
|
this._opened = true;
|
||||||
this._params = params;
|
this._params = params;
|
||||||
|
this._newIcon = "icon" in params.config ? params.config.icon : undefined;
|
||||||
this._newName =
|
this._newName =
|
||||||
params.config.alias ||
|
params.config.alias ||
|
||||||
this.hass.localize("ui.panel.config.automation.editor.default_name");
|
this.hass.localize("ui.panel.config.automation.editor.default_name");
|
||||||
@ -82,6 +93,25 @@ class DialogAutomationRename extends LitElement implements HassDialog {
|
|||||||
@input=${this._valueChanged}
|
@input=${this._valueChanged}
|
||||||
></ha-textfield>
|
></ha-textfield>
|
||||||
|
|
||||||
|
${this._params.domain === "script"
|
||||||
|
? html`
|
||||||
|
<ha-icon-picker
|
||||||
|
.hass=${this.hass}
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.icon"
|
||||||
|
)}
|
||||||
|
.value=${this._newIcon}
|
||||||
|
@value-changed=${this._iconChanged}
|
||||||
|
>
|
||||||
|
<ha-domain-icon
|
||||||
|
slot="fallback"
|
||||||
|
domain=${this._params.domain}
|
||||||
|
.hass=${this.hass}
|
||||||
|
>
|
||||||
|
</ha-domain-icon>
|
||||||
|
</ha-icon-picker>
|
||||||
|
`
|
||||||
|
: nothing}
|
||||||
<ha-textarea
|
<ha-textarea
|
||||||
.label=${this.hass.localize(
|
.label=${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.description.label"
|
"ui.panel.config.automation.editor.description.label"
|
||||||
@ -109,6 +139,11 @@ class DialogAutomationRename extends LitElement implements HassDialog {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _iconChanged(ev: CustomEvent) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
this._newIcon = ev.detail.value || undefined;
|
||||||
|
}
|
||||||
|
|
||||||
private _valueChanged(ev: CustomEvent) {
|
private _valueChanged(ev: CustomEvent) {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
const target = ev.target as any;
|
const target = ev.target as any;
|
||||||
@ -124,11 +159,21 @@ class DialogAutomationRename extends LitElement implements HassDialog {
|
|||||||
this._error = "Name is required";
|
this._error = "Name is required";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._params.updateConfig({
|
if (this._params.domain === "script") {
|
||||||
...this._params.config,
|
this._params.updateConfig({
|
||||||
alias: this._newName,
|
...this._params.config,
|
||||||
description: this._newDescription,
|
alias: this._newName,
|
||||||
});
|
description: this._newDescription,
|
||||||
|
icon: this._newIcon,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this._params.updateConfig({
|
||||||
|
...this._params.config,
|
||||||
|
alias: this._newName,
|
||||||
|
description: this._newDescription,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,9 +183,13 @@ class DialogAutomationRename extends LitElement implements HassDialog {
|
|||||||
haStyleDialog,
|
haStyleDialog,
|
||||||
css`
|
css`
|
||||||
ha-textfield,
|
ha-textfield,
|
||||||
ha-textarea {
|
ha-textarea,
|
||||||
|
ha-icon-picker {
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
ha-icon-picker {
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
ha-alert {
|
ha-alert {
|
||||||
display: block;
|
display: block;
|
||||||
margin-bottom: 16px;
|
margin-bottom: 16px;
|
||||||
|
@ -5,21 +5,23 @@ import type { ScriptConfig } from "../../../../data/script";
|
|||||||
export const loadAutomationRenameDialog = () =>
|
export const loadAutomationRenameDialog = () =>
|
||||||
import("./dialog-automation-rename");
|
import("./dialog-automation-rename");
|
||||||
|
|
||||||
export interface AutomationRenameDialog {
|
export interface AutomationRenameDialogParams {
|
||||||
config: AutomationConfig;
|
config: AutomationConfig;
|
||||||
|
domain: "automation";
|
||||||
updateConfig: (config: AutomationConfig) => void;
|
updateConfig: (config: AutomationConfig) => void;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ScriptRenameDialog {
|
export interface ScriptRenameDialogParams {
|
||||||
config: ScriptConfig;
|
config: ScriptConfig;
|
||||||
|
domain: "script";
|
||||||
updateConfig: (config: ScriptConfig) => void;
|
updateConfig: (config: ScriptConfig) => void;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const showAutomationRenameDialog = (
|
export const showAutomationRenameDialog = (
|
||||||
element: HTMLElement,
|
element: HTMLElement,
|
||||||
dialogParams: AutomationRenameDialog | ScriptRenameDialog
|
dialogParams: AutomationRenameDialogParams | ScriptRenameDialogParams
|
||||||
): void => {
|
): void => {
|
||||||
fireEvent(element, "show-dialog", {
|
fireEvent(element, "show-dialog", {
|
||||||
dialogTag: "ha-dialog-automation-rename",
|
dialogTag: "ha-dialog-automation-rename",
|
||||||
|
@ -32,10 +32,11 @@ import { computeRTL } from "../../../common/util/compute_rtl";
|
|||||||
import { afterNextRender } from "../../../common/util/render-status";
|
import { afterNextRender } from "../../../common/util/render-status";
|
||||||
import "../../../components/ha-button-menu";
|
import "../../../components/ha-button-menu";
|
||||||
import "../../../components/ha-fab";
|
import "../../../components/ha-fab";
|
||||||
|
import "../../../components/ha-icon";
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
|
import "../../../components/ha-list-item";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import "../../../components/ha-yaml-editor";
|
import "../../../components/ha-yaml-editor";
|
||||||
import "../../../components/ha-list-item";
|
|
||||||
import {
|
import {
|
||||||
AutomationConfig,
|
AutomationConfig,
|
||||||
AutomationEntity,
|
AutomationEntity,
|
||||||
@ -688,6 +689,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
showAutomationRenameDialog(this, {
|
showAutomationRenameDialog(this, {
|
||||||
config: this._config!,
|
config: this._config!,
|
||||||
|
domain: "automation",
|
||||||
updateConfig: (config) => {
|
updateConfig: (config) => {
|
||||||
this._config = config;
|
this._config = config;
|
||||||
this._dirty = true;
|
this._dirty = true;
|
||||||
|
@ -33,9 +33,9 @@ import "../../../components/ha-button-menu";
|
|||||||
import "../../../components/ha-fab";
|
import "../../../components/ha-fab";
|
||||||
|
|
||||||
import "../../../components/ha-icon-button";
|
import "../../../components/ha-icon-button";
|
||||||
|
import "../../../components/ha-list-item";
|
||||||
import "../../../components/ha-svg-icon";
|
import "../../../components/ha-svg-icon";
|
||||||
import "../../../components/ha-yaml-editor";
|
import "../../../components/ha-yaml-editor";
|
||||||
import "../../../components/ha-list-item";
|
|
||||||
import { validateConfig } from "../../../data/config";
|
import { validateConfig } from "../../../data/config";
|
||||||
import { UNAVAILABLE } from "../../../data/entity";
|
import { UNAVAILABLE } from "../../../data/entity";
|
||||||
import { EntityRegistryEntry } from "../../../data/entity_registry";
|
import { EntityRegistryEntry } from "../../../data/entity_registry";
|
||||||
@ -50,6 +50,7 @@ import {
|
|||||||
triggerScript,
|
triggerScript,
|
||||||
} from "../../../data/script";
|
} from "../../../data/script";
|
||||||
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
|
||||||
|
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
||||||
import "../../../layouts/hass-subpage";
|
import "../../../layouts/hass-subpage";
|
||||||
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
import { KeyboardShortcutMixin } from "../../../mixins/keyboard-shortcut-mixin";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
@ -60,7 +61,6 @@ import { showAutomationRenameDialog } from "../automation/automation-rename-dial
|
|||||||
import "./blueprint-script-editor";
|
import "./blueprint-script-editor";
|
||||||
import "./manual-script-editor";
|
import "./manual-script-editor";
|
||||||
import type { HaManualScriptEditor } from "./manual-script-editor";
|
import type { HaManualScriptEditor } from "./manual-script-editor";
|
||||||
import { showMoreInfoDialog } from "../../../dialogs/more-info/show-ha-more-info-dialog";
|
|
||||||
|
|
||||||
export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@ -654,6 +654,7 @@ export class HaScriptEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
showAutomationRenameDialog(this, {
|
showAutomationRenameDialog(this, {
|
||||||
config: this._config!,
|
config: this._config!,
|
||||||
|
domain: "script",
|
||||||
updateConfig: (config) => {
|
updateConfig: (config) => {
|
||||||
this._config = config;
|
this._config = config;
|
||||||
this._dirty = true;
|
this._dirty = true;
|
||||||
|
@ -2768,6 +2768,7 @@
|
|||||||
"placeholder": "Optional description",
|
"placeholder": "Optional description",
|
||||||
"add": "Add description"
|
"add": "Add description"
|
||||||
},
|
},
|
||||||
|
"icon": "Icon",
|
||||||
"blueprint": {
|
"blueprint": {
|
||||||
"header": "Blueprint",
|
"header": "Blueprint",
|
||||||
"blueprint_to_use": "Blueprint to use",
|
"blueprint_to_use": "Blueprint to use",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user