mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 23:06:40 +00:00
Confirm when resetting hassio optoins (#4718)
This commit is contained in:
parent
24c591fbf3
commit
82ff444cec
@ -25,6 +25,7 @@ import { fireEvent } from "../../../src/common/dom/fire_event";
|
|||||||
import "../../../src/components/ha-yaml-editor";
|
import "../../../src/components/ha-yaml-editor";
|
||||||
// tslint:disable-next-line: no-duplicate-imports
|
// tslint:disable-next-line: no-duplicate-imports
|
||||||
import { HaYamlEditor } from "../../../src/components/ha-yaml-editor";
|
import { HaYamlEditor } from "../../../src/components/ha-yaml-editor";
|
||||||
|
import { showConfirmationDialog } from "../../../src/dialogs/generic/show-dialog-box";
|
||||||
|
|
||||||
@customElement("hassio-addon-config")
|
@customElement("hassio-addon-config")
|
||||||
class HassioAddonConfig extends LitElement {
|
class HassioAddonConfig extends LitElement {
|
||||||
@ -115,6 +116,16 @@ class HassioAddonConfig extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _resetTapped(): Promise<void> {
|
private async _resetTapped(): Promise<void> {
|
||||||
|
const confirmed = await showConfirmationDialog(this, {
|
||||||
|
title: this.addon.name,
|
||||||
|
text: "Are you sure you want to reset all your options?",
|
||||||
|
confirmText: "reset options",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!confirmed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
const data: HassioAddonSetOptionParams = {
|
const data: HassioAddonSetOptionParams = {
|
||||||
options: null,
|
options: null,
|
||||||
|
@ -1,26 +1,32 @@
|
|||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
|
||||||
export interface AlertDialogParams {
|
interface BaseDialogParams {
|
||||||
confirmText?: string;
|
confirmText?: string;
|
||||||
text?: string;
|
text?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
confirm?: (out?: string) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ConfirmationDialogParams extends AlertDialogParams {
|
export interface AlertDialogParams extends BaseDialogParams {
|
||||||
|
confirm?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ConfirmationDialogParams extends BaseDialogParams {
|
||||||
dismissText?: string;
|
dismissText?: string;
|
||||||
|
confirm?: () => void;
|
||||||
cancel?: () => void;
|
cancel?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PromptDialogParams extends AlertDialogParams {
|
export interface PromptDialogParams extends BaseDialogParams {
|
||||||
inputLabel?: string;
|
inputLabel?: string;
|
||||||
inputType?: string;
|
inputType?: string;
|
||||||
defaultValue?: string;
|
defaultValue?: string;
|
||||||
|
confirm?: (out?: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DialogParams
|
export interface DialogParams
|
||||||
extends ConfirmationDialogParams,
|
extends ConfirmationDialogParams,
|
||||||
PromptDialogParams {
|
PromptDialogParams {
|
||||||
|
confirm?: (out?: string) => void;
|
||||||
confirmation?: boolean;
|
confirmation?: boolean;
|
||||||
prompt?: boolean;
|
prompt?: boolean;
|
||||||
}
|
}
|
||||||
@ -28,35 +34,57 @@ export interface DialogParams
|
|||||||
export const loadGenericDialog = () =>
|
export const loadGenericDialog = () =>
|
||||||
import(/* webpackChunkName: "confirmation" */ "./dialog-box");
|
import(/* webpackChunkName: "confirmation" */ "./dialog-box");
|
||||||
|
|
||||||
|
const showDialogHelper = (
|
||||||
|
element: HTMLElement,
|
||||||
|
dialogParams: DialogParams,
|
||||||
|
extra?: {
|
||||||
|
confirmation?: DialogParams["confirmation"];
|
||||||
|
prompt?: DialogParams["prompt"];
|
||||||
|
}
|
||||||
|
) =>
|
||||||
|
new Promise((resolve) => {
|
||||||
|
const origCancel = dialogParams.cancel;
|
||||||
|
const origConfirm = dialogParams.confirm;
|
||||||
|
|
||||||
|
fireEvent(element, "show-dialog", {
|
||||||
|
dialogTag: "dialog-box",
|
||||||
|
dialogImport: loadGenericDialog,
|
||||||
|
dialogParams: {
|
||||||
|
...dialogParams,
|
||||||
|
...extra,
|
||||||
|
cancel: () => {
|
||||||
|
resolve(extra?.prompt ? null : false);
|
||||||
|
if (origCancel) {
|
||||||
|
origCancel();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirm: (out) => {
|
||||||
|
resolve(extra?.prompt ? out : true);
|
||||||
|
if (origConfirm) {
|
||||||
|
origConfirm(out);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
export const showAlertDialog = (
|
export const showAlertDialog = (
|
||||||
element: HTMLElement,
|
element: HTMLElement,
|
||||||
dialogParams: AlertDialogParams
|
dialogParams: AlertDialogParams
|
||||||
): void => {
|
) => showDialogHelper(element, dialogParams);
|
||||||
fireEvent(element, "show-dialog", {
|
|
||||||
dialogTag: "dialog-box",
|
|
||||||
dialogImport: loadGenericDialog,
|
|
||||||
dialogParams,
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const showConfirmationDialog = (
|
export const showConfirmationDialog = (
|
||||||
element: HTMLElement,
|
element: HTMLElement,
|
||||||
dialogParams: ConfirmationDialogParams
|
dialogParams: ConfirmationDialogParams
|
||||||
): void => {
|
) =>
|
||||||
fireEvent(element, "show-dialog", {
|
showDialogHelper(element, dialogParams, { confirmation: true }) as Promise<
|
||||||
dialogTag: "dialog-box",
|
boolean
|
||||||
dialogImport: loadGenericDialog,
|
>;
|
||||||
dialogParams: { ...dialogParams, confirmation: true },
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const showPromptDialog = (
|
export const showPromptDialog = (
|
||||||
element: HTMLElement,
|
element: HTMLElement,
|
||||||
dialogParams: PromptDialogParams
|
dialogParams: PromptDialogParams
|
||||||
): void => {
|
) =>
|
||||||
fireEvent(element, "show-dialog", {
|
showDialogHelper(element, dialogParams, { prompt: true }) as Promise<
|
||||||
dialogTag: "dialog-box",
|
null | string
|
||||||
dialogImport: loadGenericDialog,
|
>;
|
||||||
dialogParams: { ...dialogParams, prompt: true },
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user