mirror of
https://github.com/home-assistant/frontend.git
synced 2026-04-17 23:54:28 +01:00
Consolidate into a single customStrategies registry for all strategy types
The window.customStrategies array now accepts entries with a strategyType field (dashboard, view, or section). The dialog filters for dashboard strategies. This allows future use of the same registry for view and section strategy registration. https://claude.ai/code/session_019MXBdWUQrFQfH54QVjbq8y
This commit is contained in:
@@ -1,22 +1,33 @@
|
||||
import type { LovelaceStrategyConfigType } from "../panels/lovelace/strategies/get-strategy";
|
||||
|
||||
export interface CustomStrategyEntry {
|
||||
type: string;
|
||||
name?: string;
|
||||
description?: string;
|
||||
documentationURL?: string;
|
||||
strategyType: LovelaceStrategyConfigType;
|
||||
}
|
||||
|
||||
export interface CustomStrategiesWindow {
|
||||
customDashboardStrategies?: CustomStrategyEntry[];
|
||||
customStrategies?: CustomStrategyEntry[];
|
||||
}
|
||||
|
||||
const customStrategiesWindow = window as CustomStrategiesWindow;
|
||||
|
||||
if (!("customDashboardStrategies" in customStrategiesWindow)) {
|
||||
customStrategiesWindow.customDashboardStrategies = [];
|
||||
if (!("customStrategies" in customStrategiesWindow)) {
|
||||
customStrategiesWindow.customStrategies = [];
|
||||
}
|
||||
|
||||
export const customDashboardStrategies =
|
||||
customStrategiesWindow.customDashboardStrategies!;
|
||||
export const customStrategies = customStrategiesWindow.customStrategies!;
|
||||
|
||||
export const getCustomDashboardStrategyEntry = (type: string) =>
|
||||
customDashboardStrategies.find((strategy) => strategy.type === type);
|
||||
export const getCustomStrategiesForType = (
|
||||
strategyType: LovelaceStrategyConfigType
|
||||
) => customStrategies.filter((s) => s.strategyType === strategyType);
|
||||
|
||||
export const getCustomStrategyEntry = (
|
||||
type: string,
|
||||
strategyType: LovelaceStrategyConfigType
|
||||
) =>
|
||||
customStrategies.find(
|
||||
(s) => s.type === type && s.strategyType === strategyType
|
||||
);
|
||||
|
||||
@@ -14,7 +14,7 @@ import "../../../components/input/ha-input-search";
|
||||
import type { HaInputSearch } from "../../../components/input/ha-input-search";
|
||||
import { CUSTOM_TYPE_PREFIX } from "../../../data/lovelace_custom_cards";
|
||||
import {
|
||||
customDashboardStrategies,
|
||||
getCustomStrategiesForType,
|
||||
type CustomStrategyEntry,
|
||||
} from "../../../data/lovelace_custom_strategies";
|
||||
import type { LovelaceConfig } from "../../../data/lovelace/config/types";
|
||||
@@ -94,7 +94,7 @@ class DialogNewDashboard extends LitElement implements HassDialog {
|
||||
strategy.description as LocalizeKeys
|
||||
),
|
||||
}));
|
||||
this._customStrategies = [...customDashboardStrategies];
|
||||
this._customStrategies = getCustomStrategiesForType("dashboard");
|
||||
}
|
||||
|
||||
public closeDialog() {
|
||||
|
||||
Reference in New Issue
Block a user