diff --git a/webapp/.storybook/preview.js b/webapp/.storybook/preview.js index 48afd56..ca528f9 100644 --- a/webapp/.storybook/preview.js +++ b/webapp/.storybook/preview.js @@ -1,9 +1,10 @@ + export const parameters = { - actions: { argTypesRegex: "^on[A-Z].*" }, - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/, + actions: { argTypesRegex: "^on[A-Z].*" }, + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/, + }, }, - }, -} \ No newline at end of file +} diff --git a/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx b/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx new file mode 100644 index 0000000..a8d8b88 --- /dev/null +++ b/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx @@ -0,0 +1,40 @@ +import { ComponentMeta, ComponentStory } from "@storybook/react"; +import { useState } from "react"; +import { usePageTheme } from "styles/page"; +import { AutoInfoBox } from "./AutoInfoBox"; + +export default { + title: 'AutomationEditor/AutoInfoBox', + component: AutoInfoBox, + parameters: { actions: { argTypesRegex: '^on.*' } }, +} as ComponentMeta; + + +export const Basic: ComponentStory = args => { + const { classes } = usePageTheme({}); + const [state, setState] = useState(args.metadata) + return ( +
+ { + args.onUpdate(up) + setState(up) + }} + /> +
+ ) +} +Basic.args = { + ...Basic.args, + metadata: { + id: "random", + alias: "Random", + description: "Example Metadata", + trigger_variables: { + 'wowo': '!' + }, + mode: 'single', + } +} diff --git a/webapp/src/components/AutomationEditor/AutoInfoBox.tsx b/webapp/src/components/AutomationEditor/AutoInfoBox.tsx new file mode 100644 index 0000000..1521be8 --- /dev/null +++ b/webapp/src/components/AutomationEditor/AutoInfoBox.tsx @@ -0,0 +1,40 @@ +import { AutomationMetadata } from "types/automations"; +import InputList from "components/Inputs/InputList"; +import InputText from "components/Inputs/InputText"; +import InputTextArea from "components/Inputs/InputTextArea"; + +interface Props { + className: string; + metadata: AutomationMetadata; + onUpdate: (m: AutomationMetadata) => void; +} +export function AutoInfoBox({ + metadata, + onUpdate, + className, +}: Props) { + + // aliases + const onUpdateMetadata = (k: K) => (update: AutomationMetadata[K]) => onUpdate({ + ...metadata, + [k]: update + }) + + // render + return
+ + + + +
+} diff --git a/webapp/src/components/AutomationEditor/index.stories.tsx b/webapp/src/components/AutomationEditor/index.stories.tsx new file mode 100644 index 0000000..2051ead --- /dev/null +++ b/webapp/src/components/AutomationEditor/index.stories.tsx @@ -0,0 +1,94 @@ +import React from "react"; +import { ComponentMeta, ComponentStory } from '@storybook/react'; +import { AutomationEditor } from './index'; +import { NODE_HEIGHT, NODE_WIDTH, DISTANCE_FACTOR, ADD_HEIGHT, ADD_WIDTH, CIRCLE_SIZE } from '../DAGSvgs/constants'; +import { useState } from 'react'; +import { usePageTheme } from "styles/page"; + + +export default { + title: 'AutomationEditor/AutomationEditor', + component: AutomationEditor, + parameters: { actions: { argTypesRegex: '^on.*' } }, + args: { + dims: { + nodeHeight: NODE_HEIGHT, + nodeWidth: NODE_WIDTH, + addHeight: ADD_HEIGHT, + addWidth: ADD_WIDTH, + circleSize: CIRCLE_SIZE, + distanceFactor: DISTANCE_FACTOR, + } + } +} as ComponentMeta + +const Template: ComponentStory = args => { + const [state, setState] = useState(args.automation) + const { classes } = usePageTheme({}); + return
+ +
+} + +export const Simple = Template.bind({}) +Simple.args = { + ...Simple.args, + automation: { + metadata: { + id: "random", + alias: "Random", + description: "Example Metadata", + trigger_variables: { + 'wowo': '!' + }, + mode: 'single', + }, + trigger: [ + + ], + sequence: [ + { + $smType: "condition", + condition: 'and', + 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"' + } + } + ] + } + }, + { + $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", + } + } + } + ] + } +} diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx new file mode 100644 index 0000000..d81554a --- /dev/null +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -0,0 +1,50 @@ +import { DAGBoardElmDims } from "components/DAGSvgs/DAGBoard"; +import { SequenceNodes } from "components/SequenceNodes"; +import { FC } from "react"; +import { AutomationData, AutomationSequenceNode } from "types/automations"; +import useWindowSize from "utils/useWindowSize"; +import { AutoInfoBox } from "./AutoInfoBox"; +import { useEditorStyles } from "./styles"; + + +interface Props { + automation: AutomationData; + dims: DAGBoardElmDims; + onUpdate: (auto: AutomationData) => void; +} +export const AutomationEditor: FC = ({ + dims, + automation, + onUpdate, +}) => { + // state + const { ratioWbh } = useWindowSize(); + const { classes } = useEditorStyles({}); + + // alias + // const nHDF = 1.5 // node horizontal distance factor (aspect ratio) + // const graphHeight = 300; + // const graphWidth = Math.round(graphHeight * ratioWbh); + const updateSequence = (sequence: AutomationSequenceNode[]) => onUpdate({ + ...automation, + sequence, + }); + + // render + return
= 0.75 ? 'row' : 'column' + }}> + onUpdate({ ...automation, metadata })} + /> + +
+} diff --git a/webapp/src/components/AutomationEditor/styles.ts b/webapp/src/components/AutomationEditor/styles.ts new file mode 100644 index 0000000..4964fc1 --- /dev/null +++ b/webapp/src/components/AutomationEditor/styles.ts @@ -0,0 +1,26 @@ +import { createAppUseStyles } from "styles/theme"; + + +export const useEditorStyles = createAppUseStyles(theme => ({ + root: { + height: '100%', + width: '100%', + color: theme.primaryAccent, + display: 'flex', + flexDirection: 'row', + }, + dag: { + borderWidth: 1, + borderStyle: 'solid', + borderColor: theme.secondaryAccent, + width: '100%', + }, + infoBox: { + paddingLeft: '10px', + paddingRight: '10px', + display: 'flex', + flexDirection: 'column', + justifyContent: 'flex-start', + overflow: 'auto', + }, +})) diff --git a/webapp/src/components/DAGSvgs/Board.tsx b/webapp/src/components/DAGSvgs/Board.tsx index f23949e..dc89d51 100644 --- a/webapp/src/components/DAGSvgs/Board.tsx +++ b/webapp/src/components/DAGSvgs/Board.tsx @@ -34,24 +34,20 @@ export const SVGBoard: FC<{ // render - return
= 0.75 ? 'row' : 'column' - }}> -
- - - - - - - {children} - -
+ return
+ + + + + + + {children} +
} diff --git a/webapp/src/components/DAGSvgs/styles.ts b/webapp/src/components/DAGSvgs/styles.ts index ddfcaf1..917b154 100644 --- a/webapp/src/components/DAGSvgs/styles.ts +++ b/webapp/src/components/DAGSvgs/styles.ts @@ -8,18 +8,12 @@ export const useBoardStyles = createAppUseStyles<{ boardHeight: number, boardWidth: number, }>(theme => ({ - root: { - height: '99%', - width: '99%', - color: theme.primaryAccent, - background: theme.primary, - display: 'flex', - flexDirection: 'row', - }, dag: { borderWidth: 1, borderStyle: 'solid', borderColor: theme.secondaryAccent, + color: theme.primaryAccent, + background: theme.primary, width: '100%', height: '100%', overflow: 'scroll' diff --git a/webapp/src/components/SequenceNodes/index.tsx b/webapp/src/components/SequenceNodes/index.tsx index 1e0512c..46d0f84 100644 --- a/webapp/src/components/SequenceNodes/index.tsx +++ b/webapp/src/components/SequenceNodes/index.tsx @@ -9,8 +9,11 @@ import { NodeEditor } from 'components/NodeEditor'; import { MultiNodeEditor } from "components/MultiNodeEditors"; export const SequenceNodes: FC = (props) => { + // state const theme = useTheme(); const [modalState, setModalState] = useState(null); + + // modal let modalBody = <> if (modalState) { if (modalState.single) { @@ -47,6 +50,7 @@ export const SequenceNodes: FC = (pro } } + // render return <> = (pro edgeNextColor: theme.secondaryAccent, edgeChildColor: Color(theme.secondaryAccent).set('rgb.b', 200).hex(), }} + children={props.children} /> {modalBody} diff --git a/webapp/src/styles/root.css b/webapp/src/styles/root.css new file mode 100644 index 0000000..b1fbe28 --- /dev/null +++ b/webapp/src/styles/root.css @@ -0,0 +1,45 @@ + +:root { + --primary: #111111; + --secondary: #1c1c1c; + --primaryAccent: #bbbbbb; + --secondaryAccent: #929191; + touch-action: pan-x pan-y; + height: 100%; +} + + +html, +body, +#root { + margin: 0 !important; + padding: 0 !important; + height: 100vh; + width: 100vw; + overflow: hidden !important; + font-family: Tahoma, Geneva, sans-serif; + display: flex !important; + align-items: center; + justify-items: center; +} + +/* width */ +::-webkit-scrollbar { + width: 10px; + } + + /* Track */ + ::-webkit-scrollbar-track { + background: var(--secondary); + } + + /* Handle */ + ::-webkit-scrollbar-thumb { + background: var(--secondary-accent); + } + + /* Handle on hover */ + ::-webkit-scrollbar-thumb:hover { + background: var(--primary-accent); + } + diff --git a/webapp/src/styles/theme.ts b/webapp/src/styles/theme.ts index acbdf70..4f0d699 100644 --- a/webapp/src/styles/theme.ts +++ b/webapp/src/styles/theme.ts @@ -1,8 +1,9 @@ +import "styles/root.css"; + import { Classes } from "jss"; import { Context, createContext } from "react" import { createUseStyles, Styles } from "react-jss"; import { createTheming } from "theming" -// import Color from 'color'; export const { context: ThemeContext, @@ -34,4 +35,4 @@ export const createAppUseStyles = < const useStyles = createUseStyles(f) const classes = useStyles({...props, theme}) as Classes>; return {classes, theme}; -} \ No newline at end of file +}