mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## Summary
* Resolved hanging buttons in Explorer's QueryResultError panel that
were wired to stub no-ops (`buildPrompt={() => ''}`,
`onOpenAssistant={() => {}}`).
* "Debug with Assistant" now opens a new chat seeded with a real prompt
combining the SQL query and error context using existing
`buildDebugPromptText` util and `useCreateChat` hook.
* "Copy prompt" now copies the same real debug prompt text to clipboard.
* Threaded `sql` and query `source` props down through `QueryEditor` →
`QueryResultRenderer` → `QueryResultError` while keeping them optional
for backward compatibility with other callers like
`AssistantNotebookPreviewCell`.
## Test plan
- [X] Run `pnpm typecheck` — passes
- [X] Run `pnpm lint --filter=studio` — passes
- [X] Run `pnpm test:studio --run
apps/studio/components/interfaces/Explorer/QueryEditor` — Explorer
vitest suite (99 tests across 13 files) passes with no regressions
- [X] Manually verify in Explorer: trigger an ad-hoc SQL query that
fails, confirm "Debug with Assistant" opens a new chat with the error
prompt seeded, and "Copy prompt" copies the prompt to clipboard
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **New Features**
- Added “Debug with Assistant” to query errors using the submitted SQL
and error details.
- Added an option to copy the debugging prompt for easier
troubleshooting.
- Assistant actions are hidden when query details are unavailable or
restricted.
- **Bug Fixes**
- Ensured query errors reference the SQL that produced them, rather than
later editor changes.
- **Tests**
- Added coverage for assistant debugging, prompt copying, conditional
visibility, and self-hosted behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { type SqlSnippetSource } from '../../SQLEditor/querySource'
|
|
import { type QueryResult } from '../types'
|
|
import { QueryResultChart } from './QueryResultChart'
|
|
import { QueryResultError } from './QueryResultError'
|
|
import { DataGridResults } from '@/components/ui/DataGridResults'
|
|
import { type ChartConfig } from '@/data/content/notebooks/notebook-schema'
|
|
|
|
interface QueryResultRendererProps {
|
|
result?: QueryResult
|
|
view?: 'table' | 'chart'
|
|
chart?: ChartConfig
|
|
/** The query that produced `result`, used to build the "Debug with Assistant" prompt on error. */
|
|
sql?: string
|
|
source?: SqlSnippetSource
|
|
}
|
|
|
|
export const QueryResultRenderer = ({
|
|
result,
|
|
view,
|
|
chart,
|
|
sql,
|
|
source,
|
|
}: QueryResultRendererProps) => {
|
|
const { rows, error, autoLimit } = result ?? {}
|
|
|
|
if (!result) {
|
|
return <p className="text-xs text-foreground-lighter py-8">Run the query to see results</p>
|
|
}
|
|
|
|
if (error) {
|
|
return <QueryResultError error={error} autoLimit={autoLimit} sql={sql} source={source} />
|
|
}
|
|
|
|
if ((rows ?? []).length === 0) {
|
|
return <p className="text-xs text-foreground-lighter py-8">Success. No rows returned</p>
|
|
}
|
|
|
|
if (rows && rows.length > 0) {
|
|
if (view === 'table') return <DataGridResults rows={rows} />
|
|
if (view === 'chart') return <QueryResultChart chart={chart} result={result} />
|
|
}
|
|
|
|
return null
|
|
}
|