mirror of
https://github.com/home-assistant/frontend.git
synced 2025-04-29 15:57:20 +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 {
|
export interface BaseActionConfig {
|
||||||
|
action: string;
|
||||||
confirmation?: ConfirmationRestrictionConfig;
|
confirmation?: ConfirmationRestrictionConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
import {
|
import {
|
||||||
object,
|
|
||||||
string,
|
|
||||||
union,
|
|
||||||
boolean,
|
|
||||||
optional,
|
|
||||||
array,
|
array,
|
||||||
literal,
|
boolean,
|
||||||
|
dynamic,
|
||||||
enums,
|
enums,
|
||||||
|
literal,
|
||||||
|
object,
|
||||||
|
optional,
|
||||||
|
string,
|
||||||
type,
|
type,
|
||||||
|
union,
|
||||||
} from "superstruct";
|
} from "superstruct";
|
||||||
|
import { BaseActionConfig } from "../../../../data/lovelace";
|
||||||
|
|
||||||
const actionConfigStructUser = object({
|
const actionConfigStructUser = object({
|
||||||
user: string(),
|
user: string(),
|
||||||
@ -65,10 +67,23 @@ export const actionConfigStructType = object({
|
|||||||
confirmation: optional(actionConfigStructConfirmation),
|
confirmation: optional(actionConfigStructConfirmation),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const actionConfigStruct = union([
|
export const actionConfigStruct = dynamic<any>((value) => {
|
||||||
actionConfigStructType,
|
if (value && typeof value === "object" && "action" in value) {
|
||||||
actionConfigStructUrl,
|
switch ((value as BaseActionConfig).action!) {
|
||||||
actionConfigStructNavigate,
|
case "call-service": {
|
||||||
actionConfigStructService,
|
return actionConfigStructService;
|
||||||
actionConfigStructCustom,
|
}
|
||||||
]);
|
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