From a7fda74168d2260a7b1487cf8db7e384ab288de8 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Tue, 9 Nov 2021 14:12:11 -0500 Subject: [PATCH] initial work on dag converison --- web/src/automation/types/index.ts | 2 +- web/src/components/AutomationDAG/index.tsx | 2 +- web/src/components/AutomationDAG/types.ts | 5 ++- .../components/AutomationDAG/utils.spec.ts | 19 ++++++++++- web/src/components/AutomationDAG/utils.ts | 34 ++++++++++++++++--- 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/web/src/automation/types/index.ts b/web/src/automation/types/index.ts index 7be10fd..5a16edf 100644 --- a/web/src/automation/types/index.ts +++ b/web/src/automation/types/index.ts @@ -6,7 +6,7 @@ export interface Automation { id: string; alias: string; description: string; - trigger_variables: Record; + trigger_variables?: Record; mode: "single" | "restart" | "queued" | "parallel"; trigger: AutomationTrigger[]; condition: AutomationCondition[]; diff --git a/web/src/components/AutomationDAG/index.tsx b/web/src/components/AutomationDAG/index.tsx index 807d905..f9efc61 100644 --- a/web/src/components/AutomationDAG/index.tsx +++ b/web/src/components/AutomationDAG/index.tsx @@ -36,7 +36,7 @@ export default function AutomationDAG({ - + {/* */} {edges.map(({from, to, direction}, i) => ; edges: Array; +} +export interface NormalizedDag extends DAG { + // overflow: boolean; } \ No newline at end of file diff --git a/web/src/components/AutomationDAG/utils.spec.ts b/web/src/components/AutomationDAG/utils.spec.ts index df472c3..e277ae7 100644 --- a/web/src/components/AutomationDAG/utils.spec.ts +++ b/web/src/components/AutomationDAG/utils.spec.ts @@ -1,6 +1,6 @@ import { GRAPH_HEIGHT, GRAPH_WIDTH, NODE_HEIGHT, NODE_WIDTH } from "./constants"; -import {clip} from "./utils"; +import {clip, computeDAG} from "./utils"; test('it clips overflowing values', () => { expect(clip([GRAPH_WIDTH, GRAPH_HEIGHT])).toEqual([ @@ -13,4 +13,21 @@ test('it clips overflowing values', () => { expect(clip([0, 0])).toEqual([ 0, 0 ]) +}) + +test('simple empty input dag', () => { + expect(computeDAG({ + id: "root", + alias: "root", + description: 'root', + mode: 'single', + trigger: [], + condition: [], + action: [ + ], + })).toEqual({ + nodes: {}, + edges: [ + ], + }) }) \ No newline at end of file diff --git a/web/src/components/AutomationDAG/utils.ts b/web/src/components/AutomationDAG/utils.ts index 2846e7f..93a34f1 100644 --- a/web/src/components/AutomationDAG/utils.ts +++ b/web/src/components/AutomationDAG/utils.ts @@ -1,15 +1,13 @@ +import { Automation } from "../../automation/types"; import { GRAPH_HEIGHT, GRAPH_WIDTH, NODE_HEIGHT, NODE_WIDTH } from "./constants"; -import {DAG, Node, Point} from "./types"; +import {DAG, Node, Point, NormalizedDag} from "./types"; export const clip = (p: Point) : Point => { const [x,y] = p.map(c => Math.max(0, c)); return [Math.min(GRAPH_WIDTH-NODE_WIDTH, x), Math.min(GRAPH_HEIGHT-NODE_HEIGHT, y)] } -export interface NormalizedDag extends DAG { - // overflow: boolean; -} export const normalizeDAG = (dag: DAG): NormalizedDag => { // let overflow: bo const nodes = Object.keys(dag.nodes).map<[string, Node]>(nodeId => [nodeId, { @@ -29,4 +27,32 @@ export const normalizeDAG = (dag: DAG): NormalizedDag => { nodes, edges: dag.edges, } +} +export const computeDAG = (automation: Automation) : DAG => { + const nodes: DAG['nodes'] = {}; + const edges: DAG['edges'] = []; + + automation.action + + // let currentNode: InputDagNode | null = rootNode; + // let currLoc: Point = [0,0]; + // let idPath = ''; + // // let + // while (currentNode) { + // const n = { + // text: currentNode.display, + // loc: currLoc, + // } + // if(idPath) { + // nodes[idPath + "." + currentNode.name] = n + // edges + // } else { + // nodes[currentNode.name] = n + // } + // currentNode = currentNode.next[0] + // } + + return { + nodes, edges + } } \ No newline at end of file