@@ -11,31 +11,25 @@ import ReactFlow, {
11
11
useEdgesState ,
12
12
addEdge ,
13
13
} from 'reactflow' ;
14
- import { useSelector } from 'react-redux' ;
15
14
import { EuiFlexItem , EuiFlexGroup } from '@elastic/eui' ;
16
- import { AppState , rfContext } from '../../../store' ;
17
- import { convertToReactFlowData } from '../../../../common' ;
15
+ import { rfContext } from '../../../store' ;
16
+ import { Workflow } from '../../../../common' ;
17
+ import { getCore } from '../../../services' ;
18
18
19
19
// styling
20
20
import 'reactflow/dist/style.css' ;
21
21
import './reactflow-styles.scss' ;
22
22
23
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
24
- interface WorkspaceProps { }
23
+ interface WorkspaceProps {
24
+ workflow ?: Workflow ;
25
+ }
25
26
26
27
export function Workspace ( props : WorkspaceProps ) {
27
28
const reactFlowWrapper = useRef ( null ) ;
28
29
const { reactFlowInstance, setReactFlowInstance } = useContext ( rfContext ) ;
29
30
30
- // Fetching workspace state to populate the initial nodes/edges.
31
- // Where/how the low-level ReactFlow JSON will be persisted is TBD.
32
- // TODO: update when that design is finalized
33
- const storedComponents = useSelector (
34
- ( state : AppState ) => state . workspace . components
35
- ) ;
36
- const { rfNodes, rfEdges } = convertToReactFlowData ( storedComponents ) ;
37
- const [ nodes , setNodes , onNodesChange ] = useNodesState ( rfNodes ) ;
38
- const [ edges , setEdges , onEdgesChange ] = useEdgesState ( rfEdges ) ;
31
+ const [ nodes , setNodes , onNodesChange ] = useNodesState ( [ ] ) ;
32
+ const [ edges , setEdges , onEdgesChange ] = useEdgesState ( [ ] ) ;
39
33
40
34
const onConnect = useCallback (
41
35
( params ) => {
@@ -88,16 +82,24 @@ export function Workspace(props: WorkspaceProps) {
88
82
89
83
setNodes ( ( nds ) => nds . concat ( newNode ) ) ;
90
84
} ,
91
- // eslint-disable-next-line react-hooks/exhaustive-deps
92
85
[ reactFlowInstance ]
93
86
) ;
94
87
95
- // Initialization hook
88
+ // Initialization. Set the nodes and edges to an existing workflow,
89
+ // if applicable.
96
90
useEffect ( ( ) => {
97
- // TODO: fetch the nodes/edges dynamically (loading existing flow,
98
- // creating fresh from template, creating blank template, etc.)
99
- // Will involve populating and/or fetching from redux store
100
- } , [ ] ) ;
91
+ const workflow = props . workflow ;
92
+ if ( workflow ) {
93
+ if ( workflow . reactFlowState ) {
94
+ setNodes ( workflow . reactFlowState . nodes ) ;
95
+ setEdges ( workflow . reactFlowState . edges ) ;
96
+ } else {
97
+ getCore ( ) . notifications . toasts . addWarning (
98
+ `There is no configured UI flow for workflow: ${ workflow . name } `
99
+ ) ;
100
+ }
101
+ }
102
+ } , [ props . workflow ] ) ;
101
103
102
104
return (
103
105
< EuiFlexItem grow = { true } >
0 commit comments