Skip to content

Commit

Permalink
structural and naming lint (#724)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Jan 9, 2025
1 parent 70a1a43 commit 272cc87
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions ui100/src/ApiConsole.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {JSX, useCallback, useEffect, useRef, useState} from "react";
import {Configuration, MetadataApi} from "./api";
import {layout, mergeVisualOverview, nodesEqual, VisualOverview} from "./model/visualizer.ts";
import {Graph, layout, mergeGraph, nodesEqual} from "./model/graph.ts";
import {Grid2} from "@mui/material";
import NavBar from "./NavBar.tsx";
import Visualizer from "./Visualizer.tsx";
Expand All @@ -17,9 +17,9 @@ interface ApiConsoleProps {

const ApiConsole = ({ logout }: ApiConsoleProps) => {
const user = useStore((state) => state.user);
const overview = useStore((state) => state.overview);
const updateOverview = useStore((state) => state.updateOverview);
const oldVov = useRef<VisualOverview>(overview);
const graph = useStore((state) => state.graph);
const updateGraph = useStore((state) => state.updateGraph);
const oldGraph = useRef<Graph>(graph);
const updateNodes = useStore((state) => state.updateNodes);
const updateEdges = useStore((state) => state.updateEdges);
const selectedNode = useStore((state) => state.selectedNode);
Expand Down Expand Up @@ -55,11 +55,11 @@ const ApiConsole = ({ logout }: ApiConsoleProps) => {
let api = new MetadataApi(cfg);
api.overview()
.then(d => {
let newVov = mergeVisualOverview(oldVov.current, user, d.accountLimited!, d);
if(!nodesEqual(oldVov.current.nodes, newVov.nodes)) {
console.log("refreshed vov", oldVov.current.nodes, newVov.nodes);
updateOverview(newVov);
oldVov.current = newVov;
let newVov = mergeGraph(oldGraph.current, user, d.accountLimited!, d);
if(!nodesEqual(oldGraph.current.nodes, newVov.nodes)) {
console.log("refreshed vov", oldGraph.current.nodes, newVov.nodes);
updateGraph(newVov);
oldGraph.current = newVov;

let laidOut = layout(newVov.nodes, newVov.edges);
let selected = laidOut.nodes.map((n) => ({
Expand Down
10 changes: 5 additions & 5 deletions ui100/src/model/visualizer.ts → ui100/src/model/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {Edge, Node} from "@xyflow/react";
import {User} from "./user.ts";
import {stratify, tree} from "d3-hierarchy";

export class VisualOverview {
export class Graph {
nodes: Node[];
edges: Edge[];
}

export const mergeVisualOverview = (oldVov: VisualOverview, u: User, limited: boolean, newOv: Overview): VisualOverview => {
let newVov = new VisualOverview();
export const mergeGraph = (oldVov: Graph, u: User, limited: boolean, newOv: Overview): Graph => {
let newVov = new Graph();

let accountNode = {
id: u.token,
Expand Down Expand Up @@ -152,7 +152,7 @@ export const nodesEqual = (a: Node[], b: Node[]) => {
return a.every((e, i) => e.id === b[i].id && e.data.limited === b[i].data.limited && e.data.label === b[i].data.label);
}

export const layout = (nodes, edges): VisualOverview => {
export const layout = (nodes, edges): Graph => {
if(!nodes) {
return { nodes: [], edges: [] };
}
Expand All @@ -170,5 +170,5 @@ export const layout = (nodes, edges): VisualOverview => {
.descendants()
.map((node) => ({...node.data, position: {x: node.x, y: node.y}})),
edges,
} as VisualOverview
} as Graph
}
10 changes: 5 additions & 5 deletions ui100/src/model/store.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {create} from "zustand";
import {Environment} from "../api";
import {VisualOverview} from "./visualizer.ts";
import {Graph} from "./graph.ts";
import {Edge, Node, Viewport} from "@xyflow/react";
import {User} from "./user.ts";

type StoreState = {
user: User;
overview: VisualOverview;
graph: Graph;
environments: Array<Environment>;
nodes: Node[];
edges: Edge[];
Expand All @@ -16,7 +16,7 @@ type StoreState = {

type StoreAction = {
updateUser: (user: StoreState['user']) => void,
updateOverview: (vov: StoreState['overview']) => void,
updateGraph: (vov: StoreState['graph']) => void,
updateEnvironments: (environments: StoreState['environments']) => void,
updateSelectedNode: (selectedNode: StoreState['selectedNode']) => void,
updateNodes: (nodes: StoreState['nodes']) => void,
Expand All @@ -26,14 +26,14 @@ type StoreAction = {

const useStore = create<StoreState & StoreAction>((set) => ({
user: null,
overview: new VisualOverview(),
graph: new Graph(),
environments: new Array<Environment>(),
nodes: [],
edges: [],
selectedNode: null,
viewport: {x: 0, y: 0, zoom: 1},
updateUser: (user) => set({user: user}),
updateOverview: (vov) => set({overview: vov}),
updateGraph: (vov) => set({overview: vov}),
updateEnvironments: (environments) => set({environments: environments}),
updateNodes: (nodes) => set({nodes: nodes}),
updateEdges: (edges) => set({edges: edges}),
Expand Down

0 comments on commit 272cc87

Please sign in to comment.