mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
## Context As per PR title - just adjusts the vertical height for a couple of empty states in QueryCells for Notebooks ### Query not run yet | Before | After | | -------- | -------- | | <img width="1072" height="350" alt="image" src="https://github.com/user-attachments/assets/cbf14619-ac01-4082-9732-41737a028c40" /> | <img width="1083" height="313" alt="image" src="https://github.com/user-attachments/assets/1144eebf-7293-4be4-adaf-af2dc21bc40f" /> | | <img width="1083" height="292" alt="image" src="https://github.com/user-attachments/assets/511754f8-5128-41b7-a4c8-542fb93b77e5" /> | <img width="1100" height="163" alt="image" src="https://github.com/user-attachments/assets/53de5b4a-8284-406a-a8ae-4602f61f3ca3" /> | ### Chart empty state | Before | After | | -------- | -------- | | <img width="1079" height="291" alt="image" src="https://github.com/user-attachments/assets/068fe573-1f65-4efc-831c-db2ddda2be1a" /> | <img width="1078" height="225" alt="image" src="https://github.com/user-attachments/assets/b9d58d8f-162d-463d-90e2-fbf3470c6db8" /> | <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Style** - Improved query editor layout by reducing unnecessary spacing and ensuring result areas fit more consistently within available space. - Refined chart empty states with cleaner borders, compact spacing, and improved vertical sizing. - Updated query error presentation with more compact padding. - Simplified result panel sizing for a more consistent viewing experience. - **User Experience** - Added a play icon alongside the “Run the query to see results” prompt when no results are available. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
137 lines
4.1 KiB
TypeScript
137 lines
4.1 KiB
TypeScript
import { useMemo } from 'react'
|
|
import { cn, type ChartConfig as ChartSeriesConfig } from 'ui'
|
|
import { Chart, ChartBar, ChartCard, ChartContent, ChartLine } from 'ui-patterns/Chart'
|
|
|
|
import { type QueryResult } from '../types'
|
|
import NoDataPlaceholder from '@/components/ui/Charts/NoDataPlaceholder'
|
|
import {
|
|
computeYAxisWidth,
|
|
formatLogTick,
|
|
formatYAxisTick,
|
|
getCumulativeResults,
|
|
} from '@/components/ui/QueryBlock/QueryBlock.utils'
|
|
import { type ChartConfig } from '@/data/content/notebooks/notebook-schema'
|
|
|
|
interface QueryResultChartProps {
|
|
chart?: ChartConfig
|
|
result?: QueryResult
|
|
}
|
|
|
|
const Y_SERIES_COLORS = [
|
|
'hsl(var(--brand-default))',
|
|
'hsl(var(--chart-blue))',
|
|
'hsl(var(--chart-3))',
|
|
]
|
|
|
|
const toChartValue = (value: unknown): string | number => {
|
|
if (typeof value === 'number' || typeof value === 'string') return value
|
|
if (value === null || value === undefined) return ''
|
|
return String(value)
|
|
}
|
|
|
|
export const QueryResultChart = ({ chart, result }: QueryResultChartProps) => {
|
|
const { type, x_column, y_series = [], cumulative, show_labels, scale } = chart ?? {}
|
|
|
|
const hasConfig = !!x_column && y_series.length > 0
|
|
// Logarithmic scale only makes sense for a single series — DisplaySettingsButton
|
|
// resets `scale` to linear once a second Y column is added
|
|
const effectiveScale = y_series.length > 1 ? 'linear' : scale
|
|
|
|
const chartConfig: ChartSeriesConfig = useMemo(
|
|
() =>
|
|
y_series.reduce((acc, key, index) => {
|
|
acc[key] = { label: key, color: Y_SERIES_COLORS[index] }
|
|
return acc
|
|
}, {} as ChartSeriesConfig),
|
|
[y_series]
|
|
)
|
|
|
|
const chartRows = useMemo(() => {
|
|
const xKey = x_column ?? ''
|
|
return (result?.rows ?? []).map((row) => {
|
|
const chartRow: Record<string, string | number> = { [xKey]: toChartValue(row[xKey]) }
|
|
y_series.forEach((yKey) => {
|
|
chartRow[yKey] = toChartValue(row[yKey])
|
|
})
|
|
return chartRow
|
|
})
|
|
}, [result, x_column, y_series])
|
|
|
|
const cumulativeResults = useMemo(
|
|
() => getCumulativeResults({ rows: chartRows }, { yKey: y_series }),
|
|
[chartRows, y_series]
|
|
)
|
|
const resultToRender = cumulative ? cumulativeResults : chartRows
|
|
|
|
const yAxisWidth = Math.max(
|
|
36,
|
|
...y_series.map((key) =>
|
|
computeYAxisWidth(resultToRender, key, { isLogScale: effectiveScale === 'log' })
|
|
)
|
|
)
|
|
|
|
const yAxisProps = {
|
|
...(show_labels ? { width: yAxisWidth } : {}),
|
|
scale: effectiveScale === 'log' ? 'log' : 'auto',
|
|
domain: effectiveScale === 'log' ? ([1, 'auto'] as const) : undefined,
|
|
tickFormatter: effectiveScale === 'log' ? formatLogTick : formatYAxisTick,
|
|
}
|
|
|
|
if (!result || (result?.rows && result.rows.length === 0)) {
|
|
return (
|
|
<NoDataPlaceholder
|
|
className="border-0 min-h-0! py-8"
|
|
size="normal"
|
|
message="No results"
|
|
description="Your query returned no rows"
|
|
/>
|
|
)
|
|
}
|
|
|
|
if (!hasConfig) {
|
|
return (
|
|
<NoDataPlaceholder
|
|
className="border-0 min-h-0! py-8"
|
|
size="normal"
|
|
message="Configure your chart"
|
|
description="Select your X and Y axis in the display settings"
|
|
/>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Chart className="flex flex-grow min-h-0">
|
|
<ChartCard className="flex flex-grow rounded-none border-0 min-h-0">
|
|
<ChartContent className={cn('min-h-0 h-full w-full', show_labels && 'pl-2 pb-2')}>
|
|
{type === 'bar' && (
|
|
<ChartBar
|
|
isFullHeight
|
|
xKey={x_column}
|
|
dataKey={y_series[0]}
|
|
dataKeys={y_series}
|
|
config={chartConfig}
|
|
showXAxis={show_labels}
|
|
showYAxis={show_labels}
|
|
data={resultToRender}
|
|
YAxisProps={yAxisProps}
|
|
/>
|
|
)}
|
|
{type === 'line' && (
|
|
<ChartLine
|
|
isFullHeight
|
|
xKey={x_column}
|
|
dataKey={y_series[0]}
|
|
dataKeys={y_series}
|
|
config={chartConfig}
|
|
showXAxis={show_labels}
|
|
showYAxis={show_labels}
|
|
data={resultToRender}
|
|
YAxisProps={yAxisProps}
|
|
/>
|
|
)}
|
|
</ChartContent>
|
|
</ChartCard>
|
|
</Chart>
|
|
)
|
|
}
|