mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Block moving card to a section view or a strategy view (#20016)
This commit is contained in:
parent
3b885dd01f
commit
233c969402
@ -28,6 +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 { isStrategyView } from "../../../data/lovelace/config/view";
|
||||||
import {
|
import {
|
||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
showPromptDialog,
|
showPromptDialog,
|
||||||
@ -51,6 +52,7 @@ import {
|
|||||||
} from "../editor/lovelace-path";
|
} from "../editor/lovelace-path";
|
||||||
import { showSelectViewDialog } from "../editor/select-view/show-select-view-dialog";
|
import { showSelectViewDialog } from "../editor/select-view/show-select-view-dialog";
|
||||||
import { Lovelace, LovelaceCard } from "../types";
|
import { Lovelace, LovelaceCard } from "../types";
|
||||||
|
import { SECTION_VIEW_LAYOUT } from "../views/const";
|
||||||
|
|
||||||
@customElement("hui-card-options")
|
@customElement("hui-card-options")
|
||||||
export class HuiCardOptions extends LitElement {
|
export class HuiCardOptions extends LitElement {
|
||||||
@ -351,6 +353,21 @@ 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) => {
|
||||||
|
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) {
|
if (urlPath === this.lovelace!.urlPath) {
|
||||||
this.lovelace!.saveConfig(
|
this.lovelace!.saveConfig(
|
||||||
moveCardToContainer(this.lovelace!.config, this.path!, [viewIndex])
|
moveCardToContainer(this.lovelace!.config, this.path!, [viewIndex])
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
import { haStyleDialog } from "../../../../resources/styles";
|
import { haStyleDialog } from "../../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../../types";
|
import { HomeAssistant } from "../../../../types";
|
||||||
import type { SelectViewDialogParams } from "./show-select-view-dialog";
|
import type { SelectViewDialogParams } from "./show-select-view-dialog";
|
||||||
|
import { isStrategyView } from "../../../../data/lovelace/config/view";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface HASSDomEvents {
|
interface HASSDomEvents {
|
||||||
@ -117,8 +118,10 @@ export class HuiDialogSelectView extends LitElement {
|
|||||||
: this._config.views.length > 1
|
: this._config.views.length > 1
|
||||||
? html`
|
? html`
|
||||||
<mwc-list dialogInitialFocus>
|
<mwc-list dialogInitialFocus>
|
||||||
${this._config.views.map(
|
${this._config.views.map((view, idx) => {
|
||||||
(view, idx) => html`
|
const isStrategy = isStrategyView(view);
|
||||||
|
|
||||||
|
return html`
|
||||||
<mwc-radio-list-item
|
<mwc-radio-list-item
|
||||||
.graphic=${this._config?.views.some(({ icon }) => icon)
|
.graphic=${this._config?.views.some(({ icon }) => icon)
|
||||||
? "icon"
|
? "icon"
|
||||||
@ -126,12 +129,19 @@ export class HuiDialogSelectView extends LitElement {
|
|||||||
@click=${this._viewChanged}
|
@click=${this._viewChanged}
|
||||||
.value=${idx.toString()}
|
.value=${idx.toString()}
|
||||||
.selected=${this._selectedViewIdx === idx}
|
.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>
|
<ha-icon .icon=${view.icon} slot="graphic"></ha-icon>
|
||||||
</mwc-radio-list-item>
|
</mwc-radio-list-item>
|
||||||
`
|
`;
|
||||||
)}
|
})}
|
||||||
</mwc-list>
|
</mwc-list>
|
||||||
`
|
`
|
||||||
: ""}
|
: ""}
|
||||||
|
@ -5,6 +5,7 @@ import { LovelaceDashboard } from "../../../../data/lovelace/dashboard";
|
|||||||
export interface SelectViewDialogParams {
|
export interface SelectViewDialogParams {
|
||||||
lovelaceConfig: LovelaceConfig;
|
lovelaceConfig: LovelaceConfig;
|
||||||
allowDashboardChange: boolean;
|
allowDashboardChange: boolean;
|
||||||
|
includeStrategyViews?: boolean;
|
||||||
dashboards?: LovelaceDashboard[];
|
dashboards?: LovelaceDashboard[];
|
||||||
urlPath?: string | null;
|
urlPath?: string | null;
|
||||||
header?: string;
|
header?: string;
|
||||||
|
@ -5184,7 +5184,9 @@
|
|||||||
"search_cards": "Search cards"
|
"search_cards": "Search cards"
|
||||||
},
|
},
|
||||||
"move_card": {
|
"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": {
|
"change_position": {
|
||||||
"title": "Change card position",
|
"title": "Change card position",
|
||||||
@ -5195,7 +5197,8 @@
|
|||||||
"dashboard_label": "Dashboard",
|
"dashboard_label": "Dashboard",
|
||||||
"views_label": "View",
|
"views_label": "View",
|
||||||
"no_config": "No config found.",
|
"no_config": "No config found.",
|
||||||
"no_views": "No views in this dashboard."
|
"no_views": "No views in this dashboard.",
|
||||||
|
"strategy_type": "strategy"
|
||||||
},
|
},
|
||||||
"section": {
|
"section": {
|
||||||
"unnamed_section": "Unnamed section",
|
"unnamed_section": "Unnamed section",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user