refactored data heirarchy

This commit is contained in:
Michael Quigley 2022-08-05 13:54:34 -04:00
parent 581e864029
commit dd2b9d006b
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 24 additions and 29 deletions

View File

@ -46,7 +46,6 @@ const App = () => {
</div>
<div className="main">
<Network />
<Environments user={user}/>
</div>
</div>
</div>

View File

@ -1,55 +1,42 @@
import {useEffect, useState} from "react";
import * as metadata from './api/metadata';
import DataTable from 'react-data-table-component';
const Environments = (props) => {
const [environments, setEnvironments] = useState([])
const columns = [
{
name: 'Host',
selector: row => row.host,
selector: row => row.environment.host,
sortable: true,
},
{
name: 'Address',
selector: row => row.address,
selector: row => row.environment.address,
sortable: true,
},
{
name: 'Description',
selector: row => row.description,
selector: row => row.environment.description,
sortable: true,
},
{
name: 'Ziti Identity',
selector: row => row.zitiIdentityId,
selector: row => row.environment.zitiIdentityId,
sortable: true,
},
{
name: 'Active',
selector: row => row.active ? 'Active' : 'Inactive',
selector: row => row.environment.active ? 'Active' : 'Inactive',
sortable: true,
},
]
useEffect(() => {
let mounted = true;
metadata.listEnvironments().then((resp) => {
setEnvironments(resp.data)
console.log(resp.data);
})
return () => { mounted = false; }
}, [])
return (
<div>
<h1>Environments</h1>
{ environments && environments.length > 0 && (
<h2>Environments</h2>
{ props.overview && props.overview.length > 0 && (
<div>
<DataTable
columns={columns}
data={environments}
data={props.overview}
defaultSortFieldId={1}
/>
</div>

View File

@ -1,9 +1,11 @@
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 dagre from 'dagre';
const Network = (props) => {
const Network = () => {
const [overview, setOverview] = useState([]);
const [nodes, setNodes, onNodesChange] = useNodesState([]);
const [edges, setEdges] = useState([]);
@ -11,6 +13,8 @@ const Network = (props) => {
let mounted = true
let interval = setInterval(() => {
metadata.overview().then(resp => {
setOverview(resp.data)
let g = buildGraph(resp.data)
setNodes(getLayout(g))
setEdges(g.edges)
@ -23,12 +27,17 @@ const Network = (props) => {
}, [])
return (
<div className={"network"}>
<h1>Network</h1>
<ReactFlow
nodes={nodes}
edges={edges}
onNodesChange={onNodesChange}
<div>
<div className={"network"}>
<h1>Network</h1>
<ReactFlow
nodes={nodes}
edges={edges}
onNodesChange={onNodesChange}
/>
</div>
<Environments
overview={overview}
/>
</div>
)