support for if/else
This commit is contained in:
1 parent
a1ca9d62b7
commit
bbb87ebf9e
12 files changed
+93
-11
No files matched your search
@@ -501,3 +501,19 @@ BadNodes.args = {
|
||||
] as any,
|
||||
},
|
||||
};
|
||||
|
||||
export const IfElseNode = Template.bind({});
|
||||
IfElseNode.args = {
|
||||
...BadNodes.args,
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
sequence: [
|
||||
{
|
||||
if: [],
|
||||
else: [],
|
||||
then: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -26,8 +26,8 @@ import { getNodeSubType } from "../../../utils/automations";
|
||||
import DeleteForeverIcon from "@mui/icons-material/DeleteForever";
|
||||
import Add from "@mui/icons-material/Add";
|
||||
import { SequenceNodeDataProps } from "../nodes/SequenceNode/types";
|
||||
import InfoOutlined from "@mui/icons-material/InfoOutlined";
|
||||
import { convertFailuresToSequenceNodeDataProps } from "./util";
|
||||
import { convertChooseActionToOrignal } from "../updater/util";
|
||||
|
||||
export const useAutomationNodes = (
|
||||
automation: AutomationActionData,
|
||||
@@ -242,7 +242,8 @@ export const makeSequenceNodes: ElementMaker<AutomationSequenceNode> = (
|
||||
|
||||
export const makeChooseeNodes = makeSpecialNodeMaker(
|
||||
"choose",
|
||||
(node, outputState, args) => {
|
||||
(incmNode, outputState, args) => {
|
||||
const node = convertChooseActionToOrignal(incmNode);
|
||||
// offset position
|
||||
let offsetPos: XYPosition = distance.offsetBy(
|
||||
"node",
|
||||
@@ -377,7 +378,6 @@ export const makeChooseeNodes = makeSpecialNodeMaker(
|
||||
args.dims,
|
||||
true
|
||||
);
|
||||
console.log({ addPos, lastConditionState });
|
||||
if (lastConditionState !== null) {
|
||||
addPos = distance.moveFromTo(
|
||||
"collection",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { AutomationNodeSubtype } from "types/automations";
|
||||
import { ActionType, ActionTypeMapping } from "types/automations/actions";
|
||||
import { DAGElementsOutputState } from "./outputState";
|
||||
import { ElementMaker, ElementMakerProps } from "./types";
|
||||
@@ -41,3 +42,6 @@ export const makeSpecialNodeMaker = <
|
||||
export const getSpecialNodeMaker = <AT extends ActionType>(
|
||||
nodeType: AT
|
||||
): ElementMaker<AT> | null => SpecialNodeRegistry[nodeType] ?? null;
|
||||
|
||||
export const isSpecialNode = (nodeType: AutomationNodeSubtype) =>
|
||||
nodeType in SpecialNodeRegistry;
|
||||
@@ -1,5 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { AutomationNode } from "types/automations";
|
||||
import { isSpecialNode } from "./specialnodes";
|
||||
import { getNodeSubType } from "utils/automations";
|
||||
|
||||
export type DAGNodeState = Partial<{
|
||||
isClosed: boolean;
|
||||
@@ -27,7 +29,7 @@ export const useDAGElementsState = () => {
|
||||
},
|
||||
|
||||
getIsClosedActions(nodeId: string, node: AutomationNode) {
|
||||
if ("choose" in node || "repeat" in node) {
|
||||
if (isSpecialNode(getNodeSubType(node))) {
|
||||
return {
|
||||
isClosed: this.get(nodeId).isClosed ?? false,
|
||||
setIsClosed: (v: boolean) => this.set(nodeId, "isClosed", v),
|
||||
|
||||
Reference in new issue
Block a user