choose options

This commit is contained in:
ari committed 2022-07-13 15:03:22 -04:00
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
const prefix = Math.floor(zoom / (2.5 / 6));
const prefix = zoom;
const elements = {
nodes: state.data.elements.nodes.map((n) => ({
...n,
@@ -1,10 +1,4 @@
import {
DAGDims,
ElementData,
ElementMaker,
ElementMakerBaseProps,
LastNode,
} from "./types";
import { DAGDims, ElementMaker, ElementMakerBaseProps } from "./types";
import { AutomationTrigger } from "types/automations/triggers";
import * as distance from "./distance";
import { getDescriptionFromAutomationNode } from "utils/formatting";
@@ -22,6 +16,7 @@ import { getNodeType } from "utils/automations";
import { ButtonNodeMaker } from "../nodes/ButtonNode";
import { AddIcon } from "components/Icons";
import { useDAGElementsState } from "./state";
import AddBox from "@mui/icons-material/AddBox";
export const useAutomationNodes = (
automation: AutomationActionData,
@@ -222,6 +217,39 @@ export const makeChooseeNodes: ElementMaker<ChooseAction> = (nodes, args) => {
(node.enabled ?? true) &&
!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
let offsetPos: XYPosition = {
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,
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);
pos = distance.moveFromTo("condition", "node", pos, args.dims);
lastNodeId = conditionState.lastNodeId;
@@ -264,6 +295,9 @@ export const makeChooseeNodes: ElementMaker<ChooseAction> = (nodes, args) => {
outputState.addEdge(lastNodeId, output.data.nodes[0].id, {
animated: true,
label: j === "else" ? "else" : undefined,
style: {
stroke: "var(--mui-error-main)",
},
});
}
offsetPos = distance.moveAlongRelativeTo(
@@ -1,5 +1,6 @@
import InputYaml from "components/Inputs/InputYaml";
import { ChooseAction } from "types/automations/actions";
import { OptionManager } from "./OptionManager";
import { OptionManager, updateActionData } from "./OptionManager";
export const ActionChooseState: OptionManager<ChooseAction> = {
defaultState: () => ({
@@ -8,7 +9,20 @@ export const ActionChooseState: OptionManager<ChooseAction> = {
choose: [],
}),
isReady: () => true,
Component: () => {
return <></>;
Component: ({ state, setState }) => {
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: [],
},
}),
isReady: ({ alias, repeat }) => alias !== "" && repeat?.sequence.length > 0,
isReady: ({}) => true,
renderOptionList: (state, setState) => {
const update = updateActionData(state, setState);
return (
+4 -1
View File
@@ -137,7 +137,10 @@ export const getDescriptionFromAutomationNode = <
return namer.getServiceName(node.service);
}
if ("repeat" in node) {
return "Repeat " + node.repeat.count;
return (
"Repeat " +
(Number.isInteger(node.repeat.count) ? node.repeat.count : "indefintely")
);
}
if ("delay" in node) {
return `Wait for ${convertTimeToString(node.delay)}`;