Skip to content

Commit c9cfc81

Browse files
committed
refactor: remove legacy graph explorer
1 parent a85dafc commit c9cfc81

File tree

6 files changed

+65
-683
lines changed

6 files changed

+65
-683
lines changed

frontend/app/src/components/graph/GraphEditor.tsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import useSWR from 'swr';
2121

2222
export function GraphEditor ({ knowledgeBaseId }: { knowledgeBaseId: number }) {
2323
const [query, setQuery] = useSearchParam('query', 'sample-question:What is TiDB?');
24-
const [graphStyle, setGraphStyle] = useState<'new' | 'legacy'>('new');
2524

2625
const [key, fetcher] = getFetchInfo(knowledgeBaseId, query);
2726

@@ -34,20 +33,18 @@ export function GraphEditor ({ knowledgeBaseId }: { knowledgeBaseId: number }) {
3433
return (
3534
<div className="p-4 space-y-4">
3635
<SubgraphSelector knowledgeBaseId={knowledgeBaseId} query={query} onQueryChange={setQuery} />
37-
<GraphStyleSelector style={graphStyle} onStyleChange={setGraphStyle} />
3836
{(error != null) && <Alert variant="destructive">
3937
<AlertTitle>Failed to fetch subgraph</AlertTitle>
4038
<AlertDescription>{getErrorMessage(error)}</AlertDescription>
4139
</Alert>}
4240
<div className="w-full flex gap-4">
4341
<div className="flex-1">
4442
<NetworkViewer
45-
key={`${query}-${graphStyle}`}
43+
key={query}
4644
className="border rounded h-auto aspect-square"
4745
loading={isLoading}
4846
loadingTitle={'Loading knowledge graph...'}
4947
network={network}
50-
useCanvasRenderer={graphStyle === 'new'}
5148
Details={(props) => (
5249
ref.current && createPortal(
5350
<Editor
@@ -130,22 +127,6 @@ function SubgraphSelector ({ knowledgeBaseId, query, onQueryChange }: { knowledg
130127
);
131128
}
132129

133-
function GraphStyleSelector ({ style, onStyleChange }: { style: 'new' | 'legacy', onStyleChange: (style: 'new' | 'legacy') => void }) {
134-
return (
135-
<div>
136-
<Select value={style} onValueChange={(value) => onStyleChange(value as 'new' | 'legacy')}>
137-
<SelectTrigger className="w-max">
138-
<SelectValue />
139-
</SelectTrigger>
140-
<SelectContent>
141-
<SelectItem value="legacy">Legacy (SVG)</SelectItem>
142-
<SelectItem value="new">New (Canvas)</SelectItem>
143-
</SelectContent>
144-
</Select>
145-
</div>
146-
)
147-
}
148-
149130
function Editor ({ knowledgeBaseId, network, target, onTargetChange, onEnterSubgraph }: NetworkViewerDetailsProps & { knowledgeBaseId: number, onEnterSubgraph: (type: string, entityId: IdType) => void }) {
150131
if (target) {
151132
if (target.type === 'link') {

frontend/app/src/components/graph/components/NetworkCanvas.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
import { useEffect, useRef, useState } from 'react';
21
import type { IdType, NetworkLink, NetworkNode, ReadonlyNetwork } from '../network/Network';
3-
import { NetworkRenderer, type NetworkRendererOptions } from '../network/NetworkRenderer';
2+
import { useEffect, useRef, useState } from 'react';
3+
44
import { CanvasNetworkRenderer } from '../network/CanvasNetworkRenderer';
5+
import type { NetworkRendererOptions } from '../network/NetworkRendererOptions';
56

67
export interface NetworkCanvasProps<Node extends NetworkNode, Link extends NetworkLink> extends NetworkRendererOptions<Node, Link> {
78
network: ReadonlyNetwork<Node, Link>;
89
target: { type: string, id: IdType } | undefined;
910
className?: string;
10-
useCanvasRenderer?: boolean;
1111
}
1212

13-
export function NetworkCanvas<Node extends NetworkNode, Link extends NetworkLink> ({ className, network, target, useCanvasRenderer = false, ...options }: NetworkCanvasProps<Node, Link>) {
13+
export function NetworkCanvas<Node extends NetworkNode, Link extends NetworkLink> ({ className, network, target, ...options }: NetworkCanvasProps<Node, Link>) {
1414
const ref = useRef<HTMLDivElement>(null);
15-
const [renderer, setRenderer] = useState<NetworkRenderer<Node, Link> | CanvasNetworkRenderer<Node, Link>>();
15+
const [renderer, setRenderer] = useState<CanvasNetworkRenderer<Node, Link>>();
1616

1717
useEffect(() => {
18-
// Cleanup previous renderer if it exists (needed for renderer switching)
18+
// Cleanup previous renderer if it exists
1919
if (renderer) {
2020
renderer.unmount();
2121
}
2222

23-
const newRenderer = useCanvasRenderer
24-
? new CanvasNetworkRenderer(network, options)
25-
: new NetworkRenderer(network, options);
23+
const newRenderer = new CanvasNetworkRenderer(network, options);
2624

2725
if (ref.current) {
2826
newRenderer.mount(ref.current);
@@ -33,7 +31,7 @@ export function NetworkCanvas<Node extends NetworkNode, Link extends NetworkLink
3331
newRenderer.unmount();
3432
setRenderer(undefined);
3533
};
36-
}, [network, useCanvasRenderer]);
34+
}, [network]);
3735

3836
useEffect(() => {
3937
if (!renderer) {

frontend/app/src/components/graph/components/NetworkViewer.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { type FC, type ReactNode, useMemo, useState } from 'react';
44
import { NetworkCanvas } from '../components/NetworkCanvas';
55
import { NetworkContext } from '../components/NetworkContext';
66
import { BaseNetwork, type IdType } from '../network/Network';
7-
import type { NetworkRendererOptions } from '../network/NetworkRenderer';
7+
import type { NetworkRendererOptions } from '../network/NetworkRendererOptions';
88
import { type Entity, type Relationship } from '../utils';
99

1010
export interface NetworkViewerProps {
@@ -13,7 +13,6 @@ export interface NetworkViewerProps {
1313
loading: boolean;
1414
loadingTitle: ReactNode;
1515
Details: FC<NetworkViewerDetailsProps>;
16-
useCanvasRenderer?: boolean;
1716
}
1817

1918
export interface NetworkViewerDetailsProps {
@@ -32,7 +31,7 @@ function randomPosition (radius: number, kbSpacing: number, kbIndex: number, kbC
3231
};
3332
}
3433

35-
export function NetworkViewer ({ network, loading, loadingTitle, className, Details, useCanvasRenderer = false }: NetworkViewerProps) {
34+
export function NetworkViewer ({ network, loading, loadingTitle, className, Details }: NetworkViewerProps) {
3635
const [target, setTarget] = useState<{ type: string, id: IdType }>();
3736

3837
const knowledgeGraphIndexMap = useMemo(() => {
@@ -146,7 +145,6 @@ export function NetworkViewer ({ network, loading, loadingTitle, className, Deta
146145
className={cn('w-full h-full overflow-hidden')}
147146
network={network}
148147
target={target}
149-
useCanvasRenderer={useCanvasRenderer}
150148
{...networkOptions}
151149
/>
152150
<Details

frontend/app/src/components/graph/network/CanvasNetworkRenderer.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
import * as d3 from 'd3';
2-
import ForceGraph from 'force-graph';
2+
33
import type { IdType, NetworkLink, NetworkNode, ReadonlyNetwork } from './Network';
4-
import type { NetworkRendererOptions, NetworkNodeView, NetworkLinkView } from './NetworkRenderer';
4+
import type { SimulationLinkDatum, SimulationNodeDatum } from 'd3';
5+
6+
import ForceGraph from 'force-graph';
7+
import type { NetworkRendererOptions } from './NetworkRendererOptions';
8+
9+
export interface NetworkNodeView extends SimulationNodeDatum {
10+
id: IdType;
11+
index: number;
12+
radius: number;
13+
label?: string;
14+
details?: string;
15+
meta?: any;
16+
}
17+
18+
export interface NetworkLinkView extends SimulationLinkDatum<NetworkNodeView> {
19+
id: IdType;
20+
index: number;
21+
source: NetworkNodeView;
22+
target: NetworkNodeView;
23+
label?: string;
24+
details?: string;
25+
meta?: any;
26+
}
527

628
export class CanvasNetworkRenderer<Node extends NetworkNode, Link extends NetworkLink> {
729
private _el: HTMLElement | undefined;

0 commit comments

Comments
 (0)