Repository navigation
feat(studio): log date range domain + session logRange state - #48401
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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughShared Logs date-picker helpers are extracted into a framework-free module. SQL editor query-source utilities add validated log date-range conversions and resolution, while SQL editor session state stores per-snippet log ranges and clears them with snippet state. ChangesSQL editor log support
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 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 |
🎭 Playwright Test Results (tanstack)Details
Skipped testsFeatures › auth-users.spec.ts › should show web3 users as enabled when the matching web3 provider is enabled |
0db771a to
66b10a8
Compare
496637c to
8ee731a
Compare
- Add the logs time-range domain to querySource.ts: branded IsoDateTimeString, LogDateRange (relative/absolute), a single date-picker parser (datePickerValueToLogDateRange / logDateRangeToDatePickerValue), and resolveLogRunRange that re-resolves relative ranges against now. - Add per-snippet session logRange state (setLogRange), not persisted, keyed by snippet id. - Extract the picker's pure date helpers into Logs.datePickerHelpers.ts and share the Unit type + generateDynamicHelper with the logs domain instead of duplicating them; importers updated to the new module (no re-export shim).
Record in the studio-best-practices skill that moving/extracting code must update importers directly rather than leaving a backward-compat re-export shim.
8ee731a to
be10d93
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
apps/studio/state/sql-editor/sql-editor-rules.test.ts (1)
129-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid the assertion cast in this test assertion.
Use a structural matcher instead of
payload.content as { ... }/as any, e.g.expect(payload).toMatchObject({ content: { content_id: 'log-snippet-1' } }), to keep the test type checked.🤖 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/state/sql-editor/sql-editor-rules.test.ts` around lines 129 - 133, Update the test around buildUpsertPayload and the log_sql assertion to remove the assertion cast on payload.content. Use a structural matcher such as toMatchObject to validate content.content_id while preserving the existing payload.type expectation.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/Settings/Logs/Logs.datePickerHelpers.ts`:
- Around line 30-32: Update the custom range parsing around the parseInt call to
use Number.parseInt with base 10 and reject parsed values unless
Number.isFinite(value) is true, while preserving the existing invalid result for
non-positive values. Ensure only finite positive values reach
generateDynamicHelper().
In `@apps/studio/data/content/content-remap.ts`:
- Around line 33-42: Update remapWireSnippet to validate the external row with a
discriminated Zod schema instead of casting it to SnippetWithContent. Preserve
the wire type distinction by mapping sql content through untrustedSql and
log_sql content through untrustedLogSql, then return the parsed remapped snippet
with status; remove the existing row as SnippetWithContent assertion.
---
Nitpick comments:
In `@apps/studio/state/sql-editor/sql-editor-rules.test.ts`:
- Around line 129-133: Update the test around buildUpsertPayload and the log_sql
assertion to remove the assertion cast on payload.content. Use a structural
matcher such as toMatchObject to validate content.content_id while preserving
the existing payload.type expectation.
🪄 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: 48adf966-2c4d-4b34-8090-748280e9ce7b
📒 Files selected for processing (23)
apps/studio/CLAUDE.mdapps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.tsapps/studio/components/interfaces/SQLEditor/SQLEditor.utils.tsapps/studio/components/interfaces/SQLEditor/SQLEditorControllers.tsxapps/studio/components/interfaces/SQLEditor/querySource.test.tsapps/studio/components/interfaces/SQLEditor/querySource.tsapps/studio/components/interfaces/SQLEditor/usePrettifyQuery.tsapps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsxapps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.tsapps/studio/data/content/content-id-query.tsapps/studio/data/content/content-remap.tsapps/studio/data/content/content-upsert-mutation.tsapps/studio/data/content/sql-folders-query.tsapps/studio/data/content/sql-snippets-query.tsapps/studio/state/sql-editor/sql-editor-rules.test.tsapps/studio/state/sql-editor/sql-editor-rules.tsapps/studio/state/sql-editor/sql-editor-save-scheduler.test.tsapps/studio/state/sql-editor/sql-editor-save.test.tsapps/studio/state/sql-editor/sql-editor-session-state.tsapps/studio/state/sql-editor/sql-editor-state.test.tsapps/studio/state/sql-editor/sql-editor-state.tsapps/studio/tests/features/logs/Logs.Datepickers.test.tsxapps/studio/tests/lib/sql-editor-test-utils.tsx
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 2
🧹 Nitpick comments (1)
apps/studio/state/sql-editor/sql-editor-rules.test.ts (1)
129-133: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid the assertion cast in this test assertion.
Use a structural matcher instead of
payload.content as { ... }/as any, e.g.expect(payload).toMatchObject({ content: { content_id: 'log-snippet-1' } }), to keep the test type checked.🤖 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/state/sql-editor/sql-editor-rules.test.ts` around lines 129 - 133, Update the test around buildUpsertPayload and the log_sql assertion to remove the assertion cast on payload.content. Use a structural matcher such as toMatchObject to validate content.content_id while preserving the existing payload.type expectation.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/Settings/Logs/Logs.datePickerHelpers.ts`:
- Around line 30-32: Update the custom range parsing around the parseInt call to
use Number.parseInt with base 10 and reject parsed values unless
Number.isFinite(value) is true, while preserving the existing invalid result for
non-positive values. Ensure only finite positive values reach
generateDynamicHelper().
In `@apps/studio/data/content/content-remap.ts`:
- Around line 33-42: Update remapWireSnippet to validate the external row with a
discriminated Zod schema instead of casting it to SnippetWithContent. Preserve
the wire type distinction by mapping sql content through untrustedSql and
log_sql content through untrustedLogSql, then return the parsed remapped snippet
with status; remove the existing row as SnippetWithContent assertion.
---
Nitpick comments:
In `@apps/studio/state/sql-editor/sql-editor-rules.test.ts`:
- Around line 129-133: Update the test around buildUpsertPayload and the log_sql
assertion to remove the assertion cast on payload.content. Use a structural
matcher such as toMatchObject to validate content.content_id while preserving
the existing payload.type expectation.
🪄 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: 48adf966-2c4d-4b34-8090-748280e9ce7b
📒 Files selected for processing (23)
apps/studio/CLAUDE.mdapps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.tsapps/studio/components/interfaces/SQLEditor/SQLEditor.utils.tsapps/studio/components/interfaces/SQLEditor/SQLEditorControllers.tsxapps/studio/components/interfaces/SQLEditor/querySource.test.tsapps/studio/components/interfaces/SQLEditor/querySource.tsapps/studio/components/interfaces/SQLEditor/usePrettifyQuery.tsapps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsxapps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.tsapps/studio/data/content/content-id-query.tsapps/studio/data/content/content-remap.tsapps/studio/data/content/content-upsert-mutation.tsapps/studio/data/content/sql-folders-query.tsapps/studio/data/content/sql-snippets-query.tsapps/studio/state/sql-editor/sql-editor-rules.test.tsapps/studio/state/sql-editor/sql-editor-rules.tsapps/studio/state/sql-editor/sql-editor-save-scheduler.test.tsapps/studio/state/sql-editor/sql-editor-save.test.tsapps/studio/state/sql-editor/sql-editor-session-state.tsapps/studio/state/sql-editor/sql-editor-state.test.tsapps/studio/state/sql-editor/sql-editor-state.tsapps/studio/tests/features/logs/Logs.Datepickers.test.tsxapps/studio/tests/lib/sql-editor-test-utils.tsx
🛑 Comments failed to post (1)
apps/studio/data/content/content-remap.ts (1)
33-42: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Preserve the logs SQL brand at the wire boundary.
remapWireSnippet()routeslog_sqlrows through the existinguntrustedSqlconversion, then Line 40 coerces the result intoSnippetWithContent. A persisted logs query can therefore acquire the Postgres SQL brand and be accepted by database-only typed paths. Parse the wire row as a discriminated schema, mapsqlwithuntrustedSqlandlog_sqlwithuntrustedLogSql, and remove this assertion.As per coding guidelines, “Avoid TypeScript
ascasts; parse external data with zod usingparseorsafeParse.”🤖 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/data/content/content-remap.ts` around lines 33 - 42, Update remapWireSnippet to validate the external row with a discriminated Zod schema instead of casting it to SnippetWithContent. Preserve the wire type distinction by mapping sql content through untrustedSql and log_sql content through untrustedLogSql, then return the parsed remapped snippet with status; remove the existing row as SnippetWithContent assertion.Source: Coding guidelines
…nite Use Number.parseInt(base 10) and guard with Number.isFinite so only finite positive values reach generateDynamicHelper(); NaN and Infinity are now rejected alongside the existing non-positive check.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/querySource.ts`:
- Around line 39-46: Update isoDateTimeString to validate raw input with the
existing ISO datetime schema and strict calendar-aware parsing before returning
the branded value, rejecting overflow dates such as 2022-01-33. Derive the
IsoDateTimeString result from the validated schema output rather than casting
the original text; also update nowIsoDateTime to use the same validated branding
path instead of a direct cast.
🪄 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: 36092837-ca68-4dbd-93ce-6c3b638f87d8
📒 Files selected for processing (7)
apps/studio/CLAUDE.mdapps/studio/components/interfaces/SQLEditor/querySource.test.tsapps/studio/components/interfaces/SQLEditor/querySource.tsapps/studio/components/interfaces/Settings/Logs/Logs.DatePickers.tsxapps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.tsapps/studio/state/sql-editor/sql-editor-session-state.tsapps/studio/tests/features/logs/Logs.Datepickers.test.tsx
🚧 Files skipped from review as they are similar to previous changes (5)
- apps/studio/state/sql-editor/sql-editor-session-state.ts
- apps/studio/tests/features/logs/Logs.Datepickers.test.tsx
- apps/studio/CLAUDE.md
- apps/studio/components/interfaces/Settings/Logs/Logs.datePickerHelpers.ts
- apps/studio/components/interfaces/SQLEditor/querySource.test.ts
Braintrust eval report
|
…48414) ## 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? Feature (SQL editor: execution wiring for logs-source snippets). Part of the stacked SQL-editor "Database vs Logs" query-source series. ## What is the current behavior? The SQL editor only ever runs queries against the user's Postgres database. There is no execution path for a logs (`log_sql`) snippet, and the run-button telemetry event carries no backend discriminator. ## What is the new behavior? - `useRunSource(id)` derives the run backend from the snippet type; a `log_sql` snippet resolves to `{ type: 'logs', dateRange }`, pairing the run with its session time range (default: last hour). - `useLogsSqlExecution` runs a promoted `SafeLogSqlFragment` against the analytics OTEL (ClickHouse) endpoint with the resolved time range as `iso_timestamp_start`/`iso_timestamp_end` request params. The endpoint is **pinned to OTEL** — a snippet's dialect must not flip with org migration. - The run gestures (toolbar button and Cmd+Enter) branch on the source and promote with the matching `acceptUntrusted*` right at the user action, preserving the auditable promotion-at-gesture boundary. pg intellisense is gated off for logs snippets. - The `sql_editor_query_run_button_clicked` telemetry event gains a required `{ source: 'database' | 'logs' }` property, fired from both execution paths. - Capability guard: a `log_sql` snippet is reachable by direct URL regardless of the (later) entry-point flag gating, so `executeLogsQuery` short-circuits when `otelLegacyLogs` is off — recording a clear "not available yet" result message instead of firing a request that would only return an opaque backend error on a non-ClickHouse project. This is a guard on the gesture, not endpoint selection. - Tests: `useRunSource` routing, `useLogsSqlExecution` endpoint/range/structured-error/capability-guard, and a reusable `flags` option on `renderSqlEditorHook`. No UI entry points are added — the feature runs dark until the flag-gated creation/nav PRs later in the stack. ## Additional context Stacked on the query-source series; base branch is `master` now that PR 4 (log date range domain + session state, #48401) is merged. Follow-ups in the stack add the toolbar/creation UI (with a run-affordance gate on `otelLegacyLogs`), nav section, AI dialect support, and reports guard. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added support for running log queries directly from the SQL editor. * Log query results, errors, and time ranges are now handled within the editor session. * Added automatic selection between database and log query execution, including support for custom date ranges. * SQL assistance is disabled while editing log queries where database definitions do not apply. * **Tests** * Added coverage for log query execution, date ranges, feature availability, and execution source selection. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
I have read the CONTRIBUTING.md file.
YES
What kind of change does this PR introduce?
Feature (+ a small refactor and a docs/convention note). PR 4 of the stacked SQL-editor query-source series (Database vs Logs).
What is the current behavior?
The SQL editor has no representation of a logs query's time range:
querySource.tsonly knows how to map a snippet type to a source (getSnippetSource), and session state (sql-editor-session-state.ts) tracks results and the row limit but not a per-snippet time range. The Logs date picker's pure range helpers (parseCustomInput,generateDynamicHelper, theUnittype) are trapped inside theLogs.DatePickers.tsxReact component.What is the new behavior?
querySource.ts: brandedIsoDateTimeString+isoDateTimeString(),RelativeTimeUnit, aLogDateRangediscriminated union (relative/absolute),DEFAULT_LOG_DATE_RANGE, a single date-picker parser (datePickerValueToLogDateRange/logDateRangeToDatePickerValue— handles the five presets and dynamic2h/30mhelpers;calcTo === ''means "now"; unparseable helpers degrade to absolute), andresolveLogRunRangewhich re-resolves relative ranges againstnowat run time (reusing the existingResolvedLogDateRangeshape).logRange+setLogRange— session-only, never written to snippet content, so it works on read-only shared snippets and is cleaned up inclearForSnippet.Logs.datePickerHelpers.ts; the logs domain now shares theUnittype and reusesgenerateDynamicHelperinstead of duplicating them. Importers point at the new module directly (no re-export shim). Hardened the amount parse againstNaN.querySource.test.ts. Recorded the no-shim refactoring convention in thestudio-best-practicesskill.Verification:
pnpm typecheckclean, lint ratchet improved, 43 tests pass (querySource + Logs.Datepickers), Prettier clean.Additional context
Summary by CodeRabbit