enable/disable node
This commit is contained in:
1 parent
869c23212b
commit
5bd5c5e445
6 files changed
+129
-78
No files matched your search
@@ -25,12 +25,6 @@
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
|
||||
/* overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: break-word; */
|
||||
}
|
||||
|
||||
.dagnode--label span {
|
||||
@@ -40,6 +34,12 @@
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.dagnode--enabled-flag {
|
||||
position: absolute;
|
||||
top: -1.5em;
|
||||
right: -2.5em;
|
||||
}
|
||||
|
||||
.dagnode .dagnode--inner .speed-dial {
|
||||
height: 2em;
|
||||
width: 2em;
|
||||
|
||||
@@ -12,6 +12,7 @@ import { createToNodeMakerFunction } from "./helpers";
|
||||
import { SpeedDial } from "components/SpeedDial";
|
||||
import Edit from "@mui/icons-material/Edit";
|
||||
import { useTheme } from "@mui/material";
|
||||
import InputBoolean from "components/Inputs/InputBoolean";
|
||||
|
||||
export type DAGNodeOnMove<Direction extends string> = Record<
|
||||
Direction,
|
||||
@@ -23,10 +24,12 @@ export type DAGNodeOnMoveEvents = Partial<
|
||||
export interface DAGNodeDataProps {
|
||||
onXClick?: () => void;
|
||||
onEditClick?: () => void;
|
||||
onSetEnabled?: () => void;
|
||||
onMove?: DAGNodeOnMoveEvents;
|
||||
color: NodeColor;
|
||||
label: ReactNode;
|
||||
hasInput?: boolean;
|
||||
enabled: boolean;
|
||||
}
|
||||
export interface DAGNodeProps extends DAGNodeDataProps {
|
||||
height: number;
|
||||
@@ -42,12 +45,12 @@ export const makeConditionPoint = createToNodeMakerFunction<
|
||||
DAGNodeProps
|
||||
>((pre, { conditionWidth, conditionHeight, flipped }) => ({
|
||||
color: "lblue",
|
||||
label: pre.label,
|
||||
height: conditionHeight,
|
||||
width: conditionWidth,
|
||||
hasInput: true,
|
||||
onEditClick: pre.onEditClick,
|
||||
enabled: true,
|
||||
flipped,
|
||||
...pre,
|
||||
}));
|
||||
|
||||
export const makeActionPoint = createToNodeMakerFunction<
|
||||
@@ -70,12 +73,18 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
||||
color,
|
||||
hasInput = false,
|
||||
flipped,
|
||||
enabled,
|
||||
onSetEnabled,
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={["dagnode", flipped ? "flipped" : ""].join(" ")}
|
||||
className={[
|
||||
"dagnode",
|
||||
flipped ? "flipped" : "",
|
||||
enabled ? "enabled" : "disabled",
|
||||
].join(" ")}
|
||||
style={{
|
||||
height,
|
||||
width,
|
||||
@@ -100,7 +109,9 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
||||
: color === "red"
|
||||
? theme.palette.error.dark
|
||||
: "none",
|
||||
backgroundColor: theme.palette.background.default,
|
||||
backgroundColor: enabled
|
||||
? theme.palette.background.default
|
||||
: theme.palette.grey[600],
|
||||
}}
|
||||
>
|
||||
<SpeedDial
|
||||
@@ -109,9 +120,6 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
||||
<IconButton onClick={onEditClick} size="small">
|
||||
<Edit color="success" fontSize="inherit" />
|
||||
</IconButton>
|
||||
<IconButton onClick={onXClick} size="small">
|
||||
<DeleteForeverIcon fontSize="inherit" color="error" />
|
||||
</IconButton>
|
||||
{Object.entries(onMove).map(([key, action]) => (
|
||||
<IconButton
|
||||
key={key}
|
||||
@@ -122,7 +130,19 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
||||
<ArrowBackIcon fontSize="inherit" />
|
||||
</IconButton>
|
||||
))}
|
||||
<IconButton onClick={onXClick} size="small">
|
||||
<DeleteForeverIcon fontSize="inherit" color="error" />
|
||||
</IconButton>
|
||||
</SpeedDial>
|
||||
{!!onSetEnabled && (
|
||||
<InputBoolean
|
||||
key="enabled-flag"
|
||||
className="dagnode--enabled-flag"
|
||||
label=""
|
||||
value={enabled}
|
||||
onChange={onSetEnabled}
|
||||
/>
|
||||
)}
|
||||
|
||||
{hasInput && (
|
||||
<Handle
|
||||
|
||||
@@ -139,6 +139,12 @@ export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
|
||||
onTriggerUpdate([...trigger.slice(0, i), t, ...trigger.slice(i + 1)]),
|
||||
allowedTypes: ["trigger"],
|
||||
}),
|
||||
onSetEnabled: (i) =>
|
||||
onTriggerUpdate([
|
||||
...trigger.slice(0, i),
|
||||
{ ...trigger[i], enabled: !(trigger[i] ?? true) },
|
||||
...trigger.slice(i + 1),
|
||||
]),
|
||||
});
|
||||
sequenceToFlow(
|
||||
flowData,
|
||||
|
||||
@@ -82,6 +82,11 @@ export const sequenceToFlow = (
|
||||
onXClick: () => updater.removeNode(i),
|
||||
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
||||
namer,
|
||||
onSetEnabled: () =>
|
||||
updater.updateNode(i, {
|
||||
...node,
|
||||
enabled: !(node.enabled ?? true),
|
||||
}),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -90,6 +95,11 @@ export const sequenceToFlow = (
|
||||
onXClick: () => updater.removeNode(i),
|
||||
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
||||
namer,
|
||||
onSetEnabled: () =>
|
||||
updater.updateNode(i, {
|
||||
...node,
|
||||
enabled: !(node.enabled ?? true),
|
||||
}),
|
||||
});
|
||||
}
|
||||
addEdge(flowData, lastPointId, nodeId, false);
|
||||
@@ -164,6 +174,7 @@ const addSingleNode = (
|
||||
onXClick: () => void;
|
||||
namer: Namer;
|
||||
onMove: DAGNodeOnMoveEvents;
|
||||
onSetEnabled: () => void;
|
||||
}
|
||||
) =>
|
||||
flowData.nodes.push(
|
||||
@@ -174,6 +185,7 @@ const addSingleNode = (
|
||||
label: getDescriptionFromAutomationNode(node, opts.namer, true),
|
||||
color: getNodeType(node) === "action" ? "green" : "blue",
|
||||
hasInput: true,
|
||||
enabled: node.enabled ?? true,
|
||||
...opts,
|
||||
},
|
||||
dims
|
||||
@@ -220,6 +232,11 @@ const addChooseNode = (
|
||||
onXClick: () => updater.removeNode(i),
|
||||
namer,
|
||||
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
||||
onSetEnabled: () =>
|
||||
updater.updateNode(i, {
|
||||
...node,
|
||||
enabled: !(node.enabled ?? true),
|
||||
}),
|
||||
});
|
||||
let lastPos: XYPosition = position;
|
||||
// conditions
|
||||
|
||||
@@ -2,6 +2,7 @@ import { AutomationTrigger } from "types/automations/triggers";
|
||||
import { DAGAutomationFlowDims, FlowData, TriggerMakerOptions } from "./types";
|
||||
import { makeAddButton } from "./flowDataMods";
|
||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||
import { makeActionPoint } from "./DAGNode";
|
||||
|
||||
export const triggerToFlow = (
|
||||
flowData: FlowData,
|
||||
@@ -22,28 +23,29 @@ export const triggerToFlow = (
|
||||
// convert all triggers to dag nodes
|
||||
trigger.forEach((t, i) => {
|
||||
const flowId = `t-${i}`;
|
||||
flowData.nodes.push({
|
||||
id: flowId,
|
||||
type: "dagnode",
|
||||
data: {
|
||||
label: getDescriptionFromAutomationNode(t, opts.namer, true),
|
||||
height: nodeHeight,
|
||||
width: nodeWidth,
|
||||
flipped,
|
||||
color: "red",
|
||||
onEditClick: () => opts.onEdit(i),
|
||||
onXClick: () => opts.onDelete(i),
|
||||
},
|
||||
position: flipped
|
||||
? {
|
||||
y: padding.y,
|
||||
x: padding.x + nodeWidth * distanceFactor * i,
|
||||
}
|
||||
: {
|
||||
x: padding.x,
|
||||
y: padding.y + nodeHeight * distanceFactor * i,
|
||||
},
|
||||
});
|
||||
flowData.nodes.push(
|
||||
makeActionPoint(
|
||||
flowId,
|
||||
flipped
|
||||
? {
|
||||
y: padding.y,
|
||||
x: padding.x + nodeWidth * distanceFactor * i,
|
||||
}
|
||||
: {
|
||||
x: padding.x,
|
||||
y: padding.y + nodeHeight * distanceFactor * i,
|
||||
},
|
||||
{
|
||||
label: getDescriptionFromAutomationNode(t, opts.namer, true),
|
||||
color: "red",
|
||||
onEditClick: () => opts.onEdit(i),
|
||||
onXClick: () => opts.onDelete(i),
|
||||
enabled: t.enabled ?? true,
|
||||
onSetEnabled: () => opts.onSetEnabled(i),
|
||||
},
|
||||
dims
|
||||
)
|
||||
);
|
||||
flowData.edges.push({
|
||||
id: `e(${flowId})-(${toPoint})`,
|
||||
source: flowId,
|
||||
|
||||
@@ -1,51 +1,57 @@
|
||||
import { Edge, Node, XYPosition } from 'react-flow-renderer';
|
||||
import { AutomationSequenceNode } from 'types/automations';
|
||||
import { DAGCircleProps } from './DAGCircle';
|
||||
import { DAGNodeProps } from './DAGNode';
|
||||
import { AutomationTrigger } from 'types/automations/triggers';
|
||||
import { MultiNodeEditorProps } from 'components/MultiNodeEditors/types';
|
||||
import { DAGErrorNodeProps } from './DAGErrorNode';
|
||||
import { Namer } from 'utils/formatting';
|
||||
|
||||
import { Edge, Node, XYPosition } from "react-flow-renderer";
|
||||
import { AutomationSequenceNode } from "types/automations";
|
||||
import { DAGCircleProps } from "./DAGCircle";
|
||||
import { DAGNodeProps } from "./DAGNode";
|
||||
import { AutomationTrigger } from "types/automations/triggers";
|
||||
import { MultiNodeEditorProps } from "components/MultiNodeEditors/types";
|
||||
import { DAGErrorNodeProps } from "./DAGErrorNode";
|
||||
import { Namer } from "utils/formatting";
|
||||
|
||||
export type DAGAutomationFlowDims = {
|
||||
padding: XYPosition;
|
||||
nodeHeight: number;
|
||||
nodeWidth: number;
|
||||
conditionWidth: number;
|
||||
conditionHeight: number;
|
||||
circleSize: number;
|
||||
distanceFactor: number;
|
||||
flipped: boolean;
|
||||
}
|
||||
padding: XYPosition;
|
||||
nodeHeight: number;
|
||||
nodeWidth: number;
|
||||
conditionWidth: number;
|
||||
conditionHeight: number;
|
||||
circleSize: number;
|
||||
distanceFactor: number;
|
||||
flipped: boolean;
|
||||
};
|
||||
|
||||
export type DAGAutomationFlowNode = Node<DAGNodeProps | DAGCircleProps | DAGErrorNodeProps | any>;
|
||||
export type DAGAutomationFlowNode = Node<
|
||||
DAGNodeProps | DAGCircleProps | DAGErrorNodeProps | any
|
||||
>;
|
||||
export type FlowData = {
|
||||
nodes: DAGAutomationFlowNode[],
|
||||
edges: Edge[],
|
||||
}
|
||||
nodes: DAGAutomationFlowNode[];
|
||||
edges: Edge[];
|
||||
};
|
||||
|
||||
export type TriggerMakerOptions = {
|
||||
onAdd: () => void,
|
||||
onEdit: (i: number) => void,
|
||||
onDelete: (i: number) => void,
|
||||
namer: Namer,
|
||||
}
|
||||
onAdd: () => void;
|
||||
onEdit: (i: number) => void;
|
||||
onDelete: (i: number) => void;
|
||||
namer: Namer;
|
||||
onSetEnabled: (i: number) => void;
|
||||
};
|
||||
|
||||
export type UpdateModalState<T extends AutomationSequenceNode | AutomationTrigger = any> = (
|
||||
s: ModalState<T>
|
||||
) => void;
|
||||
export type UpdateModalState<
|
||||
T extends AutomationSequenceNode | AutomationTrigger = any
|
||||
> = (s: ModalState<T>) => void;
|
||||
|
||||
export type ModalState<T extends AutomationSequenceNode | AutomationTrigger = any> = {
|
||||
single: true,
|
||||
isError?: boolean,
|
||||
node: T
|
||||
update: (n: T) => void;
|
||||
saveBtnCreateText?: boolean;
|
||||
allowedTypes: MultiNodeEditorProps['allowedTypes'],
|
||||
} | {
|
||||
single: false,
|
||||
node: AutomationSequenceNode[]
|
||||
update: (n: AutomationSequenceNode[]) => void;
|
||||
allowedTypes: ['condition']
|
||||
}
|
||||
export type ModalState<
|
||||
T extends AutomationSequenceNode | AutomationTrigger = any
|
||||
> =
|
||||
| {
|
||||
single: true;
|
||||
isError?: boolean;
|
||||
node: T;
|
||||
update: (n: T) => void;
|
||||
saveBtnCreateText?: boolean;
|
||||
allowedTypes: MultiNodeEditorProps["allowedTypes"];
|
||||
}
|
||||
| {
|
||||
single: false;
|
||||
node: AutomationSequenceNode[];
|
||||
update: (n: AutomationSequenceNode[]) => void;
|
||||
allowedTypes: ["condition"];
|
||||
};
|
||||
Reference in new issue
Block a user