Send program to backend in the latest form #22
@@ -109,9 +109,20 @@ function VisualProgrammingUI() {
|
|||||||
|
|
||||||
// currently outputs the prepared program to the console
|
// currently outputs the prepared program to the console
|
||||||
function runProgram() {
|
function runProgram() {
|
||||||
const program = graphReducer();
|
const phases = graphReducer();
|
||||||
console.log(program);
|
const program = {phases}
|
||||||
console.log(JSON.stringify(program, null, 2));
|
console.log(JSON.stringify(program, null, 2));
|
||||||
|
fetch(
|
||||||
|
"http://localhost:8000/program",
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {"Content-Type": "application/json"},
|
||||||
|
body: JSON.stringify(program),
|
||||||
|
}
|
||||||
|
).then((res) => {
|
||||||
|
if (!res.ok) throw new Error("Failed communicating with the backend.")
|
||||||
|
console.log("Successfully sent the program to the backend.");
|
||||||
|
}).catch(() => console.log("Failed to send program to the backend."));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -67,18 +67,28 @@ export default function TriggerNode(props: NodeProps<TriggerNode>) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Reduces each Trigger, including its children down into its relevant data.
|
* Reduces each Trigger, including its children down into its relevant data.
|
||||||
* @param node: The Node Properties of this node.
|
* @param node The Node Properties of this node.
|
||||||
* @param nodes: all the nodes in the graph.
|
* @param nodes all the nodes in the graph.
|
||||||
*/
|
*/
|
||||||
export function TriggerReduce(node: Node, nodes: Node[]) {
|
export function TriggerReduce(node: TriggerNode, nodes: Node[]) {
|
||||||
// Replace this for nodes functionality
|
// Replace this for nodes functionality
|
||||||
if (nodes.length <= -1) {
|
if (nodes.length <= -1) {
|
||||||
console.warn("Impossible nodes length in TriggerReduce")
|
console.warn("Impossible nodes length in TriggerReduce")
|
||||||
}
|
}
|
||||||
const data = node.data as TriggerNodeData;
|
const data = node.data;
|
||||||
|
switch (data.triggerType) {
|
||||||
|
case "keywords":
|
||||||
return {
|
return {
|
||||||
|
id: node.id,
|
||||||
|
type: "keywords",
|
||||||
label: data.label,
|
label: data.label,
|
||||||
list: data.triggers,
|
keywords: data.triggers,
|
||||||
|
};
|
||||||
|
default:
|
||||||
|
return {
|
||||||
|
...data,
|
||||||
|
id: node.id,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user