react flow auto zoom

This commit is contained in:
Michael Quigley 2022-10-03 17:06:14 -04:00
parent 4dde90a447
commit 17a1455d52
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
2 changed files with 7 additions and 2 deletions

View File

@ -1,7 +1,7 @@
import Environments from './Environments';
import * as metadata from './api/metadata';
import {useEffect, useLayoutEffect, useRef, useState} from "react";
import ReactFlow, {isNode, useNodesState} from "react-flow-renderer";
import ReactFlow, {isNode, useNodesState, useReactFlow} from "react-flow-renderer";
import dagre from 'dagre';
import { mdiDesktopClassic, mdiAccessPointNetwork } from '@mdi/js';
import Icon from "@mdi/react";
@ -10,6 +10,7 @@ const Network = () => {
const [overview, setOverview] = useState([]);
const [nodes, setNodes, onNodesChange] = useNodesState([]);
const [edges, setEdges] = useState([]);
const reactFlow = useReactFlow();
useEffect(() => {
let mounted = true
@ -20,6 +21,7 @@ const Network = () => {
let g = buildGraph(resp.data)
setNodes(getLayout(g))
setEdges(g.edges)
reactFlow.fitView()
}
});
})

View File

@ -4,6 +4,7 @@ import Version from "./Version";
import Token from "./Token";
import Logout from "./Logout";
import Network from "./Network";
import {ReactFlowProvider} from "react-flow-renderer";
const Overview = () => {
const [user, setUser] = useState();
@ -45,7 +46,9 @@ const Overview = () => {
</div>
</div>
<div className="main">
<ReactFlowProvider>
<Network />
</ReactFlowProvider>
</div>
</div>
</div>