mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Block moving card to a section view or a strategy view (#20016)
This commit is contained in:
parent
d9ab9db211
commit
d03825d200
@ -28,6 +28,7 @@ import "../../../components/ha-icon-button";
|
||||
import "../../../components/ha-list-item";
|
||||
import { LovelaceCardConfig } from "../../../data/lovelace/config/card";
|
||||
import { saveConfig } from "../../../data/lovelace/config/types";
|
||||
import { isStrategyView } from "../../../data/lovelace/config/view";
|
||||
import {
|
||||
showAlertDialog,
|
||||
showPromptDialog,
|
||||
@ -51,6 +52,7 @@ import {
|
||||
} from "../editor/lovelace-path";
|
||||
import { showSelectViewDialog } from "../editor/select-view/show-select-view-dialog";
|
||||
import { Lovelace, LovelaceCard } from "../types";
|
||||
import { SECTION_VIEW_LAYOUT } from "../views/const";
|
||||
|
||||
@customElement("hui-card-options")
|
||||
export class HuiCardOptions extends LitElement {
|
||||
@ -351,6 +353,21 @@ export class HuiCardOptions extends LitElement {
|
||||
allowDashboardChange: true,
|
||||
header: this.hass!.localize("ui.panel.lovelace.editor.move_card.header"),
|
||||
viewSelectedCallback: async (urlPath, selectedDashConfig, viewIndex) => {
|
||||
const view = this.lovelace!.config.views[viewIndex];
|
||||
|
||||
if (!isStrategyView(view) && view.type === SECTION_VIEW_LAYOUT) {
|
||||
showAlertDialog(this, {
|
||||
title: this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.move_card.error_title"
|
||||
),
|
||||
text: this.hass!.localize(
|
||||
"ui.panel.lovelace.editor.move_card.error_text_section"
|
||||
),
|
||||
warning: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (urlPath === this.lovelace!.urlPath) {
|
||||
this.lovelace!.saveConfig(
|
||||
moveCardToContainer(this.lovelace!.config, this.path!, [viewIndex])
|
||||
|
@ -21,6 +21,7 @@ import {
|
||||
import { haStyleDialog } from "../../../../resources/styles";
|
||||
import { HomeAssistant } from "../../../../types";
|
||||
import type { SelectViewDialogParams } from "./show-select-view-dialog";
|
||||
import { isStrategyView } from "../../../../data/lovelace/config/view";
|
||||
|
||||
declare global {
|
||||
interface HASSDomEvents {
|
||||
@ -117,8 +118,10 @@ export class HuiDialogSelectView extends LitElement {
|
||||
: this._config.views.length > 1
|
||||
? html`
|
||||
<mwc-list dialogInitialFocus>
|
||||
${this._config.views.map(
|
||||
(view, idx) => html`
|
||||
${this._config.views.map((view, idx) => {
|
||||
const isStrategy = isStrategyView(view);
|
||||
|
||||
return html`
|
||||
<mwc-radio-list-item
|
||||
.graphic=${this._config?.views.some(({ icon }) => icon)
|
||||
? "icon"
|
||||
@ -126,12 +129,19 @@ export class HuiDialogSelectView extends LitElement {
|
||||
@click=${this._viewChanged}
|
||||
.value=${idx.toString()}
|
||||
.selected=${this._selectedViewIdx === idx}
|
||||
.disabled=${isStrategy &&
|
||||
!this._params?.includeStrategyViews}
|
||||
>
|
||||
<span>${view.title}</span>
|
||||
<span>
|
||||
${view.title}${isStrategy
|
||||
? ` (${this.hass.localize("ui.panel.lovelace.editor.select_view.strategy_type")})`
|
||||
: nothing}
|
||||
</span>
|
||||
|
||||
<ha-icon .icon=${view.icon} slot="graphic"></ha-icon>
|
||||
</mwc-radio-list-item>
|
||||
`
|
||||
)}
|
||||
`;
|
||||
})}
|
||||
</mwc-list>
|
||||
`
|
||||
: ""}
|
||||
|
@ -5,6 +5,7 @@ import { LovelaceDashboard } from "../../../../data/lovelace/dashboard";
|
||||
export interface SelectViewDialogParams {
|
||||
lovelaceConfig: LovelaceConfig;
|
||||
allowDashboardChange: boolean;
|
||||
includeStrategyViews?: boolean;
|
||||
dashboards?: LovelaceDashboard[];
|
||||
urlPath?: string | null;
|
||||
header?: string;
|
||||
|
@ -5160,7 +5160,9 @@
|
||||
"search_cards": "Search cards"
|
||||
},
|
||||
"move_card": {
|
||||
"header": "Choose a view to move the card to"
|
||||
"header": "Choose a view to move the card to",
|
||||
"error_title": "Impossible to move the card",
|
||||
"error_text_section": "Moving a card to a section view is not supported yet. Use copy/cut/paste instead."
|
||||
},
|
||||
"change_position": {
|
||||
"title": "Change card position",
|
||||
@ -5171,7 +5173,8 @@
|
||||
"dashboard_label": "Dashboard",
|
||||
"views_label": "View",
|
||||
"no_config": "No config found.",
|
||||
"no_views": "No views in this dashboard."
|
||||
"no_views": "No views in this dashboard.",
|
||||
"strategy_type": "strategy"
|
||||
},
|
||||
"section": {
|
||||
"unnamed_section": "Unnamed section",
|
||||
|
Loading…
x
Reference in New Issue
Block a user