mirror of
https://github.com/supabase/supabase.git
synced 2026-10-08 10:55:06 +03:00
* Create QueryBlock component which will be a shared component used in AI Assistant and Reports * Deprecate AIAssistantPanel/SqlSnippet.ts * Fix user messages not getting persisted, only assistant messages * Add loading state to for query results in QueryBlock + hide block view configuration if query block is not chart * Address feedback * Fix TS * fix double border --------- Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import { useState } from 'react'
|
|
|
|
import { useParams } from 'common'
|
|
import { ChartConfig } from 'components/interfaces/SQLEditor/UtilityPanel/ChartConfig'
|
|
import { useContentIdQuery } from 'data/content/content-id-query'
|
|
import { Parameter } from 'lib/sql-parameters'
|
|
import { SqlSnippets } from 'types'
|
|
import { QueryBlock } from './QueryBlock'
|
|
|
|
interface QueryBlockWrapperProps {
|
|
item: {
|
|
label: string
|
|
id?: string
|
|
sql?: string
|
|
isSnippet?: boolean
|
|
isChart?: boolean
|
|
chartConfig?: ChartConfig
|
|
results?: any
|
|
}
|
|
maxHeight?: number
|
|
lockColumns?: boolean
|
|
runQuery?: boolean
|
|
isLoading?: boolean
|
|
parameterValues?: Record<string, string>
|
|
onUpdateChartConfig: (config: ChartConfig) => void
|
|
onSetParameter?: (params: Parameter[]) => void
|
|
}
|
|
|
|
// [Joshen ReportsV2] I'm actually not sure if this wrapper but keeping for now till it becomes clearer
|
|
// when we progress on with the work for ReportsV2. Currently the only logic here is just fetching data for QueryBlock
|
|
export const QueryBlockWrapper = ({
|
|
item,
|
|
maxHeight,
|
|
lockColumns = false,
|
|
runQuery = false,
|
|
isLoading = false,
|
|
parameterValues,
|
|
onUpdateChartConfig,
|
|
onSetParameter,
|
|
}: QueryBlockWrapperProps) => {
|
|
const { ref: projectRef } = useParams()
|
|
const [sql, setSql] = useState(item.sql || '')
|
|
|
|
useContentIdQuery(
|
|
{ projectRef, id: item.id },
|
|
{
|
|
enabled: item.isSnippet && !!item.id,
|
|
onSuccess: (data) => setSql((data.content as SqlSnippets.Content).sql),
|
|
}
|
|
)
|
|
|
|
return (
|
|
<QueryBlock
|
|
id={''}
|
|
label={item.label}
|
|
sql={sql}
|
|
maxHeight={maxHeight}
|
|
chartConfig={item.chartConfig}
|
|
isChart={item.isChart}
|
|
isLoading={isLoading}
|
|
runQuery={runQuery}
|
|
lockColumns={lockColumns}
|
|
parameterValues={parameterValues}
|
|
onUpdateChartConfig={onUpdateChartConfig}
|
|
onSetParameter={onSetParameter}
|
|
/>
|
|
)
|
|
}
|