From 019fa23758929bbbc1d799358eb2a73b7da3a3d7 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Wed, 17 Nov 2021 12:41:21 -0500 Subject: [PATCH] all work --- .../components/ChooseEditor/index.stories.tsx | 38 +++++++++++++++++++ web/src/components/ChooseEditor/index.tsx | 30 +++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 web/src/components/ChooseEditor/index.stories.tsx create mode 100644 web/src/components/ChooseEditor/index.tsx diff --git a/web/src/components/ChooseEditor/index.stories.tsx b/web/src/components/ChooseEditor/index.stories.tsx new file mode 100644 index 0000000..9845d15 --- /dev/null +++ b/web/src/components/ChooseEditor/index.stories.tsx @@ -0,0 +1,38 @@ +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 new file mode 100644 index 0000000..8663e63 --- /dev/null +++ b/web/src/components/ChooseEditor/index.tsx @@ -0,0 +1,30 @@ +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