Skip to content

Instantly share code, notes, and snippets.

@PintoGideon
Last active August 20, 2019 04:08
Show Gist options
  • Save PintoGideon/02b32222fbcd6906c07d3dd826ac31e1 to your computer and use it in GitHub Desktop.
Save PintoGideon/02b32222fbcd6906c07d3dd826ac31e1 to your computer and use it in GitHub Desktop.
Breaking the ChRIS UI (Add a Node)

Some helper functions to think about the Node graph

const daughter={name:'Kisha'}

const son={name:'Gideon'}
const daughter={name:'Alex'}

const mother={
name:'Asheleigh',
children:[son, daughter]
}
class Tree{

constructor(value)
{
this.value=value;
this.children=[];
}

insertChild(value){
const newTree=new Tree(value)
this.children.push(newTree);
return newTree
}
}
const myTree=new Tree(1);
console.log(myTree)

/*
{
value:1,
children:[]

}
*/

Data Structure for Add Node

AddNode Component

this.state={
data:{}
nodes:[]
}

I receive the selected plugin (node in this example) as props. The selected node is of the type feed item. Matan converts it into a plugin instance.

this.setState({
nodes:transformedNodes,
data:{
...prevState.data,
parent
})

The 1st screen has a dropdown which allows the user to select the parent from the tree. I pass down a handleSelect function as a prop to the 1st screen so that the transformedNodes can be displayed as a dropdown and the selected parent node can bubble up and I can change the selected plugin in the parent component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment