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

View File

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

View File

@ -2390,6 +2390,7 @@
"lovelace": { "lovelace": {
"cards": { "cards": {
"confirm_delete": "Are you sure you want to delete this card?", "confirm_delete": "Are you sure you want to delete this card?",
"action_confirmation": "Are you sure you want to exectue action \"{action}\"?",
"empty_state": { "empty_state": {
"title": "Welcome Home", "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.", "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.",