mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +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 -->
100 lines
3.8 KiB
TypeScript
100 lines
3.8 KiB
TypeScript
import { NotebookText, SquareCode } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import { cn } from 'ui'
|
|
|
|
import { isSqlStatement } from './ExplorerHomeTab.utils'
|
|
import { useCreateChat, useCreateNotebook, useCreateQuery } from './hooks'
|
|
import { NOTEBOOK_TEMPLATES } from './templates'
|
|
import { ActionCard } from '@/components/layouts/Tabs/ActionCard'
|
|
import { CHAT_TEMPLATES } from '@/components/ui/AIAssistantPanel/AIAssistant.prompts'
|
|
import { AssistantAgentHarnessFooter } from '@/components/ui/AIAssistantPanel/AssistantAgentHarnessFooter'
|
|
import { AssistantChatForm } from '@/components/ui/AIAssistantPanel/AssistantChatForm'
|
|
|
|
export const ExplorerHomeTab = () => {
|
|
const { createNotebook } = useCreateNotebook()
|
|
const { createQuery } = useCreateQuery()
|
|
const { createChat } = useCreateChat()
|
|
|
|
const [value, setValue] = useState<string>('')
|
|
|
|
return (
|
|
<div className="flex flex-col h-full">
|
|
<div
|
|
className={cn(
|
|
'flex-grow min-h-0 overflow-y-auto bg-surface-100 h-full',
|
|
'flex flex-col items-center px-10'
|
|
)}
|
|
>
|
|
<div className="w-full max-w-2xl my-auto py-10">
|
|
<div className="text-center mb-6">
|
|
<h1 className="heading-section">Run SQL. Chat with your project. Create a Notebook</h1>
|
|
</div>
|
|
|
|
<AssistantChatForm
|
|
loading={false}
|
|
className="bg"
|
|
placeholder="Explore your data, check project health, create a notebook..."
|
|
value={value}
|
|
onValueChange={(e) => setValue(e.target.value)}
|
|
onSubmit={(message) =>
|
|
isSqlStatement(message)
|
|
? createQuery({ sql: message, autoRun: true })
|
|
: createChat({ initialMessage: message })
|
|
}
|
|
/>
|
|
<AssistantAgentHarnessFooter />
|
|
|
|
<section className="mt-6">
|
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
|
<ActionCard
|
|
icon={<SquareCode className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
|
|
title="Run SQL"
|
|
description="Write and run an ad-hoc query"
|
|
bgColor="bg-blue-500"
|
|
onClick={() => createQuery()}
|
|
/>
|
|
<ActionCard
|
|
icon={<NotebookText className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
|
|
title="Create a notebook"
|
|
description="Combine notes, queries, and results"
|
|
bgColor="bg-blue-500"
|
|
onClick={() => createNotebook()}
|
|
/>
|
|
</div>
|
|
</section>
|
|
|
|
<section className="mt-8 flex flex-col gap-y-3">
|
|
<h2 className="text-sm font-medium text-foreground">Start with a template</h2>
|
|
|
|
<div className="grid grid-cols-1 gap-3 sm:grid-cols-3">
|
|
{NOTEBOOK_TEMPLATES.map((template) => (
|
|
<ActionCard
|
|
key={template.title}
|
|
icon={<NotebookText className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
|
|
title={template.title}
|
|
description={template.description}
|
|
bgColor="bg-blue-500"
|
|
onClick={() =>
|
|
createNotebook({ name: template.title, cells: template.buildCells() })
|
|
}
|
|
/>
|
|
))}
|
|
{CHAT_TEMPLATES.map((template) => (
|
|
<ActionCard
|
|
key={template.title}
|
|
icon={<template.icon className="h-4 w-4 text-foreground" strokeWidth={1.5} />}
|
|
title={template.title}
|
|
bgColor="bg-blue-500"
|
|
onClick={() =>
|
|
createChat({ name: template.title, initialMessage: template.initialMessage })
|
|
}
|
|
/>
|
|
))}
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|