complex movements
This commit is contained in:
1 parent
939ec2dc99
commit
6722854700
9 files changed
+412
-214
No files matched your search
@@ -0,0 +1,32 @@
|
||||
.dagnode--actions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
min-height: 100%;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.dagnode--actions--list.close {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.dagnode--actions--list {
|
||||
position: absolute;
|
||||
bottom: -3em;
|
||||
left: 0em;
|
||||
background: var(--secondary);
|
||||
}
|
||||
|
||||
.dagnode--actions--move.right {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
|
||||
.dagnode--actions--move.up {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.dagnode--actions--move.down {
|
||||
transform: rotate(270deg);
|
||||
}
|
||||
@@ -1,48 +1,87 @@
|
||||
|
||||
|
||||
import React from "react";
|
||||
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
||||
import { DAGAutomationFlow } from '.';
|
||||
import { useState } 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 ReactFlow, { Controls } from "react-flow-renderer";
|
||||
import { DAGNode } from "./DAGNode";
|
||||
import { convertToFlowNode } from "./helpers";
|
||||
import { Page } from "components/Page";
|
||||
|
||||
|
||||
export default {
|
||||
title: 'DAGAutomationFlow/Viewer/DAGNode',
|
||||
title: "DAGAutomationFlow/Viewer/DAGNode",
|
||||
component: DAGAutomationFlow,
|
||||
parameters: { actions: { argTypesRegex: '^on.*' } },
|
||||
parameters: { actions: { argTypesRegex: "^on.*" } },
|
||||
args: {
|
||||
"color": "lblue",
|
||||
"height": dgconst.NODE_HEIGHT,
|
||||
"width": dgconst.NODE_WIDTH,
|
||||
"label": "test",
|
||||
"hasInput": true,
|
||||
}
|
||||
} as ComponentMeta<typeof DAGNode>
|
||||
color: "lblue",
|
||||
height: dgconst.NODE_HEIGHT,
|
||||
width: dgconst.NODE_WIDTH,
|
||||
label: "test",
|
||||
hasInput: true,
|
||||
},
|
||||
} as ComponentMeta<typeof DAGNode>;
|
||||
|
||||
export const Colors: ComponentStory<typeof DAGNode> = args => {
|
||||
const Template: ComponentStory<typeof DAGNode> = (args) => {
|
||||
return (
|
||||
<Page>
|
||||
<ReactFlow
|
||||
defaultNodes={[
|
||||
{
|
||||
id: "one",
|
||||
position: { x: 0, y: 0 },
|
||||
type: "mynode",
|
||||
data: args,
|
||||
},
|
||||
]}
|
||||
nodeTypes={{
|
||||
mynode: convertToFlowNode(DAGNode),
|
||||
}}
|
||||
snapToGrid
|
||||
onlyRenderVisibleElements
|
||||
nodesConnectable={false}
|
||||
nodesDraggable={false}
|
||||
>
|
||||
<Controls />
|
||||
</ReactFlow>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
|
||||
export const Colors: ComponentStory<typeof DAGNode> = (args) => {
|
||||
const nodes = ["blue", "red", "green", "lblue"].map((color, i) => ({
|
||||
"data": { ...args, color },
|
||||
"id": color,
|
||||
"type": "mynode",
|
||||
"position": { "x": 50 + dgconst.NODE_HEIGHT * dgconst.DISTANCE_FACTOR * i, "y": 50 + dgconst.NODE_HEIGHT * dgconst.DISTANCE_FACTOR * i }
|
||||
data: { ...args, color },
|
||||
id: color,
|
||||
type: "mynode",
|
||||
position: {
|
||||
x: 50 + dgconst.NODE_HEIGHT * dgconst.DISTANCE_FACTOR * i,
|
||||
y: 50 + dgconst.NODE_HEIGHT * dgconst.DISTANCE_FACTOR * i,
|
||||
},
|
||||
}));
|
||||
return <Page>
|
||||
<ReactFlow
|
||||
defaultNodes={nodes}
|
||||
nodeTypes={{
|
||||
"mynode": convertToFlowNode(DAGNode)
|
||||
}}
|
||||
snapToGrid
|
||||
onlyRenderVisibleElements
|
||||
nodesConnectable={false}
|
||||
nodesDraggable={false}
|
||||
>
|
||||
<Controls />
|
||||
</ReactFlow>
|
||||
</Page>
|
||||
}
|
||||
return (
|
||||
<Page>
|
||||
<ReactFlow
|
||||
defaultNodes={nodes}
|
||||
nodeTypes={{
|
||||
mynode: convertToFlowNode(DAGNode),
|
||||
}}
|
||||
snapToGrid
|
||||
onlyRenderVisibleElements
|
||||
nodesConnectable={false}
|
||||
nodesDraggable={false}
|
||||
>
|
||||
<Controls />
|
||||
</ReactFlow>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
|
||||
export const OnMoveAllDirections = Template.bind({});
|
||||
OnMoveAllDirections.args = {
|
||||
...OnMoveAllDirections.args,
|
||||
onMove: {
|
||||
up: console.log,
|
||||
down: console.log,
|
||||
left: console.log,
|
||||
right: console.log,
|
||||
},
|
||||
};
|
||||
@@ -1,27 +1,74 @@
|
||||
import { PencilIcon } from "components/Icons"
|
||||
import "./DAGNode.css";
|
||||
import { PencilIcon } from "components/Icons";
|
||||
import { NodeColor } from "types/graphs";
|
||||
import { useNodeStyles } from "./styles";
|
||||
import { Handle, Position } from 'react-flow-renderer';
|
||||
import { FC } from "react";
|
||||
import { Handle, Position } from "react-flow-renderer";
|
||||
import { FC, ReactNode, useState } from "react";
|
||||
import ClickAwayListener from "@mui/material/ClickAwayListener";
|
||||
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";
|
||||
|
||||
|
||||
export interface DAGNodeProps {
|
||||
height: number;
|
||||
width: number;
|
||||
export type DAGNodeOnMove<Direction extends string> = Record<
|
||||
Direction,
|
||||
() => void
|
||||
>;
|
||||
export type DAGNodeOnMoveEvents = Partial<
|
||||
DAGNodeOnMove<"up" | "down" | "left" | "right">
|
||||
>;
|
||||
export interface DAGNodeDataProps {
|
||||
onXClick?: () => void;
|
||||
onEditClick?: () => void;
|
||||
onMove?: DAGNodeOnMoveEvents;
|
||||
color: NodeColor;
|
||||
label: string;
|
||||
label: ReactNode;
|
||||
hasInput?: boolean;
|
||||
accentBackground?: boolean;
|
||||
}
|
||||
export interface DAGNodeProps extends DAGNodeDataProps {
|
||||
height: number;
|
||||
width: number;
|
||||
flipped: boolean;
|
||||
}
|
||||
|
||||
export const makeConditionPoint = createToNodeMakerFunction<
|
||||
{
|
||||
totalConditions: number;
|
||||
onEditClick: () => void;
|
||||
},
|
||||
DAGNodeProps
|
||||
>((pre, { conditionWidth, conditionHeight, flipped }) => ({
|
||||
color: "lblue",
|
||||
accentBackground: true,
|
||||
label: `${pre.totalConditions} Condition${
|
||||
pre.totalConditions !== 1 ? "s" : ""
|
||||
}`,
|
||||
height: conditionHeight,
|
||||
width: conditionWidth,
|
||||
hasInput: true,
|
||||
onEditClick: pre.onEditClick,
|
||||
flipped,
|
||||
}));
|
||||
|
||||
export const makeActionPoint = createToNodeMakerFunction<
|
||||
DAGNodeDataProps,
|
||||
DAGNodeProps
|
||||
>((pre, { nodeHeight, nodeWidth, flipped }) => ({
|
||||
...pre,
|
||||
height: nodeHeight,
|
||||
width: nodeWidth,
|
||||
flipped,
|
||||
}));
|
||||
|
||||
export const DAGNode: FC<DAGNodeProps> = ({
|
||||
label,
|
||||
height,
|
||||
width,
|
||||
onXClick,
|
||||
onEditClick = () => { },
|
||||
onEditClick = () => {},
|
||||
onMove = {},
|
||||
color,
|
||||
hasInput = false,
|
||||
accentBackground = false,
|
||||
@@ -33,25 +80,60 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
||||
nodeWidth: width,
|
||||
accentBackground,
|
||||
});
|
||||
return <>
|
||||
{hasInput && <Handle type="target" position={flipped ? Position.Top : Position.Left} />}
|
||||
<Handle type="source" position={flipped ? Position.Bottom : Position.Right} />
|
||||
<div className={classes.root}>
|
||||
<div className={classes.inner}>
|
||||
<div className={classes.leftEdge} onClick={onXClick}>
|
||||
{!!onXClick && <button className={classes.buttonDelete}>X</button>}
|
||||
</div>
|
||||
<div className={classes.textWrap}>
|
||||
<span className={classes.text} title={label}>
|
||||
{label}
|
||||
</span>
|
||||
</div>
|
||||
<div className={classes.rightEdge} onClick={onEditClick}>
|
||||
<button className={classes.buttonEdit}>
|
||||
<PencilIcon size={1.1} color={theme.green} />
|
||||
</button>
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<>
|
||||
{hasInput && (
|
||||
<Handle
|
||||
type="target"
|
||||
position={flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
)}
|
||||
<Handle
|
||||
type="source"
|
||||
position={flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
<div className={classes.root}>
|
||||
<div className={classes.inner}>
|
||||
<ClickAwayListener onClickAway={() => setOpen(false)}>
|
||||
<div
|
||||
className={classes.leftEdge}
|
||||
onClick={() => setOpen(!open)}
|
||||
onMouseEnter={() => setOpen(true)}
|
||||
>
|
||||
<SettingsOutlinedIcon className="dagnode--actions" />
|
||||
<div
|
||||
className={[
|
||||
"dagnode--actions--list",
|
||||
open ? "open" : "close",
|
||||
].join(" ")}
|
||||
>
|
||||
<IconButton onClick={onXClick} size="small">
|
||||
<DeleteForeverIcon fontSize="inherit" />
|
||||
</IconButton>
|
||||
{Object.entries(onMove).map(([key, action]) => (
|
||||
<IconButton
|
||||
key={key}
|
||||
onClick={action}
|
||||
size="small"
|
||||
className={["dagnode--actions--move", key].join(" ")}
|
||||
>
|
||||
<ArrowBackIcon fontSize="inherit" />
|
||||
</IconButton>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</ClickAwayListener>
|
||||
<div className={classes.textWrap}>
|
||||
<span className={classes.text}>{label}</span>
|
||||
</div>
|
||||
<div className={classes.rightEdge} onClick={onEditClick}>
|
||||
<button className={classes.buttonEdit}>
|
||||
<PencilIcon size={1.1} color={theme.green} />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -1,51 +1,18 @@
|
||||
import { DAGCircleProps, makeFlowCircle } from "./DAGCircle"
|
||||
import { DAGAutomationFlowDims } from "./types"
|
||||
import { Node, XYPosition } from 'react-flow-renderer';
|
||||
import { DAGNodeProps } from "./DAGNode";
|
||||
import { DAGCircleProps, makeFlowCircle } from "./DAGCircle";
|
||||
import { DAGAutomationFlowDims } from "./types";
|
||||
import { Node, XYPosition } from "react-flow-renderer";
|
||||
|
||||
export const makeAddButton = (
|
||||
id: string,
|
||||
position: XYPosition,
|
||||
{
|
||||
circleSize,
|
||||
flipped,
|
||||
}: DAGAutomationFlowDims,
|
||||
onAdd: () => void,
|
||||
disableTarget: boolean = true,
|
||||
): Node<DAGCircleProps> => makeFlowCircle(
|
||||
id,
|
||||
position,
|
||||
{
|
||||
flipped,
|
||||
size: circleSize,
|
||||
onAdd,
|
||||
disableSource: true,
|
||||
disableTarget,
|
||||
}
|
||||
)
|
||||
|
||||
export const makeConditionPoint = (
|
||||
id: string,
|
||||
position: XYPosition,
|
||||
{
|
||||
conditionWidth,
|
||||
conditionHeight,
|
||||
flipped,
|
||||
}: DAGAutomationFlowDims,
|
||||
totalConditions: number,
|
||||
onEditClick: () => void,
|
||||
): Node<DAGNodeProps> => ({
|
||||
id,
|
||||
type: 'dagnode',
|
||||
position,
|
||||
data: {
|
||||
color: 'lblue',
|
||||
accentBackground: true,
|
||||
label: `${totalConditions} Condition${totalConditions !== 1 ? 's' : ''}`,
|
||||
height: conditionHeight,
|
||||
width: conditionWidth,
|
||||
hasInput: true,
|
||||
onEditClick,
|
||||
flipped,
|
||||
}
|
||||
})
|
||||
id: string,
|
||||
position: XYPosition,
|
||||
{ circleSize, flipped }: DAGAutomationFlowDims,
|
||||
onAdd: () => void,
|
||||
disableTarget: boolean = true
|
||||
): Node<DAGCircleProps> =>
|
||||
makeFlowCircle(id, position, {
|
||||
flipped,
|
||||
size: circleSize,
|
||||
onAdd,
|
||||
disableSource: true,
|
||||
disableTarget,
|
||||
});
|
||||
@@ -1,9 +1,25 @@
|
||||
import { FC } from 'react';
|
||||
import { FC } from "react";
|
||||
import { DAGAutomationFlowDims } from "components/DAGFlow/types";
|
||||
import { Node, XYPosition } from "react-flow-renderer";
|
||||
|
||||
export const convertToFlowNode =
|
||||
<D extends {}>(Component: FC<D>): FC<{ data: D }> =>
|
||||
({ data }) => {
|
||||
return <Component {...data} />;
|
||||
};
|
||||
|
||||
export const convertToFlowNode = <D extends {}>(
|
||||
Component: FC<D>
|
||||
): FC<{ data: D }> =>
|
||||
({ data }) => {
|
||||
return <Component {...data} />
|
||||
}
|
||||
export const createToNodeMakerFunction =
|
||||
<NodePreData extends {}, NodeData extends {}>(
|
||||
convert: (pre: NodePreData, dims: DAGAutomationFlowDims) => NodeData
|
||||
) =>
|
||||
(
|
||||
id: string,
|
||||
position: XYPosition,
|
||||
data: NodePreData,
|
||||
dims: DAGAutomationFlowDims
|
||||
): Node<NodeData> => ({
|
||||
id,
|
||||
type: "dagnode",
|
||||
position,
|
||||
data: convert(data, dims),
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import ReactFlow, { Controls } from "react-flow-renderer";
|
||||
import { AutomationSequenceNode } from "types/automations";
|
||||
import { AutomationTrigger } from "types/automations/triggers";
|
||||
import { triggerToFlow } from "./triggerConvertor";
|
||||
import { DAGNode } from "./DAGNode";
|
||||
import { DAGNode, makeConditionPoint } from "./DAGNode";
|
||||
import {
|
||||
DAGAutomationFlowDims,
|
||||
FlowData,
|
||||
@@ -18,7 +18,6 @@ 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";
|
||||
import { convertToFlowNode } from "./helpers";
|
||||
import { DAGErrorNode } from "./DAGErrorNode";
|
||||
import { useHA } from "haService";
|
||||
@@ -108,9 +107,15 @@ export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
|
||||
x: dims.padding.x + dims.nodeWidth * dims.distanceFactor,
|
||||
y: dims.padding.y + dims.nodeHeight * 0.25,
|
||||
},
|
||||
dims,
|
||||
condition.length,
|
||||
makeOnEditAutomationConditions(condition, onConditionUpdate, setModalState)
|
||||
{
|
||||
totalConditions: condition.length,
|
||||
onEditClick: makeOnEditAutomationConditions(
|
||||
condition,
|
||||
onConditionUpdate,
|
||||
setModalState
|
||||
),
|
||||
},
|
||||
dims
|
||||
);
|
||||
const flowData: FlowData = {
|
||||
nodes: [condPoint],
|
||||
|
||||
@@ -6,7 +6,12 @@ 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";
|
||||
import { makeAddButton } from "./flowDataMods";
|
||||
import {
|
||||
makeActionPoint,
|
||||
makeConditionPoint,
|
||||
DAGNodeOnMoveEvents,
|
||||
} from "./DAGNode";
|
||||
|
||||
export const sequenceToFlow = (
|
||||
flowData: FlowData,
|
||||
@@ -75,6 +80,7 @@ export const sequenceToFlow = (
|
||||
addSingleNode(flowData, node, position, nodeId, dims, {
|
||||
onEditClick: updater.makeOnModalOpenForNode(i, node),
|
||||
onXClick: () => updater.removeNode(i),
|
||||
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
||||
namer,
|
||||
});
|
||||
}
|
||||
@@ -82,6 +88,7 @@ export const sequenceToFlow = (
|
||||
addSingleNode(flowData, node, position, nodeId, dims, {
|
||||
onEditClick: updater.makeOnModalOpenForNode(i, node),
|
||||
onXClick: () => updater.removeNode(i),
|
||||
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
||||
namer,
|
||||
});
|
||||
}
|
||||
@@ -151,27 +158,27 @@ const addSingleNode = (
|
||||
node: AutomationSequenceNode,
|
||||
position: XYPosition,
|
||||
nodeId: string,
|
||||
{ flipped, nodeHeight, nodeWidth }: DAGAutomationFlowDims,
|
||||
dims: DAGAutomationFlowDims,
|
||||
opts: {
|
||||
onEditClick: () => void;
|
||||
onXClick: () => void;
|
||||
namer: Namer;
|
||||
onMove: DAGNodeOnMoveEvents;
|
||||
}
|
||||
) =>
|
||||
flowData.nodes.push({
|
||||
id: nodeId,
|
||||
type: "dagnode",
|
||||
data: {
|
||||
label: getDescriptionFromAutomationNode(node, opts.namer, true),
|
||||
height: nodeHeight,
|
||||
width: nodeWidth,
|
||||
color: getNodeType(node) === "action" ? "green" : "blue",
|
||||
hasInput: true,
|
||||
flipped,
|
||||
...opts,
|
||||
},
|
||||
position,
|
||||
});
|
||||
flowData.nodes.push(
|
||||
makeActionPoint(
|
||||
nodeId,
|
||||
position,
|
||||
{
|
||||
label: getDescriptionFromAutomationNode(node, opts.namer, true),
|
||||
color: getNodeType(node) === "action" ? "green" : "blue",
|
||||
hasInput: true,
|
||||
...opts,
|
||||
},
|
||||
dims
|
||||
)
|
||||
);
|
||||
|
||||
const addErrorNode = (
|
||||
flowData: FlowData,
|
||||
@@ -212,6 +219,7 @@ const addChooseNode = (
|
||||
onEditClick: updater.makeOnModalOpenForNode(i, node),
|
||||
onXClick: () => updater.removeNode(i),
|
||||
namer,
|
||||
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
||||
});
|
||||
let lastPos: XYPosition = position;
|
||||
// conditions
|
||||
@@ -252,9 +260,11 @@ const addChooseNode = (
|
||||
x: circle.position.x + dims.circleSize * dims.distanceFactor,
|
||||
y: circle.position.y + dims.circleSize / 8,
|
||||
},
|
||||
dims,
|
||||
conditions.length,
|
||||
updater.makeOnEditConditionsForChooseNode(i, j)
|
||||
{
|
||||
totalConditions: conditions.length,
|
||||
onEditClick: updater.makeOnEditConditionsForChooseNode(i, j),
|
||||
},
|
||||
dims
|
||||
);
|
||||
flowData.nodes.push(condNode);
|
||||
addEdge(flowData, circle.id, condNode.id, true);
|
||||
|
||||
@@ -3,38 +3,42 @@ import { createAppUseStyles } from "styles/theme";
|
||||
import { NodeColor } from "types/graphs";
|
||||
|
||||
export const useNodeStyles = createAppUseStyles<{
|
||||
color: NodeColor,
|
||||
nodeHeight: number,
|
||||
nodeWidth: number,
|
||||
accentBackground: boolean,
|
||||
}>(theme => {
|
||||
color: NodeColor;
|
||||
nodeHeight: number;
|
||||
nodeWidth: number;
|
||||
accentBackground: boolean;
|
||||
}>((theme) => {
|
||||
const edgeStyle: Styles = {
|
||||
flex: '1',
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
flexWrap: 'nowrap',
|
||||
borderRadius: '1em',
|
||||
justifyContent: 'space-around',
|
||||
alignItems: 'center',
|
||||
'&:hover': {
|
||||
flex: "1",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
flexWrap: "nowrap",
|
||||
borderRadius: "1em",
|
||||
justifyContent: "space-around",
|
||||
alignItems: "center",
|
||||
"&:hover": {
|
||||
backgroundColor: theme.primaryAccent,
|
||||
cursor: 'pointer',
|
||||
}
|
||||
}
|
||||
cursor: "pointer",
|
||||
},
|
||||
};
|
||||
const buttonStyle: Styles = {
|
||||
fontSize: '8px',
|
||||
fontSize: "8px",
|
||||
backgroundColor: "rgba(0,0,0,0)",
|
||||
color: theme.primaryAccent,
|
||||
borderStyle: 'none',
|
||||
height: '15px',
|
||||
width: '15px',
|
||||
cursor: 'pointer',
|
||||
}
|
||||
borderStyle: "none",
|
||||
height: "15px",
|
||||
width: "15px",
|
||||
cursor: "pointer",
|
||||
};
|
||||
return {
|
||||
speeddial: {
|
||||
height: "2em",
|
||||
width: "2em",
|
||||
},
|
||||
root: ({ nodeHeight, nodeWidth }) => ({
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
justifyContent: 'flex-end',
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
justifyContent: "flex-end",
|
||||
height: nodeHeight,
|
||||
maxHeight: nodeHeight,
|
||||
maxWidth: nodeWidth,
|
||||
@@ -42,56 +46,64 @@ export const useNodeStyles = createAppUseStyles<{
|
||||
fontSize: 10,
|
||||
}),
|
||||
inner: ({ color, accentBackground }) => ({
|
||||
position: 'relative',
|
||||
display: 'flex',
|
||||
flexDirection: 'row',
|
||||
backgroundColor: !accentBackground ? theme.secondary :
|
||||
color === 'lblue' ? theme.condition.primaryColorOpaque : 'none',
|
||||
borderRadius: '1em',
|
||||
position: "relative",
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
backgroundColor: !accentBackground
|
||||
? theme.secondary
|
||||
: color === "lblue"
|
||||
? theme.condition.primaryColorOpaque
|
||||
: "none",
|
||||
borderRadius: "1em",
|
||||
flex: 1,
|
||||
height: `100%`,
|
||||
maxHeight: `100%`,
|
||||
maxWidth: '100%',
|
||||
marginTop: '2.5px',
|
||||
marginBottom: '2.5px',
|
||||
borderTopWidth: '1px',
|
||||
borderTopStyle: 'solid',
|
||||
borderTopLeftRadius: '10px',
|
||||
borderTopRightRadius: '10px',
|
||||
borderTopColor: color === 'red' ? theme.redAccent :
|
||||
color === 'blue' ? theme.condition.primaryColor :
|
||||
color === 'green' ? theme.green :
|
||||
color === 'lblue' ? theme.condition.primaryAccent :
|
||||
'none'
|
||||
maxWidth: "100%",
|
||||
marginTop: "2.5px",
|
||||
marginBottom: "2.5px",
|
||||
borderTopWidth: "1px",
|
||||
borderTopStyle: "solid",
|
||||
borderTopLeftRadius: "10px",
|
||||
borderTopRightRadius: "10px",
|
||||
borderTopColor:
|
||||
color === "red"
|
||||
? theme.redAccent
|
||||
: color === "blue"
|
||||
? theme.condition.primaryColor
|
||||
: color === "green"
|
||||
? theme.green
|
||||
: color === "lblue"
|
||||
? theme.condition.primaryAccent
|
||||
: "none",
|
||||
}),
|
||||
textWrap: {
|
||||
display: 'flex',
|
||||
display: "flex",
|
||||
flex: 4,
|
||||
textAlign: 'center',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
height: '100%',
|
||||
maxHeight: '100%',
|
||||
textAlign: "center",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
height: "100%",
|
||||
maxHeight: "100%",
|
||||
maxWidth: "50%",
|
||||
},
|
||||
text: {
|
||||
textOverflow: 'ellipsis',
|
||||
textOverflow: "ellipsis",
|
||||
overflow: "hidden",
|
||||
whiteSpace: "break-spaces",
|
||||
lineBreak: "anywhere",
|
||||
cursor: 'default',
|
||||
cursor: "default",
|
||||
},
|
||||
buttonDelete: {
|
||||
...buttonStyle,
|
||||
"&:hover": {
|
||||
color: theme.primary,
|
||||
}
|
||||
},
|
||||
},
|
||||
buttonEdit: {
|
||||
...buttonStyle,
|
||||
"&:hover": {
|
||||
transform: "rotate(45deg)"
|
||||
}
|
||||
transform: "rotate(45deg)",
|
||||
},
|
||||
},
|
||||
leftEdge: {
|
||||
...edgeStyle,
|
||||
@@ -105,35 +117,35 @@ export const useNodeStyles = createAppUseStyles<{
|
||||
borderTopLeftRadius: 0,
|
||||
borderBottomLeftRadius: 0,
|
||||
},
|
||||
}
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
export const useCircleStyles = createAppUseStyles<{
|
||||
size: number,
|
||||
hasOnFunction: boolean,
|
||||
hasRemoveFunction: boolean,
|
||||
backgroundColor?: string,
|
||||
}>(theme => ({
|
||||
size: number;
|
||||
hasOnFunction: boolean;
|
||||
hasRemoveFunction: boolean;
|
||||
backgroundColor?: string;
|
||||
}>((theme) => ({
|
||||
root: ({ size, hasOnFunction, hasRemoveFunction, backgroundColor }) => {
|
||||
const baseColor = backgroundColor ? backgroundColor : theme.green;
|
||||
const hoverColor = hasOnFunction ? theme.greenOpaque : baseColor
|
||||
const hoverColor = hasOnFunction ? theme.greenOpaque : baseColor;
|
||||
return {
|
||||
backgroundColor: baseColor,
|
||||
borderRadius: hasRemoveFunction ? 10 : 500,
|
||||
height: size,
|
||||
width: size,
|
||||
color: theme.primary,
|
||||
cursor: hasOnFunction ? "pointer" : 'default',
|
||||
cursor: hasOnFunction ? "pointer" : "default",
|
||||
"&:hover": {
|
||||
backgroundColor: hoverColor,
|
||||
},
|
||||
fontSize: `${size * 0.4}px`,
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
alignItems: 'center',
|
||||
}
|
||||
display: "flex",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
};
|
||||
},
|
||||
trashIcon: {
|
||||
padding: 1,
|
||||
}
|
||||
}))
|
||||
},
|
||||
}));
|
||||
@@ -3,6 +3,8 @@ import { ChooseAction } from "types/automations/actions";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { UpdateModalState } from "./types";
|
||||
import { getNodeType } from "../../utils/automations";
|
||||
import { DAGNodeOnMoveEvents } from "./DAGNode";
|
||||
import { cleanUpUndefined } from "components/NodeEditor/OptionManager/OptionManager";
|
||||
|
||||
export type SequenceUpdater = ReturnType<typeof makeSequenceUpdater>;
|
||||
|
||||
@@ -121,6 +123,39 @@ export const makeSequenceUpdater = (
|
||||
update: (n) => this.updateNode(i, n),
|
||||
});
|
||||
},
|
||||
makeOnMoveEvents(i: number, flipped: boolean): DAGNodeOnMoveEvents {
|
||||
const moveBack =
|
||||
i > 0
|
||||
? () =>
|
||||
onChange([
|
||||
...sequence.slice(0, i - 1),
|
||||
sequence[i],
|
||||
sequence[i - 1],
|
||||
...sequence.slice(i + 1),
|
||||
])
|
||||
: undefined;
|
||||
const moveForward =
|
||||
i < sequence.length - 1
|
||||
? () =>
|
||||
onChange([
|
||||
...sequence.slice(0, i),
|
||||
sequence[i + 1],
|
||||
sequence[i],
|
||||
...sequence.slice(i + 2),
|
||||
])
|
||||
: undefined;
|
||||
if (flipped) {
|
||||
return cleanUpUndefined({
|
||||
up: moveBack,
|
||||
down: moveForward,
|
||||
});
|
||||
} else {
|
||||
return cleanUpUndefined({
|
||||
right: moveForward,
|
||||
left: moveBack,
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const createOnRemoveForChooseNode =
|
||||
|
||||
Reference in new issue
Block a user