Revert "Allow to move card from other view to section view"

This reverts commit 203d900d16373dc219bcf88f8bb961c51f34bbf5.
This commit is contained in:
Paul Bottein 2024-10-16 16:20:41 +02:00
parent 203d900d16
commit e01e31341b
No known key found for this signature in database
2 changed files with 8 additions and 28 deletions

View File

@ -28,10 +28,7 @@ import "../../../components/ha-icon-button";
import "../../../components/ha-list-item"; import "../../../components/ha-list-item";
import { LovelaceCardConfig } from "../../../data/lovelace/config/card"; import { LovelaceCardConfig } from "../../../data/lovelace/config/card";
import { saveConfig } from "../../../data/lovelace/config/types"; import { saveConfig } from "../../../data/lovelace/config/types";
import { import { isStrategyView } from "../../../data/lovelace/config/view";
isStrategyView,
LovelaceViewConfig,
} from "../../../data/lovelace/config/view";
import { import {
showAlertDialog, showAlertDialog,
showPromptDialog, showPromptDialog,
@ -43,14 +40,12 @@ import { computeCardSize } from "../common/compute-card-size";
import { showEditCardDialog } from "../editor/card-editor/show-edit-card-dialog"; import { showEditCardDialog } from "../editor/card-editor/show-edit-card-dialog";
import { import {
addCard, addCard,
addSection,
deleteCard, deleteCard,
moveCardToContainer, moveCardToContainer,
moveCardToIndex, moveCardToIndex,
} from "../editor/config-util"; } from "../editor/config-util";
import { import {
LovelaceCardPath, LovelaceCardPath,
LovelaceContainerPath,
findLovelaceItems, findLovelaceItems,
getLovelaceContainerPath, getLovelaceContainerPath,
parseLovelaceCardPath, parseLovelaceCardPath,
@ -358,49 +353,34 @@ export class HuiCardOptions extends LitElement {
allowDashboardChange: true, allowDashboardChange: true,
header: this.hass!.localize("ui.panel.lovelace.editor.move_card.header"), header: this.hass!.localize("ui.panel.lovelace.editor.move_card.header"),
viewSelectedCallback: async (urlPath, selectedDashConfig, viewIndex) => { viewSelectedCallback: async (urlPath, selectedDashConfig, viewIndex) => {
let view = selectedDashConfig.views[viewIndex]; const view = selectedDashConfig.views[viewIndex];
let newConfig = selectedDashConfig;
if (isStrategyView(view)) { if (!isStrategyView(view) && view.type === SECTION_VIEW_LAYOUT) {
showAlertDialog(this, { showAlertDialog(this, {
title: this.hass!.localize( title: this.hass!.localize(
"ui.panel.lovelace.editor.move_card.error_title" "ui.panel.lovelace.editor.move_card.error_title"
), ),
text: this.hass!.localize( text: this.hass!.localize(
"ui.panel.lovelace.editor.move_card.error_text_strategy" "ui.panel.lovelace.editor.move_card.error_text_section"
), ),
warning: true, warning: true,
}); });
return; return;
} }
const isSectionView = view.type === SECTION_VIEW_LAYOUT;
// If the view is a section view and has no sections, add a default section.
if (isSectionView && !view.sections?.length) {
const newSection = { type: "grid", cards: [] };
newConfig = addSection(selectedDashConfig, viewIndex, newSection);
view = newConfig.views[viewIndex] as LovelaceViewConfig;
}
const toPath: LovelaceContainerPath = isSectionView
? [viewIndex, view.sections!.length - 1]
: [viewIndex];
if (urlPath === this.lovelace!.urlPath) { if (urlPath === this.lovelace!.urlPath) {
this.lovelace!.saveConfig( this.lovelace!.saveConfig(
moveCardToContainer(newConfig, this.path!, toPath) moveCardToContainer(this.lovelace!.config, this.path!, [viewIndex])
); );
showSaveSuccessToast(this, this.hass!); showSaveSuccessToast(this, this.hass!);
return; return;
} }
try { try {
const { cardIndex } = parseLovelaceCardPath(this.path!); const { cardIndex } = parseLovelaceCardPath(this.path!);
const card = this._cards[cardIndex];
await saveConfig( await saveConfig(
this.hass!, this.hass!,
urlPath, urlPath,
addCard(newConfig, toPath, card) addCard(selectedDashConfig, [viewIndex], this._cards[cardIndex])
); );
this.lovelace!.saveConfig( this.lovelace!.saveConfig(
deleteCard(this.lovelace!.config, this.path!) deleteCard(this.lovelace!.config, this.path!)

View File

@ -5682,8 +5682,8 @@
}, },
"move_card": { "move_card": {
"header": "Choose a view to move the card to", "header": "Choose a view to move the card to",
"strategy_error_title": "Impossible to move the card", "error_title": "Impossible to move the card",
"strategy_error_text_strategy": "Moving a card to a strategy view is not supported." "error_text_section": "Moving a card to a section view is not supported yet. Use copy/cut/paste instead."
}, },
"change_position": { "change_position": {
"title": "Change card position", "title": "Change card position",