-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDependencyVisualizer.tsx
More file actions
144 lines (140 loc) · 5.53 KB
/
DependencyVisualizer.tsx
File metadata and controls
144 lines (140 loc) · 5.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import { useState } from "react";
import { useSearchParams } from "react-router";
import type { AuditManifest, DependencyManifest } from "@stackcore/manifests";
import { SidebarProvider, SidebarTrigger } from "../shadcn/Sidebar.tsx";
import { FileExplorerSidebar } from "./components/FileExplorerSidebar.tsx";
import BreadcrumbNav from "./components/BreadcrumNav.tsx";
import ProjectVisualizer from "./visualizers/ProjectVisualizer.tsx";
import FileVisualizer from "./visualizers/FileVisualizer.tsx";
import SymbolVisualizer from "./visualizers/SymbolVisualizer.tsx";
export interface VisualizerContext {
manifestId: number;
dependencyManifest: DependencyManifest;
auditManifest: AuditManifest;
highlightedCytoscapeRef: {
filePath: string;
symbolId: string | undefined;
} | undefined;
}
export default function DependencyVisualizer(props: {
manifestId: number;
dependencyManifest: DependencyManifest;
auditManifest: AuditManifest;
}) {
const [searchParams] = useSearchParams();
const [highlightedCytoscapeRef, setHighlightedCytoscapeRef] = useState<
{
filePath: string;
symbolId: string | undefined;
} | undefined
>(undefined);
return (
<SidebarProvider
defaultOpen={false}
style={{ "--sidebar-width": "30rem" } as React.CSSProperties}
// min-h-0 needed to prevent the sidebar
// from growing to the height of the screen
// within the parent container
className="grow flex min-h-0"
>
<FileExplorerSidebar
dependencyManifest={props.dependencyManifest}
auditManifest={props.auditManifest}
onHighlightInCytoscape={(node) => {
if (!node.fileId) return;
const newRef = {
filePath: node.fileId,
symbolId: node.symbolId,
};
// If the new ref is the same as the current ref, we un set it (unhighlight)
if (
highlightedCytoscapeRef?.filePath === newRef.filePath &&
highlightedCytoscapeRef?.symbolId === newRef.symbolId
) {
setHighlightedCytoscapeRef(undefined);
} else {
setHighlightedCytoscapeRef(newRef);
}
}}
toDetails={(node) => {
if (node.symbolId && node.fileId) {
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.set("fileId", node.fileId);
newSearchParams.set("instanceId", node.symbolId);
return `?${newSearchParams.toString()}`;
} else if (node.fileId) {
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.set("fileId", node.fileId);
newSearchParams.delete("instanceId");
return `?${newSearchParams.toString()}`;
} else {
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.delete("fileId");
newSearchParams.delete("instanceId");
return `?${newSearchParams.toString()}`;
}
}}
/>
<div className="w-full flex flex-col overflow-hidden">
<div className="flex items-center py-2 justify-between">
<div className="flex items-center gap-2 ml-2">
<SidebarTrigger />
<BreadcrumbNav
toProjectLink={() => {
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.delete("fileId");
newSearchParams.delete("instanceId");
return `?${newSearchParams.toString()}`;
}}
fileId={searchParams.get("fileId")}
toFileIdLink={(fileId) => {
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.set("fileId", fileId);
newSearchParams.delete("instanceId");
return `?${newSearchParams.toString()}`;
}}
instanceId={searchParams.get("instanceId")}
toInstanceIdLink={(fileId, instanceId) => {
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.set("fileId", fileId);
newSearchParams.set("instanceId", instanceId);
return `?${newSearchParams.toString()}`;
}}
/>
</div>
</div>
<div className="grow w-full border-t">
{searchParams.get("fileId") && searchParams.get("instanceId")
? (
<SymbolVisualizer
fileId={searchParams.get("fileId")!}
instanceId={searchParams.get("instanceId")!}
manifestId={props.manifestId}
dependencyManifest={props.dependencyManifest}
auditManifest={props.auditManifest}
highlightedCytoscapeRef={highlightedCytoscapeRef}
/>
)
: searchParams.get("fileId")
? (
<FileVisualizer
fileId={searchParams.get("fileId")!}
manifestId={props.manifestId}
dependencyManifest={props.dependencyManifest}
auditManifest={props.auditManifest}
highlightedCytoscapeRef={highlightedCytoscapeRef}
/>
)
: (
<ProjectVisualizer
manifestId={props.manifestId}
dependencyManifest={props.dependencyManifest}
auditManifest={props.auditManifest}
highlightedCytoscapeRef={highlightedCytoscapeRef}
/>
)}
</div>
</div>
</SidebarProvider>
);
}