mirror of
https://github.com/supabase/supabase.git
synced 2026-09-06 09:59:03 +08:00
## Summary - define application-owned database and logs source contracts, defaults, validation, labels, and execution endpoints - extract controlled database and logs parameter controls for reuse outside SQL snippets - adapt the SQL editor to the shared source model without changing snippet behavior - standardize source icons at 16px with a 2px stroke - keep relative logs ranges aligned with the existing date picker units ## To test 1. Open an existing query in the SQL Editor and run it against the database. 2. Switch the query source to Logs, change the time range, and confirm the query still runs as expected. ## Why Explorer queries and notebook query cells need to select an execution source without coupling that source to SQL snippets. This provides the shared registry and controlled UI foundation for those consumers. ## Impact Existing SQL snippets retain their current database/logs routing and session behavior. The registry documents the SQL editor legacy database-selector adapter while new consumers own their identifier inline. The shared Logs date picker remains unchanged; query ranges support its existing minute, hour, and day units. This PR does not add the Explorer query tab itself. ## Validation - pnpm --filter studio typecheck - focused Vitest coverage for the registry, canonical log-range utilities, SQL execution adapters, source filtering, retention locking, custom ranges, and preset selection - pnpm --filter studio run lint:ratchet Component and state tests cover this change per the Studio testing guidance; no E2E test is added. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added a unified query-source menu for database queries and logs. * Added custom log time-range selection with calendar support and retention-aware upgrade prompts. * Added consistent source icons and improved database selection handling. * Added support for relative and absolute log time ranges. * **Bug Fixes** * Improved log-range validation, defaults, and current-time handling. * Updated query execution to use the correct source-specific endpoints. * **Tests** * Expanded coverage for query sources, log ranges, menus, and retention behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
62 lines
2.0 KiB
TypeScript
62 lines
2.0 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
getSnippetSource,
|
|
isLogsSource,
|
|
resolveSnippetSource,
|
|
sqlSourceToFenceLanguage,
|
|
} from './querySource'
|
|
|
|
describe('querySource.ts:getSnippetSource', () => {
|
|
it('maps log_sql to the logs source', () => {
|
|
expect(getSnippetSource({ type: 'log_sql' })).toBe('logs')
|
|
})
|
|
|
|
it('maps sql to the database source', () => {
|
|
expect(getSnippetSource({ type: 'sql' })).toBe('database')
|
|
})
|
|
|
|
it('maps report to the database source', () => {
|
|
expect(getSnippetSource({ type: 'report' })).toBe('database')
|
|
})
|
|
})
|
|
|
|
describe('querySource.ts:isLogsSource', () => {
|
|
it('is true only for the logs source', () => {
|
|
expect(isLogsSource('logs')).toBe(true)
|
|
expect(isLogsSource('database')).toBe(false)
|
|
})
|
|
|
|
it('is false for an absent source', () => {
|
|
expect(isLogsSource(undefined)).toBe(false)
|
|
})
|
|
})
|
|
|
|
describe('querySource.ts:sqlSourceToFenceLanguage', () => {
|
|
it('labels a logs query as clickhouse and everything else as sql', () => {
|
|
expect(sqlSourceToFenceLanguage('logs')).toBe('clickhouse')
|
|
expect(sqlSourceToFenceLanguage('database')).toBe('sql')
|
|
})
|
|
|
|
// Attachments can carry no source; those are Postgres SQL.
|
|
it('treats an absent source as sql', () => {
|
|
expect(sqlSourceToFenceLanguage(undefined)).toBe('sql')
|
|
})
|
|
})
|
|
|
|
describe('querySource.ts:resolveSnippetSource', () => {
|
|
it('prefers the snippet type over the URL param', () => {
|
|
expect(resolveSnippetSource({ type: 'log_sql' }, undefined)).toBe('logs')
|
|
// A stale/mismatched param must not override a snippet that already exists.
|
|
expect(resolveSnippetSource({ type: 'sql' }, 'logs')).toBe('database')
|
|
})
|
|
|
|
// A fresh `/sql/new` tab has no snippet until the first keystroke, so the param is
|
|
// the only signal that it is a logs tab.
|
|
it('falls back to the URL param before the snippet exists', () => {
|
|
expect(resolveSnippetSource(undefined, 'logs')).toBe('logs')
|
|
expect(resolveSnippetSource(undefined, undefined)).toBe('database')
|
|
expect(resolveSnippetSource(undefined, 'nonsense')).toBe('database')
|
|
})
|
|
})
|