[200~latest changes to web~
This commit is contained in:
1 parent
f11d060ed2
commit
22bc5dfcf6
11 files changed
+629
-553
No files matched your search
@@ -0,0 +1,36 @@
|
|||||||
|
# http://editorconfig.org
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
# Use 4 spaces for the Python files
|
||||||
|
[*.py]
|
||||||
|
indent_size = 4
|
||||||
|
max_line_length = 80
|
||||||
|
|
||||||
|
# The JSON files contain newlines inconsistently
|
||||||
|
[*.json]
|
||||||
|
insert_final_newline = ignore
|
||||||
|
|
||||||
|
# Minified JavaScript files shouldn't be changed
|
||||||
|
[**.min.js]
|
||||||
|
indent_style = ignore
|
||||||
|
insert_final_newline = ignore
|
||||||
|
|
||||||
|
# Makefiles always use tabs for indentation
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
|
|
||||||
|
# Batch files use tabs for indentation
|
||||||
|
[*.bat]
|
||||||
|
indent_style = tab
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
Vendored
-18
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"type": "node",
|
|
||||||
"name": "vscode-jest-tests",
|
|
||||||
"request": "launch",
|
|
||||||
"console": "integratedTerminal",
|
|
||||||
"internalConsoleOptions": "neverOpen",
|
|
||||||
"disableOptimisticBPs": true,
|
|
||||||
"program": "${workspaceFolder}/node_modules/.bin/jest",
|
|
||||||
"cwd": "${workspaceFolder}",
|
|
||||||
"args": [
|
|
||||||
"--runInBand",
|
|
||||||
"--watchAll=false"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -7,42 +7,42 @@ import { Node } from "./types"
|
|||||||
|
|
||||||
|
|
||||||
export interface NodeProp extends Node {
|
export interface NodeProp extends Node {
|
||||||
height?: number;
|
height?: number;
|
||||||
width?: number;
|
width?: number;
|
||||||
isOpen?: boolean;
|
onXClick?: () => void;
|
||||||
onXClick?: () => void;
|
onOpenClick?: () => void;
|
||||||
onOpenClick?: () => void;
|
|
||||||
}
|
}
|
||||||
export default ({
|
export default ({
|
||||||
loc: [x,y],
|
loc: [x, y],
|
||||||
text,
|
text,
|
||||||
height=NODE_HEIGHT,
|
height = NODE_HEIGHT,
|
||||||
width=NODE_WIDTH,
|
width = NODE_WIDTH,
|
||||||
onXClick=() => {},
|
onXClick = () => { },
|
||||||
onOpenClick=() => {},
|
onOpenClick = () => { },
|
||||||
isOpen=false,
|
color,
|
||||||
color,
|
|
||||||
}: NodeProp) => {
|
}: NodeProp) => {
|
||||||
const {classes, theme} = useNodeStyles({
|
const { classes, theme } = useNodeStyles({
|
||||||
color,
|
color,
|
||||||
nodeHeight: height,
|
nodeHeight: height,
|
||||||
nodeWidth: width,
|
nodeWidth: width,
|
||||||
});
|
});
|
||||||
return <foreignObject x={x} y={y} width={width} height={height}>
|
return <foreignObject x={x} y={y} width={width} height={height}>
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<div className={classes.inner}>
|
<div className={classes.inner}>
|
||||||
<div className={classes.leftEdge} onClick={onXClick}>
|
<div className={classes.leftEdge} onClick={onXClick}>
|
||||||
<button className={classes.buttonDelete}>X</button>
|
<button className={classes.buttonDelete}>X</button>
|
||||||
</div>
|
|
||||||
<div className={classes.text}>
|
|
||||||
{text}
|
|
||||||
</div>
|
|
||||||
<div className={classes.rightEdge} onClick={onOpenClick}>
|
|
||||||
<button className={classes.buttonEdit}>
|
|
||||||
<PencilIcon size={1.1} color={Color(theme.primary).set('rgb.g', 200).hex()}/>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</foreignObject>
|
<div className={classes.textWrap}>
|
||||||
|
<span className={classes.text}>
|
||||||
|
{text}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className={classes.rightEdge} onClick={onOpenClick}>
|
||||||
|
<button className={classes.buttonEdit}>
|
||||||
|
<PencilIcon size={1.1} color={Color(theme.primary).set('rgb.g', 200).hex()} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</foreignObject>
|
||||||
}
|
}
|
||||||
@@ -7,54 +7,147 @@ import { useNodeStyles } from "./styles";
|
|||||||
import { Point } from "./types";
|
import { Point } from "./types";
|
||||||
|
|
||||||
|
|
||||||
|
interface Props extends RenderSequenceProps {
|
||||||
|
styles: ReturnType<typeof useNodeStyles>,
|
||||||
|
sequence: AutomationSequenceNode[],
|
||||||
|
triggerPoint: Point,
|
||||||
|
}
|
||||||
|
export const SequenceNodes: FC<Props> = ({
|
||||||
|
sequence,
|
||||||
|
triggerPoint,
|
||||||
|
...renderSequenceProps
|
||||||
|
}) => {
|
||||||
|
const renderSequence = makeRenderSequence(renderSequenceProps);
|
||||||
|
return <g id="sequence">
|
||||||
|
{sequence.map((n, i) => renderSequence(triggerPoint, n, i))}
|
||||||
|
</g>
|
||||||
|
}
|
||||||
|
|
||||||
export const SequenceNodes: FC<{
|
interface RenderSequenceProps {
|
||||||
styles: ReturnType<typeof useNodeStyles>,
|
styles: ReturnType<typeof useNodeStyles>,
|
||||||
sequence: AutomationSequenceNode[],
|
onUpdate: (i: number, s: AutomationSequenceNode | null) => void,
|
||||||
onUpdate: (s: AutomationSequenceNode[]) => void,
|
nodeWidth: number,
|
||||||
nodeWidth: number,
|
nodeHeight: number,
|
||||||
nodeHeight: number,
|
nHDF: number,
|
||||||
triggerPoint: Point,
|
}
|
||||||
nHDF: number,
|
const makeRenderSequence = ({
|
||||||
}> = ({
|
onUpdate,
|
||||||
styles: { classes, theme },
|
nodeHeight,
|
||||||
sequence,
|
nodeWidth,
|
||||||
onUpdate,
|
nHDF,
|
||||||
nodeWidth,
|
styles: { classes }
|
||||||
nodeHeight,
|
}: RenderSequenceProps) => (
|
||||||
triggerPoint,
|
startPoint: Point,
|
||||||
nHDF,
|
node: AutomationSequenceNode,
|
||||||
}) => {
|
i: number
|
||||||
const renderSequence = (node: AutomationSequenceNode, i: number) => {
|
) => {
|
||||||
const nodeLoc: Point = [triggerPoint[0] + nodeWidth/2 , 0];
|
const nodeLoc: Point = [startPoint[0] + nodeWidth / 2, 0];
|
||||||
let lastNodeLoc = triggerPoint;
|
let lastNodeLoc = startPoint;
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
lastNodeLoc = [nodeLoc[0] + nodeWidth*((i - 1)*nHDF+1), nodeLoc[1] + nodeHeight/2];
|
lastNodeLoc = [nodeLoc[0] + nodeWidth * ((i - 1) * nHDF + 1), nodeLoc[1] + nodeHeight / 2];
|
||||||
nodeLoc[0] += nodeWidth*i*nHDF
|
nodeLoc[0] += nodeWidth * i * nHDF
|
||||||
}
|
|
||||||
return <>
|
|
||||||
<DAGNode
|
|
||||||
key={`node.${i}`}
|
|
||||||
loc={nodeLoc}
|
|
||||||
text={getDescriptionFromAutomationNode(node)}
|
|
||||||
color={node.$smType === 'action' ? 'green' : 'blue'}
|
|
||||||
onXClick={() => {
|
|
||||||
onUpdate([
|
|
||||||
...sequence.slice(0, i),
|
|
||||||
...sequence.slice(i+1),
|
|
||||||
])
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<DAGEdge
|
|
||||||
key={`edge.${i}`}
|
|
||||||
p1={lastNodeLoc}
|
|
||||||
p2={[nodeLoc[0], nodeLoc[1] + nodeHeight/2]}
|
|
||||||
direction="1->2"
|
|
||||||
className={classes.dagEdge}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
}
|
}
|
||||||
return <g id="sequence">
|
const curretEdgeLoc: Point = [nodeLoc[0], nodeLoc[1] + nodeHeight / 2];
|
||||||
{sequence.map(renderSequence)}
|
const nextAddLoc: Point = [nodeLoc[0] + nodeWidth * nHDF, nodeLoc[1] + nodeHeight / 2];
|
||||||
</g>
|
return <>
|
||||||
|
<DAGEdge
|
||||||
|
key={`edge.${i}`}
|
||||||
|
p1={lastNodeLoc}
|
||||||
|
p2={curretEdgeLoc}
|
||||||
|
direction="1->2"
|
||||||
|
className={classes.dagEdge}
|
||||||
|
/>
|
||||||
|
<DAGNode
|
||||||
|
height={nodeHeight}
|
||||||
|
width={nodeWidth}
|
||||||
|
key={`node.${i}`}
|
||||||
|
loc={nodeLoc}
|
||||||
|
text={getDescriptionFromAutomationNode(node)}
|
||||||
|
color={node.$smType === 'action' ? 'green' : 'blue'}
|
||||||
|
onXClick={() => onUpdate(i, null)}
|
||||||
|
/>
|
||||||
|
<DAGEdge
|
||||||
|
key={`edge.${i}`}
|
||||||
|
p1={curretEdgeLoc}
|
||||||
|
p2={nextAddLoc}
|
||||||
|
direction="1->2"
|
||||||
|
className={classes.dagEdge}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
|
||||||
|
export function* getJSXNodes(
|
||||||
|
{ classes }: ReturnType<typeof useNodeStyles>,
|
||||||
|
onUpdate: (i: number, s: AutomationSequenceNode | null) => void, it: Generator<NodeEdgeLocation, Point, never>
|
||||||
|
) {
|
||||||
|
let next = it.next();
|
||||||
|
while (!next.done) {
|
||||||
|
const { node, nodeLoc, curretEdgeLoc, nextAddLoc, lastStartPoint, nodeHeight, nodeWidth } = next.value;
|
||||||
|
yield <>
|
||||||
|
<DAGEdge
|
||||||
|
key={`edge.${i}`}
|
||||||
|
p1={nodeLoc}
|
||||||
|
p2={curretEdgeLoc}
|
||||||
|
direction="1->2"
|
||||||
|
className={classes.dagEdge}
|
||||||
|
/>
|
||||||
|
<DAGNode
|
||||||
|
height={nodeHeight}
|
||||||
|
width={nodeWidth}
|
||||||
|
key={`node.${i}`}
|
||||||
|
loc={nodeLoc}
|
||||||
|
text={getDescriptionFromAutomationNode(node)}
|
||||||
|
color={node.$smType === 'action' ? 'green' : 'blue'}
|
||||||
|
onXClick={() => onUpdate(i, null)}
|
||||||
|
/>
|
||||||
|
<DAGEdge
|
||||||
|
key={`edge.${i}`}
|
||||||
|
p1={curretEdgeLoc}
|
||||||
|
p2={nextAddLoc}
|
||||||
|
direction="1->2"
|
||||||
|
className={classes.dagEdge}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type NodeEdgeLocation = {
|
||||||
|
nodeId: string;
|
||||||
|
node: AutomationSequenceNode;
|
||||||
|
nodeLoc: Point;
|
||||||
|
lastStartPoint: Point;
|
||||||
|
curretEdgeLoc: Point;
|
||||||
|
nextAddLoc: Point | null;
|
||||||
|
nodeWidth: number;
|
||||||
|
nodeHeight: number;
|
||||||
|
}
|
||||||
|
export function* computeNodeEdgeLocation(
|
||||||
|
startPoint: Point,
|
||||||
|
nodeWidth: number,
|
||||||
|
nodeHeight: number,
|
||||||
|
distanceFactor: number,
|
||||||
|
sequence: AutomationSequenceNode[]
|
||||||
|
): Generator<NodeEdgeLocation, Point, never> {
|
||||||
|
let lastStartPoint: Point = [...startPoint];
|
||||||
|
for (let i = 0; i < sequence.length; i++) {
|
||||||
|
const node = sequence[i];
|
||||||
|
const nodeLoc: Point = lastStartPoint = [lastStartPoint[0], lastStartPoint[1] + nodeWidth * distanceFactor];
|
||||||
|
const curretEdgeLoc: Point = [nodeLoc[0], nodeLoc[1] + nodeHeight / 2];
|
||||||
|
const nextAddLoc: Point | null = i < sequence.length ? null : [nodeLoc[0] + nodeWidth * distanceFactor, nodeLoc[1] + nodeHeight / 2];
|
||||||
|
// if ((node.$smType === 'action') && (node.action === 'choose')) {
|
||||||
|
// for (let { sequence } of node.action_data.choose) {
|
||||||
|
// for (let parsedChild of computeNodeEdgeLocation(
|
||||||
|
// nodeLoc,
|
||||||
|
// nodeWidth,
|
||||||
|
// nodeHeight,
|
||||||
|
// distanceFactor,
|
||||||
|
// sequence
|
||||||
|
// )) {
|
||||||
|
// yield parsedChild;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
yield { node, nodeLoc, lastStartPoint, curretEdgeLoc, nextAddLoc, nodeHeight, nodeWidth }
|
||||||
|
}
|
||||||
|
return lastStartPoint
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const NODE_WIDTH = 90 as const;
|
export const NODE_WIDTH = 100 as const;
|
||||||
export const NODE_HEIGHT = 40 as const;
|
export const NODE_HEIGHT = 40 as const;
|
||||||
@@ -5,197 +5,207 @@ import { usePageTheme } from "~/styles/page";
|
|||||||
import AutomationEditor from ".";
|
import AutomationEditor from ".";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: 'AutomationEditor',
|
title: 'AutomationEditor',
|
||||||
component: AutomationEditor,
|
component: AutomationEditor,
|
||||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||||
} as ComponentMeta<typeof AutomationEditor>;
|
} as ComponentMeta<typeof AutomationEditor>;
|
||||||
|
|
||||||
|
|
||||||
const Template: ComponentStory<typeof AutomationEditor> = ({automation, ...args}) => {
|
const Template: ComponentStory<typeof AutomationEditor> = ({ automation, ...args }) => {
|
||||||
const {classes} = usePageTheme({});
|
const { classes } = usePageTheme({});
|
||||||
const [data, setData] = useState(automation);
|
const [data, setData] = useState(automation);
|
||||||
return <div className={classes.page}>
|
return <div className={classes.page}>
|
||||||
<AutomationEditor {...args}
|
<AutomationEditor {...args}
|
||||||
automation={data}
|
automation={data}
|
||||||
onUpdate={data => {
|
onUpdate={data => {
|
||||||
setData(data)
|
setData(data)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ServiceAction = Template.bind({})
|
export const ServiceAction = Template.bind({})
|
||||||
ServiceAction.args = {
|
ServiceAction.args = {
|
||||||
automation: {
|
automation: {
|
||||||
metadata: {
|
metadata: {
|
||||||
id: "X12314akx",
|
id: "X12314akx",
|
||||||
alias: "root",
|
alias: "root",
|
||||||
description: 'Really Long Description',
|
description: 'Really Long Description',
|
||||||
mode: 'single',
|
mode: 'single',
|
||||||
},
|
},
|
||||||
trigger: [
|
trigger: [
|
||||||
{
|
{
|
||||||
platform: 'time',
|
platform: 'time',
|
||||||
at: '10:00:00'
|
at: '10:00:00'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
platform: "device",
|
platform: "device",
|
||||||
device_id: "34749",
|
device_id: "34749",
|
||||||
domain: "zha",
|
domain: "zha",
|
||||||
type: "remote_button_double_press",
|
type: "remote_button_double_press",
|
||||||
subtype: "remote_button_double_press"
|
subtype: "remote_button_double_press"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
sequence: [
|
sequence: [
|
||||||
{
|
{
|
||||||
$smType: "condition",
|
$smType: "condition",
|
||||||
condition: 'and',
|
condition: 'and',
|
||||||
|
condition_data: {
|
||||||
|
conditions: [
|
||||||
|
{
|
||||||
|
$smType: 'condition',
|
||||||
|
condition: 'numeric_state',
|
||||||
condition_data: {
|
condition_data: {
|
||||||
conditions: [
|
entity_id: 'sensor.temperature_kitchen',
|
||||||
{
|
below: '15',
|
||||||
$smType: 'condition',
|
|
||||||
condition: 'numeric_state',
|
|
||||||
condition_data: {
|
|
||||||
entity_id: 'sensor.temperature_kitchen',
|
|
||||||
below: '15',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
$smType: "condition",
|
|
||||||
condition: 'template',
|
|
||||||
condition_data: {
|
|
||||||
value_template: 'states(switch.kitchen_light) == "on"'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$smType: "condition",
|
||||||
|
condition: 'template',
|
||||||
|
condition_data: {
|
||||||
|
value_template: 'states(switch.kitchen_light) == "on"'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$smType: "action",
|
||||||
|
action: "service",
|
||||||
|
action_data: {
|
||||||
|
alias: "Start Music In Kitchen",
|
||||||
|
service: 'media_player.play_media',
|
||||||
|
target: {
|
||||||
|
entity_id: "media_player.kitchen_dot"
|
||||||
},
|
},
|
||||||
{
|
data: {
|
||||||
$smType: "action",
|
media_content_id: "Good Morning",
|
||||||
action: "service",
|
media_content_type: "SPOTIFY",
|
||||||
action_data: {
|
|
||||||
alias: "Start Music In Kitchen",
|
|
||||||
service: 'media_player.play_media',
|
|
||||||
target: {
|
|
||||||
entity_id: "media_player.kitchen_dot"
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
media_content_id: "Good Morning",
|
|
||||||
media_content_type: "SPOTIFY",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
],
|
}
|
||||||
} as AutomationData
|
}
|
||||||
|
],
|
||||||
|
} as AutomationData
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export const ChooseAction = Template.bind({})
|
export const ChooseAction = Template.bind({})
|
||||||
ChooseAction.args = {
|
ChooseAction.args = {
|
||||||
automation: {
|
automation: {
|
||||||
metadata: {
|
metadata: {
|
||||||
id: "X12314akx",
|
id: "X12314akx",
|
||||||
alias: "root",
|
alias: "root",
|
||||||
description: 'Really Long Description',
|
description: 'Really Long Description',
|
||||||
mode: 'single',
|
mode: 'single',
|
||||||
},
|
},
|
||||||
trigger: [
|
trigger: [
|
||||||
{
|
{
|
||||||
platform: 'time',
|
platform: 'time',
|
||||||
at: '10:00:00'
|
at: '10:00:00'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
platform: "device",
|
platform: "device",
|
||||||
device_id: "34749",
|
device_id: "34749",
|
||||||
domain: "zha",
|
domain: "zha",
|
||||||
type: "remote_button_double_press",
|
type: "remote_button_double_press",
|
||||||
subtype: "remote_button_double_press"
|
subtype: "remote_button_double_press"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
sequence: [
|
sequence: [
|
||||||
{
|
{
|
||||||
$smType: "condition",
|
$smType: "condition",
|
||||||
condition: 'and',
|
condition: 'and',
|
||||||
|
condition_data: {
|
||||||
|
conditions: [
|
||||||
|
{
|
||||||
|
$smType: 'condition',
|
||||||
|
condition: 'numeric_state',
|
||||||
condition_data: {
|
condition_data: {
|
||||||
conditions: [
|
entity_id: 'sensor.temperature_kitchen',
|
||||||
{
|
below: '15',
|
||||||
$smType: 'condition',
|
}
|
||||||
condition: 'numeric_state',
|
},
|
||||||
condition_data: {
|
{
|
||||||
entity_id: 'sensor.temperature_kitchen',
|
$smType: "condition",
|
||||||
below: '15',
|
condition: 'template',
|
||||||
}
|
condition_data: {
|
||||||
},
|
value_template: 'states(switch.kitchen_light) == "on"'
|
||||||
{
|
}
|
||||||
$smType: "condition",
|
}
|
||||||
condition: 'template',
|
]
|
||||||
condition_data: {
|
}
|
||||||
value_template: 'states(switch.kitchen_light) == "on"'
|
},
|
||||||
|
{
|
||||||
|
$smType: "action",
|
||||||
|
action: "choose",
|
||||||
|
action_data: {
|
||||||
|
choose: [
|
||||||
|
{
|
||||||
|
conditions: [
|
||||||
|
{
|
||||||
|
$smType: "condition",
|
||||||
|
condition: 'time',
|
||||||
|
condition_data: {
|
||||||
|
after: {
|
||||||
|
hours: 16,
|
||||||
|
minutes: 30
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
}
|
],
|
||||||
},
|
sequence: [
|
||||||
{
|
{
|
||||||
$smType: "action",
|
$smType: 'action',
|
||||||
action: "choose",
|
action: 'event',
|
||||||
action_data: {
|
action_data: {
|
||||||
choose: [
|
event: "superImportant_time",
|
||||||
{
|
event_data: {
|
||||||
conditions: [
|
time: '4:30PM'
|
||||||
{
|
}
|
||||||
$smType: "condition",
|
|
||||||
condition: 'time',
|
|
||||||
condition_data: {
|
|
||||||
after: {
|
|
||||||
hours: 16,
|
|
||||||
minutes: 30
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
sequence: [
|
|
||||||
{
|
|
||||||
$smType: 'action',
|
|
||||||
action: 'event',
|
|
||||||
action_data: {
|
|
||||||
event: "superImportant_time",
|
|
||||||
event_data: {
|
|
||||||
time: '4:30PM'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
conditions: [
|
|
||||||
{
|
|
||||||
$smType: "condition",
|
|
||||||
condition: 'time',
|
|
||||||
condition_data: {
|
|
||||||
after: {
|
|
||||||
hours: 18,
|
|
||||||
minutes: 45
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
sequence: [
|
|
||||||
{
|
|
||||||
$smType: 'action',
|
|
||||||
action: 'event',
|
|
||||||
action_data: {
|
|
||||||
event: "superImportant_time",
|
|
||||||
event_data: {
|
|
||||||
time: '6:45PM'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
}
|
||||||
}
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
conditions: [
|
||||||
|
{
|
||||||
|
$smType: "condition",
|
||||||
|
condition: 'time',
|
||||||
|
condition_data: {
|
||||||
|
after: {
|
||||||
|
hours: 18,
|
||||||
|
minutes: 45
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
sequence: [
|
||||||
|
{
|
||||||
|
$smType: 'action',
|
||||||
|
action: 'event',
|
||||||
|
action_data: {
|
||||||
|
event: "superImportant_time",
|
||||||
|
event_data: {
|
||||||
|
time: '6:45PM'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$smType: 'action',
|
||||||
|
action: "service",
|
||||||
|
action_data: {
|
||||||
|
service: "light.turn_on",
|
||||||
|
data: {
|
||||||
|
entity_id: "light.kitchen"
|
||||||
}
|
}
|
||||||
],
|
}
|
||||||
} as AutomationData
|
}
|
||||||
|
],
|
||||||
|
} as AutomationData
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
import { AutomationData, AutomationSequenceNode } from "~/automations/types";
|
import { AutomationData } from "~/automations/types";
|
||||||
import { AutomationCondition } from "~/automations/types/conditions";
|
|
||||||
import { AutomationTrigger } from "~/automations/types/triggers";
|
import { AutomationTrigger } from "~/automations/types/triggers";
|
||||||
import { getDescriptionFromAutomationNode } from "~/automations/utils";
|
import { getDescriptionFromAutomationNode } from "~/automations/utils";
|
||||||
import useWindowSize from "~/utils/useWindowSize";
|
import useWindowSize from "~/utils/useWindowSize";
|
||||||
@@ -10,95 +9,111 @@ import DAGNode from "./DAGNode";
|
|||||||
import { SequenceNodes } from "./SequenceNodes";
|
import { SequenceNodes } from "./SequenceNodes";
|
||||||
import { useEditorStyles } from "./styles";
|
import { useEditorStyles } from "./styles";
|
||||||
import { Point } from "./types";
|
import { Point } from "./types";
|
||||||
|
import { AutomationSequenceNode } from '../../automations/types/index';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
automation: AutomationData;
|
automation: AutomationData;
|
||||||
onUpdate: (auto: AutomationData) => void;
|
onUpdate: (auto: AutomationData) => void;
|
||||||
}
|
}
|
||||||
export default function AutomationEditor({
|
export default function AutomationEditor({
|
||||||
automation,
|
automation,
|
||||||
onUpdate,
|
onUpdate,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
|
|
||||||
// state
|
// state
|
||||||
const {ratioWbh} = useWindowSize();
|
const { ratioWbh } = useWindowSize();
|
||||||
const {classes, theme} = useEditorStyles({});
|
const { classes, theme } = useEditorStyles({});
|
||||||
|
|
||||||
// alias
|
// alias
|
||||||
const nHDF = 1.5 // node horizontal distance factor
|
const nHDF = 1.5 // node horizontal distance factor (aspect ratio)
|
||||||
const graphHeight = 300;
|
const graphHeight = 300;
|
||||||
const graphWidth = Math.round(graphHeight * ratioWbh);
|
const graphWidth = Math.round(graphHeight * ratioWbh);
|
||||||
const pointTrigToCond: Point = [NODE_WIDTH*nHDF, NODE_HEIGHT/2]
|
const pointTrigToCond: Point = [NODE_WIDTH * nHDF, NODE_HEIGHT / 2]
|
||||||
|
const updateSequence = (i: number, node: AutomationSequenceNode | null) => {
|
||||||
// render funcs
|
const update = (sequence: AutomationSequenceNode[]) => onUpdate({
|
||||||
const renderTrigger = (trigger: AutomationTrigger, i: number) => {
|
...automation,
|
||||||
const nodeLoc: Point = [0 ,i*NODE_HEIGHT*1.25];
|
sequence,
|
||||||
return <>
|
})
|
||||||
<DAGNode key={`node.${i}`}
|
if (node === null) {
|
||||||
loc={nodeLoc}
|
update([
|
||||||
text={getDescriptionFromAutomationNode(trigger)}
|
...automation.sequence.slice(0, i),
|
||||||
color="red"
|
...automation.sequence.slice(i + 1),
|
||||||
onXClick={() => {
|
])
|
||||||
onUpdate({
|
} else {
|
||||||
...automation,
|
update([
|
||||||
trigger: [
|
...automation.sequence.slice(0, i),
|
||||||
...automation.trigger.slice(0, i),
|
node,
|
||||||
...automation.trigger.slice(i+1),
|
...automation.sequence.slice(i + 1),
|
||||||
]
|
])
|
||||||
})
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<DAGEdge
|
|
||||||
key={`edge.${i}`}
|
|
||||||
p1={[NODE_WIDTH , nodeLoc[1] + 0.5 * NODE_HEIGHT]}
|
|
||||||
p2={pointTrigToCond}
|
|
||||||
className={classes.dagEdge}
|
|
||||||
direction="1->2"
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// render
|
// render funcs
|
||||||
return <div className={classes.root} style={{
|
const renderTrigger = (trigger: AutomationTrigger, i: number) => {
|
||||||
flexDirection: ratioWbh >= 0.75 ? 'row' : 'column'
|
const nodeLoc: Point = [0, i * NODE_HEIGHT];
|
||||||
}}>
|
return <>
|
||||||
<AutoInfoBox
|
<DAGNode key={`node.${i}`}
|
||||||
className={classes.infoBox}
|
loc={nodeLoc}
|
||||||
metadata={automation.metadata}
|
text={getDescriptionFromAutomationNode(trigger)}
|
||||||
onUpdate={metadata => onUpdate({...automation, metadata})}
|
color="red"
|
||||||
|
onXClick={() => {
|
||||||
|
onUpdate({
|
||||||
|
...automation,
|
||||||
|
trigger: [
|
||||||
|
...automation.trigger.slice(0, i),
|
||||||
|
...automation.trigger.slice(i + 1),
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<DAGEdge
|
||||||
|
key={`edge.${i}`}
|
||||||
|
p1={[NODE_WIDTH, nodeLoc[1] + 0.5 * NODE_HEIGHT]}
|
||||||
|
p2={pointTrigToCond}
|
||||||
|
className={classes.dagEdge}
|
||||||
|
direction="1->2"
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
|
||||||
|
// render
|
||||||
|
return <div className={classes.root} style={{
|
||||||
|
flexDirection: ratioWbh >= 0.75 ? 'row' : 'column'
|
||||||
|
}}>
|
||||||
|
<AutoInfoBox
|
||||||
|
className={classes.infoBox}
|
||||||
|
metadata={automation.metadata}
|
||||||
|
onUpdate={metadata => onUpdate({ ...automation, metadata })}
|
||||||
|
/>
|
||||||
|
<div className={classes.dag}>
|
||||||
|
<svg
|
||||||
|
className={classes.svg}
|
||||||
|
viewBox={[0, 0, graphWidth, graphHeight].join(" ")}
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<defs>
|
||||||
|
<marker id="arrow" viewBox="0 0 10 10" refX="10" refY="5"
|
||||||
|
markerWidth="6" markerHeight="6"
|
||||||
|
orient="auto-start-reverse">
|
||||||
|
<path d="M 0 0 L 10 5 L 0 10 z" fill={theme.secondaryAccent} />
|
||||||
|
</marker>
|
||||||
|
</defs>
|
||||||
|
<g className="triggers">
|
||||||
|
{automation.trigger.map(renderTrigger)}
|
||||||
|
</g>
|
||||||
|
<SequenceNodes
|
||||||
|
styles={{ classes, theme }}
|
||||||
|
sequence={automation.sequence}
|
||||||
|
onUpdate={updateSequence}
|
||||||
|
nHDF={nHDF}
|
||||||
|
nodeHeight={NODE_HEIGHT}
|
||||||
|
nodeWidth={NODE_WIDTH}
|
||||||
|
triggerPoint={pointTrigToCond}
|
||||||
/>
|
/>
|
||||||
<div className={classes.dag}>
|
<circle className={classes.circle} cx={pointTrigToCond[0]} cy={pointTrigToCond[1]} r={2} />
|
||||||
<svg
|
<g className="actions">
|
||||||
className={classes.svg}
|
</g>
|
||||||
viewBox={[0,0,graphWidth, graphHeight].join(" ")}
|
</svg>
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
</div>
|
||||||
>
|
</div>
|
||||||
<defs>
|
|
||||||
<marker id="arrow" viewBox="0 0 10 10" refX="10" refY="5"
|
|
||||||
markerWidth="6" markerHeight="6"
|
|
||||||
orient="auto-start-reverse">
|
|
||||||
<path d="M 0 0 L 10 5 L 0 10 z" fill={theme.secondaryAccent} />
|
|
||||||
</marker>
|
|
||||||
</defs>
|
|
||||||
<g className="triggers">
|
|
||||||
{automation.trigger.map(renderTrigger)}
|
|
||||||
</g>
|
|
||||||
<SequenceNodes
|
|
||||||
styles={{classes, theme}}
|
|
||||||
sequence={automation.sequence}
|
|
||||||
onUpdate={sequence => onUpdate({
|
|
||||||
...automation,
|
|
||||||
sequence,
|
|
||||||
})}
|
|
||||||
nHDF={nHDF}
|
|
||||||
nodeHeight={NODE_HEIGHT}
|
|
||||||
nodeWidth={NODE_WIDTH}
|
|
||||||
triggerPoint={pointTrigToCond}
|
|
||||||
/>
|
|
||||||
<circle className={classes.circle} cx={pointTrigToCond[0]} cy={pointTrigToCond[1]} r={2}/>
|
|
||||||
<g className="actions">
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
}
|
||||||
@@ -5,131 +5,139 @@ import { Node } from "./types";
|
|||||||
|
|
||||||
|
|
||||||
export const useEditorStyles = createAppUseStyles(theme => ({
|
export const useEditorStyles = createAppUseStyles(theme => ({
|
||||||
root: {
|
root: {
|
||||||
height: '99%',
|
height: '99%',
|
||||||
width: '99%',
|
width: '99%',
|
||||||
color: theme.primaryAccent,
|
color: theme.primaryAccent,
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
},
|
},
|
||||||
dag: {
|
dag: {
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
borderStyle: 'solid',
|
borderStyle: 'solid',
|
||||||
borderColor: theme.secondaryAccent,
|
borderColor: theme.secondaryAccent,
|
||||||
width: '100%',
|
width: '100%',
|
||||||
},
|
},
|
||||||
svg: {
|
svg: {
|
||||||
height: '99%',
|
height: '99%',
|
||||||
width: '99%',
|
width: '99%',
|
||||||
padding: 0,
|
padding: 0,
|
||||||
margin: 0,
|
margin: 0,
|
||||||
},
|
},
|
||||||
circle: {
|
circle: {
|
||||||
fill: Color(theme.secondary).set('rgb.b', 125).hex(),
|
fill: Color(theme.secondary).set('rgb.b', 125).hex(),
|
||||||
},
|
},
|
||||||
infoBox: {
|
infoBox: {
|
||||||
paddingLeft: '10px',
|
paddingLeft: '10px',
|
||||||
paddingRight: '10px',
|
paddingRight: '10px',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
justifyContent: 'flex-start',
|
justifyContent: 'flex-start',
|
||||||
overflow: 'auto',
|
overflow: 'auto',
|
||||||
},
|
},
|
||||||
dagEdge: {
|
dagEdge: {
|
||||||
stroke: theme.secondaryAccent,
|
stroke: theme.secondaryAccent,
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
export const useNodeStyles = createAppUseStyles<{
|
export const useNodeStyles = createAppUseStyles<{
|
||||||
color: Node['color'],
|
color: Node['color'],
|
||||||
nodeHeight: number,
|
nodeHeight: number,
|
||||||
nodeWidth: number,
|
nodeWidth: number,
|
||||||
}>(theme => {
|
}>(theme => {
|
||||||
const edgeStyle: Styles = {
|
const edgeStyle: Styles = {
|
||||||
flex: '1',
|
flex: '1',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
flexWrap: 'nowrap',
|
flexWrap: 'nowrap',
|
||||||
borderRadius: '1em',
|
borderRadius: '1em',
|
||||||
justifyContent: 'space-around',
|
justifyContent: 'space-around',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
'&:hover': {
|
'&:hover': {
|
||||||
backgroundColor: theme.primaryAccent,
|
backgroundColor: theme.primaryAccent,
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
}
|
|
||||||
}
|
|
||||||
const buttonStyle: Styles = {
|
|
||||||
fontSize: '8px',
|
|
||||||
backgroundColor: "rgba(0,0,0,0)",
|
|
||||||
color: theme.primaryAccent,
|
|
||||||
borderStyle: 'none',
|
|
||||||
height: '15px',
|
|
||||||
width: '15px',
|
|
||||||
cursor: 'pointer',
|
|
||||||
transition: "500ms east-out",
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
root: {
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
justifyContent: 'flex-end',
|
|
||||||
height: `100%`,
|
|
||||||
maxHeight: `100%`,
|
|
||||||
maxWidth: '100%',
|
|
||||||
width: '100%',
|
|
||||||
fontSize: 10,
|
|
||||||
},
|
|
||||||
inner: ({color}) => ({
|
|
||||||
position: 'relative',
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'row',
|
|
||||||
backgroundColor: theme.secondary,
|
|
||||||
borderRadius: '1em',
|
|
||||||
flex: 1,
|
|
||||||
height: `calc(100% - 10px)`,
|
|
||||||
maxHeight: `calc(100% - 10px)`,
|
|
||||||
maxWidth: '100%',
|
|
||||||
borderTopWidth: '1px',
|
|
||||||
borderTopStyle: 'solid',
|
|
||||||
borderTopLeftRadius: '10px',
|
|
||||||
borderTopRightRadius: '10px',
|
|
||||||
borderTopColor: color === 'red' ? Color(theme.secondary).set('rgb.r', 125).hex() :
|
|
||||||
color === 'blue' ? Color(theme.secondary).set('rgb.b', 125).hex() :
|
|
||||||
color === 'green' ? Color(theme.secondary).set('rgb.g', 125).hex() :
|
|
||||||
'none'
|
|
||||||
}),
|
|
||||||
text: {
|
|
||||||
flex: 4,
|
|
||||||
display: 'flex',
|
|
||||||
textAlign: 'center',
|
|
||||||
justifyContent: 'center',
|
|
||||||
alignItems: 'center',
|
|
||||||
height: '100%',
|
|
||||||
maxHeight: '100%',
|
|
||||||
},
|
|
||||||
buttonDelete: {
|
|
||||||
...buttonStyle,
|
|
||||||
"&:hover": {
|
|
||||||
color: theme.primary,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
buttonEdit: {
|
|
||||||
...buttonStyle,
|
|
||||||
"&:hover": {
|
|
||||||
transform: "rotate(45deg)"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
leftEdge: {
|
|
||||||
...edgeStyle,
|
|
||||||
borderLeft: `1px ${theme.secondaryAccent} solid`,
|
|
||||||
borderTopRightRadius: 0,
|
|
||||||
borderBottomRightRadius: 0,
|
|
||||||
},
|
|
||||||
rightEdge: {
|
|
||||||
...edgeStyle,
|
|
||||||
borderRight: `1px ${theme.secondaryAccent} solid`,
|
|
||||||
borderTopLeftRadius: 0,
|
|
||||||
borderBottomLeftRadius: 0,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
const buttonStyle: Styles = {
|
||||||
|
fontSize: '8px',
|
||||||
|
backgroundColor: "rgba(0,0,0,0)",
|
||||||
|
color: theme.primaryAccent,
|
||||||
|
borderStyle: 'none',
|
||||||
|
height: '15px',
|
||||||
|
width: '15px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
transition: "500ms east-out",
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
root: {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
justifyContent: 'flex-end',
|
||||||
|
height: `100%`,
|
||||||
|
maxHeight: `100%`,
|
||||||
|
maxWidth: '100%',
|
||||||
|
width: '100%',
|
||||||
|
fontSize: 10,
|
||||||
|
},
|
||||||
|
inner: ({ color }) => ({
|
||||||
|
position: 'relative',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
backgroundColor: theme.secondary,
|
||||||
|
borderRadius: '1em',
|
||||||
|
flex: 1,
|
||||||
|
height: `100%`,
|
||||||
|
maxHeight: `100%`,
|
||||||
|
maxWidth: '100%',
|
||||||
|
marginTop: '2.5px',
|
||||||
|
marginBottom: '2.5px',
|
||||||
|
borderTopWidth: '1px',
|
||||||
|
borderTopStyle: 'solid',
|
||||||
|
borderTopLeftRadius: '10px',
|
||||||
|
borderTopRightRadius: '10px',
|
||||||
|
borderTopColor: color === 'red' ? Color(theme.secondary).set('rgb.r', 125).hex() :
|
||||||
|
color === 'blue' ? Color(theme.secondary).set('rgb.b', 125).hex() :
|
||||||
|
color === 'green' ? Color(theme.secondary).set('rgb.g', 125).hex() :
|
||||||
|
'none'
|
||||||
|
}),
|
||||||
|
textWrap: {
|
||||||
|
display: 'flex',
|
||||||
|
flex: 4,
|
||||||
|
textAlign: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
alignItems: 'center',
|
||||||
|
height: '100%',
|
||||||
|
maxHeight: '100%',
|
||||||
|
maxWidth: "50%",
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
overflow: "hidden",
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
},
|
||||||
|
buttonDelete: {
|
||||||
|
...buttonStyle,
|
||||||
|
"&:hover": {
|
||||||
|
color: theme.primary,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
buttonEdit: {
|
||||||
|
...buttonStyle,
|
||||||
|
"&:hover": {
|
||||||
|
transform: "rotate(45deg)"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
leftEdge: {
|
||||||
|
...edgeStyle,
|
||||||
|
borderLef: `1px ${theme.secondaryAccent} solid`,
|
||||||
|
borderTopRightRadius: 0,
|
||||||
|
borderBottomRightRadius: 0,
|
||||||
|
},
|
||||||
|
rightEdge: {
|
||||||
|
...edgeStyle,
|
||||||
|
borderRight: `1px ${theme.secondaryAccent} solid`,
|
||||||
|
borderTopLeftRadius: 0,
|
||||||
|
borderBottomLeftRadius: 0,
|
||||||
|
},
|
||||||
|
}
|
||||||
})
|
})
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
export type Point = [number, number];
|
export type Point = [number, number];
|
||||||
export interface Node {
|
export interface Node {
|
||||||
loc: Point;
|
loc: Point;
|
||||||
text: JSX.Element | string;
|
text: string;
|
||||||
color: 'red' | 'blue' | 'green';
|
color: 'red' | 'blue' | 'green';
|
||||||
}
|
}
|
||||||
export interface Edge {
|
export interface Edge {
|
||||||
from: string;
|
from: string;
|
||||||
to: string;
|
to: string;
|
||||||
direction: '1->2' | '1<->2' | '1<-2';
|
direction: '1->2' | '1<->2' | '1<-2';
|
||||||
}
|
}
|
||||||
export type EdgeDirection = Edge['direction'];
|
export type EdgeDirection = Edge['direction'];
|
||||||
export interface DAG {
|
export interface DAG {
|
||||||
nodes: Record<string,Node>;
|
nodes: Record<string, Node>;
|
||||||
edges: Array<Edge>;
|
edges: Array<Edge>;
|
||||||
}
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
import { ComponentMeta, ComponentStory } from "@storybook/react";
|
|
||||||
import { useState } from "react";
|
|
||||||
import { AutomationAction } from "~/automations/types/actions";
|
|
||||||
import { usePageTheme } from "~/styles/page";
|
|
||||||
import { SequenceEditor } from ".";
|
|
||||||
|
|
||||||
export default {
|
|
||||||
title: 'SequenceEditor',
|
|
||||||
component: SequenceEditor,
|
|
||||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
|
||||||
} as ComponentMeta<typeof SequenceEditor>;
|
|
||||||
|
|
||||||
|
|
||||||
const Template: ComponentStory<typeof SequenceEditor> = ({node, ...args}) => {
|
|
||||||
const {classes} = usePageTheme({});
|
|
||||||
const [data, setData] = useState(node);
|
|
||||||
return <div className={classes.page}>
|
|
||||||
<SequenceEditor {...args}
|
|
||||||
node={data}
|
|
||||||
onUpdate={data => {
|
|
||||||
setData(data)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ServiceAction = Template.bind({})
|
|
||||||
ServiceAction.args = {
|
|
||||||
node: {
|
|
||||||
$smType: 'action',
|
|
||||||
action: 'service',
|
|
||||||
action_data: {
|
|
||||||
service: 'switch.toggle',
|
|
||||||
data: {},
|
|
||||||
target: {},
|
|
||||||
}
|
|
||||||
} as AutomationAction
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { FC } from "react";
|
|
||||||
import { ChooseAction } from "~/automations/types/actions";
|
|
||||||
|
|
||||||
|
|
||||||
export const ChooseEditor: FC<{
|
|
||||||
node: ChooseAction,
|
|
||||||
onUpdate: (u: ChooseAction) => void,
|
|
||||||
}> = ({
|
|
||||||
node,
|
|
||||||
onUpdate,
|
|
||||||
}) => {
|
|
||||||
|
|
||||||
return <div>
|
|
||||||
<div>
|
|
||||||
<span>{node.action}</span>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<div>
|
|
||||||
{node.action_data.choose.map( ({conditions, sequence}, i) => <div>
|
|
||||||
<button>X</button>
|
|
||||||
<div>{i > 0 ? "else if" : 'if'}</div>
|
|
||||||
<div>Condition</div>
|
|
||||||
<div>
|
|
||||||
{sequence.map( s => s.$smType)}
|
|
||||||
</div>
|
|
||||||
</div>)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user