-
Notifications
You must be signed in to change notification settings - Fork 4
feat: SQL metadata output renderer #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/webviews/webview-side/sql-metadata-renderer/SqlMetadataRenderer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import React, { memo } from 'react'; | ||
|
|
||
| export interface SqlMetadataRendererProps { | ||
| data: { | ||
| cache_created_at?: string; | ||
| compiled_query?: string; | ||
| integration_id?: string; | ||
| size_in_bytes?: number; | ||
| status: string; | ||
| variable_type?: string; | ||
| }; | ||
| } | ||
|
|
||
| const getStatusMessage = (status: string) => { | ||
| switch (status) { | ||
| case 'read_from_cache_success': | ||
| return { | ||
| icon: '✓', | ||
| text: 'Query result loaded from cache', | ||
| color: 'var(--vscode-testing-iconPassed)' | ||
| }; | ||
| case 'success_no_cache': | ||
| return { | ||
| icon: 'ℹ', | ||
| text: 'Query executed successfully', | ||
| color: 'var(--vscode-notificationsInfoIcon-foreground)' | ||
| }; | ||
| case 'cache_not_supported_for_query': | ||
| return { | ||
| icon: 'ℹ', | ||
| text: 'Caching not supported for this query type', | ||
| color: 'var(--vscode-notificationsInfoIcon-foreground)' | ||
| }; | ||
| default: | ||
| return { | ||
| icon: 'ℹ', | ||
| text: `Status: ${status}`, | ||
| color: 'var(--vscode-foreground)' | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| const formatBytes = (bytes: number) => { | ||
| if (bytes < 1024) { | ||
| return `${bytes} B`; | ||
| } | ||
| if (bytes < 1024 * 1024) { | ||
| return `${(bytes / 1024).toFixed(2)} KB`; | ||
| } | ||
| if (bytes < 1024 * 1024 * 1024) { | ||
| return `${(bytes / (1024 * 1024)).toFixed(2)} MB`; | ||
| } | ||
| return `${(bytes / (1024 * 1024 * 1024)).toFixed(2)} GB`; | ||
| }; | ||
|
|
||
| export const SqlMetadataRenderer = memo(function SqlMetadataRenderer({ data }: SqlMetadataRendererProps) { | ||
| const statusInfo = getStatusMessage(data.status); | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ | ||
| padding: '8px 12px', | ||
| margin: '4px 0', | ||
| borderLeft: `3px solid ${statusInfo.color}`, | ||
| backgroundColor: 'var(--vscode-textBlockQuote-background)', | ||
| fontSize: '12px', | ||
| fontFamily: 'var(--vscode-font-family)', | ||
| color: 'var(--vscode-foreground)' | ||
| }} | ||
| > | ||
| <div | ||
| style={{ | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| gap: '8px', | ||
| marginBottom: data.cache_created_at || data.size_in_bytes ? '6px' : '0' | ||
| }} | ||
| > | ||
| <span style={{ color: statusInfo.color, fontSize: '14px', fontWeight: 'bold' }}>{statusInfo.icon}</span> | ||
| <span style={{ fontWeight: 500 }}>{statusInfo.text}</span> | ||
| </div> | ||
|
|
||
| {data.cache_created_at && ( | ||
| <div style={{ marginLeft: '22px', opacity: 0.8, fontSize: '11px' }}> | ||
| Cache created: {new Date(data.cache_created_at).toLocaleString()} | ||
| </div> | ||
| )} | ||
|
|
||
| {data.size_in_bytes !== undefined && ( | ||
| <div style={{ marginLeft: '22px', opacity: 0.8, fontSize: '11px' }}> | ||
| Result size: {formatBytes(data.size_in_bytes)} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import type { ActivationFunction, OutputItem, RendererContext } from 'vscode-notebook-renderer'; | ||
| import * as React from 'react'; | ||
| import * as ReactDOM from 'react-dom'; | ||
|
|
||
| import { SqlMetadataRenderer } from './SqlMetadataRenderer'; | ||
|
|
||
| /** | ||
| * Renderer for SQL metadata output (application/vnd.deepnote.sql-output-metadata+json). | ||
| * This renderer displays information about SQL query execution, including cache status, | ||
| * query size, and other metadata. | ||
| */ | ||
| export const activate: ActivationFunction = (_context: RendererContext<unknown>) => { | ||
| const roots = new Map<string, HTMLElement>(); | ||
|
|
||
| return { | ||
| renderOutputItem(outputItem: OutputItem, element: HTMLElement) { | ||
| try { | ||
| const data = outputItem.json(); | ||
|
|
||
| const root = document.createElement('div'); | ||
| element.appendChild(root); | ||
| roots.set(outputItem.id, root); | ||
|
|
||
| ReactDOM.render(React.createElement(SqlMetadataRenderer, { data }), root); | ||
| } catch (error) { | ||
| console.error(`Error rendering SQL metadata: ${error}`); | ||
| const errorDiv = document.createElement('div'); | ||
| errorDiv.style.padding = '10px'; | ||
| errorDiv.style.color = 'var(--vscode-errorForeground)'; | ||
| errorDiv.textContent = `Error rendering SQL metadata: ${error}`; | ||
| element.appendChild(errorDiv); | ||
| } | ||
| }, | ||
|
|
||
| disposeOutputItem(id?: string) { | ||
| if (id) { | ||
| const root = roots.get(id); | ||
| if (root) { | ||
| ReactDOM.unmountComponentAtNode(root); | ||
| roots.delete(id); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.