Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
5 Skipped Deployments
|
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughAdded shared Explorer query types, a controlled SQL editor, virtualized table and chart result components, focused tests, and Explorer usage documentation. ChangesExplorer query components
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant Monaco
participant QuerySqlEditor
participant ExplorerQuery
User->>Monaco: Select SQL and press Ctrl/Cmd+Enter
Monaco->>QuerySqlEditor: Provide selection and run action
QuerySqlEditor->>ExplorerQuery: Call onExecute with trimmed SQL
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
fa0e0b5 to
3baa8cc
Compare
🎭 Playwright Test Results (tanstack)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
23c4d1b to
9b7f3e4
Compare
## Summary Adds the Studio-owned `ExplorerQuery` shell used by notebooks, SQL snippets, dedicated query tabs, and assistant query blocks within Explorer. - provides framed embedded and full-height viewport roots - provides composable editor, results, and footer layout regions - keeps result content responsible for its own scrolling while the results region fills remaining height - remains presentational: query models, execution, source resolution, persistence, and result rendering stay external - expands the project-local Explorer agent skill with composition and sizing guidance - adds focused Studio component tests All files are scoped to `apps/studio`; this PR no longer changes `ui-patterns` or the design-system app. ## Stack - Base: #48925 - Next: #48961 - This PR targets `chore/toolbar-component`, so its review diff contains only the query shell layer. ## Validation - `pnpm --filter studio exec vitest run components/interfaces/Explorer/ExplorerQuery/ExplorerQuery.test.tsx components/interfaces/Explorer/ExplorerToolbar/ExplorerToolbar.test.tsx` — 6 tests passed - `pnpm --filter studio typecheck` - Prettier - `git diff --check`
9b7f3e4 to
ec06b19
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (3)
apps/studio/components/interfaces/Explorer/QueryResultTable/QueryResultTable.test.tsx (1)
63-66: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAssert behavior instead of Tailwind class strings.
Lines 64-66 assert exact utility class fragments such as
[&_.rdg-header-row>.rdg-cell]:bg-200and[&>.rdg-cell]:border-b-0!. A styling change then breaks the test without any behavior change. These assertions also encodereact-data-gridinternals in the test.Keep the
headerRowHeightandrowHeightassertions. Drop the class-string assertions, or replace the last-row check with an assertion thatrowClassreturns a different value for the last row index than for other row indexes.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Explorer/QueryResultTable/QueryResultTable.test.tsx` around lines 63 - 66, In the QueryResultTable test, keep the headerRowHeight and rowHeight assertions but remove the assertions that inspect Tailwind/react-data-grid class strings. If preserving row styling coverage, assert that rowClass returns different values for the last row index and a non-last row index instead.apps/studio/components/interfaces/Explorer/QueryResultChart/index.tsx (1)
58-58: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRename
useLogScale. Theuseprefix reads as a React hook.In a
.tsxfile theuseprefix is reserved by convention for hooks, and the React hooks ESLint rules key off that prefix.isLogScaleEnabledmatches the required boolean naming and removes the ambiguity.As per coding guidelines: "Use boolean names beginning with
is,has,can, orshould".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Explorer/QueryResultChart/index.tsx` at line 58, Rename the boolean variable useLogScale to isLogScaleEnabled in the QueryResultChart component, updating every reference to preserve the existing behavior and avoid implying it is a React hook.Source: Coding guidelines
apps/studio/components/interfaces/Explorer/QuerySqlEditor/QuerySqlEditor.test.tsx (1)
1-2: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAll three new Explorer test files bypass the Studio test harness. Each imports
renderfrom@testing-library/reactdirectly. The Studio guideline requirescustomRender, which installs the shared providers and the MSW setup that makes unhandled network requests fail. These three components need no data today, so the tests pass. A later change that adds a query or a provider-backed UI primitive will then fail in a confusing way instead of failing clearly.
apps/studio/components/interfaces/Explorer/QuerySqlEditor/QuerySqlEditor.test.tsx#L1-L2: replace therenderimport withcustomRenderand update the threerender(...)call sites.apps/studio/components/interfaces/Explorer/QueryResultTable/QueryResultTable.test.tsx#L1-L2: replace therenderimport withcustomRenderand update the threerender(...)call sites.apps/studio/components/interfaces/Explorer/QueryResultChart/QueryResultChart.test.tsx#L1-L2: replace therenderimport withcustomRenderand update the threerender(...)call sites.As per coding guidelines: "Include relevant tests by default; use Vitest and MSW, render components with
customRenderandaddAPIMock, ensure unhandled network requests fail".🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/studio/components/interfaces/Explorer/QuerySqlEditor/QuerySqlEditor.test.tsx` around lines 1 - 2, All three Explorer test files bypass the Studio test harness; update QuerySqlEditor.test.tsx (lines 1-2), QueryResultTable.test.tsx (lines 1-2), and QueryResultChart.test.tsx (lines 1-2) to import customRender instead of render and replace all three render call sites in each file, preserving the existing test behavior while enabling shared providers and MSW request handling.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/studio/components/interfaces/Explorer/QueryResultChart/index.tsx`:
- Around line 57-58: Update the log-scale domain calculation near useLogScale to
derive its lower bound from the smallest positive chart value instead of
hardcoding 1, and use that bound wherever the domain is configured. Preserve
rejection of non-positive values while ensuring datasets entirely below 1 remain
visible without clipping.
In
`@apps/studio/components/interfaces/Explorer/QueryResultChart/QueryResultChart.test.tsx`:
- Around line 39-49: Move restoration of the
HTMLElement.prototype.getBoundingClientRect spy from the inline cleanup near the
test assertions into an afterEach hook, ensuring the spy is restored even when
assertions fail. Update the existing rectSpy setup in the QueryResultChart test
without changing the mocked return values or assertions.
In `@apps/studio/components/interfaces/Explorer/QueryResultTable/index.tsx`:
- Line 5: The new QueryResultTable must not use react-data-grid. Replace
DataGrid and its related rendering logic with `@tanstack/react-table`, integrating
`@tanstack/react-virtual` for row virtualization, column resize state, and the
existing no-rows fallback; update the table implementation around
QueryResultTable and its column definitions accordingly.
In `@apps/studio/components/interfaces/Explorer/QuerySqlEditor/index.tsx`:
- Around line 71-87: Update handleMount to register the Monaco run action
unconditionally, removing the outer onExecuteRef.current check. Keep the
existing selection extraction and invoke onExecuteRef.current inside the
action’s run callback, so late handler assignments are supported while safely
doing nothing when no handler exists.
---
Nitpick comments:
In `@apps/studio/components/interfaces/Explorer/QueryResultChart/index.tsx`:
- Line 58: Rename the boolean variable useLogScale to isLogScaleEnabled in the
QueryResultChart component, updating every reference to preserve the existing
behavior and avoid implying it is a React hook.
In
`@apps/studio/components/interfaces/Explorer/QueryResultTable/QueryResultTable.test.tsx`:
- Around line 63-66: In the QueryResultTable test, keep the headerRowHeight and
rowHeight assertions but remove the assertions that inspect
Tailwind/react-data-grid class strings. If preserving row styling coverage,
assert that rowClass returns different values for the last row index and a
non-last row index instead.
In
`@apps/studio/components/interfaces/Explorer/QuerySqlEditor/QuerySqlEditor.test.tsx`:
- Around line 1-2: All three Explorer test files bypass the Studio test harness;
update QuerySqlEditor.test.tsx (lines 1-2), QueryResultTable.test.tsx (lines
1-2), and QueryResultChart.test.tsx (lines 1-2) to import customRender instead
of render and replace all three render call sites in each file, preserving the
existing test behavior while enabling shared providers and MSW request handling.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: decdd968-574d-4188-b03c-83fb3db7f38d
📒 Files selected for processing (9)
apps/studio/.claude/skills/explorer/SKILL.mdapps/studio/components/interfaces/Explorer/ExplorerQuery/ExplorerQuery.types.tsapps/studio/components/interfaces/Explorer/ExplorerQuery/index.tsxapps/studio/components/interfaces/Explorer/QueryResultChart/QueryResultChart.test.tsxapps/studio/components/interfaces/Explorer/QueryResultChart/index.tsxapps/studio/components/interfaces/Explorer/QueryResultTable/QueryResultTable.test.tsxapps/studio/components/interfaces/Explorer/QueryResultTable/index.tsxapps/studio/components/interfaces/Explorer/QuerySqlEditor/QuerySqlEditor.test.tsxapps/studio/components/interfaces/Explorer/QuerySqlEditor/index.tsx
| const hasNonPositiveValues = chartData.some((row) => Number(row[chartValueKey]) <= 0) | ||
| const useLogScale = !!config.logScale && !hasNonPositiveValues |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Log scale clips values between 0 and 1.
hasNonPositiveValues only rejects values <= 0. A dataset whose values are all positive but below 1, for example 0.2 and 0.4, passes the guard and enables the log scale. Line 128 then sets the domain to [1, 'auto'] and line 129 sets allowDataOverflow to true. Every point falls below the domain floor and is clipped, so the chart renders empty with no explanation.
Derive the lower bound from the data instead of hardcoding 1.
🐛 Proposed fix
const hasNonPositiveValues = chartData.some((row) => Number(row[chartValueKey]) <= 0)
const useLogScale = !!config.logScale && !hasNonPositiveValues
+ const logScaleMin = useLogScale
+ ? Math.min(...chartData.map((row) => Number(row[chartValueKey])))
+ : undefined scale={useLogScale ? 'log' : 'auto'}
- domain={useLogScale ? [1, 'auto'] : undefined}
+ domain={useLogScale ? [logScaleMin!, 'auto'] : undefined}
allowDataOverflow={useLogScale}Also applies to: 127-129
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/studio/components/interfaces/Explorer/QueryResultChart/index.tsx` around
lines 57 - 58, Update the log-scale domain calculation near useLogScale to
derive its lower bound from the smallest positive chart value instead of
hardcoding 1, and use that bound wherever the domain is configured. Preserve
rejection of non-positive values while ensuring datasets entirely below 1 remain
visible without clipping.
| const rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({ | ||
| bottom: 300, | ||
| height: 300, | ||
| left: 0, | ||
| right: 600, | ||
| top: 0, | ||
| width: 600, | ||
| x: 0, | ||
| y: 0, | ||
| toJSON: () => ({}), | ||
| }) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Restore the getBoundingClientRect spy in a cleanup hook.
Line 39 replaces getBoundingClientRect on HTMLElement.prototype, which is global. Line 67 restores it, but only if every assertion on lines 58-66 passes. If one assertion fails, the test throws and line 67 never runs. The stub then leaks into later tests and turns one real failure into several confusing ones.
Move the restore into afterEach so it always runs.
🧪 Proposed fix
-import { describe, expect, it, vi } from 'vitest'
+import { afterEach, describe, expect, it, vi } from 'vitest' describe('QueryResultChart', () => {
+ afterEach(() => {
+ vi.restoreAllMocks()
+ })
+
it('renders a successful empty state', () => {- const rectSpy = vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({
+ vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({ '--color-queryValue: hsl(var(--chart-1));'
)
-
- rectSpy.mockRestore()
})Also applies to: 67-67
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In
`@apps/studio/components/interfaces/Explorer/QueryResultChart/QueryResultChart.test.tsx`
around lines 39 - 49, Move restoration of the
HTMLElement.prototype.getBoundingClientRect spy from the inline cleanup near the
test assertions into an afterEach hook, ensuring the spy is restored even when
assertions fail. Update the existing rectSpy setup in the QueryResultChart test
without changing the mocked return values or assertions.
|
|
||
| import type { Key, ReactNode } from 'react' | ||
| import { useMemo } from 'react' | ||
| import DataGrid, { type Column } from 'react-data-grid' |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | 🏗️ Heavy lift
Do not introduce new react-data-grid usage. Build this table with @tanstack/react-table.
QueryResultTable is a new table component and it imports DataGrid from react-data-grid. The Studio guidelines prohibit new react-data-grid usage. This is also a durable repository convention recorded from earlier reviews.
The requirements here are virtualization, column resize, and a no-rows fallback. @tanstack/react-table covers column definitions and resize state, and pairs with @tanstack/react-virtual for row virtualization. Moving now avoids a rewrite later, because this component is positioned as the shared Explorer result renderer and SKILL.md documents it for notebook, chat, and snippet surfaces.
If an exception is intended for this component, record the reason in the PR description so the convention stays explicit.
As per coding guidelines: "New tables must use @tanstack/react-table; do not introduce new react-data-grid usage."
Also applies to: 104-139
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/studio/components/interfaces/Explorer/QueryResultTable/index.tsx` at
line 5, The new QueryResultTable must not use react-data-grid. Replace DataGrid
and its related rendering logic with `@tanstack/react-table`, integrating
`@tanstack/react-virtual` for row virtualization, column resize state, and the
existing no-rows fallback; update the table implementation around
QueryResultTable and its column definitions accordingly.
Sources: Coding guidelines, Learnings
| if (onExecuteRef.current) { | ||
| editor.addAction({ | ||
| id: `run-query${id ? `-${id}` : ''}`, | ||
| label: 'Run query', | ||
| keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter], | ||
| contextMenuGroupId: 'operation', | ||
| contextMenuOrder: 0, | ||
| run: () => { | ||
| const selection = editor.getSelection() | ||
| const selectedSql = selection | ||
| ? editor.getModel()?.getValueInRange(selection).trim() | ||
| : undefined | ||
|
|
||
| onExecuteRef.current?.(selectedSql || editor.getValue()) | ||
| }, | ||
| }) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Register the run action unconditionally and guard inside run.
handleMount runs once. The action is registered only if onExecute is defined at mount time. If a consumer passes onExecute later (for example, after a source resolves or after permissions load), Ctrl/Cmd+Enter never works for that editor instance. The onExecuteRef indirection already handles late handler changes, so the outer gate is the only blocker.
🐛 Proposed fix
- if (onExecuteRef.current) {
- editor.addAction({
- id: `run-query${id ? `-${id}` : ''}`,
- label: 'Run query',
- keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
- contextMenuGroupId: 'operation',
- contextMenuOrder: 0,
- run: () => {
- const selection = editor.getSelection()
- const selectedSql = selection
- ? editor.getModel()?.getValueInRange(selection).trim()
- : undefined
-
- onExecuteRef.current?.(selectedSql || editor.getValue())
- },
- })
- }
+ editor.addAction({
+ id: `run-query${id ? `-${id}` : ''}`,
+ label: 'Run query',
+ keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
+ contextMenuGroupId: 'operation',
+ contextMenuOrder: 0,
+ run: () => {
+ if (!onExecuteRef.current) return
+
+ const selection = editor.getSelection()
+ const selectedSql = selection
+ ? editor.getModel()?.getValueInRange(selection).trim()
+ : undefined
+
+ onExecuteRef.current(selectedSql || editor.getValue())
+ },
+ })📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (onExecuteRef.current) { | |
| editor.addAction({ | |
| id: `run-query${id ? `-${id}` : ''}`, | |
| label: 'Run query', | |
| keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter], | |
| contextMenuGroupId: 'operation', | |
| contextMenuOrder: 0, | |
| run: () => { | |
| const selection = editor.getSelection() | |
| const selectedSql = selection | |
| ? editor.getModel()?.getValueInRange(selection).trim() | |
| : undefined | |
| onExecuteRef.current?.(selectedSql || editor.getValue()) | |
| }, | |
| }) | |
| } | |
| editor.addAction({ | |
| id: `run-query${id ? `-${id}` : ''}`, | |
| label: 'Run query', | |
| keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter], | |
| contextMenuGroupId: 'operation', | |
| contextMenuOrder: 0, | |
| run: () => { | |
| if (!onExecuteRef.current) return | |
| const selection = editor.getSelection() | |
| const selectedSql = selection | |
| ? editor.getModel()?.getValueInRange(selection).trim() | |
| : undefined | |
| onExecuteRef.current(selectedSql || editor.getValue()) | |
| }, | |
| }) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/studio/components/interfaces/Explorer/QuerySqlEditor/index.tsx` around
lines 71 - 87, Update handleMount to register the Monaco run action
unconditionally, removing the outer onExecuteRef.current check. Keep the
existing selection extraction and invoke onExecuteRef.current inside the
action’s run callback, so late handler assignments are supported while safely
doing nothing when no handler exists.
Summary
Adds Studio-owned controlled editor and result renderers for
ExplorerQuery:QuerySqlEditor, a compact Monaco SQL editor that emits edits and run requests without executing queriesQueryResultTable, a dense virtualized table using source-neutral explicit columns and rowsQueryResultChart, controlled bar and line charts composed from shared UI chart primitivesExplorerQueryfolderEach component has its own folder under
apps/studio/components/interfaces/Explorer. Studio already owns the Monaco, Recharts, and data-grid dependencies, so this PR adds no dependency or lockfile changes. It no longer changesui-patternsor the design-system app.Stack
chore/query-cell-shell, so its review diff contains only the editor and result-renderer layer.Validation
pnpm --filter studio typecheckgit diff --checkapps/studiofilesSummary by CodeRabbit