Skip to content

Commit 979751e

Browse files
committed
temp [ci skip]
1 parent cb9e2f0 commit 979751e

9 files changed

Lines changed: 139 additions & 25 deletions

File tree

vscode/extension/src/webviews/lineagePanel.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export class LineagePanel implements WebviewViewProvider, Disposable {
2020
private getServerUrl: () => string;
2121
private _extensionUri: Uri;
2222

23+
private _disposables: Disposable[] = [];
24+
2325
public constructor(extensionUri: Uri, getServerUrl: () => string) {
2426
this._extensionUri = extensionUri;
2527
this.getServerUrl = getServerUrl;
@@ -164,7 +166,42 @@ export class LineagePanel implements WebviewViewProvider, Disposable {
164166
const manifestUri = panel.asWebviewUri(Uri.joinPath(this._extensionUri, "src_react", "manifest.json"));
165167
const logoUri = panel.asWebviewUri(Uri.joinPath(this._extensionUri, "src_react", "logo192.png"));
166168

167-
return `
169+
// Handle query requests from the React app
170+
panel.onDidReceiveMessage(
171+
async (message) => {
172+
console.log('received message in lineage panel', message)
173+
if (message.key === 'query_request') {
174+
console.log('Received query request:', message.payload);
175+
const { requestId } = message.payload;
176+
try {
177+
// Process the query based on the queryKey
178+
let responseData;
179+
console.log('got query request in extension', message.payload, "with requestId", requestId)
180+
// Send successful response back to the webview
181+
panel.postMessage({
182+
key: 'vscode_response',
183+
payload: {
184+
requestId,
185+
data: responseData
186+
}
187+
});
188+
} catch (error) {
189+
// Send error response back to the webview
190+
panel.postMessage({
191+
key: 'vscode_response',
192+
payload: {
193+
requestId,
194+
error: error instanceof Error ? error.message : 'Unknown error'
195+
}
196+
});
197+
}
198+
}
199+
},
200+
undefined,
201+
this._disposables
202+
);
203+
204+
return `
168205
<!DOCTYPE html>
169206
<html lang="en">
170207
<head>

vscode/react/src/api/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import {
22
type UseQueryResult,
33
useQuery,
4-
type QueryKey,
5-
type UseQueryOptions,
6-
type QueryMeta,
4+
type QueryMeta,
75
} from '@tanstack/react-query'
86
import {
97
getModelsApiModelsGet,
@@ -83,7 +81,7 @@ export function useApiModelLineage(
8381
{
8482
queryKey: ['/api/lineage', modelName],
8583
queryFn: async ({ signal }) => {
86-
console.log('modelName', modelName)
84+
console.log('use api model lineage', modelName)
8785
return await modelLineageApiLineageModelNameGet(modelName, { signal })
8886
},
8987
},

vscode/react/src/api/instance.ts

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { IS_PRODUCTION } from '@/utilsutils/isProduction'
2+
import { getVSCodeAPI } from '@/utilsutils/vscodeapi'
13
import { tableFromIPC } from 'apache-arrow'
24

35
declare global {
@@ -6,16 +8,16 @@ declare global {
68
}
79
}
810

9-
export interface ResponseWithDetail {
11+
interface ResponseWithDetail {
1012
ok: boolean
1113
detail?: string
1214
}
1315

14-
export interface FetchOptionsWithSignal {
16+
interface FetchOptionsWithSignal {
1517
signal?: AbortSignal
1618
}
1719

18-
export interface FetchOptions<B extends object = any> {
20+
interface FetchOptions<B extends object = any> {
1921
url: string
2022
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
2123
data?: B
@@ -33,7 +35,7 @@ export interface FetchOptions<B extends object = any> {
3335
params?: Record<string, string | number | boolean | undefined | null>
3436
}
3537

36-
export async function fetchAPI<T = any, B extends object = any>(
38+
async function fetchAPIDevelopment<T = any, B extends object = any>(
3739
config: FetchOptions<B>,
3840
options?: Partial<FetchOptionsWithSignal>,
3941
): Promise<T & ResponseWithDetail> {
@@ -122,7 +124,7 @@ function toRequestBody(obj: unknown): BodyInit {
122124
}
123125
}
124126

125-
export function getUrlWithPrefix(url: string = '/'): string {
127+
function getUrlWithPrefix(url: string = '/'): string {
126128
let urlWithPrefix = `${
127129
window.__BASE_URL__ ?? '/'
128130
}/${url}`
@@ -134,4 +136,73 @@ export function getUrlWithPrefix(url: string = '/'): string {
134136
return urlWithPrefix
135137
}
136138

137-
export default fetchAPI
139+
export async function fetchAPIProduction<T = any, B extends object = any>(
140+
config: FetchOptions<B>,
141+
options?: Partial<FetchOptionsWithSignal>,
142+
): Promise<T & ResponseWithDetail> {
143+
console.log('queryFn', config, options)
144+
getVSCodeAPI().postMessage({
145+
type: 'fetchAPI',
146+
config,
147+
options,
148+
})
149+
150+
// Generate a unique ID for this request
151+
const requestId = `query_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
152+
// Create a promise that will resolve when we get a response with matching ID
153+
return new Promise((resolve, reject) => {
154+
// Set up listener for the response
155+
console.log("setting up listener for response")
156+
const messageHandler = (event: MessageEvent) => {
157+
if (
158+
event.data &&
159+
event.data.key === 'vscode_response' &&
160+
event.data.payload &&
161+
event.data.payload.requestId === requestId
162+
) {
163+
// Remove the listener once we get our response
164+
window.removeEventListener('message', messageHandler);
165+
166+
if (event.data.payload.error) {
167+
reject(new Error(event.data.payload.error));
168+
} else {
169+
resolve(event.data.payload.data);
170+
}
171+
}
172+
};
173+
174+
// Add the listener
175+
window.addEventListener('message', messageHandler);
176+
177+
// Send the message to VSCode with the query parameters and request ID
178+
// @ts-ignore
179+
const vscode = acquireVsCodeApi()
180+
vscode.postMessage({
181+
key: 'query_request',
182+
payload: {
183+
requestId,
184+
queryKey: config.url,
185+
// @ts-ignore
186+
queryParams: config.params as any
187+
}
188+
});
189+
console.log("sent message to vscode")
190+
191+
// Set a timeout to prevent hanging promises
192+
setTimeout(() => {
193+
window.removeEventListener('message', messageHandler);
194+
reject(new Error('Query request timed out'));
195+
}, 30000); // 30 second timeout
196+
});
197+
}
198+
199+
200+
export function fetchAPI<T = any, B extends object = any>(
201+
config: FetchOptions<B>,
202+
options?: Partial<FetchOptionsWithSignal>,
203+
): Promise<T & ResponseWithDetail> {
204+
if (IS_PRODUCTION) {
205+
return fetchAPIProduction(config, options)
206+
}
207+
return fetchAPIDevelopment(config, options)
208+
}

vscode/react/src/components/graph/context.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ export default function LineageFlowProvider({
157157
const [hasBackground, setHasBackground] = useState(true)
158158
const [withImpacted, setWithImpacted] = useState(true)
159159
const [withSecondary, setWithSecondary] = useState(false)
160-
console.log('withColumns in provider', withColumns)
161160

162161
const nodesMap = useMemo(
163162
() =>

vscode/react/src/pages/lineage.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import LineageFlowProvider from '@/components/graph/context'
99
import { ModelLineage } from '@/components/graph/ModelLineage'
1010
import { useVSCode } from '@/hooks/vscode'
1111
import React from 'react'
12+
import { IS_PRODUCTION } from '@/utilsutils/isProduction'
1213

1314
export function LineagePage() {
1415
// Handle messages from VSCode extension
@@ -23,7 +24,7 @@ export function LineagePage() {
2324
// Implement your focus change logic here
2425
break
2526
default:
26-
console.log('Unhandled message type:', payload.key)
27+
console.error('Unhandled message type:', payload.key)
2728
}
2829
}
2930
}
@@ -34,21 +35,14 @@ export function LineagePage() {
3435
}, [])
3536

3637
const client = new QueryClient({
37-
queryCache: new QueryCache({
38-
onError(error, query) {
39-
console.error(error, query)
40-
},
41-
onSuccess(data, query) {
42-
console.log('success', data, query)
43-
},
44-
}),
38+
queryCache: new QueryCache({}),
4539
defaultOptions: {
4640
queries: {
4741
networkMode: 'always',
4842
refetchOnWindowFocus: false,
4943
retry: false,
5044
staleTime: Infinity,
51-
},
45+
}
5246
},
5347
})
5448

vscode/react/src/routes/__root.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { LineagePage } from '@/pages/lineage'
55

66
export const Route = createRootRoute({
77
component: () => {
8-
console.log('root route')
98
return (
109
<>
1110
<Outlet />
@@ -14,7 +13,6 @@ export const Route = createRootRoute({
1413
)
1514
},
1615
notFoundComponent: () => {
17-
console.log('not found route')
1816
return <LineagePage />
1917
}
2018
})

vscode/react/src/routes/lineage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ import { LineagePage } from '@/pages/lineage'
44
export const Route = createFileRoute('/lineage')({
55
component: LineagePage,
66
})
7-
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const IS_PRODUCTION = process.env.NODE_ENV === 'production'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
let VSCODE_API: VSCodeAPI | undefined;
2+
3+
interface VSCodeAPI {
4+
postMessage: (message: any) => void;
5+
}
6+
7+
export function getVSCodeAPI(): VSCodeAPI {
8+
if (!VSCODE_API) {
9+
// @ts-ignore
10+
VSCODE_API = acquireVsCodeApi();
11+
}
12+
if (!VSCODE_API) {
13+
throw new Error('VSCode API not initialized');
14+
}
15+
console.log('getVSCodeAPI', VSCODE_API)
16+
return VSCODE_API;
17+
}

0 commit comments

Comments
 (0)