🔧 Standardize Generic Dialogs (#4726)

* 🔧 Use confirmation dialog in area deletion

* Swap automation confirmation dialogs

* Add to disable webhook

* Add to person deletion

* Add to zone deletion

* Add dialogs in raw editor

* Add/fix try catch

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
Aidan Timson 2020-03-09 12:16:02 +00:00 committed by GitHub
parent 5651a61604
commit 52160a367a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 91 additions and 68 deletions

View File

@ -31,6 +31,7 @@ import { classMap } from "lit-html/directives/class-map";
import { computeRTL } from "../../../common/util/compute_rtl"; import { computeRTL } from "../../../common/util/compute_rtl";
import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { configSections } from "../ha-panel-config"; import { configSections } from "../ha-panel-config";
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
@customElement("ha-config-areas") @customElement("ha-config-areas")
export class HaConfigAreas extends LitElement { export class HaConfigAreas extends LitElement {
@ -150,9 +151,16 @@ export class HaConfigAreas extends LitElement {
updateAreaRegistryEntry(this.hass!, entry!.area_id, values), updateAreaRegistryEntry(this.hass!, entry!.area_id, values),
removeEntry: async () => { removeEntry: async () => {
if ( if (
!confirm(`Are you sure you want to delete this area? !(await showConfirmationDialog(this, {
title: this.hass.localize(
All devices in this area will become unassigned.`) "ui.panel.config.areas.delete.confirmation_title"
),
text: this.hass.localize(
"ui.panel.config.areas.delete.confirmation_text"
),
dismissText: this.hass.localize("ui.common.no"),
confirmText: this.hass.localize("ui.common.yes"),
}))
) { ) {
return false; return false;
} }

View File

@ -16,6 +16,7 @@ import { dynamicElement } from "../../../../common/dom/dynamic-element-directive
import { fireEvent } from "../../../../common/dom/fire_event"; import { fireEvent } from "../../../../common/dom/fire_event";
import "../../../../components/ha-card"; import "../../../../components/ha-card";
import { HomeAssistant } from "../../../../types"; import { HomeAssistant } from "../../../../types";
import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box";
import { Action } from "../../../../data/script"; import { Action } from "../../../../data/script";
@ -206,15 +207,16 @@ export default class HaAutomationActionRow extends LitElement {
} }
private _onDelete() { private _onDelete() {
if ( showConfirmationDialog(this, {
confirm( text: this.hass.localize(
this.hass.localize( "ui.panel.config.automation.editor.actions.delete_confirm"
"ui.panel.config.automation.editor.actions.delete_confirm" ),
) dismissText: this.hass.localize("ui.common.no"),
) confirmText: this.hass.localize("ui.common.yes"),
) { confirm: () => {
fireEvent(this, "value-changed", { value: null }); fireEvent(this, "value-changed", { value: null });
} },
});
} }
private _typeChanged(ev: CustomEvent) { private _typeChanged(ev: CustomEvent) {

View File

@ -12,6 +12,7 @@ import {
import { fireEvent } from "../../../../common/dom/fire_event"; import { fireEvent } from "../../../../common/dom/fire_event";
import "../../../../components/ha-card"; import "../../../../components/ha-card";
import { HomeAssistant } from "../../../../types"; import { HomeAssistant } from "../../../../types";
import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box";
import "./ha-automation-condition-editor"; import "./ha-automation-condition-editor";
import { Condition } from "../../../../data/automation"; import { Condition } from "../../../../data/automation";
@ -104,15 +105,16 @@ export default class HaAutomationConditionRow extends LitElement {
} }
private _onDelete() { private _onDelete() {
if ( showConfirmationDialog(this, {
confirm( text: this.hass.localize(
this.hass.localize( "ui.panel.config.automation.editor.conditions.delete_confirm"
"ui.panel.config.automation.editor.conditions.delete_confirm" ),
) dismissText: this.hass.localize("ui.common.no"),
) confirmText: this.hass.localize("ui.common.yes"),
) { confirm: () => {
fireEvent(this, "value-changed", { value: null }); fireEvent(this, "value-changed", { value: null });
} },
});
} }
private _switchYamlMode() { private _switchYamlMode() {

View File

@ -16,6 +16,7 @@ import { dynamicElement } from "../../../../common/dom/dynamic-element-directive
import { fireEvent } from "../../../../common/dom/fire_event"; import { fireEvent } from "../../../../common/dom/fire_event";
import "../../../../components/ha-card"; import "../../../../components/ha-card";
import { HomeAssistant } from "../../../../types"; import { HomeAssistant } from "../../../../types";
import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box";
import "./types/ha-automation-trigger-device"; import "./types/ha-automation-trigger-device";
import "./types/ha-automation-trigger-event"; import "./types/ha-automation-trigger-event";
@ -180,15 +181,16 @@ export default class HaAutomationTriggerRow extends LitElement {
} }
private _onDelete() { private _onDelete() {
if ( showConfirmationDialog(this, {
confirm( text: this.hass.localize(
this.hass.localize( "ui.panel.config.automation.editor.triggers.delete_confirm"
"ui.panel.config.automation.editor.triggers.delete_confirm" ),
) dismissText: this.hass.localize("ui.common.no"),
) confirmText: this.hass.localize("ui.common.yes"),
) { confirm: () => {
fireEvent(this, "value-changed", { value: null }); fireEvent(this, "value-changed", { value: null });
} },
});
} }
private _typeChanged(ev: CustomEvent) { private _typeChanged(ev: CustomEvent) {

View File

@ -13,6 +13,7 @@ import { PaperInputElement } from "@polymer/paper-input/paper-input";
import { HomeAssistant } from "../../../../types"; import { HomeAssistant } from "../../../../types";
import { haStyle } from "../../../../resources/styles"; import { haStyle } from "../../../../resources/styles";
import { WebhookDialogParams } from "./show-dialog-manage-cloudhook"; import { WebhookDialogParams } from "./show-dialog-manage-cloudhook";
import { showConfirmationDialog } from "../../../../dialogs/generic/show-dialog-box";
const inputLabel = "Public URL Click to copy to clipboard"; const inputLabel = "Public URL Click to copy to clipboard";
@ -108,18 +109,17 @@ export class DialogManageCloudhook extends LitElement {
} }
private async _disableWebhook() { private async _disableWebhook() {
if ( showConfirmationDialog(this, {
!confirm( text: this.hass!.localize(
this.hass!.localize( "ui.panel.config.cloud.dialog_cloudhook.confirm_disable"
"ui.panel.config.cloud.dialog_cloudhook.confirm_disable" ),
) dismissText: this.hass!.localize("ui.common.no"),
) confirmText: this.hass!.localize("ui.common.yes"),
) { confirm: () => {
return; this._params!.disableHook();
} this._closeDialog();
},
this._params!.disableHook(); });
this._closeDialog();
} }
private _copyClipboard(ev: FocusEvent) { private _copyClipboard(ev: FocusEvent) {

View File

@ -29,6 +29,7 @@ import {
} from "./show-dialog-person-detail"; } from "./show-dialog-person-detail";
import { User, fetchUsers } from "../../../data/user"; import { User, fetchUsers } from "../../../data/user";
import { configSections } from "../ha-panel-config"; import { configSections } from "../ha-panel-config";
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
class HaConfigPerson extends LitElement { class HaConfigPerson extends LitElement {
@property() public hass?: HomeAssistant; @property() public hass?: HomeAssistant;
@ -189,11 +190,12 @@ class HaConfigPerson extends LitElement {
}, },
removeEntry: async () => { removeEntry: async () => {
if ( if (
!confirm(`${this.hass!.localize( !(await showConfirmationDialog(this, {
"ui.panel.config.person.confirm_delete" title: this.hass!.localize("ui.panel.config.person.confirm_delete"),
)} text: this.hass!.localize("ui.panel.config.person.confirm_delete2"),
dismissText: this.hass!.localize("ui.common.no"),
${this.hass!.localize("ui.panel.config.person.confirm_delete2")}`) confirmText: this.hass!.localize("ui.common.yes"),
}))
) { ) {
return false; return false;
} }

View File

@ -422,9 +422,12 @@ export class HaConfigZone extends SubscribeMixin(LitElement) {
private async _removeEntry(entry: Zone) { private async _removeEntry(entry: Zone) {
if ( if (
!confirm(`${this.hass!.localize("ui.panel.config.zone.confirm_delete")} !(await showConfirmationDialog(this, {
title: this.hass!.localize("ui.panel.config.zone.confirm_delete"),
${this.hass!.localize("ui.panel.config.zone.confirm_delete2")}`) text: this.hass!.localize("ui.panel.config.zone.confirm_delete2"),
dismissText: this.hass!.localize("ui.common.no"),
confirmText: this.hass!.localize("ui.common.yes"),
}))
) { ) {
return false; return false;
} }

View File

@ -168,19 +168,19 @@ class LovelaceFullConfigEditor extends LitElement {
private _closeEditor() { private _closeEditor() {
if (this._changed) { if (this._changed) {
if ( showConfirmationDialog(this, {
!confirm( text: this.hass.localize(
this.hass.localize( "ui.panel.lovelace.editor.raw_editor.confirm_unsaved_changes"
"ui.panel.lovelace.editor.raw_editor.confirm_unsaved_changes" ),
) dismissText: this.hass!.localize("ui.common.no"),
) confirmText: this.hass!.localize("ui.common.yes"),
) { confirm: () => {
return; window.onbeforeunload = null;
} if (this.closeEditor) {
} this.closeEditor();
window.onbeforeunload = null; }
if (this.closeEditor) { },
this.closeEditor(); });
} }
} }
@ -188,13 +188,13 @@ class LovelaceFullConfigEditor extends LitElement {
try { try {
await this.lovelace!.deleteConfig(); await this.lovelace!.deleteConfig();
} catch (err) { } catch (err) {
alert( showAlertDialog(this, {
this.hass.localize( text: this.hass.localize(
"ui.panel.lovelace.editor.raw_editor.error_remove", "ui.panel.lovelace.editor.raw_editor.error_remove",
"error", "error",
err err
) ),
); });
} }
window.onbeforeunload = null; window.onbeforeunload = null;
if (this.closeEditor) { if (this.closeEditor) {

View File

@ -796,6 +796,10 @@
"delete": "DELETE", "delete": "DELETE",
"update": "UPDATE", "update": "UPDATE",
"create": "CREATE" "create": "CREATE"
},
"delete": {
"confirmation_title": "Are you sure you want to delete this area?",
"confirmation_text": "All devices in this area will become unassigned."
} }
}, },
"helpers": { "helpers": {
@ -1015,7 +1019,7 @@
"add": "Add trigger", "add": "Add trigger",
"duplicate": "Duplicate", "duplicate": "Duplicate",
"delete": "[%key:ui::panel::mailbox::delete_button%]", "delete": "[%key:ui::panel::mailbox::delete_button%]",
"delete_confirm": "Sure you want to delete?", "delete_confirm": "Are you sure you want to delete this?",
"unsupported_platform": "Unsupported platform: {platform}", "unsupported_platform": "Unsupported platform: {platform}",
"type_select": "Trigger type", "type_select": "Trigger type",
"type": { "type": {