mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
### Context As per PR title - figured this might be a nice convenience. Submitting a SQL query in the chat form on the explorer home page will open the query in a query tab and run it <img width="854" height="632" alt="image" src="https://github.com/user-attachments/assets/57dc7538-74b5-4801-a7ed-83c1cfaf123f" /> <img width="872" height="519" alt="image" src="https://github.com/user-attachments/assets/597ce0eb-76d4-4f12-83db-20b628c03904" /> ### To test - [ ] Run a couple of SQL statements in the home tab - should open it in query tab and run it - [ ] Run a couple of non-SQL statements in the home tab, should default to opening in a chat tab <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Summary by CodeRabbit - **New Features** - SQL statements submitted from the Explorer home screen now open in a query tab and run automatically. - Natural-language prompts continue to open in the chat experience. - Queries restored from drafts can automatically run once the editor is ready. - **Bug Fixes** - Improved recognition of SQL with leading whitespace, comments, and common statement formats while avoiding misclassification of conversational prompts. - Draft-based auto-run behavior now waits until the query editor is ready. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import { isSqlStatement } from './ExplorerHomeTab.utils'
|
|
|
|
describe('isSqlStatement', () => {
|
|
it.each([
|
|
'select * from profiles',
|
|
'SELECT id FROM profiles WHERE id = 1;',
|
|
"insert into logs (msg) values ('hi')",
|
|
'update profiles set name = null',
|
|
'delete from profiles where id = 1',
|
|
'with recent as (select 1) select * from recent',
|
|
' \n select 1',
|
|
'-- get everyone\nselect * from profiles',
|
|
'create table users (id serial primary key)',
|
|
'CREATE OR REPLACE FUNCTION foo() RETURNS void AS $$ BEGIN END; $$ LANGUAGE plpgsql',
|
|
'create policy my_policy on profiles for select using (true)',
|
|
'show search_path',
|
|
'SHOW ALL;',
|
|
'set search_path to public',
|
|
"SET TIME ZONE 'UTC'",
|
|
])('returns true for %s', (message) => {
|
|
expect(isSqlStatement(message)).toBe(true)
|
|
})
|
|
|
|
it.each([
|
|
'',
|
|
' ',
|
|
'How do I add a new column to my table?',
|
|
'What indexes exist on my users table?',
|
|
'Explain how RLS works',
|
|
'Can you help me select the right plan for my project?',
|
|
'Create a new table for storing user profiles',
|
|
'Show me my tables',
|
|
'Set up RLS on my users table',
|
|
'With my current schema, what tables should I add?',
|
|
])('returns false for %s', (message) => {
|
|
expect(isSqlStatement(message)).toBe(false)
|
|
})
|
|
})
|