Files
supabase/apps/studio/components/ui/QueryBlock/BlockViewConfiguration.tsx
Joshen Lim 2c53ca4a79 Support listing and reading custom reports from Assistant (#48530)
## Context

This is pre-requisite work for adding support to managing custom reports
from the Assistant. Planning to break this into a number of PRs, briefly
- Adding read support for custom reports
- Adding write support for custom reports
- Adding run support for custom reports
  - Should be able to infer data from the results then

This PR starts with adding support for listing and reading custom
reports from the Assistant

## Other changes involved
- Updates setting up of the home page report to have better title and
description
- Swaps the variant of the ToggleGroup in the SQL block for custom
reports as the default variant blends into the background color of the
PopoverContent

## To test
- [ ] Assistant should be able to list custom reports + read its
contents
<img width="428" height="755" alt="image"
src="https://github.com/user-attachments/assets/6a15b660-c0ee-4a06-984c-87eff3943eec"
/>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Added AI-assisted tools to list reports and retrieve report details,
including chart counts, layouts, configurations, and SQL-backed chart
information.
  - Added clearer empty-state messaging when no snippets are available.

- **Improvements**
- New homepage reports now use the name “Homepage Report” and include a
descriptive project-home summary.
  - Updated query controls with refreshed visual styling.
  - Improved content requests to support additional request context.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-08-03 13:59:50 +07:00

146 lines
4.5 KiB
TypeScript

import { BarChart2, Settings2, Table } from 'lucide-react'
import {
Checkbox,
Label,
Popover,
PopoverContent,
PopoverTrigger,
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectTrigger,
ToggleGroup,
ToggleGroupItem,
} from 'ui'
import { ButtonTooltip } from '../ButtonTooltip'
import { ChartConfig } from '@/components/interfaces/SQLEditor/UtilityPanel/ChartConfig'
interface BlockViewConfigurationProps {
columns: string[]
view: 'chart' | 'table'
isChart: boolean
lockColumns?: boolean
chartConfig?: ChartConfig
changeView: (value: 'chart' | 'table') => void
updateChartConfig: (config: ChartConfig) => void
}
export const BlockViewConfiguration = ({
columns,
view,
isChart,
lockColumns = false,
chartConfig,
changeView,
updateChartConfig,
}: BlockViewConfigurationProps) => {
return (
<Popover modal={false}>
<PopoverTrigger asChild>
<ButtonTooltip
id="help-popover-button"
variant="text"
className="px-1"
icon={<Settings2 size={14} strokeWidth={1.5} />}
tooltip={{ content: { side: 'bottom', text: 'View data' } }}
/>
</PopoverTrigger>
<PopoverContent side="bottom" align="center" className="w-[240px] p-3">
<form className="grid gap-2">
<ToggleGroup
type="single"
variant="outline"
value={view}
className="w-full"
onValueChange={(view: 'chart' | 'table') => {
if (view) changeView(view)
}}
>
<ToggleGroupItem className="w-full" value="table" aria-label="Show as table">
<Table className="h-4 w-4" />
<p className="text-xs ml-2">As table</p>
</ToggleGroupItem>
<ToggleGroupItem className="w-full" value="chart" aria-label="Show as chart">
<BarChart2 className="h-4 w-4" />
<p className="text-xs ml-2">As chart</p>
</ToggleGroupItem>
</ToggleGroup>
{isChart && chartConfig && (
<>
<Select
disabled={lockColumns}
value={chartConfig?.xKey}
onValueChange={(value) => updateChartConfig({ ...chartConfig, xKey: value })}
>
<SelectTrigger className="text-left">
X Axis {chartConfig?.xKey && `- ${chartConfig.xKey}`}
</SelectTrigger>
<SelectContent>
<SelectGroup>
{columns.map((key) => (
<SelectItem value={key} key={key}>
{key}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
<Select
disabled={lockColumns}
value={chartConfig?.yKey}
onValueChange={(value) => updateChartConfig({ ...chartConfig, yKey: value })}
>
<SelectTrigger className="text-left">
Y Axis {chartConfig?.yKey && `- ${chartConfig.yKey}`}
</SelectTrigger>
<SelectContent>
<SelectGroup>
{columns.map((key) => (
<SelectItem value={key} key={key}>
{key}
</SelectItem>
))}
</SelectGroup>
</SelectContent>
</Select>
<div className="*:flex *:gap-2 *:items-center grid gap-2 *:text-foreground-light *:p-1.5 *:pl-0">
<Label htmlFor="cumulative">
<Checkbox
id="cumulative"
checked={chartConfig?.cumulative}
onClick={() =>
updateChartConfig({
...chartConfig,
cumulative: !chartConfig?.cumulative,
})
}
/>
Cumulative
</Label>
<Label htmlFor="logScale">
<Checkbox
id="logScale"
checked={chartConfig?.logScale}
onClick={() =>
updateChartConfig({
...chartConfig,
logScale: !chartConfig?.logScale,
})
}
/>
Log scale
</Label>
</div>
</>
)}
</form>
</PopoverContent>
</Popover>
)
}