From 22bc5dfcf63a444be53bfffcba588b3177601d78 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Wed, 24 Nov 2021 11:30:00 -0500 Subject: [PATCH] =?UTF-8?q?=1B[200~latest=20changes=20to=20web~?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/.editorconfig | 36 ++ web/.vscode/launch.json | 18 - .../components/AutomationEditor/DAGNode.tsx | 68 ++-- .../AutomationEditor/SequenceNodes.tsx | 191 +++++++--- .../components/AutomationEditor/constants.ts | 4 +- .../AutomationEditor/index.stories.tsx | 358 +++++++++--------- web/src/components/AutomationEditor/index.tsx | 183 +++++---- web/src/components/AutomationEditor/styles.ts | 254 +++++++------ web/src/components/AutomationEditor/types.ts | 16 +- .../components/ChooseEditor/index.stories.tsx | 38 -- web/src/components/ChooseEditor/index.tsx | 30 -- 11 files changed, 636 insertions(+), 560 deletions(-) create mode 100644 web/.editorconfig delete mode 100644 web/.vscode/launch.json delete mode 100644 web/src/components/ChooseEditor/index.stories.tsx delete mode 100644 web/src/components/ChooseEditor/index.tsx diff --git a/web/.editorconfig b/web/.editorconfig new file mode 100644 index 0000000..7c0e9b0 --- /dev/null +++ b/web/.editorconfig @@ -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 + diff --git a/web/.vscode/launch.json b/web/.vscode/launch.json deleted file mode 100644 index 200d9e9..0000000 --- a/web/.vscode/launch.json +++ /dev/null @@ -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" - ] - } - ] -} \ No newline at end of file diff --git a/web/src/components/AutomationEditor/DAGNode.tsx b/web/src/components/AutomationEditor/DAGNode.tsx index 3d18a29..c4c7514 100644 --- a/web/src/components/AutomationEditor/DAGNode.tsx +++ b/web/src/components/AutomationEditor/DAGNode.tsx @@ -7,42 +7,42 @@ import { Node } from "./types" export interface NodeProp extends Node { - height?: number; - width?: number; - isOpen?: boolean; - onXClick?: () => void; - onOpenClick?: () => void; + height?: number; + width?: number; + onXClick?: () => void; + onOpenClick?: () => void; } export default ({ - loc: [x,y], - text, - height=NODE_HEIGHT, - width=NODE_WIDTH, - onXClick=() => {}, - onOpenClick=() => {}, - isOpen=false, - color, + loc: [x, y], + text, + height = NODE_HEIGHT, + width = NODE_WIDTH, + onXClick = () => { }, + onOpenClick = () => { }, + color, }: NodeProp) => { - const {classes, theme} = useNodeStyles({ - color, - nodeHeight: height, - nodeWidth: width, - }); - return -
-
-
- -
-
- {text} -
-
- -
-
+ const { classes, theme } = useNodeStyles({ + color, + nodeHeight: height, + nodeWidth: width, + }); + return +
+
+
+
- +
+ + {text} + +
+
+ +
+
+
+
} diff --git a/web/src/components/AutomationEditor/SequenceNodes.tsx b/web/src/components/AutomationEditor/SequenceNodes.tsx index 5bdf225..ac7bda8 100644 --- a/web/src/components/AutomationEditor/SequenceNodes.tsx +++ b/web/src/components/AutomationEditor/SequenceNodes.tsx @@ -7,54 +7,147 @@ import { useNodeStyles } from "./styles"; import { Point } from "./types"; - -export const SequenceNodes: FC<{ - styles: ReturnType, - sequence: AutomationSequenceNode[], - onUpdate: (s: AutomationSequenceNode[]) => void, - nodeWidth: number, - nodeHeight: number, - triggerPoint: Point, - nHDF: number, -}> = ({ - styles: { classes, theme }, - sequence, - onUpdate, - nodeWidth, - nodeHeight, - triggerPoint, - nHDF, +interface Props extends RenderSequenceProps { + styles: ReturnType, + sequence: AutomationSequenceNode[], + triggerPoint: Point, +} +export const SequenceNodes: FC = ({ + sequence, + triggerPoint, + ...renderSequenceProps }) => { - const renderSequence = (node: AutomationSequenceNode, i: number) => { - const nodeLoc: Point = [triggerPoint[0] + nodeWidth/2 , 0]; - let lastNodeLoc = triggerPoint; - if (i > 0) { - lastNodeLoc = [nodeLoc[0] + nodeWidth*((i - 1)*nHDF+1), nodeLoc[1] + nodeHeight/2]; - nodeLoc[0] += nodeWidth*i*nHDF - } - return <> - { - onUpdate([ - ...sequence.slice(0, i), - ...sequence.slice(i+1), - ]) - }} - /> - - + const renderSequence = makeRenderSequence(renderSequenceProps); + return + {sequence.map((n, i) => renderSequence(triggerPoint, n, i))} + +} + +interface RenderSequenceProps { + styles: ReturnType, + onUpdate: (i: number, s: AutomationSequenceNode | null) => void, + nodeWidth: number, + nodeHeight: number, + nHDF: number, +} +const makeRenderSequence = ({ + onUpdate, + nodeHeight, + nodeWidth, + nHDF, + styles: { classes } +}: RenderSequenceProps) => ( + startPoint: Point, + node: AutomationSequenceNode, + i: number +) => { + const nodeLoc: Point = [startPoint[0] + nodeWidth / 2, 0]; + let lastNodeLoc = startPoint; + if (i > 0) { + lastNodeLoc = [nodeLoc[0] + nodeWidth * ((i - 1) * nHDF + 1), nodeLoc[1] + nodeHeight / 2]; + nodeLoc[0] += nodeWidth * i * nHDF } - return - {sequence.map(renderSequence)} - -} \ No newline at end of file + const curretEdgeLoc: Point = [nodeLoc[0], nodeLoc[1] + nodeHeight / 2]; + const nextAddLoc: Point = [nodeLoc[0] + nodeWidth * nHDF, nodeLoc[1] + nodeHeight / 2]; + return <> + + onUpdate(i, null)} + /> + + + } + +export function* getJSXNodes( + { classes }: ReturnType, + onUpdate: (i: number, s: AutomationSequenceNode | null) => void, it: Generator +) { + let next = it.next(); + while (!next.done) { + const { node, nodeLoc, curretEdgeLoc, nextAddLoc, lastStartPoint, nodeHeight, nodeWidth } = next.value; + yield <> + + onUpdate(i, null)} + /> + + + } +} + +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 { + 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 +} diff --git a/web/src/components/AutomationEditor/constants.ts b/web/src/components/AutomationEditor/constants.ts index 272853f..f7485fe 100644 --- a/web/src/components/AutomationEditor/constants.ts +++ b/web/src/components/AutomationEditor/constants.ts @@ -1,5 +1,5 @@ -export const NODE_WIDTH = 90 as const; -export const NODE_HEIGHT = 40 as const; \ No newline at end of file +export const NODE_WIDTH = 100 as const; +export const NODE_HEIGHT = 40 as const; diff --git a/web/src/components/AutomationEditor/index.stories.tsx b/web/src/components/AutomationEditor/index.stories.tsx index 9741274..8321231 100644 --- a/web/src/components/AutomationEditor/index.stories.tsx +++ b/web/src/components/AutomationEditor/index.stories.tsx @@ -5,197 +5,207 @@ import { usePageTheme } from "~/styles/page"; import AutomationEditor from "."; export default { - title: 'AutomationEditor', - component: AutomationEditor, - parameters: { actions: { argTypesRegex: '^on.*' } }, - } as ComponentMeta; - + title: 'AutomationEditor', + component: AutomationEditor, + parameters: { actions: { argTypesRegex: '^on.*' } }, +} as ComponentMeta; -const Template: ComponentStory = ({automation, ...args}) => { - const {classes} = usePageTheme({}); - const [data, setData] = useState(automation); - return
- { - setData(data) - }} + +const Template: ComponentStory = ({ automation, ...args }) => { + const { classes } = usePageTheme({}); + const [data, setData] = useState(automation); + return
+ { + setData(data) + }} /> -
+
} export const ServiceAction = Template.bind({}) ServiceAction.args = { - automation: { - metadata: { - id: "X12314akx", - alias: "root", - description: 'Really Long Description', - mode: 'single', - }, - trigger: [ - { - platform: 'time', - at: '10:00:00' - }, - { - platform: "device", - device_id: "34749", - domain: "zha", - type: "remote_button_double_press", - subtype: "remote_button_double_press" - } - ], - sequence: [ - { - $smType: "condition", - condition: 'and', + automation: { + metadata: { + id: "X12314akx", + alias: "root", + description: 'Really Long Description', + mode: 'single', + }, + trigger: [ + { + platform: 'time', + at: '10:00:00' + }, + { + platform: "device", + device_id: "34749", + domain: "zha", + type: "remote_button_double_press", + subtype: "remote_button_double_press" + } + ], + sequence: [ + { + $smType: "condition", + condition: 'and', + condition_data: { + conditions: [ + { + $smType: 'condition', + condition: 'numeric_state', condition_data: { - conditions: [ - { - $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"' - } - } - ] + entity_id: 'sensor.temperature_kitchen', + below: '15', } + }, + { + $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" }, - { - $smType: "action", - action: "service", - 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", - } - } + data: { + media_content_id: "Good Morning", + media_content_type: "SPOTIFY", } - ], - } as AutomationData + } + } + ], + } as AutomationData } export const ChooseAction = Template.bind({}) ChooseAction.args = { - automation: { - metadata: { - id: "X12314akx", - alias: "root", - description: 'Really Long Description', - mode: 'single', - }, - trigger: [ - { - platform: 'time', - at: '10:00:00' - }, - { - platform: "device", - device_id: "34749", - domain: "zha", - type: "remote_button_double_press", - subtype: "remote_button_double_press" - } - ], - sequence: [ - { - $smType: "condition", - condition: 'and', + automation: { + metadata: { + id: "X12314akx", + alias: "root", + description: 'Really Long Description', + mode: 'single', + }, + trigger: [ + { + platform: 'time', + at: '10:00:00' + }, + { + platform: "device", + device_id: "34749", + domain: "zha", + type: "remote_button_double_press", + subtype: "remote_button_double_press" + } + ], + sequence: [ + { + $smType: "condition", + condition: 'and', + condition_data: { + conditions: [ + { + $smType: 'condition', + condition: 'numeric_state', condition_data: { - conditions: [ - { - $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"' + entity_id: 'sensor.temperature_kitchen', + below: '15', + } + }, + { + $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 } } - ] - } - }, - { - $smType: "action", - action: "choose", - action_data: { - choose: [ - { - conditions: [ - { - $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' - } - } - } - ] + } + ], + 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' + } + } + } + ] + } + ] + } + }, + { + $smType: 'action', + action: "service", + action_data: { + service: "light.turn_on", + data: { + entity_id: "light.kitchen" } - ], - } as AutomationData -} \ No newline at end of file + } + } + ], + } as AutomationData +} diff --git a/web/src/components/AutomationEditor/index.tsx b/web/src/components/AutomationEditor/index.tsx index 79dd18e..48a1b4f 100644 --- a/web/src/components/AutomationEditor/index.tsx +++ b/web/src/components/AutomationEditor/index.tsx @@ -1,5 +1,4 @@ -import { AutomationData, AutomationSequenceNode } from "~/automations/types"; -import { AutomationCondition } from "~/automations/types/conditions"; +import { AutomationData } from "~/automations/types"; import { AutomationTrigger } from "~/automations/types/triggers"; import { getDescriptionFromAutomationNode } from "~/automations/utils"; import useWindowSize from "~/utils/useWindowSize"; @@ -10,95 +9,111 @@ import DAGNode from "./DAGNode"; import { SequenceNodes } from "./SequenceNodes"; import { useEditorStyles } from "./styles"; import { Point } from "./types"; +import { AutomationSequenceNode } from '../../automations/types/index'; interface Props { - automation: AutomationData; - onUpdate: (auto: AutomationData) => void; + automation: AutomationData; + onUpdate: (auto: AutomationData) => void; } export default function AutomationEditor({ - automation, - onUpdate, + automation, + onUpdate, }: Props) { - // state - const {ratioWbh} = useWindowSize(); - const {classes, theme} = useEditorStyles({}); + // state + const { ratioWbh } = useWindowSize(); + const { classes, theme } = useEditorStyles({}); - // alias - const nHDF = 1.5 // node horizontal distance factor - const graphHeight = 300; - const graphWidth = Math.round(graphHeight * ratioWbh); - const pointTrigToCond: Point = [NODE_WIDTH*nHDF, NODE_HEIGHT/2] - - // render funcs - const renderTrigger = (trigger: AutomationTrigger, i: number) => { - const nodeLoc: Point = [0 ,i*NODE_HEIGHT*1.25]; - return <> - { - onUpdate({ - ...automation, - trigger: [ - ...automation.trigger.slice(0, i), - ...automation.trigger.slice(i+1), - ] - }) - }} - /> - - + // alias + const nHDF = 1.5 // node horizontal distance factor (aspect ratio) + const graphHeight = 300; + const graphWidth = Math.round(graphHeight * ratioWbh); + const pointTrigToCond: Point = [NODE_WIDTH * nHDF, NODE_HEIGHT / 2] + const updateSequence = (i: number, node: AutomationSequenceNode | null) => { + const update = (sequence: AutomationSequenceNode[]) => onUpdate({ + ...automation, + sequence, + }) + if (node === null) { + update([ + ...automation.sequence.slice(0, i), + ...automation.sequence.slice(i + 1), + ]) + } else { + update([ + ...automation.sequence.slice(0, i), + node, + ...automation.sequence.slice(i + 1), + ]) } + }; - // render - return
= 0.75 ? 'row' : 'column' - }}> - onUpdate({...automation, metadata})} + // render funcs + const renderTrigger = (trigger: AutomationTrigger, i: number) => { + const nodeLoc: Point = [0, i * NODE_HEIGHT]; + return <> + { + onUpdate({ + ...automation, + trigger: [ + ...automation.trigger.slice(0, i), + ...automation.trigger.slice(i + 1), + ] + }) + }} + /> + + + } + + // render + return
= 0.75 ? 'row' : 'column' + }}> + onUpdate({ ...automation, metadata })} + /> +
+ + + + + + + + {automation.trigger.map(renderTrigger)} + + -
- - - - - - - - {automation.trigger.map(renderTrigger)} - - onUpdate({ - ...automation, - sequence, - })} - nHDF={nHDF} - nodeHeight={NODE_HEIGHT} - nodeWidth={NODE_WIDTH} - triggerPoint={pointTrigToCond} - /> - - - - -
-
-} \ No newline at end of file + + + + +
+
+} diff --git a/web/src/components/AutomationEditor/styles.ts b/web/src/components/AutomationEditor/styles.ts index 566caa8..065635f 100644 --- a/web/src/components/AutomationEditor/styles.ts +++ b/web/src/components/AutomationEditor/styles.ts @@ -5,131 +5,139 @@ import { Node } from "./types"; export const useEditorStyles = createAppUseStyles(theme => ({ - root: { - height: '99%', - width: '99%', - color: theme.primaryAccent, - display: 'flex', - flexDirection: 'row', - }, - dag: { - borderWidth: 1, - borderStyle: 'solid', - borderColor: theme.secondaryAccent, - width: '100%', - }, - svg: { - height: '99%', - width: '99%', - padding: 0, - margin: 0, - }, - circle: { - fill: Color(theme.secondary).set('rgb.b', 125).hex(), - }, - infoBox: { - paddingLeft: '10px', - paddingRight: '10px', - display: 'flex', - flexDirection: 'column', - justifyContent: 'flex-start', - overflow: 'auto', - }, - dagEdge: { - stroke: theme.secondaryAccent, - }, + root: { + height: '99%', + width: '99%', + color: theme.primaryAccent, + display: 'flex', + flexDirection: 'row', + }, + dag: { + borderWidth: 1, + borderStyle: 'solid', + borderColor: theme.secondaryAccent, + width: '100%', + }, + svg: { + height: '99%', + width: '99%', + padding: 0, + margin: 0, + }, + circle: { + fill: Color(theme.secondary).set('rgb.b', 125).hex(), + }, + infoBox: { + paddingLeft: '10px', + paddingRight: '10px', + display: 'flex', + flexDirection: 'column', + justifyContent: 'flex-start', + overflow: 'auto', + }, + dagEdge: { + stroke: theme.secondaryAccent, + }, })) export const useNodeStyles = createAppUseStyles<{ - color: Node['color'], - nodeHeight: number, - nodeWidth: number, + color: Node['color'], + nodeHeight: number, + nodeWidth: number, }>(theme => { - const edgeStyle: Styles = { - flex: '1', - display: 'flex', - flexDirection: 'column', - flexWrap: 'nowrap', - borderRadius: '1em', - justifyContent: 'space-around', - alignItems: 'center', - '&:hover': { - backgroundColor: theme.primaryAccent, - cursor: 'pointer', - } + const edgeStyle: Styles = { + flex: '1', + display: 'flex', + flexDirection: 'column', + flexWrap: 'nowrap', + borderRadius: '1em', + justifyContent: 'space-around', + alignItems: 'center', + '&:hover': { + backgroundColor: theme.primaryAccent, + 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, - }, - } -}) \ No newline at end of file + } + 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, + }, + } +}) diff --git a/web/src/components/AutomationEditor/types.ts b/web/src/components/AutomationEditor/types.ts index 8a6f109..3880d45 100644 --- a/web/src/components/AutomationEditor/types.ts +++ b/web/src/components/AutomationEditor/types.ts @@ -1,16 +1,16 @@ export type Point = [number, number]; export interface Node { - loc: Point; - text: JSX.Element | string; - color: 'red' | 'blue' | 'green'; + loc: Point; + text: string; + color: 'red' | 'blue' | 'green'; } export interface Edge { - from: string; - to: string; - direction: '1->2' | '1<->2' | '1<-2'; + from: string; + to: string; + direction: '1->2' | '1<->2' | '1<-2'; } export type EdgeDirection = Edge['direction']; export interface DAG { - nodes: Record; - edges: Array; + nodes: Record; + edges: Array; } diff --git a/web/src/components/ChooseEditor/index.stories.tsx b/web/src/components/ChooseEditor/index.stories.tsx deleted file mode 100644 index 9845d15..0000000 --- a/web/src/components/ChooseEditor/index.stories.tsx +++ /dev/null @@ -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; - - -const Template: ComponentStory = ({node, ...args}) => { - const {classes} = usePageTheme({}); - const [data, setData] = useState(node); - return
- { - setData(data) - }} - /> -
-} - -export const ServiceAction = Template.bind({}) -ServiceAction.args = { - node: { - $smType: 'action', - action: 'service', - action_data: { - service: 'switch.toggle', - data: {}, - target: {}, - } - } as AutomationAction -} \ No newline at end of file diff --git a/web/src/components/ChooseEditor/index.tsx b/web/src/components/ChooseEditor/index.tsx deleted file mode 100644 index 8663e63..0000000 --- a/web/src/components/ChooseEditor/index.tsx +++ /dev/null @@ -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
-
- {node.action} -
-
-
- {node.action_data.choose.map( ({conditions, sequence}, i) =>
- -
{i > 0 ? "else if" : 'if'}
-
Condition
-
- {sequence.map( s => s.$smType)} -
-
)} -
-
-
-} \ No newline at end of file