Adds confirmation dialog to updates (#6709)

This commit is contained in:
Joakim Sørensen 2020-08-26 18:13:22 +02:00 committed by GitHub
parent 5113222050
commit c1a4b27bc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,11 @@ import {
import { haStyle } from "../../../src/resources/styles"; import { haStyle } from "../../../src/resources/styles";
import { HomeAssistant } from "../../../src/types"; import { HomeAssistant } from "../../../src/types";
import { hassioStyle } from "../resources/hassio-style"; import { hassioStyle } from "../resources/hassio-style";
import {
showConfirmationDialog,
showAlertDialog,
} from "../../../src/dialogs/generic/show-dialog-box";
import { HassioResponse } from "../../../src/data/hassio/common";
@customElement("hassio-update") @customElement("hassio-update")
export class HassioUpdate extends LitElement { export class HassioUpdate extends LitElement {
@ -126,30 +131,38 @@ export class HassioUpdate extends LitElement {
<a href="${releaseNotesUrl}" target="_blank" rel="noreferrer"> <a href="${releaseNotesUrl}" target="_blank" rel="noreferrer">
<mwc-button>Release notes</mwc-button> <mwc-button>Release notes</mwc-button>
</a> </a>
<ha-call-api-button <mwc-button
.hass=${this.hass} label="Update"
.path=${apiPath} .apiPath=${apiPath}
@hass-api-called=${this._apiCalled} .name=${name}
> .version=${lastVersion}
Update @click=${this._confirmUpdate}
</ha-call-api-button> ></mwc-button>
</div> </div>
</ha-card> </ha-card>
`; `;
} }
private _apiCalled(ev): void { private async _confirmUpdate(ev): Promise<void> {
if (ev.detail.success) { const item = ev.target;
this._error = ""; const confirmed = await showConfirmationDialog(this, {
title: `Update ${item.name}`,
text: `Are you sure you want to upgrade ${item.name} to version ${item.version}?`,
confirmText: "update",
dismissText: "cancel",
});
if (!confirmed) {
return; return;
} }
try {
const response = ev.detail.response; await this.hass.callApi<HassioResponse<void>>("POST", item.apiPath);
} catch (err) {
if (typeof response.body === "object") { showAlertDialog(this, {
this._error = response.body.message || "Unknown error"; title: "Update failed",
} else { text:
this._error = response.body; typeof err === "object" ? err.body?.message || "Unkown error" : err,
});
} }
} }