Use proper styled confirmation dialog for handled actions (#8077)

This commit is contained in:
Philip Allgaier 2021-01-05 14:04:45 +01:00 committed by GitHub
parent cb2c6d8560
commit f2e9b3577d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import { forwardHaptic } from "../../../data/haptics";
import { ActionConfig } from "../../../data/lovelace";
import { HomeAssistant } from "../../../types";
import { toggleEntity } from "./entity/toggle-entity";
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
declare global {
interface HASSDomEvents {
@ -11,7 +12,7 @@ declare global {
}
}
export const handleAction = (
export const handleAction = async (
node: HTMLElement,
hass: HomeAssistant,
config: {
@ -22,7 +23,7 @@ export const handleAction = (
double_tap_action?: ActionConfig;
},
action: string
): void => {
): Promise<void> => {
let actionConfig: ActionConfig | undefined;
if (action === "double_tap" && config.double_tap_action) {
@ -49,10 +50,15 @@ export const handleAction = (
forwardHaptic("warning");
if (
!confirm(
actionConfig.confirmation.text ||
`Are you sure you want to ${actionConfig.action}?`
)
!(await showConfirmationDialog(node, {
text:
actionConfig.confirmation.text ||
hass.localize(
"ui.panel.lovelace.cards.action_confirmation",
"action",
actionConfig.action
),
}))
) {
return;
}

View File

@ -48,9 +48,9 @@ export class HuiServiceButtonElement extends LitElement
return html`
<ha-call-service-button
.hass=${this.hass}
.domain="${this._domain}"
.service="${this._service}"
.serviceData="${this._config.service_data}"
.domain=${this._domain}
.service=${this._service}
.serviceData=${this._config.service_data}
>${this._config.title}</ha-call-service-button
>
`;

View File

@ -2390,6 +2390,7 @@
"lovelace": {
"cards": {
"confirm_delete": "Are you sure you want to delete this card?",
"action_confirmation": "Are you sure you want to exectue action \"{action}\"?",
"empty_state": {
"title": "Welcome Home",
"no_devices": "This page allows you to control your devices, however it looks like you have no devices set up yet. Head to the integrations page to get started.",