Add error handling for application credentials removal (#12686)

This commit is contained in:
Allen Porter 2022-05-19 07:51:33 -07:00 committed by GitHub
parent f6411dce66
commit 788f76ab9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 7 deletions

View File

@ -19,7 +19,10 @@ import {
fetchApplicationCredentials,
} from "../../../data/application_credential";
import { domainToName } from "../../../data/integration";
import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box";
import {
showAlertDialog,
showConfirmationDialog,
} from "../../../dialogs/generic/show-dialog-box";
import "../../../layouts/hass-tabs-subpage-data-table";
import type { HaTabsSubpageDataTable } from "../../../layouts/hass-tabs-subpage-data-table";
import { HomeAssistant, Route } from "../../../types";
@ -171,11 +174,24 @@ export class HaConfigApplicationCredentials extends LitElement {
confirmText: this.hass.localize("ui.common.remove"),
dismissText: this.hass.localize("ui.common.cancel"),
confirm: async () => {
await Promise.all(
this._selected.map(async (applicationCredential) => {
await deleteApplicationCredential(this.hass, applicationCredential);
})
);
try {
await Promise.all(
this._selected.map(async (applicationCredential) => {
await deleteApplicationCredential(
this.hass,
applicationCredential
);
})
);
} catch (err: any) {
showAlertDialog(this, {
title: this.hass.localize(
"ui.panel.config.application_credentials.picker.remove_selected.error_title"
),
text: err.message,
});
return;
}
this._dataTable.clearSelection();
this._fetchApplicationCredentials();
},

View File

@ -2895,7 +2895,8 @@
"remove_selected": {
"button": "Remove selected",
"confirm_title": "Do you want to remove {number} {number, plural,\n one {credential}\n other {credentialss}\n}?",
"confirm_text": "Application Credentials in use by an integration may not be removed."
"confirm_text": "Application Credentials in use by an integration may not be removed.",
"error_title": "Removing Application Credential failed"
},
"selected": "{number} selected"
}