top bar
This commit is contained in:
1 parent
a35e8e127f
commit
2ea96973ad
20 files changed
+372
-150
No files matched your search
@@ -69,7 +69,7 @@ export const DAGGraphBoardInner: FC<DAGGraphBoardProps> = ({
|
||||
nodesDraggable={false}
|
||||
{...elements}
|
||||
>
|
||||
<Controls showInteractive={false} />
|
||||
<Controls showInteractive={false} showFitView />
|
||||
</ReactFlow>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -468,3 +468,36 @@ ParallelAuto.args = {
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export const BadNodes = Template.bind({});
|
||||
BadNodes.args = {
|
||||
...BadNodes.args,
|
||||
automation: {
|
||||
condition: [
|
||||
{
|
||||
event: "triggerme",
|
||||
},
|
||||
{
|
||||
condition: "and",
|
||||
thisshouldnotbehere: "1",
|
||||
conditions: "1234",
|
||||
},
|
||||
] as any,
|
||||
trigger: [
|
||||
{ platform: "homeassistant" },
|
||||
{ platfom: "bobid" },
|
||||
{ condition: "and" },
|
||||
"text?",
|
||||
] as any,
|
||||
sequence: [
|
||||
{
|
||||
parallel: {
|
||||
bad: "me",
|
||||
},
|
||||
},
|
||||
{
|
||||
platform: "event",
|
||||
},
|
||||
] as any,
|
||||
},
|
||||
};
|
||||
@@ -14,6 +14,7 @@ import { SequenceNodeMaker } from "../nodes/SequenceNode";
|
||||
import {
|
||||
getNodeType,
|
||||
convertScriptConditionFieldToAutomationConditions,
|
||||
validateNode,
|
||||
} from "utils/automations";
|
||||
import { ButtonNodeMaker } from "../nodes/ButtonNode";
|
||||
import { AddIcon } from "components/Icons";
|
||||
@@ -24,6 +25,9 @@ import { getSpecialNodeMaker, makeSpecialNodeMaker } from "./specialnodes";
|
||||
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";
|
||||
|
||||
export const useAutomationNodes = (
|
||||
automation: AutomationActionData,
|
||||
@@ -91,11 +95,23 @@ export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
||||
...dims.collection,
|
||||
collectionType: "trigger",
|
||||
onAddNode: () => stateUpdater.basic.trigger.addNode(null),
|
||||
nodes: nodes.map((node, index) => ({
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...stateUpdater.createNodeActions("trigger", index, {}),
|
||||
})),
|
||||
nodes: nodes.map((node, index) => {
|
||||
const failures = validateNode(node, ["condition"]);
|
||||
|
||||
if (failures) {
|
||||
return {
|
||||
enabled: node.enabled ?? true,
|
||||
...stateUpdater.createNodeActions("trigger", index, {}),
|
||||
...convertFailuresToSequenceNodeDataProps(failures),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...stateUpdater.createNodeActions("trigger", index, {}),
|
||||
};
|
||||
}),
|
||||
})
|
||||
);
|
||||
return outputState;
|
||||
@@ -112,11 +128,23 @@ export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
||||
collectionType: "condition",
|
||||
hasInput: !!lastNodeId,
|
||||
onAddNode: () => stateUpdater.basic.condition.addNode(null),
|
||||
nodes: nodes.map((node, index) => ({
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...stateUpdater.createNodeActions("condition", index, {}),
|
||||
})),
|
||||
nodes: nodes.map((node, index) => {
|
||||
const failures = validateNode(node, ["condition"]);
|
||||
|
||||
if (failures) {
|
||||
return {
|
||||
enabled: node.enabled ?? true,
|
||||
...stateUpdater.createNodeActions("condition", index, {}),
|
||||
...convertFailuresToSequenceNodeDataProps(failures),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...stateUpdater.createNodeActions("condition", index, {}),
|
||||
};
|
||||
}),
|
||||
})
|
||||
);
|
||||
if (lastNodeId && outputState.lastNodeId) {
|
||||
@@ -133,10 +161,25 @@ export const makeSequenceNodes: ElementMaker<AutomationSequenceNode> = (
|
||||
const outputState = new DAGElementsOutputState(position, dims);
|
||||
nodes.forEach((node, nodeIndex) => {
|
||||
// the JSON.stringify is hack to make the edges render nicely
|
||||
const nodeId = `${args.nodeId}-${
|
||||
args.nodeIndex
|
||||
}-${nodeIndex}-${JSON.stringify(node)}`;
|
||||
const nodeId = `${args.nodeId}-${args.nodeIndex}-${nodeIndex}`;
|
||||
outputState.incNextPos("node");
|
||||
let nodeData: SequenceNodeDataProps = {
|
||||
color: getNodeType(node) === "action" ? "green" : "blue",
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...state.getIsClosedActions(nodeId, node),
|
||||
...stateUpdater.createNodeActions("sequence", nodeIndex, {
|
||||
includeAdd: true,
|
||||
flipped: dims.flipped,
|
||||
}),
|
||||
};
|
||||
const failures = validateNode(node, ["action", "condition"]);
|
||||
if (failures) {
|
||||
nodeData = {
|
||||
...nodeData,
|
||||
...convertFailuresToSequenceNodeDataProps(failures),
|
||||
};
|
||||
}
|
||||
const element = outputState.addNode(
|
||||
SequenceNodeMaker.makeElement(
|
||||
{
|
||||
@@ -144,36 +187,29 @@ export const makeSequenceNodes: ElementMaker<AutomationSequenceNode> = (
|
||||
position: outputState.nextPos,
|
||||
},
|
||||
dims,
|
||||
{
|
||||
color: getNodeType(node) === "action" ? "green" : "blue",
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...state.getIsClosedActions(nodeId, node),
|
||||
...stateUpdater.createNodeActions("sequence", nodeIndex, {
|
||||
includeAdd: true,
|
||||
flipped: dims.flipped,
|
||||
}),
|
||||
}
|
||||
nodeData
|
||||
),
|
||||
true
|
||||
);
|
||||
if (nodeIndex === 0 && lastNodeId) {
|
||||
outputState.addEdge(lastNodeId, element.id);
|
||||
}
|
||||
const specialNodeMaker = getSpecialNodeMaker(
|
||||
getNodeSubType(node, true) as any
|
||||
);
|
||||
if (specialNodeMaker) {
|
||||
outputState.extend(
|
||||
specialNodeMaker([node] as any, {
|
||||
...args,
|
||||
nodeId,
|
||||
lastNodeId: element.id,
|
||||
position: outputState.getLastNodePos(),
|
||||
nodeIndex,
|
||||
}),
|
||||
true
|
||||
if (!failures) {
|
||||
const specialNodeMaker = getSpecialNodeMaker(
|
||||
getNodeSubType(node, true) as any
|
||||
);
|
||||
if (specialNodeMaker) {
|
||||
outputState.extend(
|
||||
specialNodeMaker([node] as any, {
|
||||
...args,
|
||||
nodeId,
|
||||
lastNodeId: element.id,
|
||||
position: outputState.getLastNodePos(),
|
||||
nodeIndex,
|
||||
}),
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import { MiniFailure } from "types/validators/helper";
|
||||
import { SequenceNodeColor } from "../nodes/SequenceNode/types";
|
||||
import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined";
|
||||
|
||||
export const convertFailuresToSequenceNodeDataProps = (
|
||||
failures: MiniFailure[]
|
||||
) => {
|
||||
return {
|
||||
label: (
|
||||
<>
|
||||
<InfoOutlinedIcon />
|
||||
<div className="daggraph--error">
|
||||
{failures.map((f, i) => (
|
||||
<span key={i}>{f.message}</span>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
),
|
||||
color: "error" as SequenceNodeColor,
|
||||
};
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
import { Button } from "components/Inputs/Button";
|
||||
import InputYaml from "components/Inputs/InputYaml";
|
||||
import { FC } from "react";
|
||||
import { DAGGraphBoardProps } from "../board/types";
|
||||
|
||||
export const ErroredBoard: FC<
|
||||
DAGGraphBoardProps & {
|
||||
error: Error | any;
|
||||
}
|
||||
> = (props) => {
|
||||
// const makeSet = <K extends keyof FailedStateData>(k: K) => (d: FailedStateData[K]) => this.setState({
|
||||
// ...this.state,
|
||||
// [k]: d,
|
||||
// });
|
||||
// const makeSave = <K extends keyof FailedStateData>(k: K) => () => {
|
||||
// if (!this.state.hasError) {
|
||||
// return
|
||||
// }
|
||||
// if (k === 'condition') {
|
||||
// this.props.onConditionUpdate(this.state.condition)
|
||||
// } else if (k === 'sequence') {
|
||||
// this.props.onSequenceUpdate(this.state.sequence)
|
||||
// } else if (k === 'trigger') {
|
||||
// this.props.onTriggerUpdate(this.state.trigger)
|
||||
// }
|
||||
// }
|
||||
return (
|
||||
<div className="dag-flow-safe">
|
||||
<h1>An Error has occured.</h1>
|
||||
<h1>Failed to Open Autmation!</h1>
|
||||
Something is likely not configured in your automation properly.
|
||||
<hr />
|
||||
<h2>Error:</h2>
|
||||
{/* <h2>{String(this.state.error)}</h2> */}
|
||||
<br />
|
||||
{/* {JSON.stringify(this.state.error, null, 4)} */}
|
||||
{/* {this.state.errorInfo && this.state.errorInfo.componentStack.split('\n').map((s, i) => <>
|
||||
<span key={i}>{s}</span><br key={`br-${i}`} />
|
||||
</>)} */}
|
||||
<h2>Automation YAML</h2>
|
||||
{/* <InputYaml label="Trigger" value={this.state.trigger} onChange={makeSet('trigger')} />
|
||||
<Button onClick={makeSave('trigger')}>Save Triggers</Button>
|
||||
<InputYaml label="Condition" value={this.state.condition} onChange={makeSet('condition')} />
|
||||
<Button onClick={makeSave('condition')}>Save Conditions</Button>
|
||||
<InputYaml label="Action" value={this.state.sequence} onChange={makeSet('sequence')} />
|
||||
<Button onClick={makeSave('sequence')}>Save Actions</Button> */}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -71,11 +71,11 @@ export const CollectionNode: FC<CollectionNodeProps> = ({
|
||||
<div className="collection-nodes--inner">
|
||||
{nodes.map((n, i) => (
|
||||
<SequenceNodeElement
|
||||
{...n}
|
||||
{...sequenceNode}
|
||||
key={i}
|
||||
color={color}
|
||||
flipped={flipped}
|
||||
{...n}
|
||||
{...sequenceNode}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { AutomationActionData } from "types/automations";
|
||||
export type CollectionNodeChildProps = Partial<SequenceNodeActions> & {
|
||||
enabled: boolean;
|
||||
label: ReactNode;
|
||||
color?: SequenceNodeColor;
|
||||
};
|
||||
export type CollectionNodeDataProps = Size & {
|
||||
nodes: CollectionNodeChildProps[];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ReactNode } from "react";
|
||||
|
||||
export type SequenceNodeColor = "red" | "blue" | "green" | "lblue";
|
||||
export type SequenceNodeColor = "red" | "blue" | "green" | "lblue" | "error";
|
||||
export type SequenceNodeOnMove<Direction extends string> = Record<
|
||||
Direction,
|
||||
() => void
|
||||
|
||||
@@ -11,6 +11,8 @@ export const useSequenceNodeColor = (color: SequenceNodeColor): string => {
|
||||
: color === "lblue"
|
||||
? theme.palette.info.light
|
||||
: color === "red"
|
||||
? theme.palette.warning.dark
|
||||
: color === "error"
|
||||
? theme.palette.error.dark
|
||||
: "none";
|
||||
};
|
||||
Reference in new issue
Block a user