Fix navigation after deleting a view and allow deleting view with cards (#5085)

* Fix navigation after deleting a view

* Allow deleting views with cards
This commit is contained in:
Bram Kragten 2020-03-06 13:14:43 +01:00 committed by GitHub
parent 503dec7345
commit 9e07cf67a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions

View File

@ -207,7 +207,7 @@ export class HuiEditView extends LitElement {
deleteView(this.lovelace!.config, this.viewIndex!)
);
this._closeDialog();
navigate(this, `/lovelace/0`);
navigate(this, `/${window.location.pathname.split("/")[1]}`);
} catch (err) {
showAlertDialog(this, {
text: `Deleting failed: ${err.message}`,
@ -216,15 +216,21 @@ export class HuiEditView extends LitElement {
}
private _deleteConfirm(): void {
if (this._cards && this._cards.length > 0) {
showAlertDialog(this, {
text: this.hass!.localize("ui.panel.lovelace.views.existing_cards"),
});
return;
}
showConfirmationDialog(this, {
text: this.hass!.localize("ui.panel.lovelace.views.confirm_delete"),
title: this.hass!.localize(
`ui.panel.lovelace.views.confirm_delete${
this._cards?.length ? `_existing_cards` : ""
}`
),
text: this.hass!.localize(
`ui.panel.lovelace.views.confirm_delete${
this._cards?.length ? `_existing_cards` : ""
}_text`,
"name",
this._config?.title || "Unnamed view",
"number",
this._cards?.length || 0
),
confirm: () => this._delete(),
});
}

View File

@ -1875,8 +1875,10 @@
"saving_failed": "Saving Lovelace UI configuration failed."
},
"views": {
"confirm_delete": "Are you sure you want to delete this view?",
"existing_cards": "You can't delete a view that has cards in it. Remove the cards first."
"confirm_delete": "Delete view?",
"confirm_delete_text": "Are you sure you want to delete your '{name}' view?",
"confirm_delete_existing_cards": "Deleting this view will also remove the cards",
"confirm_delete_existing_cards_text": "Are you sure you want to delete your '{name}' view? The view contains {number} cards that will be deleted. This action cannot be undone."
},
"menu": {
"configure_ui": "Configure UI",