From 4b3d0ec9e7aaa21d251cf4ad92a1679501e96faf Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Sat, 4 Nov 2023 21:23:06 +0100 Subject: [PATCH] visualizer: initial tree visualizer Signed-off-by: Patrik Oldsberg --- .../AppVisualizerPage/AppVisualizerPage.tsx | 2 + .../AppVisualizerPage/TreeVisualizer.tsx | 57 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 plugins/visualizer/src/components/AppVisualizerPage/TreeVisualizer.tsx diff --git a/plugins/visualizer/src/components/AppVisualizerPage/AppVisualizerPage.tsx b/plugins/visualizer/src/components/AppVisualizerPage/AppVisualizerPage.tsx index ec6145a1af..78ace296b4 100644 --- a/plugins/visualizer/src/components/AppVisualizerPage/AppVisualizerPage.tsx +++ b/plugins/visualizer/src/components/AppVisualizerPage/AppVisualizerPage.tsx @@ -21,6 +21,7 @@ import Box from '@material-ui/core/Box'; import React, { useState } from 'react'; import { GraphVisualizer } from './GraphVisualizer'; import { TextVisualizer } from './TextVisualizer'; +import { TreeVisualizer } from './TreeVisualizer'; export function AppVisualizerPage() { const appTreeApi = useApi(appTreeApiRef); @@ -29,6 +30,7 @@ export function AppVisualizerPage() { const tabs = [ { id: 'graph', label: 'Graph', element: }, + { id: 'tree', label: 'Tree', element: }, { id: 'text', label: 'Text', element: }, ]; diff --git a/plugins/visualizer/src/components/AppVisualizerPage/TreeVisualizer.tsx b/plugins/visualizer/src/components/AppVisualizerPage/TreeVisualizer.tsx new file mode 100644 index 0000000000..1260da3c32 --- /dev/null +++ b/plugins/visualizer/src/components/AppVisualizerPage/TreeVisualizer.tsx @@ -0,0 +1,57 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { + DependencyGraph, + DependencyGraphTypes, +} from '@backstage/core-components'; +import { AppTree } from '@backstage/frontend-plugin-api'; +import Box from '@material-ui/core/Box'; +import { useMemo } from 'react'; + +function resolveGraphData(tree: AppTree) { + const nodes = [...tree.nodes.values()] + .filter(n => n.instance) + .map(n => ({ ...n, id: n.spec.id })); + return { + nodes, + edges: nodes + .filter(n => n.edges.attachedTo) + .map(n => ({ + from: n.spec.id, + to: n.edges.attachedTo!.node.spec.id, + label: n.edges.attachedTo!.input, + })), + }; +} + +export function TreeVisualizer({ tree }: { tree: AppTree }) { + const graphData = useMemo(() => resolveGraphData(tree), [tree]); + + return ( + + + + ); +}