-
Notifications
You must be signed in to change notification settings - Fork 1
Feat/adding graph to mcp #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a graph visualization feature to the control plane view, displaying managed resources and their relationships in an interactive graph format. The graph shows resource dependencies and status information with configurable color coding.
- Adds a new Graph component with interactive visualization using ReactFlow
- Integrates the graph as a new section in the ControlPlaneView
- Implements color-coded visualization options (by provider or provider config)
Reviewed Changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
src/views/ControlPlanes/ControlPlaneView.tsx | Adds graph section and reformats import statements |
src/components/Yaml/YamlViewButton.tsx | Reformats import statement for consistency |
src/components/Graphs/*.tsx | New graph components including main Graph, CustomNode, StatusIcon, and Legend |
src/components/Graphs/*.ts | Graph utility functions and type definitions |
src/components/Graphs/*.css | Styling for graph components |
public/locales/en.json | Adds translation for graph title |
package.json | Adds dependencies for ReactFlow and Dagre graph layout |
We want to get them manually, because there are many references, that are not related to resources references and there are a lot of issues with that. If there will be any not working reference, we will need to fix it my providing correct path or name (example there is orgRef, and not organizationalRef - kind + Ref name.) (different path in cloudManagementRef - not in spec.ForProviders, but in spec.
7f6e5e5
to
822c966
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UI looks very nice 💅, and great job piecing together all the connections between the nodes! 👍🏻
I have a few suggestions:
- Missing “translation” of strings (i.e. missing use of
t()
). I've marked some examples, not all - Instead of inline styles (
style={{}}
) we could use CSS modules for better clarity and consistency. Here too I highlighted a few spots. - I noticed there’s a newer version of react-flow (v12) available. It wasn’t immediately obvious because they changed the package name. Since we’re starting fresh, it might make sense to use the latest version. There is a migration guide from v11 to v12.
- I haven’t looked at the business logic to transform the resources and providers into a graph in close detail yet. One suggestion might be to move logic out of the
<Graph>
component into auseGraph()
hook and then further out into a pure function. This might make it easier to understand and maintain. Could also add unit tests then which test the transformation into UI-agnostic nodes and edges given a set ofmanagedResources
andproviderConfigsList
(see comments below in the coding).
You’ve been deep in this topic for a while now. If you feel like bouncing ideas around or doing a bit of pair programming, just let me know, I’m happy to lend a second pair of eyes 🙂
BTW: I added a follow-up task to the epic to support proper theming (light and dark mode).
…p-project/ui-frontend into feat/adding-graphs-to-mcp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there! Thanks for the changes, it’s better now. I noticed a few things though (see coding for details):
- Missing error handling in
useGraph
, it used to be there in the previous revision - There's a warning in the console because of memoization issues (see https://reactflow.dev/error#002). Could we add that?
- Types: Instead of creating new type definitions for provider config and managed resources (in the new
types.ts
file), I think we’d better refine our existing types to avoid duplication of types. If we also move theNodeData
type definitions e.g. to theuseGraph
file, we might be able to removetypes.ts
entirely which I wouldn’t mind. - If you have time and agree: To make the code more maintainable, we could separate the “node data” that’s used internally (to construct the graph) from the data structure that’s eventually passed to the custom nodes and shown on the UI. I think it makes sense to define a type, e.g.
NodeDataUi
or similar, which only contains the relevant fields, e.g. without providerConfigName, providerType etc. (which are only used internally for calculating the graph).
Let me know what you think about these suggestions! Happy to discuss alternatives.
src/components/Graphs/Graph.tsx
Outdated
setYamlDialogOpen(true); | ||
}; | ||
|
||
const nodeTypes = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be memoized, otherwise there is a warning on the console (documentation).
@@ -0,0 +1,64 @@ | |||
export interface Condition { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Merge these types with the types already defined in listManagedResoueces.ts
and shared/types.ts
. They should be consistent across our app. Feel free to break them up into smaller subtypes as you did here.
items?: ProviderConfigItem[]; | ||
} | ||
|
||
export interface NodeData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type contains internal logic to build the graph as well as logic which is only used on the UI.
Maybe we should try separating this a bit better by introducing another type just for the UI representation (i.e. without provider…
fields or extraRefs
). Also [key: string]
doesn't seem to be necessary then. This way, it’ll be easier to understand that the fields are just internal implementation details.
treeData: NodeData[], | ||
colorBy: 'provider' | 'source', | ||
colorMap: Record<string, string>, | ||
): { nodes: Node<NodeData>[]; edges: Edge[] } { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we go for different types (internal and UI), this should return the UI structure then, e.g.
): { nodes: Node<NodeData>[]; edges: Edge[] } { | |
): { nodes: Node<NodeDataUi>[]; edges: Edge[] } { |
|
||
const loading = managedResourcesLoading || providerConfigsLoading; | ||
|
||
const treeData = useMemo(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you find a need to use memoization? Also for building the color map below. For me it seems to be quite fast to work without memoization (if this was the reason to use it).
Also: Can we move this function to the utils file? (Or vice versa integrate the other helper functions (resolveProviderType
etc) inside this hook)? I'm thinking of just extracting this whole thing into a function which gets the managedResources and providerConfigsList and returns the treedata (graphData 🤔)
const [nodes, setNodes] = useState<Node<NodeData>[]>([]); | ||
const [edges, setEdges] = useState<Edge[]>([]); | ||
|
||
useEffect(() => { | ||
if (!treeData.length) { | ||
setNodes([]); | ||
setEdges([]); | ||
return; | ||
} | ||
const { nodes, edges } = buildGraph(treeData, colorBy, colorMap); | ||
setNodes(nodes); | ||
setEdges(edges); | ||
}, [treeData, colorBy, colorMap]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why we hold nodes
and edges
as state like this? Would it also work if we just returned the calculated nodes and edges “on the fly” (directly)? (i.e. without useState
)
@andreaskienle I fixed as much as I could now. Maybe we can move this to another PR which I'm preparing (adding another colorization)? Maybe we can discuss this on daily, but most of the change are just some code cleaning - I thought that we are aiming for "fast solution" to enable this feature to the stakeholders ASAP. I think we can polish this after that if you agree - but finally decision we can discuss tomorrow. |
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer: