mirror of
https://github.com/supabase/supabase.git
synced 2026-10-16 06:39:09 +03:00
## Context Adds the clickhouse migration banner into the QueryEditor for explorer if the source selected is logs - will apply for both the notebook query cells and query tab JFYI i've omitted out the diffing view for now, like what've currently got for the SQL Editor Got a separate ticket to look into that, but was thinking of waiting for [this PR](https://github.com/supabase/supabase/pull/49112) from Charis to go in first <img width="1391" height="369" alt="image" src="https://github.com/user-attachments/assets/5880df99-44b5-4a9f-8ff7-c9d7af3bcb93" /> <img width="1054" height="474" alt="image" src="https://github.com/user-attachments/assets/ef5d225b-3b53-4d6d-ab6c-19804e3358e6" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added guidance in SQL editors to identify and rewrite legacy logs queries. * Integrated rewrite suggestions into the query editor’s existing SQL diff workflow. * Increased the height of embedded query editors for improved usability. * Kept rewrite guidance available when no rewrite is needed or an attempt is unsuccessful. * **Bug Fixes** * Improved spacing for empty query-result messages. * **Tests** * Added coverage for rewrite visibility, acceptance, dismissal, and no-change outcomes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Ali Waseem <waseema393@gmail.com>
48 lines
2.0 KiB
TypeScript
48 lines
2.0 KiB
TypeScript
import { DiffType } from './SQLEditor.types'
|
|
import { useSqlEditorAssistant, useSqlEditorRun, useSqlEditorSnippet } from './SQLEditorControllers'
|
|
import { LegacyLogsRewriteBanner as SharedLegacyLogsRewriteBanner } from '@/components/interfaces/Settings/Logs/LegacyLogsRewriteBanner'
|
|
import {
|
|
getSqlEditorV2StateSnapshot,
|
|
useSqlEditorV2StateSnapshot,
|
|
} from '@/state/sql-editor/sql-editor-state'
|
|
|
|
/**
|
|
* Legacy Logs Explorer saved queries open in the SQL editor as `log_sql` snippets,
|
|
* and those queries error against the ClickHouse-backed endpoint the editor runs
|
|
* them on. This adapts the shared rewrite offer to the SQL editor's snippet store
|
|
* and routes an accepted rewrite into the editor's existing AI diff view, so the
|
|
* user accepts or discards it the same way as any other AI edit rather than
|
|
* having the snippet rewritten under them.
|
|
*
|
|
* Mount with `key={id}` so the offer resets when the user switches snippets. This
|
|
* component must NOT be conditionally mounted by its parent — it hides itself, so
|
|
* that opening a diff doesn't unmount it and throw away a dismissal.
|
|
*/
|
|
export const LegacyLogsRewriteBanner = () => {
|
|
const { id } = useSqlEditorSnippet()
|
|
const { runSource } = useSqlEditorRun()
|
|
const {
|
|
diff: { isDiffOpen, setSourceSqlDiff, setSelectedDiffType },
|
|
} = useSqlEditorAssistant()
|
|
|
|
const snapV2 = useSqlEditorV2StateSnapshot()
|
|
const sql = snapV2.snippets[id]?.snippet.content?.unchecked_sql ?? ''
|
|
|
|
return (
|
|
<SharedLegacyLogsRewriteBanner
|
|
isLogsSource={runSource._tag === 'logs'}
|
|
sql={sql}
|
|
// Rewrite exactly what's in the editor now, not the debounced value the
|
|
// visibility check used — they differ if the user clicked mid-edit.
|
|
readSql={() =>
|
|
getSqlEditorV2StateSnapshot().snippets[id]?.snippet.content?.unchecked_sql ?? ''
|
|
}
|
|
onProposal={({ original, modified }) => {
|
|
setSourceSqlDiff({ original, modified })
|
|
setSelectedDiffType(DiffType.Modification)
|
|
}}
|
|
hidden={isDiffOpen}
|
|
/>
|
|
)
|
|
}
|