Skip to content

Commit 2dcacce

Browse files
committed
code review changes
1 parent 85cfd9e commit 2dcacce

File tree

2 files changed

+53
-47
lines changed

2 files changed

+53
-47
lines changed

src/webviews/webview-side/sql-metadata-renderer/SqlMetadataRenderer.tsx

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,50 @@ export interface SqlMetadataRendererProps {
1111
};
1212
}
1313

14-
export const SqlMetadataRenderer = memo(function SqlMetadataRenderer({ data }: SqlMetadataRendererProps) {
15-
const getStatusMessage = () => {
16-
switch (data.status) {
17-
case 'read_from_cache_success':
18-
return {
19-
icon: '✓',
20-
text: 'Query result loaded from cache',
21-
color: 'var(--vscode-testing-iconPassed)'
22-
};
23-
case 'success_no_cache':
24-
return {
25-
icon: 'ℹ',
26-
text: 'Query executed successfully',
27-
color: 'var(--vscode-notificationsInfoIcon-foreground)'
28-
};
29-
case 'cache_not_supported_for_query':
30-
return {
31-
icon: 'ℹ',
32-
text: 'Caching not supported for this query type',
33-
color: 'var(--vscode-notificationsInfoIcon-foreground)'
34-
};
35-
default:
36-
return {
37-
icon: 'ℹ',
38-
text: `Status: ${data.status}`,
39-
color: 'var(--vscode-foreground)'
40-
};
41-
}
42-
};
14+
const getStatusMessage = (status: string) => {
15+
switch (status) {
16+
case 'read_from_cache_success':
17+
return {
18+
icon: '✓',
19+
text: 'Query result loaded from cache',
20+
color: 'var(--vscode-testing-iconPassed)'
21+
};
22+
case 'success_no_cache':
23+
return {
24+
icon: 'ℹ',
25+
text: 'Query executed successfully',
26+
color: 'var(--vscode-notificationsInfoIcon-foreground)'
27+
};
28+
case 'cache_not_supported_for_query':
29+
return {
30+
icon: 'ℹ',
31+
text: 'Caching not supported for this query type',
32+
color: 'var(--vscode-notificationsInfoIcon-foreground)'
33+
};
34+
default:
35+
return {
36+
icon: 'ℹ',
37+
text: `Status: ${status}`,
38+
color: 'var(--vscode-foreground)'
39+
};
40+
}
41+
};
4342

44-
const statusInfo = getStatusMessage();
43+
const formatBytes = (bytes: number) => {
44+
if (bytes < 1024) {
45+
return `${bytes} B`;
46+
}
47+
if (bytes < 1024 * 1024) {
48+
return `${(bytes / 1024).toFixed(2)} KB`;
49+
}
50+
if (bytes < 1024 * 1024 * 1024) {
51+
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
52+
}
53+
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
54+
};
4555

46-
const formatBytes = (bytes: number) => {
47-
if (bytes < 1024) {
48-
return `${bytes} B`;
49-
}
50-
if (bytes < 1024 * 1024) {
51-
return `${(bytes / 1024).toFixed(2)} KB`;
52-
}
53-
if (bytes < 1024 * 1024 * 1024) {
54-
return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
55-
}
56-
return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`;
57-
};
56+
export const SqlMetadataRenderer = memo(function SqlMetadataRenderer({ data }: SqlMetadataRendererProps) {
57+
const statusInfo = getStatusMessage(data.status);
5858

5959
return (
6060
<div

src/webviews/webview-side/sql-metadata-renderer/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import { SqlMetadataRenderer } from './SqlMetadataRenderer';
1010
* query size, and other metadata.
1111
*/
1212
export const activate: ActivationFunction = (_context: RendererContext<unknown>) => {
13+
const roots = new Map<string, HTMLElement>();
14+
1315
return {
1416
renderOutputItem(outputItem: OutputItem, element: HTMLElement) {
15-
console.log(`SQL metadata renderer - rendering output item: ${outputItem.id}`);
1617
try {
1718
const data = outputItem.json();
1819

19-
console.log(`SQL metadata renderer - received data:`, data);
20-
2120
const root = document.createElement('div');
2221
element.appendChild(root);
22+
roots.set(outputItem.id, root);
2323

2424
ReactDOM.render(React.createElement(SqlMetadataRenderer, { data }), root);
2525
} catch (error) {
@@ -32,8 +32,14 @@ export const activate: ActivationFunction = (_context: RendererContext<unknown>)
3232
}
3333
},
3434

35-
disposeOutputItem(_id?: string) {
36-
// Cleanup if needed
35+
disposeOutputItem(id?: string) {
36+
if (id) {
37+
const root = roots.get(id);
38+
if (root) {
39+
ReactDOM.unmountComponentAtNode(root);
40+
roots.delete(id);
41+
}
42+
}
3743
}
3844
};
3945
};

0 commit comments

Comments
 (0)