From 8d804add13d6c7ae977c4f7b390891c9678e9202 Mon Sep 17 00:00:00 2001 From: Ari Date: Thu, 12 May 2022 16:31:30 -0400 Subject: [PATCH] cleaned up styling --- webapp/package.json | 1 - .../AutomationEditor/index.stories.tsx | 13 +-- .../src/components/AutomationEditor/index.tsx | 3 + .../src/components/AutomationEditor/state.ts | 3 + .../src/components/ConditionEditor/style.ts | 27 +++---- webapp/src/components/DAGFlow/DAGCircle.tsx | 19 ++--- webapp/src/components/DAGFlow/DAGNode.tsx | 10 ++- webapp/src/components/DAGFlow/flowDataMods.ts | 52 ++++++++++++ .../src/components/DAGFlow/index.stories.tsx | 20 ++--- webapp/src/components/DAGFlow/index.tsx | 51 +++++++----- .../components/DAGFlow/sequenceConvertor.ts | 80 ++++++++++++------- webapp/src/components/DAGFlow/styles.ts | 32 +++----- .../components/DAGFlow/triggerConvertor.ts | 25 +++--- webapp/src/components/DAGFlow/types.ts | 2 + webapp/src/components/DAGFlow/updater.ts | 2 +- webapp/src/components/DAGSvgs/constants.ts | 12 ++- webapp/src/components/Inputs/styles.ts | 11 ++- webapp/src/components/Modal/index.tsx | 3 +- webapp/src/styles/root.css | 16 +++- webapp/src/styles/theme.ts | 44 ++++++---- webapp/src/types/automations/index.ts | 1 + webapp/src/types/graphs.ts | 2 +- webapp/src/utils/defaults.ts | 1 + webapp/src/utils/mocks.ts | 1 + webapp/yarn.lock | 14 ---- 25 files changed, 259 insertions(+), 186 deletions(-) create mode 100644 webapp/src/components/DAGFlow/flowDataMods.ts diff --git a/webapp/package.json b/webapp/package.json index 02235f0..509a6b9 100644 --- a/webapp/package.json +++ b/webapp/package.json @@ -8,7 +8,6 @@ "@types/node": "^12.0.0", "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", - "chroma-js": "^2.1.2", "jss": "^10.8.2", "react": "^17.0.2", "react-dom": "^17.0.2", diff --git a/webapp/src/components/AutomationEditor/index.stories.tsx b/webapp/src/components/AutomationEditor/index.stories.tsx index baa288f..8b8de8d 100644 --- a/webapp/src/components/AutomationEditor/index.stories.tsx +++ b/webapp/src/components/AutomationEditor/index.stories.tsx @@ -10,16 +10,7 @@ export default { component: AutomationEditor, parameters: { actions: { argTypesRegex: '^on.*' } }, args: { - dims: { - nodeHeight: dgconst.NODE_HEIGHT, - nodeWidth: dgconst.NODE_WIDTH, - distanceFactor: dgconst.DISTANCE_FACTOR, - circleSize: dgconst.CIRCLE_SIZE, - padding: { - x: dgconst.PADDING, - y: dgconst.PADDING, - }, - } + dims: dgconst.DEFAULT_DIMS } } as ComponentMeta @@ -43,6 +34,7 @@ export const Simple = Template.bind({}) Simple.args = { ...Simple.args, automation: { + condition: [], tags: { "Room": "Bathroom", "For": "Toliet", @@ -103,6 +95,7 @@ export const EmptyStart = Template.bind({}) EmptyStart.args = { ...EmptyStart.args, automation: { + condition: [], tags: {}, metadata: { id: "random", diff --git a/webapp/src/components/AutomationEditor/index.tsx b/webapp/src/components/AutomationEditor/index.tsx index ad9f1bc..b6ba10d 100644 --- a/webapp/src/components/AutomationEditor/index.tsx +++ b/webapp/src/components/AutomationEditor/index.tsx @@ -25,6 +25,7 @@ export const AutomationEditor: FC = ({ updateSequence, updateTrigger, updateMetadata, + updateCondition, save, } = useAutomatioEditorState(propsAutos, propsOnUpdate); @@ -64,8 +65,10 @@ export const AutomationEditor: FC = ({ className="automation-editor--flow-wrapper--flow" sequence={state.data.sequence} trigger={state.data.trigger} + condition={state.data.condition} onSequenceUpdate={updateSequence} onTriggerUpdate={updateTrigger} + onConditionUpdate={updateCondition} dims={dims} /> diff --git a/webapp/src/components/AutomationEditor/state.ts b/webapp/src/components/AutomationEditor/state.ts index 3f1939e..0913d2d 100644 --- a/webapp/src/components/AutomationEditor/state.ts +++ b/webapp/src/components/AutomationEditor/state.ts @@ -41,6 +41,7 @@ export const useAutomatioEditorState = ( return { updateTrigger: makeUpdate('trigger'), updateSequence: makeUpdate('sequence'), + updateCondition: makeUpdate('condition'), updateMetadata: (metadata: AutomationMetadata, tags: Array<[string, string]>) => { if (state.status !== 'loading') { update({ @@ -80,6 +81,7 @@ const genEditorData = (automation: AutomationData) => { metadata, trigger, sequence, + condition, } = automation; const tags: [string, string][] = Object.keys(automation.tags).map(tagName => [tagName, automation.tags[tagName]]); @@ -88,6 +90,7 @@ const genEditorData = (automation: AutomationData) => { metadata, trigger, sequence, + condition, tags, } } \ No newline at end of file diff --git a/webapp/src/components/ConditionEditor/style.ts b/webapp/src/components/ConditionEditor/style.ts index b8397f2..70d99a0 100644 --- a/webapp/src/components/ConditionEditor/style.ts +++ b/webapp/src/components/ConditionEditor/style.ts @@ -1,5 +1,4 @@ import { Styles } from "jss"; -import Color from 'chroma-js'; import { createAppUseStyles } from "styles/theme"; export const useStyles = createAppUseStyles<{ @@ -26,9 +25,9 @@ export const useStyles = createAppUseStyles<{ padding: 0, position: 'relative', display: 'flex', - flexDirection: hasChildren? 'column' : 'row', + flexDirection: hasChildren ? 'column' : 'row', }), - title: ({hasChildren}) => ({ + title: ({ hasChildren }) => ({ display: 'flex', border: hasChildren ? `1px solid ${theme.primaryAccent}` : 'none', borderRadius: 10, @@ -36,7 +35,7 @@ export const useStyles = createAppUseStyles<{ borderBottomLeftRadius: 0, height: '100%', }), - titleText: ({hasChildren}) => ({ + titleText: ({ hasChildren }) => ({ background: theme.condition.primaryColor, border: `1px solid ${theme.primaryAccent}`, borderRadius: 10, @@ -57,7 +56,7 @@ export const useStyles = createAppUseStyles<{ left: -35, top: 10, }, - modifyBtn: ({hasChildren}) => ({ + modifyBtn: ({ hasChildren }) => ({ // styling backgroundColor: theme.primary, fill: theme.primaryAccent, @@ -67,7 +66,7 @@ export const useStyles = createAppUseStyles<{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0, cursor: 'pointer', - + // positioning display: 'flex', justifyContent: 'center', @@ -79,8 +78,8 @@ export const useStyles = createAppUseStyles<{ // on hover "&:hover": { - backgroundColor: Color(theme.primary).brighten().hex(), - fill: Color(theme.primaryAccent).brighten().hex(), + backgroundColor: theme.primaryLight, + fill: theme.primaryAccentLight, }, "&:hover $icon": { transform: "rotate(90deg)" @@ -88,13 +87,13 @@ export const useStyles = createAppUseStyles<{ }), icon: {}, deleteBtn, - children: ({hasChildren}) => ({ + children: ({ hasChildren }) => ({ flex: 1, paddingLeft: hasChildren ? 50 : 10, paddingRight: hasChildren ? 0 : 10, display: 'flex', flexDirection: 'column', - justifyContent: 'center', + justifyContent: 'center', border: `1px solid ${theme.primaryAccent}`, borderBottomRightRadius: hasChildren ? 10 : 0, borderBottomLeftRadius: hasChildren ? 10 : 0, @@ -114,8 +113,8 @@ export const useStyles = createAppUseStyles<{ paddingRight: 20, cursor: 'pointer', "&:hover": { - backgroundColor: Color(theme.primary).brighten().hex(), - fill: Color(theme.primaryAccent).brighten().hex(), + backgroundColor: theme.primaryLight, + fill: theme.primaryAccentLight, }, }, addBtn: { @@ -131,8 +130,8 @@ export const useStyles = createAppUseStyles<{ paddingRight: 20, cursor: 'pointer', "&:hover": { - backgroundColor: Color(theme.primary).brighten().hex(), - fill: Color(theme.primaryAccent).brighten().hex(), + backgroundColor: theme.primaryLight, + fill: theme.primaryAccentLight, }, } } diff --git a/webapp/src/components/DAGFlow/DAGCircle.tsx b/webapp/src/components/DAGFlow/DAGCircle.tsx index 7895890..76d64d5 100644 --- a/webapp/src/components/DAGFlow/DAGCircle.tsx +++ b/webapp/src/components/DAGFlow/DAGCircle.tsx @@ -6,7 +6,6 @@ import { Handle, Position, XYPosition } from 'react-flow-renderer'; export interface DAGCircleProps { - onEdit?: () => void; onAdd?: () => void; onRemove?: () => void; size: number, @@ -28,7 +27,6 @@ export const makeFlowCircle = ( export const DAGCircle: FC<{ data: DAGCircleProps }> = ({ data: { size, - onEdit, onAdd, onRemove, backgroundColor, @@ -38,7 +36,7 @@ export const DAGCircle: FC<{ data: DAGCircleProps }> = ({ }) => { const { classes } = useCircleStyles({ size, - hasOnFunction: !!onEdit || !!onAdd, + hasOnFunction: !!onRemove || !!onAdd, hasRemoveFunction: !!onRemove, backgroundColor, }); @@ -47,18 +45,13 @@ export const DAGCircle: FC<{ data: DAGCircleProps }> = ({ {!disableTarget && }
{ - onEdit ? - : onAdd ? - - : backgroundColor ? "" : "else" + onClick={onAdd} + /> + : (backgroundColor || onRemove) ? "" : "else" } {onRemove ? : <>}
diff --git a/webapp/src/components/DAGFlow/DAGNode.tsx b/webapp/src/components/DAGFlow/DAGNode.tsx index 0c178bf..05d35d0 100644 --- a/webapp/src/components/DAGFlow/DAGNode.tsx +++ b/webapp/src/components/DAGFlow/DAGNode.tsx @@ -1,4 +1,3 @@ -import Color from "chroma-js"; import { PencilIcon } from "components/Icons" import { NodeColor } from "types/graphs"; import { useNodeStyles } from "./styles"; @@ -14,22 +13,25 @@ export interface DAGNodeProps { color: NodeColor; label: string; hasInput?: boolean; + accentBackground?: boolean; } export const DAGNode: FC<{ data: DAGNodeProps }> = ({ data: { label, height, width, - onXClick = () => { }, + onXClick, onEditClick = () => { }, color, hasInput = false, + accentBackground = false, }, }) => { const { classes, theme } = useNodeStyles({ color, nodeHeight: height, nodeWidth: width, + accentBackground, }); return <> {hasInput && } @@ -37,7 +39,7 @@ export const DAGNode: FC<{ data: DAGNodeProps }> = ({
- + {!!onXClick && }
@@ -48,7 +50,7 @@ export const DAGNode: FC<{ data: DAGNodeProps }> = ({ console.log('editing me', label, onEditClick, onEditClick()) }}>
diff --git a/webapp/src/components/DAGFlow/flowDataMods.ts b/webapp/src/components/DAGFlow/flowDataMods.ts new file mode 100644 index 0000000..22db4fc --- /dev/null +++ b/webapp/src/components/DAGFlow/flowDataMods.ts @@ -0,0 +1,52 @@ +import { makeFlowCircle } from "./DAGCircle" +import { DAGAutomationFlowDims, FlowData } from "./types" +import { XYPosition } from 'react-flow-renderer'; + +export const makeAddButton = ( + id: string, + position: XYPosition, + { + circleSize, + }: DAGAutomationFlowDims, + onAdd: () => void, + disableTarget: boolean = true, +) => makeFlowCircle( + id, + position, + { + size: circleSize, + onAdd, + disableSource: true, + disableTarget, + } +) + +export const makeConditionPoint = ( + id: string, + position: XYPosition, + { + padding, + conditionWidth, + conditionHeight, + nodeWidth, + nodeHeight, + circleSize, + distanceFactor, + }: DAGAutomationFlowDims, + totalConditions: number, + onEditClick: () => void, +) => ({ + id, + type: 'dagnode', + position, + data: { + size: circleSize, + color: 'lblue', + accentBackground: true, + label: `${totalConditions} Condition${totalConditions !== 1 ? 's' : ''}`, + height: conditionHeight, + width: conditionWidth, + hasInput: true, + onEditClick, + } +}) \ No newline at end of file diff --git a/webapp/src/components/DAGFlow/index.stories.tsx b/webapp/src/components/DAGFlow/index.stories.tsx index 9fa3747..56ecca3 100644 --- a/webapp/src/components/DAGFlow/index.stories.tsx +++ b/webapp/src/components/DAGFlow/index.stories.tsx @@ -12,16 +12,7 @@ export default { component: DAGAutomationFlow, parameters: { actions: { argTypesRegex: '^on.*' } }, args: { - dims: { - nodeHeight: dgconst.NODE_HEIGHT, - nodeWidth: dgconst.NODE_WIDTH, - distanceFactor: dgconst.DISTANCE_FACTOR, - circleSize: dgconst.CIRCLE_SIZE, - padding: { - x: dgconst.PADDING, - y: dgconst.PADDING, - }, - } + dims: dgconst.DEFAULT_DIMS } } as ComponentMeta @@ -29,8 +20,8 @@ const Template: ComponentStory = args => { const [state, setState] = useState({ trigger: args.trigger, sequence: args.sequence, + condition: args.condition, }) - console.log(state) return
= args => { setState({ ...state, trigger }) }} onSequenceUpdate={sequence => setState({ ...state, sequence })} + onConditionUpdate={condition => setState({ ...state, condition })} />
} @@ -47,6 +39,7 @@ const Template: ComponentStory = args => { export const Simple = Template.bind({}) Simple.args = { ...Simple.args, + condition: [], trigger: [ { "platform": "numeric_state", @@ -90,6 +83,7 @@ Simple.args = { export const Complex = Template.bind({}) Complex.args = { ...Complex.args, + condition: [], trigger: [ { "platform": "numeric_state", @@ -213,7 +207,7 @@ Complex.args = { export const EmptyStart = Template.bind({}) EmptyStart.args = { ...EmptyStart.args, - trigger: [ - ], + condition: [], + trigger: [], sequence: [] } diff --git a/webapp/src/components/DAGFlow/index.tsx b/webapp/src/components/DAGFlow/index.tsx index 6d0e398..67a4795 100644 --- a/webapp/src/components/DAGFlow/index.tsx +++ b/webapp/src/components/DAGFlow/index.tsx @@ -5,13 +5,15 @@ import { AutomationSequenceNode } from "types/automations"; import { AutomationTrigger } from 'types/automations/triggers'; import { triggerToFlow } from "./triggerConvertor"; import { DAGNode } from "./DAGNode"; -import { DAGAutomationFlowDims, FlowData, ModalState } from './types'; +import { DAGAutomationFlowDims, FlowData, ModalState, UpdateModalState } from './types'; import { DAGCircle } from './DAGCircle'; import { sequenceToFlow } from "./sequenceConvertor"; import { makeSequenceUpdater } from "./updater"; import { NodeEditor } from "components/NodeEditor"; import { MultiNodeEditor } from "components/MultiNodeEditors"; import { Modal } from "components/Modal"; +import { AutomationCondition } from "types/automations/conditions"; +import { makeConditionPoint } from "./flowDataMods"; const nodeTypes = { 'dagnode': DAGNode, @@ -20,19 +22,23 @@ const nodeTypes = { interface Props { className?: string; - sequence: AutomationSequenceNode[]; trigger: AutomationTrigger[]; + condition: AutomationCondition[]; + sequence: AutomationSequenceNode[]; dims: DAGAutomationFlowDims; onTriggerUpdate: (t: AutomationTrigger[]) => void; onSequenceUpdate: (s: AutomationSequenceNode[]) => void; + onConditionUpdate: (s: AutomationCondition[]) => void; } export const DAGAutomationFlow: FC = ({ className, - sequence, trigger, + condition, + sequence, onTriggerUpdate, onSequenceUpdate, + onConditionUpdate, dims, }) => { // state @@ -63,7 +69,14 @@ export const DAGAutomationFlow: FC = ({ } // convert automation to flow data - const condPoint = makeConditionPoint(dims); + const condPoint = makeConditionPoint('c', { + x: dims.padding.x + dims.nodeWidth * dims.distanceFactor, + y: dims.padding.y + dims.nodeHeight * 0.25 + }, dims, condition.length, makeOnEditAutomationConditions( + condition, + onConditionUpdate, + setModalState, + )); const flowData: FlowData = { nodes: [condPoint], edges: [], @@ -94,7 +107,12 @@ export const DAGAutomationFlow: FC = ({ flowData, sequence, condPoint.id, - dims, + { + ...dims, padding: { + x: condPoint.position.x - dims.nodeWidth - dims.conditionWidth, + y: dims.padding.y, + } + }, makeSequenceUpdater(sequence, onSequenceUpdate, setModalState), ); @@ -118,18 +136,13 @@ export const DAGAutomationFlow: FC = ({ ; } - -const makeConditionPoint = ({ - padding, - nodeWidth, - nodeHeight, - circleSize, -}: DAGAutomationFlowDims) => ({ - id: `c`, - type: 'dagcircle', - position: { x: padding.x + nodeWidth * 2, y: padding.y + nodeHeight * 0.25 }, - data: { - size: circleSize, - backgroundColor: 'blue', - } +const makeOnEditAutomationConditions = ( + conditions: AutomationCondition[], + updateConditions: (c: AutomationCondition[]) => void, + openModal: UpdateModalState, +) => () => openModal({ + single: false, + node: conditions, + allowedTypes: ['condition'], + update: c => updateConditions(c as any), }) \ No newline at end of file diff --git a/webapp/src/components/DAGFlow/sequenceConvertor.ts b/webapp/src/components/DAGFlow/sequenceConvertor.ts index 8392acb..55c2913 100644 --- a/webapp/src/components/DAGFlow/sequenceConvertor.ts +++ b/webapp/src/components/DAGFlow/sequenceConvertor.ts @@ -6,6 +6,7 @@ import { ChooseAction } from 'types/automations/actions'; import { makeFlowCircle } from './DAGCircle'; import { createOnRemoveForChooseNode, SequenceUpdater } from './updater'; import { getNodeType } from 'utils/automations'; +import { makeAddButton, makeConditionPoint } from './flowDataMods'; export const sequenceToFlow = ( @@ -56,13 +57,19 @@ export const sequenceToFlow = ( lasPos = position; } // add button - const addCircle = makeFlowCircle( + const addCircle = makeAddButton( `${prefix}-+`, { - x: (lasPos === null ? dims.padding.x + dims.nodeWidth * dims.distanceFactor * (sequence.length + 1) : lasPos.x) + dims.nodeWidth * dims.distanceFactor, - y: dims.padding.y + dims.circleSize / 2 + x: ( + lasPos === null ? + dims.padding.x + dims.nodeWidth * dims.distanceFactor * (sequence.length + 1) : + lasPos.x + ) + dims.nodeWidth * dims.distanceFactor, + y: dims.padding.y + dims.circleSize / 4 }, - { onAdd: updater.addNode, size: dims.circleSize, disableSource: true, } + dims, + updater.addNode, + false, ) flowData.nodes.push(addCircle) addEdge(flowData, lastPointId, addCircle.id, false) @@ -130,12 +137,11 @@ const addChooseNode = ( node.choose.forEach(({ sequence, conditions }, j) => { const sequenceId = `${nodeId}.${j}`; // edit/delete circle - const circle = makeFlowCircle(`${sequenceId}>cond`, { + const circle = makeFlowCircle(`${sequenceId}>delete`, { x: position.x + dims.nodeWidth * dims.distanceFactor, y: lastPos.y + dims.nodeHeight * dims.distanceFactor, }, { - size: dims.circleSize * dims.distanceFactor, - onEdit: updater.makeOnEditConditionsForChooseNode(i, j), + size: dims.circleSize, onRemove: createOnRemoveForChooseNode( node, d => updater.updateNode(i, d), @@ -144,12 +150,25 @@ const addChooseNode = ( }) flowData.nodes.push(circle) addEdge(flowData, nodeId, circle.id, true) + const condNode = makeConditionPoint( + `${sequenceId}>cond`, + { + x: circle.position.x + dims.circleSize * dims.distanceFactor, + y: circle.position.y + dims.circleSize / 8, + }, + dims, + conditions.length, + updater.makeOnEditConditionsForChooseNode(i, j) + ); + flowData.nodes.push(condNode) + addEdge(flowData, circle.id, condNode.id, true) + // actual sub sequence - const lastPoint = sequenceToFlow(flowData, sequence, circle.id, { + const lastPoint = sequenceToFlow(flowData, sequence, condNode.id, { ...dims, padding: { - x: position.x - dims.nodeWidth, - y: circle.position.y, + x: condNode.position.x - (dims.nodeWidth + dims.conditionWidth), + y: condNode.position.y - dims.conditionHeight / 2, }, }, updater.makeChildUpdaterForChooseAction(i, j), `${sequenceId}.`); if (lastPoint.position) { @@ -161,41 +180,40 @@ const addChooseNode = ( const totalChildren = node.choose.length; // add button - const addCirlce = makeFlowCircle( - `${nodeId}>add`, { - x: position.x + dims.nodeWidth * dims.distanceFactor, - y: lastPos.y + dims.nodeHeight * dims.distanceFactor, - }, + const addCirlce = makeAddButton( + `${nodeId}>add`, { - size: dims.circleSize * dims.distanceFactor, - onAdd: () => updater.updateNode(i, { - ...node, - choose: [ - ...node.choose, - { - sequence: [], - conditions: [], - } - ] - }), - disableSource: true, - } + x: position.x + dims.nodeWidth * dims.distanceFactor, + y: lastPos.y + dims.nodeHeight * dims.distanceFactor, + }, + dims, + () => updater.updateNode(i, { + ...node, + choose: [ + ...node.choose, + { + sequence: [], + conditions: [], + } + ] + }), + false, ); flowData.nodes.push(addCirlce) addEdge(flowData, nodeId, addCirlce.id, true) - // default + // else const elseCircle = makeFlowCircle(`${nodeId}>else`, { x: position.x + dims.nodeWidth * dims.distanceFactor, y: lastPos.y + dims.nodeHeight * dims.distanceFactor * 2, - }, { size: dims.circleSize * dims.distanceFactor }) + }, { size: dims.circleSize }) flowData.nodes.push(elseCircle) addEdge(flowData, nodeId, elseCircle.id, true) const lastPoint = sequenceToFlow(flowData, node.default, elseCircle.id, { ...dims, padding: { x: position.x - dims.nodeWidth, - y: elseCircle.position.y, + y: elseCircle.position.y - dims.circleSize / 4, }, }, updater.makeChildUpdaterForChooseAction(i, null), `${nodeId}.${totalChildren}.`) if (lastPoint.position) { diff --git a/webapp/src/components/DAGFlow/styles.ts b/webapp/src/components/DAGFlow/styles.ts index 96ea1c0..3331983 100644 --- a/webapp/src/components/DAGFlow/styles.ts +++ b/webapp/src/components/DAGFlow/styles.ts @@ -1,5 +1,4 @@ import { Styles } from "jss"; -import Color from 'chroma-js'; import { createAppUseStyles } from "styles/theme"; import { NodeColor } from "types/graphs"; @@ -7,6 +6,7 @@ export const useNodeStyles = createAppUseStyles<{ color: NodeColor, nodeHeight: number, nodeWidth: number, + accentBackground: boolean, }>(theme => { const edgeStyle: Styles = { flex: '1', @@ -41,11 +41,12 @@ export const useNodeStyles = createAppUseStyles<{ width: nodeWidth, fontSize: 10, }), - inner: ({ color }) => ({ + inner: ({ color, accentBackground }) => ({ position: 'relative', display: 'flex', flexDirection: 'row', - backgroundColor: theme.secondary, + backgroundColor: !accentBackground ? theme.secondary : + color === 'lblue' ? theme.condition.primaryColorOpaque : 'none', borderRadius: '1em', flex: 1, height: `100%`, @@ -57,10 +58,11 @@ export const useNodeStyles = createAppUseStyles<{ 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' + borderTopColor: color === 'red' ? theme.redAccent : + color === 'blue' ? theme.condition.primaryColor : + color === 'green' ? theme.green : + color === 'lblue' ? theme.condition.primaryAccent : + 'none' }), textWrap: { display: 'flex', @@ -112,13 +114,14 @@ export const useCircleStyles = createAppUseStyles<{ backgroundColor?: string, }>(theme => ({ root: ({ size, hasOnFunction, hasRemoveFunction, backgroundColor }) => { - const baseColor = backgroundColor ? backgroundColor : Color(theme.primary).set('rgb.g', 100).hex(); - const hoverColor = (hasOnFunction && !hasRemoveFunction) ? Color(theme.primary).set('rgb.g', 150).hex() : baseColor + const baseColor = backgroundColor ? backgroundColor : theme.green; + const hoverColor = hasOnFunction ? theme.greenOpaque : baseColor return { backgroundColor: baseColor, borderRadius: hasRemoveFunction ? 10 : 500, height: size, width: size, + color: theme.primary, cursor: hasOnFunction ? "pointer" : 'default', "&:hover": { backgroundColor: hoverColor, @@ -129,18 +132,7 @@ export const useCircleStyles = createAppUseStyles<{ alignItems: 'center', } }, - icon: { - "&:hover": { - borderRadius: 500, - background: Color(theme.primary).set('rgb.g', 150).hex(), - } - }, trashIcon: { padding: 1, - "&:hover": { - borderRadius: 500, - background: Color(theme.primary).set('rgb.g', 150).hex(), - cursor: 'pointer', - } } })) diff --git a/webapp/src/components/DAGFlow/triggerConvertor.ts b/webapp/src/components/DAGFlow/triggerConvertor.ts index f471a99..530c5ba 100644 --- a/webapp/src/components/DAGFlow/triggerConvertor.ts +++ b/webapp/src/components/DAGFlow/triggerConvertor.ts @@ -1,20 +1,23 @@ import { AutomationTrigger } from 'types/automations/triggers'; import { DAGAutomationFlowDims, FlowData, TriggerMakerOptions } from './types'; import { makeFlowCircle } from './DAGCircle'; +import { makeAddButton } from './flowDataMods'; export const triggerToFlow = ( flowData: FlowData, trigger: AutomationTrigger[], toPoint: string, - { + dims: DAGAutomationFlowDims, + opts: TriggerMakerOptions, +) => { + const { distanceFactor, nodeHeight, nodeWidth, circleSize, padding, - }: DAGAutomationFlowDims, - opts: TriggerMakerOptions, -) => { + conditionHeight, + } = dims; // convert all triggers to dag nodes trigger.forEach((t, i) => { const flowId = `t-${i}`; @@ -39,19 +42,13 @@ export const triggerToFlow = ( }); // create a 'add button' - flowData.nodes.push(makeFlowCircle( + flowData.nodes.push(makeAddButton( 'trigger-add', { x: padding.x + nodeWidth * 0.4, - y: padding.y + nodeHeight * distanceFactor * trigger.length, + y: padding.y + conditionHeight / 2 + nodeHeight * distanceFactor * trigger.length, }, - { - size: circleSize, - backgroundColor: 'green', - onAdd: opts.onAdd, - disableSource: true, - disableTarget: true, - } - + dims, + opts.onAdd )) } \ No newline at end of file diff --git a/webapp/src/components/DAGFlow/types.ts b/webapp/src/components/DAGFlow/types.ts index b936005..23a91dd 100644 --- a/webapp/src/components/DAGFlow/types.ts +++ b/webapp/src/components/DAGFlow/types.ts @@ -10,6 +10,8 @@ export type DAGAutomationFlowDims = { padding: XYPosition; nodeHeight: number; nodeWidth: number; + conditionWidth: number; + conditionHeight: number; circleSize: number; distanceFactor: number; } diff --git a/webapp/src/components/DAGFlow/updater.ts b/webapp/src/components/DAGFlow/updater.ts index cd6d869..306a013 100644 --- a/webapp/src/components/DAGFlow/updater.ts +++ b/webapp/src/components/DAGFlow/updater.ts @@ -113,7 +113,7 @@ export const makeSequenceUpdater = ( }), }) } - } + }, }); diff --git a/webapp/src/components/DAGSvgs/constants.ts b/webapp/src/components/DAGSvgs/constants.ts index acf8908..b732c41 100644 --- a/webapp/src/components/DAGSvgs/constants.ts +++ b/webapp/src/components/DAGSvgs/constants.ts @@ -1,18 +1,22 @@ +import { DAGAutomationFlowDims } from "components/DAGFlow/types"; + export const NODE_WIDTH = 150 as const; export const NODE_HEIGHT = 60 as const; -export const ADD_HEIGHT = 10 as const; -export const ADD_WIDTH = 10 as const; -export const CIRCLE_SIZE = 30 as const; +export const CONDITION_HEIGHT = 30 as const; +export const CONDITION_WIDTH = 120 as const; +export const CIRCLE_SIZE = 40 as const; export const DISTANCE_FACTOR = 1.5 as const; export const PADDING = 50 as const; export const DEFAULT_DIMS = { nodeHeight: NODE_HEIGHT, nodeWidth: NODE_WIDTH, + conditionHeight: CONDITION_HEIGHT, + conditionWidth: CONDITION_WIDTH, distanceFactor: DISTANCE_FACTOR, circleSize: CIRCLE_SIZE, padding: { x: PADDING, y: PADDING, }, -} \ No newline at end of file +} as DAGAutomationFlowDims \ No newline at end of file diff --git a/webapp/src/components/Inputs/styles.ts b/webapp/src/components/Inputs/styles.ts index d9c5cbf..6f4f0e9 100644 --- a/webapp/src/components/Inputs/styles.ts +++ b/webapp/src/components/Inputs/styles.ts @@ -1,5 +1,4 @@ import { createAppUseStyles, AppTheme } from "styles/theme"; -import Color from 'chroma-js'; const commonInputStyle = (theme: AppTheme) => ({ input: { @@ -251,8 +250,8 @@ export const useInputBubblesStyles = createAppUseStyles<{}>(theme => ({ position: 'relative', border: `1px solid ${theme.primaryAccent}`, borderRadius: 10, - backgroundColor: Color(theme.primary).set('rgb.g', 150).alpha(0.35).hex(), - color: Color(theme.primary).brighten(5).hex(), + backgroundColor: theme.greenOpaque, + color: theme.primaryLight, fontSize: 16, marginLeft: 1, @@ -262,8 +261,8 @@ export const useInputBubblesStyles = createAppUseStyles<{}>(theme => ({ cursor: 'pointer', "&:hover": { - backgroundColor: Color(theme.primary).set('rgb.r', 150).alpha(0.35).hex(), - color: Color(theme.primary).brighten(5).alpha(0.35).hex(), + backgroundColor: theme.redOpaque, + color: theme.primaryLightOpaque, }, "&:hover $deleteIcon": { @@ -291,7 +290,7 @@ export const useInputBubblesStyles = createAppUseStyles<{}>(theme => ({ padding: "3px 7px", "&:hover": { borderRadius: 100, - backgroundColor: Color(theme.primary).set('rgb.g', 150).alpha(0.35).hex(), + backgroundColor: theme.greenOpaque, borderColor: theme.secondaryAccent, }, } diff --git a/webapp/src/components/Modal/index.tsx b/webapp/src/components/Modal/index.tsx index 52a0be5..50564a7 100644 --- a/webapp/src/components/Modal/index.tsx +++ b/webapp/src/components/Modal/index.tsx @@ -1,6 +1,5 @@ import { FC } from "react"; import { createAppUseStyles } from "styles/theme"; -import Color from 'chroma-js'; export interface ModalStyleProps { open: boolean; @@ -26,7 +25,7 @@ const useModalStyle = createAppUseStyles(theme => ({ width: '100vw', top: 0, left: 0, - backgroundColor: Color(theme.secondary).alpha(0.5).hex(), + backgroundColor: theme.secondaryOpaque, }, inner: { zIndex: 10, diff --git a/webapp/src/styles/root.css b/webapp/src/styles/root.css index 70a5ed1..090cdb3 100644 --- a/webapp/src/styles/root.css +++ b/webapp/src/styles/root.css @@ -1,10 +1,22 @@ :root { - --primary: #111111; + --primary: #111; + --primary-light: #333; + --primary-light-opaque: #3335; + --secondary-opaque: #1c1c1c; --secondary: #1c1c1c; - --primary-accent: #bbbbbb; + --primary-accent: #bbb; + --primary-accent-light: #eee; --secondary-accent: #929191; + --green: #1f1; + --green-opaque: #1f15; + --green-light: #6f5; --error: #c55; + --error-opaque: #c555; + --error-accent: #9f3a3a; --change: #0f9; + --condition-primary: #447; + --condition-accent: #8af; + --condition-primary-opaque: #4476; touch-action: pan-x pan-y; height: 100%; } diff --git a/webapp/src/styles/theme.ts b/webapp/src/styles/theme.ts index 959e72e..e3aa1b4 100644 --- a/webapp/src/styles/theme.ts +++ b/webapp/src/styles/theme.ts @@ -11,29 +11,39 @@ export const { ThemeProvider, useTheme, } = createTheming(createContext({ - primary: '#111111', - secondary: '#1c1c1c', - primaryAccent: '#bbbbbb', - secondaryAccent: '#929191', + primary: 'var(--primary)', + primaryLight: 'var(--primary-light)', + primaryLightOpaque: 'var(--primary-light-opaque)', + secondary: 'var(--secondary)', + secondaryOpaque: 'var(--secondary-opaque)', + primaryAccent: 'var(--primary-acccent)', + primaryAccentLight: 'var(--primary-acccent-light)', + secondaryAccent: 'var(--secondary-accent)', condition: { - primaryColor: '#4f4f77', + primaryColor: 'var(--condition-primary)', + primaryAccent: 'var(--condition-accent)', + primaryColorOpaque: 'var(--condition-primary-opaque)' }, - red: '#ed0c0c', - redAccent: '#9f3a3a', + green: 'var(--green)', + greenLight: 'var(--green-light)', + greenOpaque: 'var(--green-opaque)', + red: 'var(--error)', + redOpaque: 'var(--error-opaque)', + redAccent: 'var(--error-accent)', })); -export type GetThemeType> = C extends Context ? T : unknown; +export type GetThemeType> = C extends Context ? T : unknown; export type ClassNamesOfStyle any> = Record, string>; export type AppTheme = GetThemeType; export const createAppUseStyles = < Props extends {} = {}, C extends string = string, ->(f: (theme: AppTheme) => Styles) => (props: Props): { - classes: Classes>, - theme: AppTheme, -} => { - const theme = useTheme(); - const useStyles = createUseStyles(f as any) - const classes = useStyles({...props, theme}) as Classes>; - return {classes, theme}; -} + >(f: (theme: AppTheme) => Styles) => (props: Props): { + classes: Classes>, + theme: AppTheme, + } => { + const theme = useTheme(); + const useStyles = createUseStyles(f as any) + const classes = useStyles({ ...props, theme }) as Classes>; + return { classes, theme }; + } diff --git a/webapp/src/types/automations/index.ts b/webapp/src/types/automations/index.ts index 62e5254..60add1d 100644 --- a/webapp/src/types/automations/index.ts +++ b/webapp/src/types/automations/index.ts @@ -13,6 +13,7 @@ export interface AutomationMetadata { export interface AutomationData { metadata: AutomationMetadata; trigger: AutomationTrigger[]; + condition: AutomationCondition[]; sequence: AutomationSequenceNode[]; tags: Record; } diff --git a/webapp/src/types/graphs.ts b/webapp/src/types/graphs.ts index d0f184f..6ec9101 100644 --- a/webapp/src/types/graphs.ts +++ b/webapp/src/types/graphs.ts @@ -1 +1 @@ -export type NodeColor = 'red' | 'blue' | 'green'; +export type NodeColor = 'red' | 'blue' | 'green' | 'lblue'; diff --git a/webapp/src/utils/defaults.ts b/webapp/src/utils/defaults.ts index 25a9a87..8db7868 100644 --- a/webapp/src/utils/defaults.ts +++ b/webapp/src/utils/defaults.ts @@ -58,4 +58,5 @@ export const defaultAutomation = (id: string): AutomationData => ({ tags: {}, trigger: [], sequence: [], + condition: [], }) diff --git a/webapp/src/utils/mocks.ts b/webapp/src/utils/mocks.ts index 0e56f42..224be0f 100644 --- a/webapp/src/utils/mocks.ts +++ b/webapp/src/utils/mocks.ts @@ -12,6 +12,7 @@ export const createMockAuto = (tags: Record = {}): AutomationDat mode: 'single', }, tags, + condition: [], trigger: [ { "platform": "numeric_state", diff --git a/webapp/yarn.lock b/webapp/yarn.lock index 7994982..70f621b 100644 --- a/webapp/yarn.lock +++ b/webapp/yarn.lock @@ -6704,13 +6704,6 @@ chownr@^2.0.0: resolved "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz" integrity sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ== -chroma-js@^2.1.2: - version "2.1.2" - resolved "https://registry.npmjs.org/chroma-js/-/chroma-js-2.1.2.tgz" - integrity sha512-ri/ouYDWuxfus3UcaMxC1Tfp3IE9K5iQzxc2hSxbBRVNQFut1UuGAsZmiAf2mOUubzGJwgMSv9lHg+XqLaz1QQ== - dependencies: - cross-env "^6.0.3" - chrome-trace-event@^1.0.2: version "1.0.2" resolved "https://registry.npmjs.org/chrome-trace-event/-/chrome-trace-event-1.0.2.tgz" @@ -7249,13 +7242,6 @@ create-require@^1.1.0: resolved "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz" integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== -cross-env@^6.0.3: - version "6.0.3" - resolved "https://registry.npmjs.org/cross-env/-/cross-env-6.0.3.tgz" - integrity sha512-+KqxF6LCvfhWvADcDPqo64yVIB31gv/jQulX2NGzKS/g3GEVz6/pt4wjHFtFWsHMddebWD/sDthJemzM4MaAag== - dependencies: - cross-spawn "^7.0.0" - cross-spawn@7.0.3, cross-spawn@^7.0.0, cross-spawn@^7.0.2: version "7.0.3" resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz"