diff --git a/webapp/src/components/DAGFlow/DAGNode.css b/webapp/src/components/DAGFlow/DAGNode.css index 27fcbe2..46aecd7 100644 --- a/webapp/src/components/DAGFlow/DAGNode.css +++ b/webapp/src/components/DAGFlow/DAGNode.css @@ -1,3 +1,59 @@ +.dagnode { + font-size: 0.9em; + display: flex; + justify-content: center; + align-items: center; + cursor: default; +} + +.dagnode--inner { + position: relative; + display: flex; + flex-direction: row; + justify-content: flex-start; + align-items: center; + padding: 1.5em 0.5em; + /* width: calc(100% - 0.5em); + height: calc(100% - 0.5em); */ + border-style: solid; + border-width: 1px; + border-radius: 10px; +} + + +.dagnode--label { + flex: 1; + display: flex; + overflow: hidden; + text-overflow: ellipsis; + word-wrap: break-word; + overflow-wrap: break-word; + align-items: center; + justify-content: center; + text-align: center; +} + +.dagnode .dagnode--inner .speed-dial { + height: 2em; + width: 2em; + min-height: 2em; + max-height: 2em; + position: absolute; + top: -1em; + left: -1em; + background-color: var(--primary); + border-color: var(--primary-accent); + border-style: solid; + border-width: 0.5px; + border-radius: 20px; +} + +.open>.dagnode--actions-btn, .dagnode--actions-btn:hover { + color: var(--primary); + background-color: var(--primary-accent); + border-radius: 20px; +} + .dagnode--actions--move.right { transform: rotate(180deg); } diff --git a/webapp/src/components/DAGFlow/DAGNode.flipped.css b/webapp/src/components/DAGFlow/DAGNode.flipped.css new file mode 100644 index 0000000..e69de29 diff --git a/webapp/src/components/DAGFlow/DAGNode.stories.tsx b/webapp/src/components/DAGFlow/DAGNode.stories.tsx index 1a76e4d..ebe1c0d 100644 --- a/webapp/src/components/DAGFlow/DAGNode.stories.tsx +++ b/webapp/src/components/DAGFlow/DAGNode.stories.tsx @@ -1,7 +1,6 @@ import React from "react"; import { ComponentMeta, ComponentStory } from "@storybook/react"; import { DAGAutomationFlow } from "."; -import { useState } from "react"; import * as dgconst from "components/DAGFlow/constants"; import ReactFlow, { Controls } from "react-flow-renderer"; import { DAGNode } from "./DAGNode"; diff --git a/webapp/src/components/DAGFlow/DAGNode.tsx b/webapp/src/components/DAGFlow/DAGNode.tsx index 54d9356..ad1a539 100644 --- a/webapp/src/components/DAGFlow/DAGNode.tsx +++ b/webapp/src/components/DAGFlow/DAGNode.tsx @@ -1,16 +1,17 @@ import "./DAGNode.css"; -import { PencilIcon } from "components/Icons"; +import "./DAGNode.flipped.css"; + import { NodeColor } from "types/graphs"; -import { useNodeStyles } from "./styles"; import { Handle, Position } from "react-flow-renderer"; -import { FC, ReactNode, useState } from "react"; -import ClickAwayListener from "@mui/material/ClickAwayListener"; +import { FC, ReactNode } from "react"; import IconButton from "@mui/material/IconButton"; import DeleteForeverIcon from "@mui/icons-material/DeleteForever"; import SettingsOutlinedIcon from "@mui/icons-material/SettingsOutlined"; import ArrowBackIcon from "@mui/icons-material/ArrowBack"; import { createToNodeMakerFunction } from "./helpers"; import { SpeedDial } from "components/SpeedDial"; +import Edit from "@mui/icons-material/Edit"; +import { useTheme } from "@mui/material"; export type DAGNodeOnMove = Record< Direction, @@ -26,7 +27,6 @@ export interface DAGNodeDataProps { color: NodeColor; label: ReactNode; hasInput?: boolean; - accentBackground?: boolean; } export interface DAGNodeProps extends DAGNodeDataProps { height: number; @@ -36,16 +36,13 @@ export interface DAGNodeProps extends DAGNodeDataProps { export const makeConditionPoint = createToNodeMakerFunction< { - totalConditions: number; + label: ReactNode; onEditClick: () => void; }, DAGNodeProps >((pre, { conditionWidth, conditionHeight, flipped }) => ({ color: "lblue", - accentBackground: true, - label: `${pre.totalConditions} Condition${ - pre.totalConditions !== 1 ? "s" : "" - }`, + label: pre.label, height: conditionHeight, width: conditionWidth, hasInput: true, @@ -72,38 +69,48 @@ export const DAGNode: FC = ({ onMove = {}, color, hasInput = false, - accentBackground = false, flipped, }) => { - const { classes, theme } = useNodeStyles({ - color, - nodeHeight: height, - nodeWidth: width, - accentBackground, - }); - const [open, setOpen] = useState(false); + const theme = useTheme(); return ( <> - {hasInput && ( - - )} - -
-
+
+
} + icon={} > - - - - + + + + {Object.entries(onMove).map(([key, action]) => ( = ({ ))} -
- {label} -
-
+ + {hasInput && ( + + )} + +
{label}
diff --git a/webapp/src/components/DAGFlow/constants.ts b/webapp/src/components/DAGFlow/constants.ts index e761c6e..5b25b4d 100644 --- a/webapp/src/components/DAGFlow/constants.ts +++ b/webapp/src/components/DAGFlow/constants.ts @@ -2,8 +2,8 @@ import { DAGAutomationFlowDims } from "components/DAGFlow/types"; export const NODE_WIDTH = 150 as const; export const NODE_HEIGHT = 60 as const; -export const CONDITION_HEIGHT = 30 as const; -export const CONDITION_WIDTH = 120 as const; +export const CONDITION_HEIGHT = 100 as const; +export const CONDITION_WIDTH = 200 as const; export const CIRCLE_SIZE = 40 as const; export const DISTANCE_FACTOR = 1.5 as const; export const PADDING = 50 as const; @@ -20,4 +20,4 @@ export const DEFAULT_DIMS = { y: PADDING, }, flipped: false, -} as DAGAutomationFlowDims \ No newline at end of file +} as DAGAutomationFlowDims; diff --git a/webapp/src/components/DAGFlow/index.tsx b/webapp/src/components/DAGFlow/index.tsx index 957afcb..7f99f5a 100644 --- a/webapp/src/components/DAGFlow/index.tsx +++ b/webapp/src/components/DAGFlow/index.tsx @@ -21,6 +21,7 @@ import { AutomationCondition } from "types/automations/conditions"; import { convertToFlowNode } from "./helpers"; import { DAGErrorNode } from "./DAGErrorNode"; import { useHA } from "haService"; +import { getDescriptionFromAutomationNode } from "utils/formatting"; const nodeTypes = { dagnode: convertToFlowNode(DAGNode), @@ -101,14 +102,21 @@ export const DAGAutomationFlow: FC = ({ dims.flipped ? { y: dims.padding.y + dims.nodeHeight * dims.distanceFactor, - x: dims.padding.x + dims.nodeWidth * 0.25, + x: dims.padding.x + (dims.nodeWidth - dims.conditionWidth) / 2, } : { x: dims.padding.x + dims.nodeWidth * dims.distanceFactor, - y: dims.padding.y + dims.nodeHeight * 0.25, + y: dims.padding.y + (dims.nodeHeight - dims.conditionHeight) / 2, }, { - totalConditions: condition.length, + label: getDescriptionFromAutomationNode( + { + condition: "and", + conditions: condition, + }, + namer, + true + ), onEditClick: makeOnEditAutomationConditions( condition, onConditionUpdate, @@ -154,11 +162,11 @@ export const DAGAutomationFlow: FC = ({ ...dims, padding: dims.flipped ? { - y: condPoint.position.y - dims.nodeHeight - dims.conditionHeight, + y: condPoint.position.y - dims.nodeHeight, x: dims.padding.x, } : { - x: condPoint.position.x - dims.nodeWidth - dims.conditionWidth, + x: condPoint.position.x - dims.nodeWidth, y: dims.padding.y, }, }, diff --git a/webapp/src/components/DAGFlow/sequenceConvertor.ts b/webapp/src/components/DAGFlow/sequenceConvertor.ts index f152c32..160d58b 100644 --- a/webapp/src/components/DAGFlow/sequenceConvertor.ts +++ b/webapp/src/components/DAGFlow/sequenceConvertor.ts @@ -231,11 +231,17 @@ const addChooseNode = ( dims.flipped ? { y: position.y + dims.nodeHeight * dims.distanceFactor, - x: lastPos.x + dims.nodeWidth * dims.distanceFactor, + x: + lastPos.x + + Math.max(dims.nodeWidth, dims.conditionWidth) * + dims.distanceFactor, } : { x: position.x + dims.nodeWidth * dims.distanceFactor, - y: lastPos.y + dims.nodeHeight * dims.distanceFactor, + y: + lastPos.y + + Math.max(dims.nodeHeight, dims.conditionHeight) * + dims.distanceFactor, }, { flipped: dims.flipped, @@ -254,14 +260,21 @@ const addChooseNode = ( dims.flipped ? { y: circle.position.y + dims.circleSize * dims.distanceFactor, - x: circle.position.x - dims.circleSize, + x: circle.position.x - (dims.conditionWidth - dims.circleSize) / 2, } : { x: circle.position.x + dims.circleSize * dims.distanceFactor, - y: circle.position.y + dims.circleSize / 8, + y: circle.position.y - (dims.conditionHeight - dims.circleSize) / 2, }, { - totalConditions: conditions.length, + label: getDescriptionFromAutomationNode( + { + condition: "and", + conditions, + }, + namer, + true + ), onEditClick: updater.makeOnEditConditionsForChooseNode(i, j), }, dims @@ -278,12 +291,16 @@ const addChooseNode = ( ...dims, padding: dims.flipped ? { - y: condNode.position.y - dims.nodeHeight * dims.distanceFactor, - x: condNode.position.x - dims.conditionHeight / 2, + y: condNode.position.y - dims.nodeHeight, + x: + condNode.position.x - + (dims.nodeWidth - dims.conditionWidth) / 2, } : { - x: condNode.position.x - (dims.nodeWidth + dims.conditionWidth), - y: condNode.position.y - dims.conditionHeight / 2, + x: condNode.position.x - dims.nodeWidth, + y: + condNode.position.y - + (dims.nodeHeight - dims.conditionHeight) / 2, }, }, namer, diff --git a/webapp/src/components/SpeedDial/index.css b/webapp/src/components/SpeedDial/index.css index db7de7a..917c628 100644 --- a/webapp/src/components/SpeedDial/index.css +++ b/webapp/src/components/SpeedDial/index.css @@ -1,4 +1,4 @@ -.speed-dial, .speed-dial--button { +.speed-dial, .speed-dial--icon { display: flex; flex-direction: column; height: 100%; @@ -8,7 +8,7 @@ position: relative; } -.speed-dial .speed-dial--button { +.speed-dial .speed-dial--icon { max-height: 2em; max-width: 2em; overflow: hidden; @@ -16,13 +16,12 @@ } .speed-dial--list.close { - display: none; + width: 0; + opacity: 0; } .speed-dial--list { position: absolute; - bottom: -3em; - left: 0em; background: var(--secondary); z-index: 10; height: fit-content; @@ -30,15 +29,17 @@ border-radius: 10px; } -.speed-dial--list.open.row { +.speed-dial--list.row { display: flex; flex-direction: row; + top: 0; + left: 2em; } -.speed-dial--list.open.column { +.speed-dial--list.column { display: flex; - top: 2em; flex-direction: column; gap: 0.25em; + top: 2em; left: 0.25em; } \ No newline at end of file diff --git a/webapp/src/components/SpeedDial/index.tsx b/webapp/src/components/SpeedDial/index.tsx index fe409d8..31f1058 100644 --- a/webapp/src/components/SpeedDial/index.tsx +++ b/webapp/src/components/SpeedDial/index.tsx @@ -16,9 +16,12 @@ export const SpeedDial: FC = (props) => {
setOpen(!open)} - onMouseEnter={() => setOpen(true)} > -
{props.icon}
+
+ {props.icon} +
+ getDescriptionFromAutomationNode(c, namer, allowJs) + ); + return childConditions.join(` ${node.condition} `).trim() ?? "None"; } else { switch (node.condition) { case "numeric_state":