diff --git a/webapp/src/components/AutomationEditor/index.stories.tsx b/webapp/src/components/AutomationEditor/index.stories.tsx index bce1f26..9b12162 100644 --- a/webapp/src/components/AutomationEditor/index.stories.tsx +++ b/webapp/src/components/AutomationEditor/index.stories.tsx @@ -101,3 +101,23 @@ Simple.args = { ] } } + + +export const EmptyStart = Template.bind({}) +EmptyStart.args = { + ...EmptyStart.args, + automation: { + metadata: { + id: "random", + alias: "Random", + description: "Example Metadata", + trigger_variables: { + 'wowo': '!' + }, + mode: 'single', + }, + trigger: [ + ], + sequence: [] + } +} diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx index 7ec6fd0..d817c2c 100644 --- a/webapp/src/components/AutomationEditor/index.tsx +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -82,6 +82,19 @@ export const AutomationEditor: FC = ({ automation.trigger, [1.5, 0.5], updateTriggers, + () => { + setModalState({ + trigger: { + $smType: "trigger", + platform: "device", + device_id: "", + domain: "", + type: "", + subtype: "" + }, + onSave: (t) => updateTriggers([...automation.trigger, t]) + }); + }, (trigger, onSave) => setModalState({ trigger, onSave, diff --git a/webapp/src/components/AutomationEditor/positions.ts b/webapp/src/components/AutomationEditor/positions.ts index 9125d94..929cb82 100644 --- a/webapp/src/components/AutomationEditor/positions.ts +++ b/webapp/src/components/AutomationEditor/positions.ts @@ -9,6 +9,7 @@ export function* computeTriggerPos( triggers: AutomationTrigger[], toPath: Point, onUpdate: (ts: AutomationTrigger[]) => void, + onAdd: () => void, onEdit: (nt: AutomationTrigger, onSave: (ts: AutomationTrigger) => void) => void, ): Generator { // functions @@ -40,15 +41,21 @@ export function* computeTriggerPos( direction: "1->2", } } + // if we had nothing to loop on + if (triggers.length === 0) { + yield { + type: "edge", + p1: [startPoint[0] - 0.25, startPoint[1] + triggers.length], + p2: toPath, + direction: "1->2", + } + } + // add circle yield { type: 'circle', icon: 'add', loc: [startPoint[0] + 0.25, startPoint[1] + triggers.length], - onAdd: () => onUpdate(triggers.concat({ - $smType: 'trigger', - platform: 'state', - entity_id: "", - })) + onAdd } } diff --git a/webapp/src/components/AutomationList/styles.css b/webapp/src/components/AutomationList/styles.css index 00bf4eb..ef20400 100644 --- a/webapp/src/components/AutomationList/styles.css +++ b/webapp/src/components/AutomationList/styles.css @@ -40,7 +40,7 @@ .automation-list--list-hide { position: absolute; - top : 0; + bottom : 10px; right : 5px; } diff --git a/webapp/src/components/Modal/index.tsx b/webapp/src/components/Modal/index.tsx index 4e29902..52a0be5 100644 --- a/webapp/src/components/Modal/index.tsx +++ b/webapp/src/components/Modal/index.tsx @@ -31,9 +31,9 @@ const useModalStyle = createAppUseStyles(theme => ({ inner: { zIndex: 10, maxWidth: '80%', - maxHeight: '60%', - minHeight: '200px', - minWidth: '200px', + maxHeight: '90%', + minHeight: 'fit-content', + minWidth: 'fit-content', padding: '15px', display: 'flex', flexDirection: 'column', @@ -43,6 +43,8 @@ const useModalStyle = createAppUseStyles(theme => ({ borderColor: theme.primaryAccent, borderRadius: '10px', color: theme.primaryAccent, + overflow: "auto", + resize: "auto", } })); export const Modal: FC = ({ diff --git a/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx b/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx index 35fce88..681aa1d 100644 --- a/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx +++ b/webapp/src/components/NodeEditor/OptionManager/ActionChoose.tsx @@ -25,7 +25,7 @@ export const ActionChooseState: OptionManager = { value={state.action_data.alias ?? ""} onChange={alias => update({ alias })} /> - update({ choose })} @@ -36,7 +36,7 @@ export const ActionChooseState: OptionManager = { value={state.action_data.default} onChange={d => update({ default: d })} resizable - /> + /> */} } } diff --git a/webapp/src/components/NodeEditor/index.css b/webapp/src/components/NodeEditor/index.css new file mode 100644 index 0000000..4187d5b --- /dev/null +++ b/webapp/src/components/NodeEditor/index.css @@ -0,0 +1,37 @@ +.node-editor--root { + display : flex; + flex-direction : column; + justify-content: center; + align-items : center; + height : 100%; +} + +.node-editor--body-title { + display : flex; + flex-direction : row; + justify-content: space-between; +} + +.node-editor--body { + flex : 1; + overflow : overlay; + width : 100%; + min-width : fit-content; + padding-left : 1%; + padding-right: 1%; + /* resize : auto; + min-width : fit-content; + max-height : 100%; + min-height : fit-content; */ +} + +.node-editor--footer { + bottom : 0; + left : 0; + display : flex; + flex-direction : row; + justify-content: space-between; + align-items : center; + width : 100%; + min-height : 50px; +} diff --git a/webapp/src/components/NodeEditor/index.tsx b/webapp/src/components/NodeEditor/index.tsx index 34a28ce..c2eb8b3 100644 --- a/webapp/src/components/NodeEditor/index.tsx +++ b/webapp/src/components/NodeEditor/index.tsx @@ -1,19 +1,17 @@ +import "./index.css"; import { FC } from "react"; -import { useNodeEditorStyles } from "./styles"; import { AutomationNode, AutomationNodeMapping } from 'types/automations/index'; import { useEditorNodeState } from "./OptionManager"; import InputList from "components/Inputs/InputList"; import { Button } from "components/Inputs/Button"; - - - export interface Props { node: AutomationNode allowedTypes?: Array; onClose?: () => void; onSave?: (n: AutomationNode) => void; + saveBtnCreateText?: boolean; } export const NodeEditor: FC = ({ @@ -21,34 +19,33 @@ export const NodeEditor: FC = ({ allowedTypes = ["action", "condition", "trigger"], onClose = () => { }, onSave = () => { }, + saveBtnCreateText = false, }) => { - const { classes } = useNodeEditorStyles({}); const state = useEditorNodeState(node); - return
-
- -
-
- {allowedTypes.length > 1 ? : {state.nodeType}} - {state.nodeType !== 'condition' ? : <>} + return
+
+
+ {allowedTypes.length > 1 ? : {state.nodeType}} + {state.nodeType !== 'condition' ? : <>} +
{state.renderOptionList()}
-
+
+ }} disabled={!state.isReady()}>{saveBtnCreateText ? "Create" : "Save"}
} diff --git a/webapp/src/components/NodeEditor/styles.ts b/webapp/src/components/NodeEditor/styles.ts deleted file mode 100644 index 90dbd28..0000000 --- a/webapp/src/components/NodeEditor/styles.ts +++ /dev/null @@ -1,31 +0,0 @@ -import Color from "chroma-js"; -import { createAppUseStyles } from "styles/theme"; - -export const useNodeEditorStyles = createAppUseStyles<{ - -}>(theme => ({ - root: { - display: 'flex', - flexDirection: 'column', - justifyContent: 'center', - alignItems: 'center', - }, - title: { - textAlign: 'center', - padding: 10, - fontWeight: 'bold', - color: theme.secondaryAccent, - }, - body: { - overflow: 'auto', - resize: 'auto', - flexGrow: 1 - }, - footer: { - display: 'flex', - flexDirection: 'row', - justifyContent: 'space-between', - alignItems: 'center', - width: '100%', - } -})) diff --git a/webapp/src/components/SequenceNodes/index.stories.tsx b/webapp/src/components/SequenceNodes/index.stories.tsx index 847e94a..116c909 100644 --- a/webapp/src/components/SequenceNodes/index.stories.tsx +++ b/webapp/src/components/SequenceNodes/index.stories.tsx @@ -78,6 +78,13 @@ Simple.args = { ] } +export const EmptyStart = Template.bind({}) +EmptyStart.args = { + ...EmptyStart.args, + sequence: [ + ] +} + export const AdditionalElemets = Template.bind({}) AdditionalElemets.args = { diff --git a/webapp/src/components/SequenceNodes/index.tsx b/webapp/src/components/SequenceNodes/index.tsx index 7a5d851..5646519 100644 --- a/webapp/src/components/SequenceNodes/index.tsx +++ b/webapp/src/components/SequenceNodes/index.tsx @@ -23,6 +23,7 @@ export const SequenceNodes: FC = (pro onClose={() => setModalState(null)} onSave={n => { modalState.update(n as any); setModalState(null) }} allowedTypes={modalState.onlyConditions ? ['condition'] : ['action', 'condition']} + saveBtnCreateText={modalState.saveBtnCreateText} /> } else { modalBody = void; @@ -146,8 +143,19 @@ export function* computeNodesEdgesPos( onChange: (s: AutomationSequenceNode[]) => void, openModal: UpdateModalState, ): Generator { - const rootUpdater = makeUpdater(sequence, onChange); - const offset = makeOffsetMaintainer(startPoint) + const rootUpdater = makeUpdater(sequence, onChange, openModal); + const offset = makeOffsetMaintainer(startPoint); + + if (sequence.length === 0) { + yield { + type: "circle", + icon: 'add', + loc: offsetPoint(startPoint, [offset.x, 0]), + onAdd: rootUpdater.addNode, + } + return + } + let lastNodeLoc: Point | null = null; for (let i = 0; i < sequence.length; i++) { offset.setI(i) diff --git a/webapp/src/components/SequenceNodes/types.ts b/webapp/src/components/SequenceNodes/types.ts index 7701e89..dc477f3 100644 --- a/webapp/src/components/SequenceNodes/types.ts +++ b/webapp/src/components/SequenceNodes/types.ts @@ -2,6 +2,10 @@ import { DAGBoardElmDims, DAGElement } from "components/DAGSvgs/DAGBoard"; import { AutomationSequenceNode } from "types/automations"; import { Point } from "types/graphs"; +export type UpdateModalState = ( + s: ModalState +) => void; + export interface SequenceNodeProps { startPoint: Point; dims: DAGBoardElmDims; @@ -14,6 +18,7 @@ export type ModalState = { single: true, node: AutomationSequenceNode update: (n: AutomationSequenceNode) => void; + saveBtnCreateText?: boolean; onlyConditions: boolean; } | { single: false, diff --git a/webapp/src/components/SequenceNodes/updater.ts b/webapp/src/components/SequenceNodes/updater.ts index 38a3edf..f33cf42 100644 --- a/webapp/src/components/SequenceNodes/updater.ts +++ b/webapp/src/components/SequenceNodes/updater.ts @@ -1,11 +1,13 @@ import { AutomationSequenceNode } from "types/automations"; import { ChooseAction } from "types/automations/actions"; +import { UpdateModalState } from "./types"; export type Updater = ReturnType; export const makeUpdater = ( sequence: AutomationSequenceNode[], - onChange: (s: AutomationSequenceNode[]) => void + onChange: (s: AutomationSequenceNode[]) => void, + openModal: UpdateModalState, ) => ({ sequence, onChange, @@ -16,17 +18,23 @@ export const makeUpdater = ( ]) }, addNode() { - return onChange([ - ...sequence, - { + return openModal({ + single: true, + saveBtnCreateText: true, + node: { $smType: 'action', action: 'choose', action_data: { choose: [], default: [], } - } - ]) + }, + update: n => onChange([ + ...sequence, + n, + ]), + onlyConditions: false, + }) }, updateNode(i: number, node: AutomationSequenceNode) { return onChange([ @@ -61,7 +69,8 @@ export const makeUpdater = ( ...node.action_data.choose.slice(j+1), ] } - }) + }), + openModal, ) } else { return makeUpdater( @@ -72,7 +81,8 @@ export const makeUpdater = ( ...node.action_data, default: seq } - }) + }), + openModal, ) } }