mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Improve lovelace card events (#19785)
This commit is contained in:
parent
a3a099126e
commit
33cdd51f00
@ -275,9 +275,9 @@ export class HuiCardOptions extends LitElement {
|
|||||||
const cardConfig = this._currentView.cards![path[1]];
|
const cardConfig = this._currentView.cards![path[1]];
|
||||||
showEditCardDialog(this, {
|
showEditCardDialog(this, {
|
||||||
lovelaceConfig: this.lovelace!.config,
|
lovelaceConfig: this.lovelace!.config,
|
||||||
cardConfig,
|
|
||||||
saveConfig: this.lovelace!.saveConfig,
|
saveConfig: this.lovelace!.saveConfig,
|
||||||
path: [path[0]],
|
path: [path[0], null],
|
||||||
|
newCardConfig: cardConfig,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,8 +214,8 @@ export class HuiCreateDialogCard
|
|||||||
showEditCardDialog(this, {
|
showEditCardDialog(this, {
|
||||||
lovelaceConfig: this._params!.lovelaceConfig,
|
lovelaceConfig: this._params!.lovelaceConfig,
|
||||||
saveConfig: this._params!.saveConfig,
|
saveConfig: this._params!.saveConfig,
|
||||||
path: this._params!.path,
|
path: [this._params!.path[0], null],
|
||||||
cardConfig: config,
|
newCardConfig: config,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.closeDialog();
|
this.closeDialog();
|
||||||
|
@ -87,12 +87,13 @@ export class HuiDialogEditCard
|
|||||||
const [view, card] = params.path;
|
const [view, card] = params.path;
|
||||||
this._viewConfig = params.lovelaceConfig.views[view];
|
this._viewConfig = params.lovelaceConfig.views[view];
|
||||||
this._cardConfig =
|
this._cardConfig =
|
||||||
card !== undefined ? this._viewConfig.cards![card] : params.cardConfig;
|
params.newCardConfig ??
|
||||||
|
(card !== null ? this._viewConfig.cards![card] : undefined);
|
||||||
this.large = false;
|
this.large = false;
|
||||||
if (this._cardConfig && !Object.isFrozen(this._cardConfig)) {
|
if (this._cardConfig && !Object.isFrozen(this._cardConfig)) {
|
||||||
this._cardConfig = deepFreeze(this._cardConfig);
|
this._cardConfig = deepFreeze(this._cardConfig);
|
||||||
}
|
}
|
||||||
if (params.cardConfig) {
|
if (params.newCardConfig) {
|
||||||
this._dirty = true;
|
this._dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -368,16 +369,13 @@ export class HuiDialogEditCard
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._saving = true;
|
this._saving = true;
|
||||||
|
const [view, card] = this._params!.path;
|
||||||
await this._params!.saveConfig(
|
await this._params!.saveConfig(
|
||||||
this._params!.path.length === 1
|
card === null
|
||||||
? addCard(
|
? addCard(this._params!.lovelaceConfig, [view], this._cardConfig!)
|
||||||
this._params!.lovelaceConfig,
|
|
||||||
this._params!.path as [number],
|
|
||||||
this._cardConfig!
|
|
||||||
)
|
|
||||||
: replaceCard(
|
: replaceCard(
|
||||||
this._params!.lovelaceConfig,
|
this._params!.lovelaceConfig,
|
||||||
this._params!.path as [number, number],
|
[view, card],
|
||||||
this._cardConfig!
|
this._cardConfig!
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -4,7 +4,7 @@ import type { LovelaceConfig } from "../../../../data/lovelace/config/types";
|
|||||||
export interface CreateCardDialogParams {
|
export interface CreateCardDialogParams {
|
||||||
lovelaceConfig: LovelaceConfig;
|
lovelaceConfig: LovelaceConfig;
|
||||||
saveConfig: (config: LovelaceConfig) => void;
|
saveConfig: (config: LovelaceConfig) => void;
|
||||||
path: [number] | [number, number];
|
path: [number];
|
||||||
entities?: string[]; // We can pass entity id's that will be added to the config when a card is picked
|
entities?: string[]; // We can pass entity id's that will be added to the config when a card is picked
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,8 +5,9 @@ import type { LovelaceConfig } from "../../../../data/lovelace/config/types";
|
|||||||
export interface EditCardDialogParams {
|
export interface EditCardDialogParams {
|
||||||
lovelaceConfig: LovelaceConfig;
|
lovelaceConfig: LovelaceConfig;
|
||||||
saveConfig: (config: LovelaceConfig) => void;
|
saveConfig: (config: LovelaceConfig) => void;
|
||||||
path: [number] | [number, number];
|
path: [number, number | null];
|
||||||
cardConfig?: LovelaceCardConfig;
|
// If specified, the card will be replaced with the new card.
|
||||||
|
newCardConfig?: LovelaceCardConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const importEditCardDialog = () => import("./hui-dialog-edit-card");
|
export const importEditCardDialog = () => import("./hui-dialog-edit-card");
|
||||||
|
@ -31,13 +31,19 @@ import {
|
|||||||
LovelaceViewConfig,
|
LovelaceViewConfig,
|
||||||
isStrategyView,
|
isStrategyView,
|
||||||
} from "../../../data/lovelace/config/view";
|
} from "../../../data/lovelace/config/view";
|
||||||
|
import { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
// for fire event
|
// for fire event
|
||||||
interface HASSDomEvents {
|
interface HASSDomEvents {
|
||||||
"ll-create-card": undefined;
|
"ll-create-card": undefined;
|
||||||
"ll-edit-card": { path: [number] | [number, number] };
|
"ll-edit-card": { path: [number, number] };
|
||||||
"ll-delete-card": { path: [number] | [number, number]; confirm: boolean };
|
"ll-delete-card": { path: [number, number]; confirm: boolean };
|
||||||
|
}
|
||||||
|
interface HTMLElementEventMap {
|
||||||
|
"ll-create-card": HASSDomEvent<HASSDomEvents["ll-create-card"]>;
|
||||||
|
"ll-edit-card": HASSDomEvent<HASSDomEvents["ll-edit-card"]>;
|
||||||
|
"ll-delete-card": HASSDomEvent<HASSDomEvents["ll-delete-card"]>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user