add to middle
This commit is contained in:
1 parent
e8b76039a9
commit
34394feb9d
8 files changed
+353
-97
No files matched your search
@@ -0,0 +1,155 @@
|
|||||||
|
import { AutomationSequenceNode } from "types/automations";
|
||||||
|
import { ModalState } from "./types";
|
||||||
|
import { makeDagFlowUpdate } from "./DAGFlowUpdater";
|
||||||
|
import { AutomationTrigger } from "types/automations/triggers";
|
||||||
|
import { AutomationCondition } from "types/automations/conditions";
|
||||||
|
|
||||||
|
const mockDAGFlowUpdater = (
|
||||||
|
initialSequences: AutomationSequenceNode[] = [],
|
||||||
|
initialTriggers: AutomationTrigger[] = [],
|
||||||
|
initialConditions: AutomationCondition[] = []
|
||||||
|
) => {
|
||||||
|
let sequence = [...initialSequences];
|
||||||
|
let trigger = [...initialTriggers];
|
||||||
|
let condition = [...initialConditions];
|
||||||
|
const modalStates: ModalState[] = [];
|
||||||
|
|
||||||
|
const updater = makeDagFlowUpdate({
|
||||||
|
sequence,
|
||||||
|
trigger,
|
||||||
|
condition,
|
||||||
|
openModal: (m) => {
|
||||||
|
modalStates.push(m);
|
||||||
|
},
|
||||||
|
onTriggerUpdate: (t) => {
|
||||||
|
trigger = [...t];
|
||||||
|
},
|
||||||
|
onSequenceUpdate: (s) => {
|
||||||
|
sequence = [...s];
|
||||||
|
},
|
||||||
|
onConditionUpdate: (c) => {
|
||||||
|
condition = [...c];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
get condition() {
|
||||||
|
return condition;
|
||||||
|
},
|
||||||
|
get trigger() {
|
||||||
|
return trigger;
|
||||||
|
},
|
||||||
|
get sequence() {
|
||||||
|
return sequence;
|
||||||
|
},
|
||||||
|
get modalStates() {
|
||||||
|
return modalStates;
|
||||||
|
},
|
||||||
|
updater,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
test("DAGFlowUpdater.onaddNode add node when we have nothing", () => {
|
||||||
|
const emptyMock = mockDAGFlowUpdater();
|
||||||
|
emptyMock.updater.addNode(null, "sequence");
|
||||||
|
expect(emptyMock.modalStates.length).toEqual(1);
|
||||||
|
emptyMock.modalStates[0].update({
|
||||||
|
device_id: "testme",
|
||||||
|
});
|
||||||
|
expect((emptyMock.sequence[0] as any).device_id).toEqual("testme");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("DAGFlowUpdater.onaddNode add node to end when we have 1 thing", () => {
|
||||||
|
const mock = mockDAGFlowUpdater([
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
mock.updater.addNode(null, "sequence");
|
||||||
|
expect(mock.modalStates.length).toEqual(1);
|
||||||
|
mock.modalStates[0].update({
|
||||||
|
device_id: "testme",
|
||||||
|
});
|
||||||
|
expect(mock.sequence.length).toEqual(2);
|
||||||
|
expect((mock.sequence[1] as any).device_id).toEqual("testme");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("DAGFlowUpdater.onaddNode add node to start when we have 1 thing", () => {
|
||||||
|
const mock = mockDAGFlowUpdater([
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
mock.updater.addNode(0, "sequence");
|
||||||
|
expect(mock.modalStates.length).toEqual(1);
|
||||||
|
mock.modalStates[0].update({
|
||||||
|
device_id: "testme",
|
||||||
|
});
|
||||||
|
expect(mock.sequence.length).toEqual(2);
|
||||||
|
expect((mock.sequence[0] as any).device_id).toEqual("testme");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("DAGFlowUpdater.onaddNode add node to start when we have many things", () => {
|
||||||
|
const mock = mockDAGFlowUpdater([
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
mock.updater.addNode(0, "sequence");
|
||||||
|
expect(mock.modalStates.length).toEqual(1);
|
||||||
|
mock.modalStates[0].update({
|
||||||
|
device_id: "testme",
|
||||||
|
});
|
||||||
|
expect(mock.sequence.length).toEqual(8);
|
||||||
|
expect((mock.sequence[0] as any).device_id).toEqual("testme");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("DAGFlowUpdater.onaddNode add node to middle when we have many things", () => {
|
||||||
|
const mock = mockDAGFlowUpdater([
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
choose: [],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
mock.updater.addNode(2, "sequence");
|
||||||
|
expect(mock.modalStates.length).toEqual(1);
|
||||||
|
mock.modalStates[0].update({
|
||||||
|
device_id: "testme",
|
||||||
|
});
|
||||||
|
expect(mock.sequence.length).toEqual(8);
|
||||||
|
expect((mock.sequence[2] as any).device_id).toEqual("testme");
|
||||||
|
});
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
import { AutomationSequenceNode } from "types/automations";
|
||||||
|
import { AutomationCondition } from "types/automations/conditions";
|
||||||
|
import { AutomationTrigger } from "types/automations/triggers";
|
||||||
|
import { Namer } from "utils/formatting";
|
||||||
|
import { makeOnEditAutomationConditions } from "./helpers";
|
||||||
|
import { ModalState, TriggerMakerOptions } from "./types";
|
||||||
|
import { makeSequenceUpdater, SequenceUpdater } from "./updater";
|
||||||
|
|
||||||
|
export type DagFlowUpdateBaseArgs = {
|
||||||
|
trigger: AutomationTrigger[];
|
||||||
|
condition: AutomationCondition[];
|
||||||
|
sequence: AutomationSequenceNode[];
|
||||||
|
onTriggerUpdate: (t: AutomationTrigger[]) => void;
|
||||||
|
onSequenceUpdate: (s: AutomationSequenceNode[]) => void;
|
||||||
|
onConditionUpdate: (s: AutomationCondition[]) => void;
|
||||||
|
};
|
||||||
|
export type DagFlowUpdateArgs = DagFlowUpdateBaseArgs & {
|
||||||
|
openModal: (m: ModalState) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type DagFlowUpdate = ReturnType<typeof makeDagFlowUpdate>;
|
||||||
|
export const makeDagFlowUpdate = (args: DagFlowUpdateArgs) => {
|
||||||
|
const methods = {
|
||||||
|
addNode(
|
||||||
|
afterIndex: number | null,
|
||||||
|
nodeType: "sequence" | "trigger" | "only-conditions"
|
||||||
|
) {
|
||||||
|
return args.openModal({
|
||||||
|
saveBtnCreateText: true,
|
||||||
|
node:
|
||||||
|
nodeType === "sequence"
|
||||||
|
? {
|
||||||
|
device_id: "",
|
||||||
|
}
|
||||||
|
: nodeType === "trigger"
|
||||||
|
? {
|
||||||
|
id: "",
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
condition: "and",
|
||||||
|
conditions: [],
|
||||||
|
},
|
||||||
|
update: (n) => {
|
||||||
|
console.log({ afterIndex, n });
|
||||||
|
if (afterIndex !== null) {
|
||||||
|
args.onSequenceUpdate([
|
||||||
|
...args.sequence.slice(0, afterIndex),
|
||||||
|
n,
|
||||||
|
...args.sequence.slice(afterIndex),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
args.onSequenceUpdate([...args.sequence, n]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
allowedTypes:
|
||||||
|
nodeType === "sequence"
|
||||||
|
? ["action", "condition"]
|
||||||
|
: nodeType === "trigger"
|
||||||
|
? ["trigger"]
|
||||||
|
: ["condition"],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
onEditAutomationConditions() {
|
||||||
|
return makeOnEditAutomationConditions(
|
||||||
|
args.condition,
|
||||||
|
args.onConditionUpdate,
|
||||||
|
args.openModal
|
||||||
|
)();
|
||||||
|
},
|
||||||
|
makeTriggerMakerOptions(namer: Namer): TriggerMakerOptions {
|
||||||
|
return {
|
||||||
|
namer,
|
||||||
|
onAdd: () =>
|
||||||
|
args.openModal({
|
||||||
|
saveBtnCreateText: true,
|
||||||
|
node: {
|
||||||
|
platform: "device",
|
||||||
|
},
|
||||||
|
update: (n) => {
|
||||||
|
args.onTriggerUpdate([...args.trigger, n]);
|
||||||
|
},
|
||||||
|
allowedTypes: ["trigger"],
|
||||||
|
}),
|
||||||
|
onDelete: (i) =>
|
||||||
|
args.onTriggerUpdate([
|
||||||
|
...args.trigger.slice(0, i),
|
||||||
|
...args.trigger.slice(i + 1),
|
||||||
|
]),
|
||||||
|
onEdit: (i) =>
|
||||||
|
args.openModal({
|
||||||
|
node: args.trigger[i],
|
||||||
|
update: (t) =>
|
||||||
|
args.onTriggerUpdate([
|
||||||
|
...args.trigger.slice(0, i),
|
||||||
|
t,
|
||||||
|
...args.trigger.slice(i + 1),
|
||||||
|
]),
|
||||||
|
allowedTypes: ["trigger"],
|
||||||
|
}),
|
||||||
|
onSetEnabled: (i) =>
|
||||||
|
args.onTriggerUpdate([
|
||||||
|
...args.trigger.slice(0, i),
|
||||||
|
{ ...args.trigger[i], enabled: !(args.trigger[i].enabled ?? true) },
|
||||||
|
...args.trigger.slice(i + 1),
|
||||||
|
]),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
get sequenceUpdater(): SequenceUpdater {
|
||||||
|
return makeSequenceUpdater(
|
||||||
|
args.sequence,
|
||||||
|
args.onSequenceUpdate,
|
||||||
|
args.openModal
|
||||||
|
);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return methods;
|
||||||
|
};
|
||||||
@@ -42,6 +42,25 @@
|
|||||||
right: -2.5em;
|
right: -2.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.dagnode--midway-options {
|
||||||
|
position: absolute;
|
||||||
|
bottom: -2.5em;
|
||||||
|
left: calc(50%-0.5em);
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dagnode--midway-options button {
|
||||||
|
padding: 0;
|
||||||
|
color: var(--mui-primary-main);
|
||||||
|
background-color: var(--mui-primary-contrastText);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dagnode--midway-options button:hover {
|
||||||
|
color: var(--mui-primary-dark);
|
||||||
|
background-color: var(--mui-primary-contrastText);
|
||||||
|
}
|
||||||
|
|
||||||
.dagnode .dagnode--inner .speed-dial {
|
.dagnode .dagnode--inner .speed-dial {
|
||||||
height: 2em;
|
height: 2em;
|
||||||
width: 2em;
|
width: 2em;
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import { useTheme } from "@mui/material";
|
|||||||
import InputBoolean from "components/Inputs/InputBoolean";
|
import InputBoolean from "components/Inputs/InputBoolean";
|
||||||
import { useConfirm } from "material-ui-confirm";
|
import { useConfirm } from "material-ui-confirm";
|
||||||
import { useSnackbar } from "notistack";
|
import { useSnackbar } from "notistack";
|
||||||
|
import { ButtonIcon } from "components/Icons/ButtonIcons";
|
||||||
|
import Add from "@mui/icons-material/Add";
|
||||||
|
|
||||||
export type DAGNodeOnMove<Direction extends string> = Record<
|
export type DAGNodeOnMove<Direction extends string> = Record<
|
||||||
Direction,
|
Direction,
|
||||||
@@ -27,6 +29,7 @@ export interface DAGNodeDataProps {
|
|||||||
onXClick?: () => void;
|
onXClick?: () => void;
|
||||||
onEditClick?: () => void;
|
onEditClick?: () => void;
|
||||||
onSetEnabled?: () => void;
|
onSetEnabled?: () => void;
|
||||||
|
onAddNode?: () => void;
|
||||||
onMove?: DAGNodeOnMoveEvents;
|
onMove?: DAGNodeOnMoveEvents;
|
||||||
color: NodeColor;
|
color: NodeColor;
|
||||||
label: ReactNode;
|
label: ReactNode;
|
||||||
@@ -43,6 +46,7 @@ export const makeConditionPoint = createToNodeMakerFunction<
|
|||||||
{
|
{
|
||||||
label: ReactNode;
|
label: ReactNode;
|
||||||
onEditClick: () => void;
|
onEditClick: () => void;
|
||||||
|
onAddNode: () => void;
|
||||||
},
|
},
|
||||||
DAGNodeProps
|
DAGNodeProps
|
||||||
>((pre, { conditionWidth, conditionHeight, flipped }) => ({
|
>((pre, { conditionWidth, conditionHeight, flipped }) => ({
|
||||||
@@ -71,6 +75,7 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
|||||||
width,
|
width,
|
||||||
onXClick,
|
onXClick,
|
||||||
onEditClick = () => {},
|
onEditClick = () => {},
|
||||||
|
onAddNode,
|
||||||
onMove = {},
|
onMove = {},
|
||||||
color,
|
color,
|
||||||
hasInput = false,
|
hasInput = false,
|
||||||
@@ -81,6 +86,16 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const confirm = useConfirm();
|
const confirm = useConfirm();
|
||||||
const snackbr = useSnackbar();
|
const snackbr = useSnackbar();
|
||||||
|
const nodeColor =
|
||||||
|
color === "blue"
|
||||||
|
? theme.palette.info.main
|
||||||
|
: color === "green"
|
||||||
|
? theme.palette.success.light
|
||||||
|
: color === "lblue"
|
||||||
|
? theme.palette.info.light
|
||||||
|
: color === "red"
|
||||||
|
? theme.palette.error.dark
|
||||||
|
: "none";
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@@ -103,16 +118,7 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
|||||||
borderBottomColor: theme.palette.grey[500],
|
borderBottomColor: theme.palette.grey[500],
|
||||||
borderLeftColor: theme.palette.grey[700],
|
borderLeftColor: theme.palette.grey[700],
|
||||||
borderRightColor: theme.palette.grey[700],
|
borderRightColor: theme.palette.grey[700],
|
||||||
borderTopColor:
|
borderTopColor: nodeColor,
|
||||||
color === "blue"
|
|
||||||
? theme.palette.info.main
|
|
||||||
: color === "green"
|
|
||||||
? theme.palette.success.light
|
|
||||||
: color === "lblue"
|
|
||||||
? theme.palette.info.light
|
|
||||||
: color === "red"
|
|
||||||
? theme.palette.error.dark
|
|
||||||
: "none",
|
|
||||||
backgroundColor: enabled
|
backgroundColor: enabled
|
||||||
? theme.palette.background.default
|
? theme.palette.background.default
|
||||||
: theme.palette.grey[600],
|
: theme.palette.grey[600],
|
||||||
@@ -167,7 +173,7 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
|||||||
onChange={onSetEnabled}
|
onChange={onSetEnabled}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{/* <Info className="dagnode--info-icon" style={{ color: nodeColor }} /> */}
|
||||||
{hasInput && (
|
{hasInput && (
|
||||||
<Handle
|
<Handle
|
||||||
type="target"
|
type="target"
|
||||||
@@ -189,6 +195,11 @@ export const DAGNode: FC<DAGNodeProps> = ({
|
|||||||
{typeof label === "string" ? <span>{label}</span> : label}
|
{typeof label === "string" ? <span>{label}</span> : label}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{onAddNode && (
|
||||||
|
<div className="dagnode--midway-options">
|
||||||
|
<ButtonIcon icon={<Add />} onClick={onAddNode} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export const NODE_HEIGHT = 70 as const;
|
|||||||
export const CONDITION_HEIGHT = 90 as const;
|
export const CONDITION_HEIGHT = 90 as const;
|
||||||
export const CONDITION_WIDTH = 200 as const;
|
export const CONDITION_WIDTH = 200 as const;
|
||||||
export const CIRCLE_SIZE = 40 as const;
|
export const CIRCLE_SIZE = 40 as const;
|
||||||
export const DISTANCE_FACTOR = 1.5 as const;
|
export const DISTANCE_FACTOR = 1.75 as const;
|
||||||
export const PADDING = 50 as const;
|
export const PADDING = 50 as const;
|
||||||
|
|
||||||
export const DEFAULT_DIMS = {
|
export const DEFAULT_DIMS = {
|
||||||
@@ -19,5 +19,5 @@ export const DEFAULT_DIMS = {
|
|||||||
x: PADDING,
|
x: PADDING,
|
||||||
y: PADDING,
|
y: PADDING,
|
||||||
},
|
},
|
||||||
flipped: false,
|
flipped: true,
|
||||||
} as DAGAutomationFlowDims;
|
} as DAGAutomationFlowDims;
|
||||||
@@ -21,6 +21,7 @@ import { convertToFlowNode, makeOnEditAutomationConditions } from "./helpers";
|
|||||||
import { DAGErrorNode } from "./DAGErrorNode";
|
import { DAGErrorNode } from "./DAGErrorNode";
|
||||||
import { useHA } from "haService";
|
import { useHA } from "haService";
|
||||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||||
|
import { DagFlowUpdateBaseArgs, makeDagFlowUpdate } from "./DAGFlowUpdater";
|
||||||
|
|
||||||
const nodeTypes = {
|
const nodeTypes = {
|
||||||
dagnode: convertToFlowNode(DAGNode),
|
dagnode: convertToFlowNode(DAGNode),
|
||||||
@@ -28,30 +29,21 @@ const nodeTypes = {
|
|||||||
dagcircle: DAGCircle,
|
dagcircle: DAGCircle,
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface DAGAutomationFlowProps {
|
export type DAGAutomationFlowProps = DagFlowUpdateBaseArgs & {
|
||||||
className?: string;
|
className?: string;
|
||||||
trigger: AutomationTrigger[];
|
|
||||||
condition: AutomationCondition[];
|
|
||||||
sequence: AutomationSequenceNode[];
|
|
||||||
dims: DAGAutomationFlowDims;
|
dims: DAGAutomationFlowDims;
|
||||||
onTriggerUpdate: (t: AutomationTrigger[]) => void;
|
};
|
||||||
onSequenceUpdate: (s: AutomationSequenceNode[]) => void;
|
|
||||||
onConditionUpdate: (s: AutomationCondition[]) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
|
export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = (props) => {
|
||||||
className,
|
|
||||||
trigger,
|
|
||||||
condition,
|
|
||||||
sequence,
|
|
||||||
onTriggerUpdate,
|
|
||||||
onSequenceUpdate,
|
|
||||||
onConditionUpdate,
|
|
||||||
dims,
|
|
||||||
}) => {
|
|
||||||
// state
|
// state
|
||||||
const [modalState, setModalState] = useState<ModalState | null>(null);
|
const [modalState, setModalState] = useState<ModalState | null>(null);
|
||||||
const { namer } = useHA();
|
const { namer } = useHA();
|
||||||
|
const dagUpdater = makeDagFlowUpdate({
|
||||||
|
...props,
|
||||||
|
openModal: setModalState,
|
||||||
|
});
|
||||||
|
// alias
|
||||||
|
const { className, dims, sequence, condition, trigger } = props;
|
||||||
// modal
|
// modal
|
||||||
let modalBody = <></>;
|
let modalBody = <></>;
|
||||||
if (modalState) {
|
if (modalState) {
|
||||||
@@ -91,11 +83,8 @@ export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
|
|||||||
namer,
|
namer,
|
||||||
true
|
true
|
||||||
),
|
),
|
||||||
onEditClick: makeOnEditAutomationConditions(
|
onEditClick: dagUpdater.onEditAutomationConditions,
|
||||||
condition,
|
onAddNode: () => dagUpdater.addNode(0, "sequence"),
|
||||||
onConditionUpdate,
|
|
||||||
setModalState
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
dims
|
dims
|
||||||
);
|
);
|
||||||
@@ -103,35 +92,13 @@ export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
|
|||||||
nodes: [condPoint],
|
nodes: [condPoint],
|
||||||
edges: [],
|
edges: [],
|
||||||
};
|
};
|
||||||
triggerToFlow(flowData, trigger, condPoint.id, dims, {
|
triggerToFlow(
|
||||||
namer,
|
flowData,
|
||||||
onAdd: () =>
|
trigger,
|
||||||
setModalState({
|
condPoint.id,
|
||||||
saveBtnCreateText: true,
|
dims,
|
||||||
node: {
|
dagUpdater.makeTriggerMakerOptions(namer)
|
||||||
platform: "device",
|
);
|
||||||
},
|
|
||||||
update: (n) => {
|
|
||||||
onTriggerUpdate([...trigger, n]);
|
|
||||||
},
|
|
||||||
allowedTypes: ["trigger"],
|
|
||||||
}),
|
|
||||||
onDelete: (i) =>
|
|
||||||
onTriggerUpdate([...trigger.slice(0, i), ...trigger.slice(i + 1)]),
|
|
||||||
onEdit: (i) =>
|
|
||||||
setModalState({
|
|
||||||
node: trigger[i],
|
|
||||||
update: (t) =>
|
|
||||||
onTriggerUpdate([...trigger.slice(0, i), t, ...trigger.slice(i + 1)]),
|
|
||||||
allowedTypes: ["trigger"],
|
|
||||||
}),
|
|
||||||
onSetEnabled: (i) =>
|
|
||||||
onTriggerUpdate([
|
|
||||||
...trigger.slice(0, i),
|
|
||||||
{ ...trigger[i], enabled: !(trigger[i].enabled ?? true) },
|
|
||||||
...trigger.slice(i + 1),
|
|
||||||
]),
|
|
||||||
});
|
|
||||||
sequenceToFlow(
|
sequenceToFlow(
|
||||||
flowData,
|
flowData,
|
||||||
sequence,
|
sequence,
|
||||||
@@ -149,7 +116,7 @@ export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
namer,
|
namer,
|
||||||
makeSequenceUpdater(sequence, onSequenceUpdate, setModalState)
|
dagUpdater.sequenceUpdater
|
||||||
);
|
);
|
||||||
// this fixes some strange edge drawing issue
|
// this fixes some strange edge drawing issue
|
||||||
flowData.edges = flowData.edges.map((e) => ({
|
flowData.edges = flowData.edges.map((e) => ({
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ export const sequenceToFlow = (
|
|||||||
onXClick: () => updater.removeNode(i),
|
onXClick: () => updater.removeNode(i),
|
||||||
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
||||||
namer,
|
namer,
|
||||||
|
onAddNode: () => updater.addNode(i + 1),
|
||||||
onSetEnabled: () =>
|
onSetEnabled: () =>
|
||||||
updater.updateNode(i, {
|
updater.updateNode(i, {
|
||||||
...node,
|
...node,
|
||||||
@@ -95,6 +96,7 @@ export const sequenceToFlow = (
|
|||||||
onXClick: () => updater.removeNode(i),
|
onXClick: () => updater.removeNode(i),
|
||||||
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
||||||
namer,
|
namer,
|
||||||
|
onAddNode: () => updater.addNode(i + 1),
|
||||||
onSetEnabled: () =>
|
onSetEnabled: () =>
|
||||||
updater.updateNode(i, {
|
updater.updateNode(i, {
|
||||||
...node,
|
...node,
|
||||||
@@ -107,34 +109,6 @@ export const sequenceToFlow = (
|
|||||||
lasPos = position;
|
lasPos = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add button
|
|
||||||
const addCircle = makeAddButton(
|
|
||||||
`${prefix}-+`,
|
|
||||||
dims.flipped
|
|
||||||
? {
|
|
||||||
y:
|
|
||||||
(lasPos === null
|
|
||||||
? dims.padding.y +
|
|
||||||
dims.nodeHeight * dims.distanceFactor * (sequence.length + 1)
|
|
||||||
: lasPos.y) +
|
|
||||||
dims.nodeHeight * dims.distanceFactor,
|
|
||||||
x: dims.padding.x + dims.circleSize * 1.5,
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
dims,
|
|
||||||
updater.addNode,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
flowData.nodes.push(addCircle);
|
|
||||||
addEdge(flowData, lastPointId, addCircle.id, false);
|
|
||||||
return {
|
return {
|
||||||
position: lasPos,
|
position: lasPos,
|
||||||
pointId: lastPointId,
|
pointId: lastPointId,
|
||||||
@@ -172,6 +146,7 @@ const addSingleNode = (
|
|||||||
opts: {
|
opts: {
|
||||||
onEditClick: () => void;
|
onEditClick: () => void;
|
||||||
onXClick: () => void;
|
onXClick: () => void;
|
||||||
|
onAddNode: () => void;
|
||||||
namer: Namer;
|
namer: Namer;
|
||||||
onMove: DAGNodeOnMoveEvents;
|
onMove: DAGNodeOnMoveEvents;
|
||||||
onSetEnabled: () => void;
|
onSetEnabled: () => void;
|
||||||
@@ -232,6 +207,7 @@ const addChooseNode = (
|
|||||||
onXClick: () => updater.removeNode(i),
|
onXClick: () => updater.removeNode(i),
|
||||||
namer,
|
namer,
|
||||||
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
onMove: updater.makeOnMoveEvents(i, dims.flipped),
|
||||||
|
onAddNode: () => updater.addNode(i + 1),
|
||||||
onSetEnabled: () =>
|
onSetEnabled: () =>
|
||||||
updater.updateNode(i, {
|
updater.updateNode(i, {
|
||||||
...node,
|
...node,
|
||||||
@@ -245,6 +221,7 @@ const addChooseNode = (
|
|||||||
// conditions
|
// conditions
|
||||||
node.choose.forEach(({ sequence, conditions }, j) => {
|
node.choose.forEach(({ sequence, conditions }, j) => {
|
||||||
const sequenceId = `${nodeId}.${j}`;
|
const sequenceId = `${nodeId}.${j}`;
|
||||||
|
const childUpdater = updater.makeChildUpdaterForChooseAction(i, j);
|
||||||
// edit/delete circle
|
// edit/delete circle
|
||||||
const circle = makeFlowCircle(
|
const circle = makeFlowCircle(
|
||||||
`${sequenceId}>delete`,
|
`${sequenceId}>delete`,
|
||||||
@@ -296,6 +273,7 @@ const addChooseNode = (
|
|||||||
true
|
true
|
||||||
),
|
),
|
||||||
onEditClick: updater.makeOnEditConditionsForChooseNode(i, j),
|
onEditClick: updater.makeOnEditConditionsForChooseNode(i, j),
|
||||||
|
onAddNode: () => childUpdater.addNode(0),
|
||||||
},
|
},
|
||||||
dims
|
dims
|
||||||
);
|
);
|
||||||
@@ -324,7 +302,7 @@ const addChooseNode = (
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
namer,
|
namer,
|
||||||
updater.makeChildUpdaterForChooseAction(i, j),
|
childUpdater,
|
||||||
`${sequenceId}.`
|
`${sequenceId}.`
|
||||||
);
|
);
|
||||||
if (lastPoint.position) {
|
if (lastPoint.position) {
|
||||||
|
|||||||
@@ -19,14 +19,23 @@ export const makeSequenceUpdater = (
|
|||||||
removeNode(i: number) {
|
removeNode(i: number) {
|
||||||
return onChange([...sequence.slice(0, i), ...sequence.slice(i + 1)]);
|
return onChange([...sequence.slice(0, i), ...sequence.slice(i + 1)]);
|
||||||
},
|
},
|
||||||
addNode() {
|
|
||||||
|
addNode(afterIndex: number | null = null) {
|
||||||
return openModal({
|
return openModal({
|
||||||
saveBtnCreateText: true,
|
saveBtnCreateText: true,
|
||||||
node: {
|
node: {
|
||||||
device_id: "",
|
device_id: "",
|
||||||
},
|
},
|
||||||
update: (n) => {
|
update: (n) => {
|
||||||
onChange([...sequence, n]);
|
if (afterIndex !== null) {
|
||||||
|
onChange([
|
||||||
|
...sequence.slice(0, afterIndex),
|
||||||
|
n,
|
||||||
|
...sequence.slice(afterIndex),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
onChange([...sequence, n]);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
allowedTypes: ["action", "condition"],
|
allowedTypes: ["action", "condition"],
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in new issue
Block a user