@ -1,4 +1,4 @@
import { CircularPlant , CircularProduct } from "./CircularData" ;
import { CircularPlant , CircularProduct , CircularCenter } from "./CircularData" ;
import { Node , Edge } from "@xyflow/react" ;
import { Node , Edge } from "@xyflow/react" ;
import styles from "./PipelineBlock.module.css" ;
import styles from "./PipelineBlock.module.css" ;
import { ReactFlow , Background , Controls , MarkerType } from '@xyflow/react' ;
import { ReactFlow , Background , Controls , MarkerType } from '@xyflow/react' ;
@ -13,12 +13,18 @@ import CustomNode, { CustomNodeData }from "./NodesAndEdges";
interface PipelineBlockProps {
interface PipelineBlockProps {
onAddPlant : ( ) = > void ;
onAddPlant : ( ) = > void ;
onAddProduct : ( ) = > void ;
onAddProduct : ( ) = > void ;
onAddCenter : ( ) = > void ;
onMovePlant : ( name : string , x : number , y : number ) = > void ;
onMovePlant : ( name : string , x : number , y : number ) = > void ;
onMoveProduct : ( name : string , x : number , y : number ) = > void ;
onMoveProduct : ( name : string , x : number , y : number ) = > void ;
onMoveCenter : ( name : string , x : number , y : number ) = > void ;
onSetPlantInput : ( plantName :string , productName : string ) = > void ;
onSetPlantInput : ( plantName :string , productName : string ) = > void ;
onAddPlantOutput : ( plantName : string , productName : string ) = > void ;
onAddPlantOutput : ( plantName : string , productName : string ) = > void ;
onAddCenterInput : ( plantName : string , productName : string ) = > void ;
onAddCenterOutput : ( plantName : string , productName : string ) = > void ;
products : Record < string , CircularProduct > ;
products : Record < string , CircularProduct > ;
plants : Record < string , CircularPlant > ;
plants : Record < string , CircularPlant > ;
centers : Record < string , CircularCenter > ;
}
}
const onNodeDoubleClick = ( ) = > { } ;
const onNodeDoubleClick = ( ) = > { } ;
@ -46,6 +52,13 @@ const PipelineBlock: React.FC<PipelineBlockProps> = (props) => {
props . onAddPlantOutput ( source , target ) ;
props . onAddPlantOutput ( source , target ) ;
}
}
else if ( sourceType === "product" && targetType === "center" ) {
props . onAddCenterInput ( target , source ) ;
}
else if ( sourceType === "center" && targetType === "product" ) {
props . onAddCenterOutput ( source , target ) ;
}
} ;
} ;
const onNodeDragStop = ( _ :any , node : Node ) = > {
const onNodeDragStop = ( _ :any , node : Node ) = > {
@ -56,9 +69,11 @@ const onNodeDragStop =(_:any, node: Node) => {
if ( data . type === "product" ) {
if ( data . type === "product" ) {
props . onMoveProduct ( id , position . x , position . y ) ;
props . onMoveProduct ( id , position . x , position . y ) ;
}
}
if ( data . type === "center" ) {
props . onMoveCenter ( id , position . x , position . y ) ;
}
} ;
} ;
for ( const [ productName , product ] of Object . entries ( props . products ) as [ string , CircularProduct ] [ ] ) {
for ( const [ productName , product ] of Object . entries ( props . products ) as [ string , CircularProduct ] [ ] ) {
if ( ! product . x || ! product . y ) hasNullPositions = true ;
if ( ! product . x || ! product . y ) hasNullPositions = true ;
mapNameToType [ productName ] = "product" ;
mapNameToType [ productName ] = "product" ;
@ -69,7 +84,7 @@ const onNodeDragStop =(_:any, node: Node) => {
position : { x :product.x , y :product.y }
position : { x :product.x , y :product.y }
} ) ;
} ) ;
}
}
console . log ( "ALL PLANTS:" , props . plants ) ;
for ( const [ plantName , plant ] of Object . entries ( props . plants ) as [ string , CircularPlant ] [ ] ) {
for ( const [ plantName , plant ] of Object . entries ( props . plants ) as [ string , CircularPlant ] [ ] ) {
if ( ! plant . x || ! plant . y ) hasNullPositions = true ;
if ( ! plant . x || ! plant . y ) hasNullPositions = true ;
mapNameToType [ plantName ] = "plant" ;
mapNameToType [ plantName ] = "plant" ;
@ -93,21 +108,50 @@ const onNodeDragStop =(_:any, node: Node) => {
} ,
} ,
} ) ;
} ) ;
}
}
/ * * f o r ( c o n s t o u t p u t P r o d u c t o f p l a n t . i n p u t s ) {
for ( const outputProduct of plant . outputs ? ? [ ] ) {
edges . push ( {
edges . push ( {
id : ` ${ plantName } - ${ outputProduct } ` ,
id : ` ${ plantName } - ${ outputProduct } ` ,
source : plantName ,
source : plantName ,
target : outputProduct ,
target : outputProduct ,
animated : true ,
animated : true ,
style : { stroke : "black" } ,
style : { stroke : 'black' } ,
markerEnd : { type : MarkerType . ArrowClosed } ,
} ) ;
} ) ;
}
}
* /
}
}
}
}
for ( const [ centerName , center ] of Object . entries ( props . centers ) ) {
mapNameToType [ centerName ] = "center" ;
nodes . push ( {
id : centerName ,
type : "default" ,
data : { label : centerName , type : "center" } ,
position : { x : center.x , y : center.y } ,
} ) ;
if ( center . input ) {
edges . push ( {
id : ` ${ center . input } - ${ centerName } ` ,
source : center.input ,
target :centerName ,
style : { stroke : "black" } ,
markerEnd : { type : MarkerType . ArrowClosed } ,
} ) ;
}
for ( const out of center . output ) {
edges . push ( {
id : ` ${ centerName } - ${ out } ` ,
source : centerName ,
target :out ,
style : { stroke : "black" } ,
markerEnd : { type : MarkerType . ArrowClosed } ,
} ) ;
}
}
useEffect ( ( ) = > {
useEffect ( ( ) = > {
if ( hasNullPositions ) onLayout ( ) ;
if ( hasNullPositions ) onLayout ( ) ;
@ -116,11 +160,11 @@ const onNodeDragStop =(_:any, node: Node) => {
return (
return (
< >
< >
< Section title = "Pipeline" / >
< Section title = "Pipeline" / >
< Card >
< Card >
< div className = { styles . PipelineBlock } >
< div className = { styles . PipelineBlock } >
< ReactFlow
< ReactFlow
nodes = { nodes }
nodes = { nodes }
edges = { edges }
edges = { edges }
onNodeDoubleClick = { onNodeDoubleClick }
onNodeDoubleClick = { onNodeDoubleClick }
@ -133,41 +177,46 @@ return (
minZoom = { 0.5 }
minZoom = { 0.5 }
snapToGrid = { true }
snapToGrid = { true }
preventScrolling = { false }
preventScrolling = { false }
nodeTypes = { { default : CustomNode } }
nodeTypes = { { default : CustomNode } }
>
>
< Background / >
< Background / >
< Controls showInteractive = { false } / >
< Controls showInteractive = { false } / >
< / ReactFlow >
< / ReactFlow >
< / div >
< / div >
< div style = { { textAlign : "center" , marginTop : "1rem" } } >
< div style = { { textAlign : "center" , marginTop : "1rem" } } >
< button
< button
style = { { margin : "0 8px" } }
style = { { margin : "0 8px" } }
onClick = { props . onAddProduct }
onClick = { props . onAddProduct }
>
>
Add product
Add product
< / button >
< / button >
< button
< button
style = { { margin : "0 8px" } }
style = { { margin : "0 8px" } }
onClick = { props . onAddPlant }
onClick = { props . onAddPlant }
>
>
Add plant
Add plant
< / button >
< / button >
< button
< button
style = { { margin : "0 8px" } }
onClick = { props . onAddCenter }
>
Add center
< / button >
< button
style = { { margin : "0 8px" } }
style = { { margin : "0 8px" } }
onClick = { onLayout }
onClick = { onLayout }
>
>
Auto Layout
Auto Layout
< / button >
< / button >
< button
< button
style = { { margin : "0 8px" } }
style = { { margin : "0 8px" } }
title = "Drag from one connector to another to create links between products and plant s. Double click to rename an element. Click an element to select and move it. Press the [Delete] key to remove it."
title = "Drag from one connector to another to create links between products , plants, and center s. Double click to rename an element. Click an element to select and move it. Press the [Delete] key to remove it."
>
>
?
?
< / button >
< / button >
< / div >
< / div >
< / Card >
< / Card >
< / >
< / >
) ;
) ;
} ;
} ;
export default PipelineBlock ;
export default PipelineBlock ;