Files
supabase/apps/studio/components/interfaces/Settings/Logs/LegacyLogsRewriteBanner.tsx
Joshen LimandAli Waseem ce2ed77c02 Add clickhouse migration banner to QueryEditor (#49184)
## 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>
2026-08-19 00:16:00 +08:00

63 lines
2.1 KiB
TypeScript

import { useDebounce } from '@uidotdev/usehooks'
import { useFlag } from 'common'
import { useMemo } from 'react'
import { LegacyLogsRewriteAdmonition } from './LegacyLogsRewriteAdmonition'
import {
LEGACY_LOGS_DIALECT_CHECK_DEBOUNCE_MS,
shouldOfferLegacyLogsRewrite,
} from '@/data/logs/logs-sql-rewrite'
import {
useLegacyLogsRewrite,
type LegacyLogsRewriteProposal,
} from '@/hooks/analytics/useLegacyLogsRewrite'
export type LegacyLogsRewriteBannerProps = {
isLogsSource: boolean
sql: string
readSql: () => string
onProposal: (proposal: LegacyLogsRewriteProposal) => void
/** An extra hide condition layered on top of the offer's own visibility, for a
* surface that has its own reason to suppress it (the SQL editor while a diff
* is open). */
hidden?: boolean
}
/**
* Offers to rewrite a logs query still written in the old BigQuery dialect
* (per-service `FROM` tables, `unnest(metadata)` joins) to ClickHouse SQL.
* Shared by every surface that can run a logs query and wants to offer this —
* each one decides how to source `sql`/`readSql` and what an accepted
* `onProposal` does with the result (the SQL editor opens a diff, Explorer's
* query editor swaps the buffer directly).
*/
export const LegacyLogsRewriteBanner = ({
isLogsSource,
sql,
readSql,
onProposal,
hidden,
}: LegacyLogsRewriteBannerProps) => {
const isOtelLogsEnabled = useFlag('otelLegacyLogs')
const settledSql = useDebounce(sql, LEGACY_LOGS_DIALECT_CHECK_DEBOUNCE_MS)
const needsRewrite = useMemo(
() =>
isLogsSource &&
shouldOfferLegacyLogsRewrite({ sql: settledSql, isClickhouseLogsEnabled: isOtelLogsEnabled }),
[isLogsSource, settledSql, isOtelLogsEnabled]
)
const { state, requestRewrite, dismiss } = useLegacyLogsRewrite({ readSql, onProposal })
const hasUnacknowledgedOutcome = state.status === 'failed' || state.status === 'noRewriteNeeded'
const isEligibleSurface = isLogsSource && isOtelLogsEnabled
if (hidden || !isEligibleSurface || !(needsRewrite || hasUnacknowledgedOutcome)) return null
return (
<LegacyLogsRewriteAdmonition state={state} onRewrite={requestRewrite} onDismiss={dismiss} />
)
}