mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-26 22:37:21 +00:00
Dynamically determine the correct action config struct (#12798)
This commit is contained in:
parent
00dcecabb7
commit
73cf0b54c9
@ -159,6 +159,7 @@ export interface CustomActionConfig extends BaseActionConfig {
|
||||
}
|
||||
|
||||
export interface BaseActionConfig {
|
||||
action: string;
|
||||
confirmation?: ConfirmationRestrictionConfig;
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,16 @@
|
||||
import {
|
||||
object,
|
||||
string,
|
||||
union,
|
||||
boolean,
|
||||
optional,
|
||||
array,
|
||||
literal,
|
||||
boolean,
|
||||
dynamic,
|
||||
enums,
|
||||
literal,
|
||||
object,
|
||||
optional,
|
||||
string,
|
||||
type,
|
||||
union,
|
||||
} from "superstruct";
|
||||
import { BaseActionConfig } from "../../../../data/lovelace";
|
||||
|
||||
const actionConfigStructUser = object({
|
||||
user: string(),
|
||||
@ -65,10 +67,23 @@ export const actionConfigStructType = object({
|
||||
confirmation: optional(actionConfigStructConfirmation),
|
||||
});
|
||||
|
||||
export const actionConfigStruct = union([
|
||||
actionConfigStructType,
|
||||
actionConfigStructUrl,
|
||||
actionConfigStructNavigate,
|
||||
actionConfigStructService,
|
||||
actionConfigStructCustom,
|
||||
]);
|
||||
export const actionConfigStruct = dynamic<any>((value) => {
|
||||
if (value && typeof value === "object" && "action" in value) {
|
||||
switch ((value as BaseActionConfig).action!) {
|
||||
case "call-service": {
|
||||
return actionConfigStructService;
|
||||
}
|
||||
case "fire-dom-event": {
|
||||
return actionConfigStructCustom;
|
||||
}
|
||||
case "navigate": {
|
||||
return actionConfigStructNavigate;
|
||||
}
|
||||
case "url": {
|
||||
return actionConfigStructUrl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return actionConfigStructType;
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user