mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Some fixes for automation picker and editor (#13634)
This commit is contained in:
parent
d1964e92ea
commit
b553a3fd92
@ -17,7 +17,7 @@ export interface IconOverflowMenuItem {
|
|||||||
narrowOnly?: boolean;
|
narrowOnly?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
tooltip?: string;
|
tooltip?: string;
|
||||||
onClick: CallableFunction;
|
action: () => any;
|
||||||
warning?: boolean;
|
warning?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
(item) => html`
|
(item) => html`
|
||||||
<mwc-list-item
|
<mwc-list-item
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
.disabled=${item.disabled}
|
?disabled=${item.disabled}
|
||||||
@click=${item.action}
|
@click=${item.action}
|
||||||
class=${classMap({ warning: Boolean(item.warning) })}
|
class=${classMap({ warning: Boolean(item.warning) })}
|
||||||
>
|
>
|
||||||
@ -80,7 +80,7 @@ export class HaIconOverflowMenu extends LitElement {
|
|||||||
@click=${item.action}
|
@click=${item.action}
|
||||||
.label=${item.label}
|
.label=${item.label}
|
||||||
.path=${item.path}
|
.path=${item.path}
|
||||||
.disabled=${item.disabled}
|
?disabled=${item.disabled}
|
||||||
></ha-icon-button>
|
></ha-icon-button>
|
||||||
</div> `
|
</div> `
|
||||||
)}
|
)}
|
||||||
|
@ -314,11 +314,25 @@ let inititialAutomationEditorData: Partial<AutomationConfig> | undefined;
|
|||||||
export const getAutomationConfig = (hass: HomeAssistant, id: string) =>
|
export const getAutomationConfig = (hass: HomeAssistant, id: string) =>
|
||||||
hass.callApi<AutomationConfig>("GET", `config/automation/config/${id}`);
|
hass.callApi<AutomationConfig>("GET", `config/automation/config/${id}`);
|
||||||
|
|
||||||
|
export const saveAutomationConfig = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
id: string,
|
||||||
|
config: AutomationConfig
|
||||||
|
) => hass.callApi<void>("POST", `config/automation/config/${id}`, config);
|
||||||
|
|
||||||
export const showAutomationEditor = (data?: Partial<AutomationConfig>) => {
|
export const showAutomationEditor = (data?: Partial<AutomationConfig>) => {
|
||||||
inititialAutomationEditorData = data;
|
inititialAutomationEditorData = data;
|
||||||
navigate("/config/automation/edit/new");
|
navigate("/config/automation/edit/new");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const duplicateAutomation = (config: AutomationConfig) => {
|
||||||
|
showAutomationEditor({
|
||||||
|
...config,
|
||||||
|
id: undefined,
|
||||||
|
alias: undefined,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const getAutomationEditorInitData = () => {
|
export const getAutomationEditorInitData = () => {
|
||||||
const data = inititialAutomationEditorData;
|
const data = inititialAutomationEditorData;
|
||||||
inititialAutomationEditorData = undefined;
|
inititialAutomationEditorData = undefined;
|
||||||
|
@ -45,6 +45,7 @@ import {
|
|||||||
deleteAutomation,
|
deleteAutomation,
|
||||||
getAutomationConfig,
|
getAutomationConfig,
|
||||||
getAutomationEditorInitData,
|
getAutomationEditorInitData,
|
||||||
|
saveAutomationConfig,
|
||||||
showAutomationEditor,
|
showAutomationEditor,
|
||||||
triggerAutomationActions,
|
triggerAutomationActions,
|
||||||
} from "../../../data/automation";
|
} from "../../../data/automation";
|
||||||
@ -203,7 +204,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
<mwc-list-item
|
<mwc-list-item
|
||||||
graphic="icon"
|
graphic="icon"
|
||||||
@click=${this._promptAutomationMode}
|
@click=${this._promptAutomationMode}
|
||||||
.disabled=${!this.automationId || this._mode === "yaml"}
|
.disabled=${this._mode === "yaml"}
|
||||||
>
|
>
|
||||||
${this.hass.localize(
|
${this.hass.localize(
|
||||||
"ui.panel.config.automation.editor.change_mode"
|
"ui.panel.config.automation.editor.change_mode"
|
||||||
@ -452,7 +453,7 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
this._dirty = false;
|
this._dirty = false;
|
||||||
this._config = config;
|
this._config = config;
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
showAlertDialog(this, {
|
await showAlertDialog(this, {
|
||||||
text:
|
text:
|
||||||
err.status_code === 404
|
err.status_code === 404
|
||||||
? this.hass.localize(
|
? this.hass.localize(
|
||||||
@ -463,7 +464,8 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
"err_no",
|
"err_no",
|
||||||
err.status_code
|
err.status_code
|
||||||
),
|
),
|
||||||
}).then(() => history.back());
|
});
|
||||||
|
history.back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -582,8 +584,10 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _delete() {
|
private async _delete() {
|
||||||
await deleteAutomation(this.hass, this.automationId as string);
|
if (this.automationId) {
|
||||||
history.back();
|
await deleteAutomation(this.hass, this.automationId);
|
||||||
|
history.back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _switchUiMode() {
|
private _switchUiMode() {
|
||||||
@ -636,26 +640,21 @@ export class HaAutomationEditor extends KeyboardShortcutMixin(LitElement) {
|
|||||||
await this._promptAutomationAlias();
|
await this._promptAutomationAlias();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.hass!.callApi(
|
try {
|
||||||
"POST",
|
await saveAutomationConfig(this.hass, id, this._config!);
|
||||||
"config/automation/config/" + id,
|
} catch (errors: any) {
|
||||||
this._config
|
this._errors = errors.body.message || errors.error || errors.body;
|
||||||
).then(
|
showToast(this, {
|
||||||
() => {
|
message: errors.body.message || errors.error || errors.body,
|
||||||
this._dirty = false;
|
});
|
||||||
|
throw errors;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.automationId) {
|
this._dirty = false;
|
||||||
navigate(`/config/automation/edit/${id}`, { replace: true });
|
|
||||||
}
|
if (!this.automationId) {
|
||||||
},
|
navigate(`/config/automation/edit/${id}`, { replace: true });
|
||||||
(errors) => {
|
}
|
||||||
this._errors = errors.body.message || errors.error || errors.body;
|
|
||||||
showToast(this, {
|
|
||||||
message: errors.body.message || errors.error || errors.body,
|
|
||||||
});
|
|
||||||
throw errors;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _subscribeAutomationConfig(ev) {
|
private _subscribeAutomationConfig(ev) {
|
||||||
|
@ -33,8 +33,8 @@ import "../../../components/ha-svg-icon";
|
|||||||
import {
|
import {
|
||||||
AutomationEntity,
|
AutomationEntity,
|
||||||
deleteAutomation,
|
deleteAutomation,
|
||||||
|
duplicateAutomation,
|
||||||
getAutomationConfig,
|
getAutomationConfig,
|
||||||
showAutomationEditor,
|
|
||||||
triggerAutomationActions,
|
triggerAutomationActions,
|
||||||
} from "../../../data/automation";
|
} from "../../../data/automation";
|
||||||
import {
|
import {
|
||||||
@ -348,19 +348,45 @@ class HaAutomationPicker extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _delete(automation) {
|
private async _delete(automation) {
|
||||||
await deleteAutomation(this.hass, automation.attributes.id);
|
try {
|
||||||
|
await deleteAutomation(this.hass, automation.attributes.id);
|
||||||
|
} catch (err: any) {
|
||||||
|
await showAlertDialog(this, {
|
||||||
|
text:
|
||||||
|
err.status_code === 400
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.load_error_not_deletable"
|
||||||
|
)
|
||||||
|
: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.load_error_unknown",
|
||||||
|
"err_no",
|
||||||
|
err.status_code
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async duplicate(automation) {
|
private async duplicate(automation) {
|
||||||
const config = await getAutomationConfig(
|
try {
|
||||||
this.hass,
|
const config = await getAutomationConfig(
|
||||||
automation.attributes.id
|
this.hass,
|
||||||
);
|
automation.attributes.id
|
||||||
showAutomationEditor({
|
);
|
||||||
...config,
|
duplicateAutomation(config);
|
||||||
id: undefined,
|
} catch (err: any) {
|
||||||
alias: undefined,
|
await showAlertDialog(this, {
|
||||||
});
|
text:
|
||||||
|
err.status_code === 404
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.load_error_not_duplicable"
|
||||||
|
)
|
||||||
|
: this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.load_error_unknown",
|
||||||
|
"err_no",
|
||||||
|
err.status_code
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _showHelp() {
|
private _showHelp() {
|
||||||
@ -389,7 +415,7 @@ class HaAutomationPicker extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (automation?.attributes.id) {
|
if (automation?.attributes.id) {
|
||||||
navigate(`/config/automation/edit/${automation?.attributes.id}`);
|
navigate(`/config/automation/edit/${automation.attributes.id}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1828,6 +1828,8 @@
|
|||||||
"default_name": "New Automation",
|
"default_name": "New Automation",
|
||||||
"missing_name": "Cannot save automation without a name",
|
"missing_name": "Cannot save automation without a name",
|
||||||
"load_error_not_editable": "Only automations in automations.yaml are editable.",
|
"load_error_not_editable": "Only automations in automations.yaml are editable.",
|
||||||
|
"load_error_not_duplicable": "Only automations in automations.yaml can be duplicated.",
|
||||||
|
"load_error_not_deletable": "Only automations in automations.yaml can be deleted.",
|
||||||
"load_error_unknown": "Error loading automation ({err_no}).",
|
"load_error_unknown": "Error loading automation ({err_no}).",
|
||||||
"save": "Save",
|
"save": "Save",
|
||||||
"unsaved_confirm": "You have unsaved changes. Are you sure you want to leave?",
|
"unsaved_confirm": "You have unsaved changes. Are you sure you want to leave?",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user