Repository navigation
feat(studio): SQL editor logs source — toolbar UI + creation flow - #48452
Conversation
Add the toolbar surface for the logs query source alongside database: QuerySourceIndicator, LogsRangePicker, source-aware UtilityActions gating (hide db selector/role/limit, show range picker, disable prettify), a run-affordance gate for non-ClickHouse orgs, and new-snippet-with-source threading through /sql/new, the nav new-query flow, and the duplicate flow. Logs snippets hide the db-only Export action. Dual-flag gated (sqlEditorLogsSource + otelLegacyLogs).
Replace the scattered QuerySourceIndicator + separate db selector / role / limit / range-picker toolbar controls with a single consolidated source dropdown (Database ▾ / Logs ▾). It labels the snippet source and hosts the source-specific controls as flyout submenus: database selector, role impersonation, and row limit for a database snippet; a time-range submenu (presets + a custom-range calendar dialog) for a logs snippet. Switching source respects immutability — an existing snippet opens a fresh tab of the target source, while a blank new tab re-flavors in place. Both preset and custom logs ranges gate on the log.retention_days entitlement and surface the upgrade prompt past retention.
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughThe SQL editor now supports source-aware database and logs workflows, including source switching, log time ranges, read-replica selection, role and row-limit controls, feature-flagged creation, and run/prettify gating. ChangesSQL editor source controls
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant UtilityActions
participant QuerySourceMenu
participant SqlEditorSession
participant Router
User->>UtilityActions: open source controls
UtilityActions->>QuerySourceMenu: render resolved source menu
User->>QuerySourceMenu: select source or range
QuerySourceMenu->>Router: navigate with source
QuerySourceMenu->>SqlEditorSession: update range or database
UtilityActions->>User: show gated run or prettify state
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (3)
apps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/QuerySourceMenu.utils.test.ts (1)
17-38: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd the missing blank-tab logs→database case.
Tests cover database→logs (push and replace) and logs→database on a non-blank tab, but not logs→database on a blank tab (expected
replace, url withoutsourceparam). This is the mirror case of the "re-flavor in place" behavior and is on the critical immutable-source-switch path.🧪 Suggested additional test
+ it('re-flavors in place (replace) when switching a blank tab from logs to database', () => { + expect( + resolveSourceSwitch({ + ref: 'abc', + target: 'database', + currentSource: 'logs', + isBlankNewTab: true, + }) + ).toEqual({ method: 'replace', url: '/project/abc/sql/new?skip=true' }) + })🤖 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/SQLEditor/UtilityPanel/QuerySourceMenu/QuerySourceMenu.utils.test.ts` around lines 17 - 38, The tests for resolveSourceSwitch are missing the blank-new-tab logs-to-database scenario. Add a test with currentSource set to logs, target set to database, and isBlankNewTab true, asserting replace navigation to /project/abc/sql/new?skip=true without a source parameter.apps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/DatabaseSubMenu.tsx (1)
36-40: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicate database-sort logic vs.
DatabaseSelector.tsx.This sort chain (primary-first, inserted_at ascending) is copy-pasted from
apps/studio/components/ui/DatabaseSelector.tsx. Consider extracting a shared helper (e.g.sortDatabasesPrimaryFirst) indata/read-replicas/replicas.utils.tsto avoid future divergence.♻️ Suggested extraction
// data/read-replicas/replicas.utils.ts export function sortDatabasesPrimaryFirst<T extends { identifier: string; inserted_at: string }>( databases: T[], projectRef: string | undefined ): T[] { return databases .slice() .sort((a, b) => (a.inserted_at > b.inserted_at ? 1 : 0)) .sort((database) => (database.identifier === projectRef ? -1 : 0)) }As per path instructions, "new utilities should be reusable and not page-coupled."
🤖 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/SQLEditor/UtilityPanel/QuerySourceMenu/DatabaseSubMenu.tsx` around lines 36 - 40, Extract the duplicated database ordering into a reusable sortDatabasesPrimaryFirst helper in data/read-replicas/replicas.utils.ts, preserving inserted_at ascending order and placing the projectRef database first. Update both DatabaseSubMenu and DatabaseSelector to use the shared helper and remove their inline sort chains.Source: Path instructions
apps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/QuerySourceMenu.tsx (1)
83-87: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider tracking the Database→Logs source switch.
Switching to the Logs source is a first-use/activation signal for a gated product feature (
sqlEditorLogsSource/otelLegacyLogs). No telemetry currently fires on this transition.📊 Example tracking addition
const switchSource = (target: SqlSnippetSource) => { const next = resolveSourceSwitch({ ref, target, currentSource, isBlankNewTab }) if (next === null) return + if (target === 'logs') track('sql_editor_logs_source_selected') router[next.method](next.url) }As per path instructions, suggest tracking growth-relevant actions like "enabling or disabling a product feature."
🤖 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/SQLEditor/UtilityPanel/QuerySourceMenu/QuerySourceMenu.tsx` around lines 83 - 87, Update switchSource to emit telemetry when the resolved transition changes from the Database source to the Logs source, using the existing tracking mechanism and feature identifiers sqlEditorLogsSource/otelLegacyLogs. Preserve the current null guard and router navigation, and avoid tracking unrelated source switches.Source: Path instructions
🤖 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/SQLEditor/useRunSource.ts`:
- Around line 27-33: Enforce the Logs source eligibility check for direct URL
sources in apps/studio/components/interfaces/SQLEditor/useRunSource.ts lines
27-33: resolve Logs only when both sqlEditorLogsSource and otelLegacyLogs are
enabled, otherwise fall back to Database. Apply the identical rule in
apps/studio/components/interfaces/SQLEditor/useSnippetEditor.ts lines 29-51
before assigning the creation source, keeping visual state and persisted snippet
metadata consistent.
In `@apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx`:
- Line 156: Update the Prettify SQL controls in UtilityActions, including the
dropdown item and icon button around prettifyQuery, to use the established
ButtonTooltip disabled-reason pattern. When isLogs is true, explain that
prettifying is unavailable because the snippet source is Logs; otherwise
preserve the existing “Prettify SQL” label and keyboard shortcut.
---
Nitpick comments:
In
`@apps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/DatabaseSubMenu.tsx`:
- Around line 36-40: Extract the duplicated database ordering into a reusable
sortDatabasesPrimaryFirst helper in data/read-replicas/replicas.utils.ts,
preserving inserted_at ascending order and placing the projectRef database
first. Update both DatabaseSubMenu and DatabaseSelector to use the shared helper
and remove their inline sort chains.
In
`@apps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/QuerySourceMenu.tsx`:
- Around line 83-87: Update switchSource to emit telemetry when the resolved
transition changes from the Database source to the Logs source, using the
existing tracking mechanism and feature identifiers
sqlEditorLogsSource/otelLegacyLogs. Preserve the current null guard and router
navigation, and avoid tracking unrelated source switches.
In
`@apps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/QuerySourceMenu.utils.test.ts`:
- Around line 17-38: The tests for resolveSourceSwitch are missing the
blank-new-tab logs-to-database scenario. Add a test with currentSource set to
logs, target set to database, and isBlankNewTab true, asserting replace
navigation to /project/abc/sql/new?skip=true without a source parameter.
🪄 Autofix (Beta)
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: 69632660-9231-4bfd-be16-21844fe7a57f
📒 Files selected for processing (18)
apps/studio/components/interfaces/SQLEditor/SQLEditorLayout.tsxapps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/DatabaseSubMenu.tsxapps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/LogsCustomRangeDialog.tsxapps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/QuerySourceMenu.tsxapps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/QuerySourceMenu.utils.test.tsapps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/QuerySourceMenu.utils.tsapps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/RowLimitSubMenu.tsxapps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/RunAsSubMenu.tsxapps/studio/components/interfaces/SQLEditor/UtilityPanel/QuerySourceMenu/TimeRangeSubMenu.tsxapps/studio/components/interfaces/SQLEditor/UtilityPanel/RunButton.tsxapps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsxapps/studio/components/interfaces/SQLEditor/querySource.test.tsapps/studio/components/interfaces/SQLEditor/querySource.tsapps/studio/components/interfaces/SQLEditor/usePrettifyQuery.tsapps/studio/components/interfaces/SQLEditor/useRunSource.tsapps/studio/components/interfaces/SQLEditor/useSnippetEditor.tsapps/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsxapps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx
| const { source: sourceParam } = useParams() | ||
| const snapV2 = useSqlEditorV2StateSnapshot() | ||
| const sessionSnap = useSqlEditorSessionSnapshot() | ||
|
|
||
| const snippetType = snapV2.snippets[id]?.snippet.type | ||
| const snippet = snapV2.snippets[id]?.snippet | ||
| const source: SqlSnippetSource = | ||
| snippet !== undefined ? getSnippetSource(snippet) : parseSqlSnippetSource(sourceParam) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Enforce logs rollout flags for direct URLs.
A user can navigate directly to /sql/new?source=logs while sqlEditorLogsSource or otelLegacyLogs is disabled. The UI resolves Logs immediately, then persists a log_sql snippet on first edit, bypassing the gated menu entry point.
apps/studio/components/interfaces/SQLEditor/useRunSource.ts#L27-L33: resolve URL-driven Logs only when both rollout flags permit it; otherwise use Database.apps/studio/components/interfaces/SQLEditor/useSnippetEditor.ts#L29-L51: apply the identical eligibility rule before setting the creationsource, so visual state and persisted metadata cannot diverge.
📍 Affects 2 files
apps/studio/components/interfaces/SQLEditor/useRunSource.ts#L27-L33(this comment)apps/studio/components/interfaces/SQLEditor/useSnippetEditor.ts#L29-L51
🤖 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/SQLEditor/useRunSource.ts` around lines 27
- 33, Enforce the Logs source eligibility check for direct URL sources in
apps/studio/components/interfaces/SQLEditor/useRunSource.ts lines 27-33: resolve
Logs only when both sqlEditorLogsSource and otelLegacyLogs are enabled,
otherwise fall back to Database. Apply the identical rule in
apps/studio/components/interfaces/SQLEditor/useSnippetEditor.ts lines 29-51
before assigning the creation source, keeping visual state and persisted snippet
metadata consistent.
| </> | ||
| )} | ||
| <DropdownMenuItem className="justify-between" onClick={prettifyQuery}> | ||
| <DropdownMenuItem className="justify-between" onClick={prettifyQuery} disabled={isLogs}> |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Disabled "Prettify SQL" button doesn't explain why it's disabled.
disabled={isLogs} is applied to both the dropdown item (L156) and the icon button (L218-235), but the Tooltip content stays static ("Prettify SQL" + shortcut) — there's no indication that it's disabled because the snippet's source is Logs. RunButton.tsx in this same PR already establishes the ButtonTooltip + reason pattern for exactly this situation (disabled Run for blocked logs queries).
🔧 Suggested fix for the icon button
- <Tooltip>
- <TooltipTrigger asChild>
- <Button
- variant="text"
- onClick={prettifyQuery}
- disabled={isLogs}
- className="px-1"
- icon={<AlignLeft strokeWidth={2} className="text-foreground-light" />}
- aria-label="Prettify SQL"
- />
- </TooltipTrigger>
- <TooltipContent side="bottom" className="p-1 pl-2.5">
- <div className="flex items-center gap-2.5">
- <span>Prettify SQL</span>
- {formatKeys && <KeyboardShortcut keys={formatKeys} />}
- </div>
- </TooltipContent>
- </Tooltip>
+ <ButtonTooltip
+ variant="text"
+ onClick={prettifyQuery}
+ disabled={isLogs}
+ className="px-1"
+ icon={<AlignLeft strokeWidth={2} className="text-foreground-light" />}
+ aria-label="Prettify SQL"
+ tooltip={{
+ content: {
+ side: 'bottom',
+ text: isLogs ? "Prettify isn't available for Logs queries" : 'Prettify SQL',
+ },
+ }}
+ />As per coding guidelines, "Use ButtonTooltip to explain disabled buttons."
Also applies to: 218-235
🤖 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/SQLEditor/UtilityPanel/UtilityActions.tsx`
at line 156, Update the Prettify SQL controls in UtilityActions, including the
dropdown item and icon button around prettifyQuery, to use the established
ButtonTooltip disabled-reason pattern. When isLogs is true, explain that
prettifying is unavailable because the snippet source is Logs; otherwise
preserve the existing “Prettify SQL” label and keyboard shortcut.
Source: Coding guidelines
There was a problem hiding this comment.
Probably can use DropdownMenuItemTooltip for this one - agree that we should add some tooltip for any disabled items, perhaps something along the lines of "Can only prettify SQL queries"
There was a problem hiding this comment.
@joshenlim Agreed — DropdownMenuItemTooltip is the better fit for the disabled dropdown action. The icon button should likewise retain an explanatory disabled-state tooltip, while preserving the normal “Prettify SQL” label and shortcut when enabled.
✏️ Learnings added
Learnt from: joshenlim
Repo: supabase/supabase PR: 48452
File: apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx:156-156
Timestamp: 2026-07-30T09:50:38.382Z
Learning: In `apps/studio`, disabled `DropdownMenuItem` controls should use `DropdownMenuItemTooltip` to explain why the action is unavailable; disabled button controls should use the established button tooltip pattern.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
You are interacting with an AI system.
🎭 Playwright Test Results (tanstack)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
| <Button | ||
| variant="text" | ||
| onClick={prettifyQuery} | ||
| disabled={isLogs} |
There was a problem hiding this comment.
Similar to CodeRabbit's comment above - should use a ButtonTooltip to describe the reason if the prettify CTA is disabled
joshenlim
left a comment
There was a problem hiding this comment.
Generally LGTM! The comments i've left are all non-blocking so feel free to address separately 🙂 🙏
Braintrust eval report
|
) ## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Bug fix ## What is the current behavior? In the SQL Editor, the Prettify SQL action (both the "More actions" dropdown menu item and the toolbar button) is disabled for logs snippets, but gives no indication why. ## What is the new behavior? The disabled Prettify menu item now uses `DropdownMenuItemTooltip` and the disabled Prettify toolbar button uses `ButtonTooltip`, both showing "Can only prettify SQL queries" while disabled. Addresses review feedback from #48452 (Linear FE-4038). ## Additional context Resolves FE-4038 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Updated SQL editor tooltips with clearer, consistent messaging. * Log-source users now see an explanation when SQL formatting is unavailable. * Regular users continue to see the SQL prettify keyboard shortcut. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…pt (#48713) ## Summary - Refactor the SQL Editor / Logs "Log retention" upgrade-prompt dialog to use the design system's `Card` + `Table` components instead of a custom flexbox-div table, matching the pattern in `apps/design-system/registry/default/example/table-demo.tsx` - No behavior or data change Fixes FE-4034 Non-blocking review nit from #48452 (comment: #48452 (comment)) ## Test plan - [x] `pnpm --filter studio typecheck` passes - [x] `pnpm --filter studio run lint:ratchet` passes (no new warnings) - [x] Prettier check passes <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Style** * Updated the upgrade prompt with a more consistent card and table layout. * Preserved existing plan names and log retention details. <!-- end of auto-generated comment: release notes by coderabbit.ai -->




What
PR 6 of the SQL-editor "query source (Database vs Logs)" stack (builds on the merged PR 5, #48414). Adds the user-facing toolbar surface for the logs query source and consolidates the SQL-editor toolbar into a single source menu.
Everything stays behind
sqlEditorLogsSource+otelLegacyLogs(dual-flag gated); with the flags off the toolbar is unchanged.Changes
QuerySourceMenu) — oneDatabase ▾/Logs ▾dropdown that both labels the snippet's source and hosts the source-specific controls as flyout submenus:Primary/ read replicas),Run as(role impersonation), andRow limit.Time range— the same relative presets as the Logs Explorer plus aCustom range…calendar dialog.resolveSourceSwitch./sql/new?source=, the nav "Create a new logs query" entry, and the duplicate flow. Logs snippets hide the (db-dialect) Export action.log.retention_dayssurface the upgrade prompt instead of applying silently. Prettify is disabled for logs (sql-formatter mangles ClickHouse).Tests
querySource.test.ts—logDateRangesEqual(structural relative/absolute matching, incl. the "Last hour" vs "Last 1 hour" label case).QuerySourceMenu.utils.test.ts—resolveSourceSwitchpush-vs-replace / no-op behavior.pnpm --filter studio typecheck·lint:ratchet· Prettier · SQL editor suite (307 tests) all green.For reviewers
To test manually, enable the
sqlEditorLogsSourcefeature flag for yourself on local/staging. There is no nav for Log SQL snippets currently (that is by design, this PR is big enough as-is), so to check an existing logs snippet, you can create one using the existing Logs Explorer, copy its UUID, and force navigate to that snippet in the SQL editor via URL.Summary by CodeRabbit