choose options
This commit is contained in:
1 parent
de2307901b
commit
89c7007612
5 files changed
+65
-14
No files matched your search
@@ -58,7 +58,7 @@ export const DAGGraphBoardInner: FC<DAGGraphBoardProps> = ({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
// this hack avoids breakage on when zooming
|
// this hack avoids breakage on when zooming
|
||||||
const prefix = Math.floor(zoom / (2.5 / 6));
|
const prefix = zoom;
|
||||||
const elements = {
|
const elements = {
|
||||||
nodes: state.data.elements.nodes.map((n) => ({
|
nodes: state.data.elements.nodes.map((n) => ({
|
||||||
...n,
|
...n,
|
||||||
|
|||||||
@@ -1,10 +1,4 @@
|
|||||||
import {
|
import { DAGDims, ElementMaker, ElementMakerBaseProps } from "./types";
|
||||||
DAGDims,
|
|
||||||
ElementData,
|
|
||||||
ElementMaker,
|
|
||||||
ElementMakerBaseProps,
|
|
||||||
LastNode,
|
|
||||||
} from "./types";
|
|
||||||
import { AutomationTrigger } from "types/automations/triggers";
|
import { AutomationTrigger } from "types/automations/triggers";
|
||||||
import * as distance from "./distance";
|
import * as distance from "./distance";
|
||||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||||
@@ -22,6 +16,7 @@ import { getNodeType } from "utils/automations";
|
|||||||
import { ButtonNodeMaker } from "../nodes/ButtonNode";
|
import { ButtonNodeMaker } from "../nodes/ButtonNode";
|
||||||
import { AddIcon } from "components/Icons";
|
import { AddIcon } from "components/Icons";
|
||||||
import { useDAGElementsState } from "./state";
|
import { useDAGElementsState } from "./state";
|
||||||
|
import AddBox from "@mui/icons-material/AddBox";
|
||||||
|
|
||||||
export const useAutomationNodes = (
|
export const useAutomationNodes = (
|
||||||
automation: AutomationActionData,
|
automation: AutomationActionData,
|
||||||
@@ -222,6 +217,39 @@ export const makeChooseeNodes: ElementMaker<ChooseAction> = (nodes, args) => {
|
|||||||
(node.enabled ?? true) &&
|
(node.enabled ?? true) &&
|
||||||
!args.state.get(args.lastNodeId ?? "").isClosed
|
!args.state.get(args.lastNodeId ?? "").isClosed
|
||||||
) {
|
) {
|
||||||
|
// add new
|
||||||
|
outputState.addNode(
|
||||||
|
ButtonNodeMaker.makeElement(
|
||||||
|
{
|
||||||
|
id: `${args.nodeId}-choose-add-new`,
|
||||||
|
position: distance.moveAlong(
|
||||||
|
"node",
|
||||||
|
outputState.nextPos,
|
||||||
|
0.3,
|
||||||
|
args.dims,
|
||||||
|
true
|
||||||
|
),
|
||||||
|
},
|
||||||
|
args.dims,
|
||||||
|
{
|
||||||
|
icon: <AddBox />,
|
||||||
|
onClick: () =>
|
||||||
|
args.stateUpdater.basic.sequence.updateNode(
|
||||||
|
{
|
||||||
|
...node,
|
||||||
|
choose: [
|
||||||
|
...node.choose,
|
||||||
|
{
|
||||||
|
conditions: [],
|
||||||
|
sequence: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
args.nodeIndex
|
||||||
|
),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
// offset position
|
// offset position
|
||||||
let offsetPos: XYPosition = {
|
let offsetPos: XYPosition = {
|
||||||
x: args.position.x + args.dims.distanceFactor.node * args.dims.node.width,
|
x: args.position.x + args.dims.distanceFactor.node * args.dims.node.width,
|
||||||
@@ -245,7 +273,10 @@ export const makeChooseeNodes: ElementMaker<ChooseAction> = (nodes, args) => {
|
|||||||
nodeIndex: j,
|
nodeIndex: j,
|
||||||
nodeId: `${args.nodeId}-choose-${j}-condition`,
|
nodeId: `${args.nodeId}-choose-${j}-condition`,
|
||||||
});
|
});
|
||||||
conditionState.data.edges[0].label = `Condition #${j + 1}`;
|
conditionState.data.edges[0].label = `Condition ${j + 1}`;
|
||||||
|
conditionState.data.edges[0].style = {
|
||||||
|
stroke: "var(--mui-info-main)",
|
||||||
|
};
|
||||||
outputState.extend(conditionState);
|
outputState.extend(conditionState);
|
||||||
pos = distance.moveFromTo("condition", "node", pos, args.dims);
|
pos = distance.moveFromTo("condition", "node", pos, args.dims);
|
||||||
lastNodeId = conditionState.lastNodeId;
|
lastNodeId = conditionState.lastNodeId;
|
||||||
@@ -264,6 +295,9 @@ export const makeChooseeNodes: ElementMaker<ChooseAction> = (nodes, args) => {
|
|||||||
outputState.addEdge(lastNodeId, output.data.nodes[0].id, {
|
outputState.addEdge(lastNodeId, output.data.nodes[0].id, {
|
||||||
animated: true,
|
animated: true,
|
||||||
label: j === "else" ? "else" : undefined,
|
label: j === "else" ? "else" : undefined,
|
||||||
|
style: {
|
||||||
|
stroke: "var(--mui-error-main)",
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
offsetPos = distance.moveAlongRelativeTo(
|
offsetPos = distance.moveAlongRelativeTo(
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
import InputYaml from "components/Inputs/InputYaml";
|
||||||
import { ChooseAction } from "types/automations/actions";
|
import { ChooseAction } from "types/automations/actions";
|
||||||
import { OptionManager } from "./OptionManager";
|
import { OptionManager, updateActionData } from "./OptionManager";
|
||||||
|
|
||||||
export const ActionChooseState: OptionManager<ChooseAction> = {
|
export const ActionChooseState: OptionManager<ChooseAction> = {
|
||||||
defaultState: () => ({
|
defaultState: () => ({
|
||||||
@@ -8,7 +9,20 @@ export const ActionChooseState: OptionManager<ChooseAction> = {
|
|||||||
choose: [],
|
choose: [],
|
||||||
}),
|
}),
|
||||||
isReady: () => true,
|
isReady: () => true,
|
||||||
Component: () => {
|
Component: ({ state, setState }) => {
|
||||||
return <></>;
|
return (
|
||||||
|
<>
|
||||||
|
<InputYaml
|
||||||
|
label="Options"
|
||||||
|
value={state.choose ?? []}
|
||||||
|
onChange={(choose) => setState({ ...state, choose })}
|
||||||
|
/>
|
||||||
|
<InputYaml
|
||||||
|
label="Else"
|
||||||
|
value={state.default ?? []}
|
||||||
|
onChange={(d) => setState({ ...state, default: d })}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -11,7 +11,7 @@ export const ActionRepeatState: OptionManager<RepeatAction> = {
|
|||||||
sequence: [],
|
sequence: [],
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
isReady: ({ alias, repeat }) => alias !== "" && repeat?.sequence.length > 0,
|
isReady: ({}) => true,
|
||||||
renderOptionList: (state, setState) => {
|
renderOptionList: (state, setState) => {
|
||||||
const update = updateActionData(state, setState);
|
const update = updateActionData(state, setState);
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -137,7 +137,10 @@ export const getDescriptionFromAutomationNode = <
|
|||||||
return namer.getServiceName(node.service);
|
return namer.getServiceName(node.service);
|
||||||
}
|
}
|
||||||
if ("repeat" in node) {
|
if ("repeat" in node) {
|
||||||
return "Repeat " + node.repeat.count;
|
return (
|
||||||
|
"Repeat " +
|
||||||
|
(Number.isInteger(node.repeat.count) ? node.repeat.count : "indefintely")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
if ("delay" in node) {
|
if ("delay" in node) {
|
||||||
return `Wait for ${convertTimeToString(node.delay)}`;
|
return `Wait for ${convertTimeToString(node.delay)}`;
|
||||||
|
|||||||
Reference in new issue
Block a user