Skip to content

Commit

Permalink
initial tabular view mode and additional state to manage viewport tra…
Browse files Browse the repository at this point in the history
…nsform (#819, #823)
  • Loading branch information
michaelquigley committed Jan 8, 2025
1 parent f5a08b2 commit 0c551c8
Show file tree
Hide file tree
Showing 7 changed files with 255 additions and 17 deletions.
188 changes: 188 additions & 0 deletions ui100/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ui100/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@mui/x-charts": "^7.23.2",
"@xyflow/react": "^12.3.5",
"d3-hierarchy": "^3.1.2",
"material-react-table": "^3.1.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router": "^7.0.1",
Expand Down
4 changes: 2 additions & 2 deletions ui100/src/ApiConsole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import EnvironmentPanel from "./EnvironmentPanel.tsx";
import SharePanel from "./SharePanel.tsx";
import AccessPanel from "./AccessPanel.tsx";
import useStore from "./model/store.ts";
import SearchPanel from "./SearchPanel.tsx";
import TabularView from "./TabularView.tsx";

interface ApiConsoleProps {
logout: () => void;
Expand All @@ -32,7 +32,7 @@ const ApiConsole = ({ logout }: ApiConsoleProps) => {
if(showVisualizer) {
setMainPanel(<Visualizer />);
} else {
setMainPanel(<SearchPanel />);
setMainPanel(<TabularView />);
}
}
}, []);
Expand Down
11 changes: 0 additions & 11 deletions ui100/src/SearchPanel.tsx

This file was deleted.

42 changes: 42 additions & 0 deletions ui100/src/TabularView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {Box, Paper} from "@mui/material";
import useStore from "./model/store.ts";
import {MaterialReactTable, type MRT_ColumnDef, useMaterialReactTable} from "material-react-table";
import {useMemo} from "react";
import {Node} from "@xyflow/react";

const data: Node[] = [];

const TabularView = () => {
const overview = useStore((state) => state.overview);

const columns = useMemo<MRT_ColumnDef<Node>[]>(
() => [
{
accessorKey: 'data.label',
header: 'Label'
},
{
accessorKey: 'type',
header: 'Type',
}
],
[],
);

const table = useMaterialReactTable({
columns: columns,
data: overview.nodes,
});

console.log(overview.nodes);

return (
<Box sx={{ width: "100%", mt: 2 }} height={{ xs: 400, sm: 600, md: 800 }}>
<Paper>
<MaterialReactTable table={table} />
</Paper>
</Box>
);
};

export default TabularView;
18 changes: 16 additions & 2 deletions ui100/src/Visualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
ReactFlow,
ReactFlowProvider,
useEdgesState,
useNodesState
useNodesState,
useStore as xyStore
} from "@xyflow/react";
import {VisualOverview} from "./model/visualizer.ts";
import {useEffect} from "react";
Expand All @@ -30,8 +31,15 @@ const nodeTypes = {
const Visualizer = () => {
const overview = useStore((state) => state.overview);
const updateSelectedNode = useStore((state) => state.updateSelectedNode);
const viewport = useStore((state) => state.viewport);
const updateViewport = useStore((state) => state.updateViewport);
const [nodes, setNodes, onNodesChange] = useNodesState([]);
const [edges, setEdges, onEdgesChange] = useEdgesState([]);
const transform = xyStore((store) => store.transform);

useEffect(() => {
updateViewport(transform);
}, [transform]);

const onSelectionChange = ({ nodes }) => {
if(nodes.length > 0) {
Expand Down Expand Up @@ -77,6 +85,12 @@ const Visualizer = () => {
}
}, [overview]);

const defaultViewport = {
x: viewport[0],
y: viewport[1],
zoom: viewport[2],
}

return (
<ReactFlow
nodeTypes={nodeTypes}
Expand All @@ -86,7 +100,7 @@ const Visualizer = () => {
onEdgesChange={onEdgesChange}
onSelectionChange={onSelectionChange}
nodesDraggable={false}
fitView
defaultViewport={defaultViewport}
>
<Background />
<Controls position="bottom-left" orientation="horizontal" showInteractive={false} />
Expand Down
8 changes: 6 additions & 2 deletions ui100/src/model/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ type StoreState = {
environments: Array<Environment>;
overview: VisualOverview;
selectedNode: Node;
viewport: Array<Number>;
};

type StoreAction = {
updateUser: (user: StoreState['user']) => void,
updateOverview: (vov: StoreState['overview']) => void,
updateEnvironments: (environments: StoreState['environments']) => void,
updateSelectedNode: (selectedNode: StoreState['selectedNode']) => void
updateSelectedNode: (selectedNode: StoreState['selectedNode']) => void,
updateViewport: (viewport: StoreState['viewport']) => void,
};

const useStore = create<StoreState & StoreAction>((set) => ({
user: null,
overview: new VisualOverview(),
environments: new Array<Environment>(),
selectedNode: null,
viewport: [0, 0, 1.5],
updateUser: (user) => set({user: user}),
updateOverview: (vov) => set({overview: vov}),
updateEnvironments: (environments) => set({environments: environments}),
updateSelectedNode: (selectedNode) => set({selectedNode: selectedNode})
updateSelectedNode: (selectedNode) => set({selectedNode: selectedNode}),
updateViewport: (viewport) => set({viewport: viewport})
}));

export default useStore;

0 comments on commit 0c551c8

Please sign in to comment.