From 90d4fbf8f6170020a87141670adc33e56a137b23 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Wed, 15 Dec 2021 13:18:42 -0500 Subject: [PATCH] functional modal --- .../NodeEditor/OptionManager/ActionChoose.tsx | 4 +- .../NodeEditor/OptionManager/ActionDevice.tsx | 4 +- .../NodeEditor/OptionManager/ActionEvent.tsx | 4 +- .../NodeEditor/OptionManager/ActionRepeat.tsx | 4 +- .../OptionManager/ActionService.tsx | 4 +- .../NodeEditor/OptionManager/ActionWait.tsx | 6 +-- .../OptionManager/ConditionLogic.tsx | 12 ++--- .../NodeEditor/OptionManager/Generic.tsx | 4 +- .../NodeEditor/OptionManager/index.ts | 3 ++ .../components/NodeEditor/index.stories.tsx | 41 ++++++++++----- webapp/src/components/NodeEditor/index.tsx | 51 ++++++++++--------- webapp/src/components/NodeEditor/styles.ts | 31 ++--------- 12 files changed, 80 insertions(+), 88 deletions(-) diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx index d818a0c..8985c2a 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx @@ -19,7 +19,7 @@ export const ActionChooseState: OptionManager = { }, renderOptionList: (state, setState) => { const update = updateActionData(state, setState); - return
+ return <> = { value={state.action_data.default} onChange={d => update({ default: d })} /> -
+ } } diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionDevice.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionDevice.tsx index 89b476d..e864091 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionDevice.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionDevice.tsx @@ -32,7 +32,7 @@ export const ActionDeviceState: OptionManager = { ), renderOptionList: (state, setState) => { const update = updateActionData(state, setState); - return
+ return <> = { value={state.action_data.entity_id ?? ""} onChange={entity_id => update({ entity_id, domain: entity_id.split('.')[0] })} /> -
+ } } diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionEvent.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionEvent.tsx index 3e18a49..a1be7db 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionEvent.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionEvent.tsx @@ -20,7 +20,7 @@ export const ActionEventState: OptionManager = { ), renderOptionList: (state, setState) => { const update = updateActionData(state, setState); - return
+ return <> = { value={state.action_data.event_data} onChange={event_data => update({ event_data })} /> -
+ } } diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionRepeat.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionRepeat.tsx index 93b0464..930653e 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionRepeat.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionRepeat.tsx @@ -26,7 +26,7 @@ export const ActionRepeatState: OptionManager = { ), renderOptionList: (state, setState) => { const update = updateActionData(state, setState); - return
+ return <> = { value={state.action_data.repeat.sequence ?? []} onChange={sequence => update({ repeat: { ...state.action_data.repeat, sequence } })} /> -
+ } } diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionService.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionService.tsx index a9dfd6d..17aeb12 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionService.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionService.tsx @@ -23,7 +23,7 @@ export const ActionCallServiceState: OptionManager = { renderOptionList: (state, setState) => { const { service, alias = "", target } = state.action_data; const update = updateActionData(state, setState); - return
+ return <> = { value={target} onChange={target => update({ target })} /> -
+ } } diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx index 44e2ab3..76a7d91 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionWait.tsx @@ -23,10 +23,10 @@ export const ActionWaitState: OptionManager = { ), renderOptionList: (state, setState) => { const update = updateActionData(state, setState); - return
+ return <> update({ alias })} /> = { value={state.action_data.continue_on_timeout ?? false} onChange={continue_on_timeout => update({ continue_on_timeout })} /> -
+ } } diff --git a/webapp/src/components/NodeEditor/OptionManager/ConditionLogic.tsx b/webapp/src/components/NodeEditor/OptionManager/ConditionLogic.tsx index afb16e7..8f22285 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ConditionLogic.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ConditionLogic.tsx @@ -13,11 +13,9 @@ export const ConditionLogicState: OptionManager = { } }), isReady: _ => true, - renderOptionList: (state, setState) =>
- { }} - /> -
+ renderOptionList: (state, setState) => { }} + /> } diff --git a/webapp/src/components/NodeEditor/OptionManager/Generic.tsx b/webapp/src/components/NodeEditor/OptionManager/Generic.tsx index bef1e30..dc4b13f 100644 --- a/webapp/src/components/NodeEditor/OptionManager/Generic.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/Generic.tsx @@ -4,7 +4,7 @@ import { OptionManager } from "./OptionManager"; export const Generic: OptionManager = { defaultState: () => ({}), isReady: _ => true, - renderOptionList: () =>
+ renderOptionList: () => <> THIS IS NOT SUPPORTED YET! -
+ } diff --git a/webapp/src/components/NodeEditor/OptionManager/index.ts b/webapp/src/components/NodeEditor/OptionManager/index.ts index 39b09f3..7e9c677 100644 --- a/webapp/src/components/NodeEditor/OptionManager/index.ts +++ b/webapp/src/components/NodeEditor/OptionManager/index.ts @@ -17,6 +17,9 @@ export const useEditorNodeState = (node: AutomationNode) => { nodeType, subType, subTypes, + get data() { + return state + }, renderOptionList() { return optionManager.renderOptionList(state, setState); }, diff --git a/webapp/src/components/NodeEditor/index.stories.tsx b/webapp/src/components/NodeEditor/index.stories.tsx index d4a7fd0..af9509c 100644 --- a/webapp/src/components/NodeEditor/index.stories.tsx +++ b/webapp/src/components/NodeEditor/index.stories.tsx @@ -3,13 +3,26 @@ import { ComponentMeta, ComponentStory } from '@storybook/react'; import { NodeEditor } from "."; import { usePageTheme } from "styles/page"; import { AutomationCondition } from "types/automations/conditions"; +import { Button } from "components/Inputs/Button"; +import { useState } from 'react'; +import { Modal } from "components/Modal"; export default { title: 'NodeEditor', component: NodeEditor, parameters: { actions: { argTypesRegex: '^on.*' } }, - args: {} + args: { + node: { + $smType: 'action', + action: 'service', + action_data: { + 'data': {}, + 'service': '', + 'target': '', + } + } + } } as ComponentMeta const Base: ComponentStory = props => { @@ -19,21 +32,9 @@ const Base: ComponentStory = props => { }; export const Action = Base.bind({}) -Action.args = { - ...Action.args, - node: { - $smType: 'action', - action: 'service', - action_data: { - 'data': {}, - 'service': '', - 'target': '', - } - } -} export const SingleOption = Action.bind({}) SingleOption.args = { - ...Action.args, + ...SingleOption.args, allowedTypes: ['action'], } export const Condition = Action.bind({}) @@ -66,3 +67,15 @@ Condition.args = { } } as AutomationCondition, } + + +export const InAModal: ComponentStory = props => { + const { classes } = usePageTheme({}); + const [open, setOpen] = useState(false); + return
+ + + setOpen(!open)} /> + +
+}; diff --git a/webapp/src/components/NodeEditor/index.tsx b/webapp/src/components/NodeEditor/index.tsx index 8fa4ce0..34a28ce 100644 --- a/webapp/src/components/NodeEditor/index.tsx +++ b/webapp/src/components/NodeEditor/index.tsx @@ -12,40 +12,43 @@ import { Button } from "components/Inputs/Button"; export interface Props { node: AutomationNode allowedTypes?: Array; + onClose?: () => void; + onSave?: (n: AutomationNode) => void; } export const NodeEditor: FC = ({ node, - allowedTypes = ["action", "condition", "trigger"] + allowedTypes = ["action", "condition", "trigger"], + onClose = () => { }, + onSave = () => { }, }) => { const { classes } = useNodeEditorStyles({}); const state = useEditorNodeState(node); return
-
-
-
+
-
-
- {allowedTypes.length > 1 ? : {state.nodeType}} - {state.nodeType !== 'condition' ? : <>} - {state.renderOptionList()} -
-
- - -
+
+
+ {allowedTypes.length > 1 ? : {state.nodeType}} + {state.nodeType !== 'condition' ? : <>} + {state.renderOptionList()} +
+
+ +
} diff --git a/webapp/src/components/NodeEditor/styles.ts b/webapp/src/components/NodeEditor/styles.ts index a27724d..90dbd28 100644 --- a/webapp/src/components/NodeEditor/styles.ts +++ b/webapp/src/components/NodeEditor/styles.ts @@ -5,36 +5,10 @@ export const useNodeEditorStyles = createAppUseStyles<{ }>(theme => ({ root: { - position: 'absolute', - display: 'flex', - justifyContent: 'center', - alignItems: 'center', - width: '100vw', - height: '100vh', - left: '0', - top: '0', - }, - background: { - position: 'absolute', - zIndex: 0, - width: '100vw', - height: '100vw', - backgroundColor: Color(theme.secondary).alpha(0.5).hex(), - }, - inner: { - zIndex: 1, - maxWidth: '80%', - maxHeight: '60%', - minHeight: '200px', - minWidth: '200px', - borderRadius: '20px', - padding: '15px', display: 'flex', flexDirection: 'column', - backgroundColor: theme.primary, - borderSize: '1px', - borderStyle: 'solid', - borderColor: theme.primaryAccent, + justifyContent: 'center', + alignItems: 'center', }, title: { textAlign: 'center', @@ -52,5 +26,6 @@ export const useNodeEditorStyles = createAppUseStyles<{ flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', + width: '100%', } }))