Skip to content

Commit 9e07cf6

Browse files
authored
Fix navigation after deleting a view and allow deleting view with cards (#5085)
* Fix navigation after deleting a view * Allow deleting views with cards
1 parent 503dec7 commit 9e07cf6

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/panels/lovelace/editor/view-editor/hui-edit-view.ts

+15-9
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export class HuiEditView extends LitElement {
207207
deleteView(this.lovelace!.config, this.viewIndex!)
208208
);
209209
this._closeDialog();
210-
navigate(this, `/lovelace/0`);
210+
navigate(this, `/${window.location.pathname.split("/")[1]}`);
211211
} catch (err) {
212212
showAlertDialog(this, {
213213
text: `Deleting failed: ${err.message}`,
@@ -216,15 +216,21 @@ export class HuiEditView extends LitElement {
216216
}
217217

218218
private _deleteConfirm(): void {
219-
if (this._cards && this._cards.length > 0) {
220-
showAlertDialog(this, {
221-
text: this.hass!.localize("ui.panel.lovelace.views.existing_cards"),
222-
});
223-
return;
224-
}
225-
226219
showConfirmationDialog(this, {
227-
text: this.hass!.localize("ui.panel.lovelace.views.confirm_delete"),
220+
title: this.hass!.localize(
221+
`ui.panel.lovelace.views.confirm_delete${
222+
this._cards?.length ? `_existing_cards` : ""
223+
}`
224+
),
225+
text: this.hass!.localize(
226+
`ui.panel.lovelace.views.confirm_delete${
227+
this._cards?.length ? `_existing_cards` : ""
228+
}_text`,
229+
"name",
230+
this._config?.title || "Unnamed view",
231+
"number",
232+
this._cards?.length || 0
233+
),
228234
confirm: () => this._delete(),
229235
});
230236
}

src/translations/en.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1875,8 +1875,10 @@
18751875
"saving_failed": "Saving Lovelace UI configuration failed."
18761876
},
18771877
"views": {
1878-
"confirm_delete": "Are you sure you want to delete this view?",
1879-
"existing_cards": "You can't delete a view that has cards in it. Remove the cards first."
1878+
"confirm_delete": "Delete view?",
1879+
"confirm_delete_text": "Are you sure you want to delete your '{name}' view?",
1880+
"confirm_delete_existing_cards": "Deleting this view will also remove the cards",
1881+
"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."
18801882
},
18811883
"menu": {
18821884
"configure_ui": "Configure UI",

0 commit comments

Comments
 (0)