-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ReactFlow to Workflow Details page (#42)
Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com> (cherry picked from commit 8980cb2)
- Loading branch information
1 parent
660ad90
commit 6a1749c
Showing
10 changed files
with
315 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { Node, Edge } from 'reactflow'; | ||
import { IComponent } from '../public/component_types'; | ||
|
||
/** | ||
* TODO: remove hardcoded nodes/edges. | ||
* | ||
* Converts the stored IComponents into the low-level ReactFlow nodes and edges. | ||
* This may change entirely, depending on how/where the ReactFlow JSON will be | ||
* persisted. Using this stub helper fn in the meantime. | ||
*/ | ||
export function convertToReactFlowData(components: IComponent[]) { | ||
const dummyNodes = [ | ||
{ | ||
id: 'semantic-search', | ||
position: { x: 40, y: 10 }, | ||
data: { label: 'Semantic Search' }, | ||
type: 'group', | ||
style: { | ||
height: 110, | ||
width: 700, | ||
}, | ||
}, | ||
{ | ||
id: 'model', | ||
position: { x: 25, y: 25 }, | ||
data: { label: 'Deployed Model ID' }, | ||
type: 'default', | ||
parentNode: 'semantic-search', | ||
extent: 'parent', | ||
}, | ||
{ | ||
id: 'ingest-pipeline', | ||
position: { x: 262, y: 25 }, | ||
data: { label: 'Ingest Pipeline Name' }, | ||
type: 'default', | ||
parentNode: 'semantic-search', | ||
extent: 'parent', | ||
}, | ||
] as Array< | ||
Node< | ||
{ | ||
label: string; | ||
}, | ||
string | undefined | ||
> | ||
>; | ||
|
||
const dummyEdges = [ | ||
{ | ||
id: 'e1-2', | ||
source: 'model', | ||
target: 'ingest-pipeline', | ||
style: { | ||
strokeWidth: 2, | ||
stroke: 'black', | ||
}, | ||
markerEnd: { | ||
type: 'arrow', | ||
strokeWidth: 1, | ||
color: 'black', | ||
}, | ||
}, | ||
] as Array<Edge<any>>; | ||
|
||
return { | ||
rfNodes: dummyNodes, | ||
rfEdges: dummyEdges, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
public/pages/workflow_detail/workspace/reactflow-styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.reactflow-parent-wrapper { | ||
display: flex; | ||
flex-grow: 1; | ||
height: 100%; | ||
} | ||
|
||
.reactflow-parent-wrapper .reactflow-wrapper { | ||
flex-grow: 1; | ||
height: 100%; | ||
} | ||
|
||
.workspace { | ||
width: 50vh; | ||
height: 50vh; | ||
padding: 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
export * from './react_flow_context_provider'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import React, { createContext, useState } from 'react'; | ||
|
||
const initialValues = { | ||
reactFlowInstance: null, | ||
setReactFlowInstance: () => {}, | ||
deleteNode: (nodeId: string) => {}, | ||
deleteEdge: (edgeId: string) => {}, | ||
}; | ||
|
||
export const rfContext = createContext(initialValues); | ||
|
||
/** | ||
* This returns a provider from the rfContext context created above. The initial | ||
* values are set so any nested components can use useContext to access these | ||
* values. | ||
* | ||
* This is how we can manage ReactFlow context consistently across the various | ||
* nested child components. | ||
*/ | ||
export function ReactFlowContextProvider({ children }: any) { | ||
const [reactFlowInstance, setReactFlowInstance] = useState(null); | ||
|
||
const deleteNode = (nodeId: string) => { | ||
// TODO: implement node deletion | ||
// reactFlowInstance.setNodes(...) | ||
}; | ||
|
||
const deleteEdge = (edgeId: string) => { | ||
// TODO: implement edge deletion | ||
// reactFlowInstance.setEdges(...) | ||
}; | ||
|
||
return ( | ||
<rfContext.Provider | ||
value={{ | ||
reactFlowInstance, | ||
// @ts-ignore | ||
setReactFlowInstance, | ||
deleteNode, | ||
deleteEdge, | ||
}} | ||
> | ||
{children} | ||
</rfContext.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
|
||
export * from './store'; | ||
export * from './reducers'; | ||
export * from './context'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters