Use cases
Reporting
Minimal report builder powered by useReport.
The stack you choose picks the code on this page. Options marked coming soon can't be chosen yet.
Copies the Quill CLI's install command: curl -fsSL https://quill.co/install.sh | shView as MarkdownThe whole page, with the code for the chosen stack.
import { useState } from 'react';
import { Chart, useReport, type SetReportBuilderInput } from '@quillsql/react';
import { Table2 } from 'lucide-react';
import { MetricTable, type MetricRowsPage } from '../components/blocks/metric-explorer/metric-explorer';
import { Button } from '../components/button/button';
import { EmptyState } from '../components/empty-state/empty-state';
import { MultiSelect, Select } from '../components/filter-builder/filter-builder';
import { InlineEdit } from '../components/inline-edit/inline-edit';
import SegmentedControl from '../components/segmented-control/segmented-control';
import { FilterSentence } from './FilterSentence';
import styles from './ReportBuilder.module.css';
import { ReportChat } from './ReportChat';
import chatStyles from './ReportChat.module.css';
const DEFAULT_REPORT_ID = '6af3445c802380dce4bba1ba';
const ROWS_PER_PAGE = 10;
/**
* A report builder powered by one `useReport`: every control binds a field and its `*Options` list
* directly to `setReport` and `setFilters`.
*/
export function ReportBuilder({ endpoint }: { endpoint: string }) {
// The report the chat last built, else the default one.
const [openReportId, setOpenReportId] = useState(DEFAULT_REPORT_ID);
const report = useReport(openReportId, { destinationDashboardName: 'Metric explorer', showTableNames: false });
const { reportId, chart, loading, chartLoading, table, tableLoading, setReport, setFilters } = report;
const [view, setView] = useState<'chart' | 'table'>('chart');
const busy = chartLoading || !reportId;
const isTable = report.chartType === 'table';
const page: MetricRowsPage = {
columns: table.columns,
rows: table.rows,
page: table.pagination.pageIndex + 1, pageCount: Math.max(0, table.getPageCount()), rowCount: table.getRowCount(),
loading: loading || tableLoading, onPageChange: (next) => table.setPageIndex(next - 1),
};
return (
<div className={chatStyles.layout}>
<section className={styles.root} aria-label="Report builder">
<header className={styles.head}>
<InlineEdit as="h2" className={styles.name} label="Report name" placeholder="Untitled report" value={report.name} onSave={(name) => setReport({ name })} />
<Button size="sm" disabled={busy || loading}>Add to dashboard</Button>
</header>
<div className={styles.controls}>
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Datasources" placeholder="Select tables"
value={report.datasources} options={report.datasourceOptions} disabled={!report.datasourceOptions.length} onChange={(datasources) => setReport({ datasources })} />
<Select className={styles.group} label="Group rows by" value={report.groupRowsBy} options={[{ value: '', label: 'None' }, ...report.groupRowsByOptions]}
disabled={busy} onChange={(groupRowsBy) => setReport({ groupRowsBy })} />
<Select className={styles.group} label="Group columns by" value={report.groupColumnsBy} options={[{ value: '', label: 'None' }, ...report.groupColumnsByOptions]}
disabled={busy || !report.groupRowsBy} onChange={(groupColumnsBy) => setReport({ groupColumnsBy, showLegend: !!groupColumnsBy })} />
<Select className={styles.group} label="Sort by" value={report.sort} options={[{ value: '', label: 'None' }, ...report.sortOptions]}
disabled={busy} onChange={(sort) => setReport({ sort })} />
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Aggregations" placeholder="Select measures"
value={report.aggregations} options={report.aggregationOptions} disabled={busy} onChange={(aggregations) => setReport({ aggregations })} />
</div>
{reportId ? (
<>
<FilterSentence filters={report.filters} queryBuilderProps={report.filterQueryBuilderProps} onChange={setFilters} />
<div className={styles.controls}>
<SegmentedControl className={styles.viewSwitch} label="View" value={view} onValueChange={(v) => setView(v as 'chart' | 'table')}
options={[{ value: 'chart', label: 'Chart' }, { value: 'table', label: 'Table' }]} />
{view === 'chart' ? (
<>
<Select className={styles.group} label="Chart type" value={report.chartType} disabled={busy}
options={report.chartTypeOptions.map((o) => ({ ...o, label: o.label[0].toUpperCase() + o.label.slice(1) }))}
onChange={(v) => setReport({ chartType: v as SetReportBuilderInput['chartType'] })} />
<Select className={styles.group} label="Chart sort" value={report.chartSort} options={[{ value: '', label: 'No sorting' }, ...report.chartSortOptions]}
disabled={busy || isTable} onChange={(chartSort) => setReport({ chartSort })} />
{report.dateBucketOptions.length > 0 && (
<Select className={styles.group} label="Date bucket" value={report.dateBucket} options={report.dateBucketOptions} disabled={busy}
onChange={(v) => setReport({ dateBucket: v as SetReportBuilderInput['dateBucket'] })} />
)}
{!isTable && (
<>
<Select className={styles.group} label="X-axis" value={report.xAxis.field} options={report.xAxisOptions} disabled={busy}
onChange={(field) => setReport({ xAxis: { field } })} />
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Y-axis" placeholder="Select fields"
value={report.yAxis.fields.map((f) => f.field)} options={report.yAxisOptions} disabled={busy}
onChange={(next) => next.length && setReport({ yAxis: { fields: [...report.yAxis.fields.filter((f) => next.includes(f.field)), ...next.filter((field) => !report.yAxis.fields.some((f) => f.field === field)).map((field) => ({ field }))] } })} />
</>
)}
</>
) : (
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Columns" placeholder="Select columns"
value={report.columns.map((c) => c.value)} options={report.columnOptions}
disabled={busy || report.columnStructureEditsLocked} onChange={(next) => report.columnActions.replace(next.map((field) => ({ field })))} />
)}
</div>
{view === 'table' ? (
<MetricTable table={page} rowsPerPage={ROWS_PER_PAGE} caption={report.name || 'Report rows'} />
) : (
<Chart chart={chart} chartLoading={loading || busy}
containerStyle={{ width: '100%', height: isTable ? undefined : 260 }} />
)}
</>
) : (
<EmptyState icon={<Table2 size={24} strokeWidth={1.75} />} title="No datasource yet" description="Pick one or more tables in Datasources to start a report." />
)}
</section>
<ReportChat endpoint={endpoint} state={report.reportBuilderState} onReport={setOpenReportId} />
</div>
);
}import { Quill } from '@quillsql/node';
const quill = new Quill({
privateKey: process.env.QUILL_PRIVATE_KEY,
databaseType: 'postgresql',
databaseConnectionString: process.env.DATABASE_URL,
});
// "authenticate" is your existing auth middleware.
app.post('/quill', authenticate, async (req, res) => {
const result = await quill.query({
tenants: [{ tenantField: 'organization_id', tenantIds: [req.user.organizationId] }],
metadata: req.body.metadata,
});
res.send(result);
});Advanced filters
import { useState } from 'react';
import { Chart, useReport, useReportQueryBuilder, type SetReportBuilderInput } from '@quillsql/react';
import { Table2 } from 'lucide-react';
import { MetricTable, type MetricRowsPage } from '../components/blocks/metric-explorer/metric-explorer';
import { Button } from '../components/button/button';
import { EmptyState } from '../components/empty-state/empty-state';
import { MultiSelect, Select, FilterBuilder } from '../components/filter-builder/filter-builder';
import { InlineEdit } from '../components/inline-edit/inline-edit';
import SegmentedControl from '../components/segmented-control/segmented-control';
import styles from './ReportBuilder.module.css';
import { ReportChat } from './ReportChat';
import chatStyles from './ReportChat.module.css';
const DEFAULT_REPORT_ID = '6af3445c802380dce4bba1ba';
const ROWS_PER_PAGE = 10;
/**
* The report builder with Quill's filter editor in place of the sentence: `useReportQueryBuilder` drafts the
* filters, and Apply hands them to `setFilters`.
*/
export function ReportBuilderAdvanced({ endpoint }: { endpoint: string }) {
// The report the chat last built, else the default one.
const [openReportId, setOpenReportId] = useState(DEFAULT_REPORT_ID);
const report = useReport(openReportId, { destinationDashboardName: 'Metric explorer', showTableNames: false });
const { reportId, chart, loading, chartLoading, table, tableLoading, setReport, setFilters } = report;
const queryBuilder = useReportQueryBuilder({ reportId, filters: report.filters, queryBuilderProps: report.filterQueryBuilderProps, onApply: setFilters });
const [view, setView] = useState<'chart' | 'table'>('chart');
const busy = chartLoading || !reportId;
const isTable = report.chartType === 'table';
const page: MetricRowsPage = {
columns: table.columns,
rows: table.rows,
page: table.pagination.pageIndex + 1, pageCount: Math.max(0, table.getPageCount()), rowCount: table.getRowCount(),
loading: loading || tableLoading, onPageChange: (next) => table.setPageIndex(next - 1),
};
return (
<div className={chatStyles.layout}>
<section className={styles.root} aria-label="Report builder">
<header className={styles.head}>
<InlineEdit as="h2" className={styles.name} label="Report name" placeholder="Untitled report" value={report.name} onSave={(name) => setReport({ name })} />
<Button size="sm" disabled={busy || loading}>Add to dashboard</Button>
</header>
<div className={styles.controls}>
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Datasources" placeholder="Select tables"
value={report.datasources} options={report.datasourceOptions} disabled={!report.datasourceOptions.length} onChange={(datasources) => setReport({ datasources })} />
<Select className={styles.group} label="Group rows by" value={report.groupRowsBy} options={[{ value: '', label: 'None' }, ...report.groupRowsByOptions]}
disabled={busy} onChange={(groupRowsBy) => setReport({ groupRowsBy })} />
<Select className={styles.group} label="Group columns by" value={report.groupColumnsBy} options={[{ value: '', label: 'None' }, ...report.groupColumnsByOptions]}
disabled={busy || !report.groupRowsBy} onChange={(groupColumnsBy) => setReport({ groupColumnsBy, showLegend: !!groupColumnsBy })} />
<Select className={styles.group} label="Sort by" value={report.sort} options={[{ value: '', label: 'None' }, ...report.sortOptions]}
disabled={busy} onChange={(sort) => setReport({ sort })} />
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Aggregations" placeholder="Select measures"
value={report.aggregations} options={report.aggregationOptions} disabled={busy} onChange={(aggregations) => setReport({ aggregations })} />
</div>
{reportId ? (
<>
<FilterBuilder label={null} layout="editor" disabled={busy} queryBuilder={queryBuilder}
filterUniqueValuesLoading={report.filterUniqueValuesLoading} onFiltersChange={setFilters} />
<div className={styles.controls}>
<SegmentedControl className={styles.viewSwitch} label="View" value={view} onValueChange={(v) => setView(v as 'chart' | 'table')}
options={[{ value: 'chart', label: 'Chart' }, { value: 'table', label: 'Table' }]} />
{view === 'chart' ? (
<>
<Select className={styles.group} label="Chart type" value={report.chartType} disabled={busy}
options={report.chartTypeOptions.map((o) => ({ ...o, label: o.label[0].toUpperCase() + o.label.slice(1) }))}
onChange={(v) => setReport({ chartType: v as SetReportBuilderInput['chartType'] })} />
<Select className={styles.group} label="Chart sort" value={report.chartSort} options={[{ value: '', label: 'No sorting' }, ...report.chartSortOptions]}
disabled={busy || isTable} onChange={(chartSort) => setReport({ chartSort })} />
{report.dateBucketOptions.length > 0 && (
<Select className={styles.group} label="Date bucket" value={report.dateBucket} options={report.dateBucketOptions} disabled={busy}
onChange={(v) => setReport({ dateBucket: v as SetReportBuilderInput['dateBucket'] })} />
)}
{!isTable && (
<>
<Select className={styles.group} label="X-axis" value={report.xAxis.field} options={report.xAxisOptions} disabled={busy}
onChange={(field) => setReport({ xAxis: { field } })} />
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Y-axis" placeholder="Select fields"
value={report.yAxis.fields.map((f) => f.field)} options={report.yAxisOptions} disabled={busy}
onChange={(next) => next.length && setReport({ yAxis: { fields: [...report.yAxis.fields.filter((f) => next.includes(f.field)), ...next.filter((field) => !report.yAxis.fields.some((f) => f.field === field)).map((field) => ({ field }))] } })} />
</>
)}
</>
) : (
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Columns" placeholder="Select columns"
value={report.columns.map((c) => c.value)} options={report.columnOptions}
disabled={busy || report.columnStructureEditsLocked} onChange={(next) => report.columnActions.replace(next.map((field) => ({ field })))} />
)}
</div>
{view === 'table' ? (
<MetricTable table={page} rowsPerPage={ROWS_PER_PAGE} caption={report.name || 'Report rows'} />
) : (
<Chart chart={chart} chartLoading={loading || busy}
containerStyle={{ width: '100%', height: isTable ? undefined : 260 }} />
)}
</>
) : (
<EmptyState icon={<Table2 size={24} strokeWidth={1.75} />} title="No datasource yet" description="Pick one or more tables in Datasources to start a report." />
)}
</section>
<ReportChat endpoint={endpoint} state={report.reportBuilderState} onReport={setOpenReportId} />
</div>
);
}import { Quill } from '@quillsql/node';
const quill = new Quill({
privateKey: process.env.QUILL_PRIVATE_KEY,
databaseType: 'postgresql',
databaseConnectionString: process.env.DATABASE_URL,
});
// "authenticate" is your existing auth middleware.
app.post('/quill', authenticate, async (req, res) => {
const result = await quill.query({
tenants: [{ tenantField: 'organization_id', tenantIds: [req.user.organizationId] }],
metadata: req.body.metadata,
});
res.send(result);
});Sidebar
import { useState } from 'react';
import { Chart, useReport, type SetReportBuilderInput } from '@quillsql/react';
import { Table2 } from 'lucide-react';
import { MetricTable, type MetricRowsPage } from '../components/blocks/metric-explorer/metric-explorer';
import { Button } from '../components/button/button';
import { EmptyState } from '../components/empty-state/empty-state';
import { MultiSelect, Select } from '../components/filter-builder/filter-builder';
import { InlineEdit } from '../components/inline-edit/inline-edit';
import { FilterSentence } from './FilterSentence';
import styles from './ReportBuilder.module.css';
import { ReportChat } from './ReportChat';
import chatStyles from './ReportChat.module.css';
const DEFAULT_REPORT_ID = '6af3445c802380dce4bba1ba';
const ROWS_PER_PAGE = 6;
/**
* The report builder with its controls in a column beside the chart: the filters read above the chart and the rows
* show under it, so there is no Chart / Table switch.
*/
export function ReportBuilderSidebar({ endpoint }: { endpoint: string }) {
// The report the chat last built, else the default one.
const [openReportId, setOpenReportId] = useState(DEFAULT_REPORT_ID);
const report = useReport(openReportId, {
destinationDashboardName: 'Metric explorer',
showTableNames: false,
initialPagination: { pageIndex: 0, pageSize: ROWS_PER_PAGE },
});
const { reportId, chart, loading, chartLoading, table, tableLoading, setReport, setFilters } = report;
const busy = chartLoading || !reportId;
const isTable = report.chartType === 'table';
const page: MetricRowsPage = {
columns: table.columns,
rows: table.rows,
page: table.pagination.pageIndex + 1, pageCount: Math.max(0, table.getPageCount()), rowCount: table.getRowCount(),
loading: loading || tableLoading, onPageChange: (next) => table.setPageIndex(next - 1),
};
return (
<div className={chatStyles.layout}>
<section className={`${styles.root} ${styles.sidebar}`} aria-label="Report builder">
<header className={styles.head}>
<InlineEdit as="h2" className={styles.name} label="Report name" placeholder="Untitled report" value={report.name} onSave={(name) => setReport({ name })} />
<Button size="sm" disabled={busy || loading}>Add to dashboard</Button>
</header>
<div className={styles.controls}>
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Datasources" placeholder="Select tables"
value={report.datasources} options={report.datasourceOptions} disabled={!report.datasourceOptions.length} onChange={(datasources) => setReport({ datasources })} />
<Select className={styles.group} label="Group rows by" value={report.groupRowsBy} options={[{ value: '', label: 'None' }, ...report.groupRowsByOptions]}
disabled={busy} onChange={(groupRowsBy) => setReport({ groupRowsBy })} />
<Select className={styles.group} label="Group columns by" value={report.groupColumnsBy} options={[{ value: '', label: 'None' }, ...report.groupColumnsByOptions]}
disabled={busy || !report.groupRowsBy} onChange={(groupColumnsBy) => setReport({ groupColumnsBy, showLegend: !!groupColumnsBy })} />
<Select className={styles.group} label="Sort by" value={report.sort} options={[{ value: '', label: 'None' }, ...report.sortOptions]}
disabled={busy} onChange={(sort) => setReport({ sort })} />
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Aggregations" placeholder="Select measures"
value={report.aggregations} options={report.aggregationOptions} disabled={busy} onChange={(aggregations) => setReport({ aggregations })} />
</div>
{reportId && (
<div className={styles.controls}>
<Select className={styles.group} label="Chart type" value={report.chartType} disabled={busy}
options={report.chartTypeOptions.map((o) => ({ ...o, label: o.label[0].toUpperCase() + o.label.slice(1) }))}
onChange={(v) => setReport({ chartType: v as SetReportBuilderInput['chartType'] })} />
<Select className={styles.group} label="Chart sort" value={report.chartSort} options={[{ value: '', label: 'No sorting' }, ...report.chartSortOptions]}
disabled={busy || isTable} onChange={(chartSort) => setReport({ chartSort })} />
{report.dateBucketOptions.length > 0 && (
<Select className={styles.group} label="Date bucket" value={report.dateBucket} options={report.dateBucketOptions} disabled={busy}
onChange={(v) => setReport({ dateBucket: v as SetReportBuilderInput['dateBucket'] })} />
)}
{!isTable && (
<>
<Select className={styles.group} label="X-axis" value={report.xAxis.field} options={report.xAxisOptions} disabled={busy}
onChange={(field) => setReport({ xAxis: { field } })} />
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Y-axis" placeholder="Select fields"
value={report.yAxis.fields.map((f) => f.field)} options={report.yAxisOptions} disabled={busy}
onChange={(next) => next.length && setReport({ yAxis: { fields: [...report.yAxis.fields.filter((f) => next.includes(f.field)), ...next.filter((field) => !report.yAxis.fields.some((f) => f.field === field)).map((field) => ({ field }))] } })} />
</>
)}
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Columns" placeholder="Select columns"
value={report.columns.map((c) => c.value)} options={report.columnOptions}
disabled={busy || report.columnStructureEditsLocked} onChange={(next) => report.columnActions.replace(next.map((field) => ({ field })))} />
</div>
)}
{reportId ? (
<div className={styles.main}>
<FilterSentence filters={report.filters} queryBuilderProps={report.filterQueryBuilderProps} onChange={setFilters} />
<div className={styles.views}>
<Chart chart={chart} chartLoading={loading || busy}
containerStyle={{ width: '100%', height: '100%', minHeight: 260, contain: 'size' }} />
<MetricTable table={page} rowsPerPage={ROWS_PER_PAGE} caption={report.name || 'Report rows'} />
</div>
</div>
) : (
<EmptyState icon={<Table2 size={24} strokeWidth={1.75} />} title="No datasource yet" description="Pick one or more tables in Datasources to start a report." />
)}
</section>
<ReportChat endpoint={endpoint} state={report.reportBuilderState} onReport={setOpenReportId} />
</div>
);
}.root { box-sizing: border-box; display: grid; gap: var(--space-4); width: min(100%, 1100px); min-width: 0; margin-inline: auto; padding: var(--space-4) var(--space-5) var(--space-5); border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--foreground); font-family: var(--font-body); font-size: var(--text-sm); letter-spacing: var(--tracking-body); line-height: var(--leading-body); }
.root > * { min-width: 0; --radius-control: 9px; }
.head { --control-height-sm: 32px; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-4); }
.head > :first-child { flex: 1 1 16rem; }
.head .name[data-variant] { --size: var(--text-base); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); }
.controls > * { min-width: 0; }
.group.group > div { display: flex; align-items: center; gap: var(--space-2); }
.group > div > label, .group > div > span:first-child { color: var(--text-secondary); font-size: 13px; font-weight: 400; white-space: nowrap; }
.group > div > div { flex: 1 1 auto; min-width: 0; }
.wide { flex: 0 1 15rem; }
.viewSwitch { border-radius: 9px; }
.viewSwitch button { min-height: 24px; border-radius: 6px; padding: 0 10px; font-size: 13px; }
/* Sidebar: the controls in a column, the sentence, chart and rows beside them; narrow, the column sits above. */
.main { display: grid; gap: var(--space-4); align-content: start; }
.views { display: grid; grid-template-columns: minmax(0, 1fr); grid-auto-rows: 1fr; gap: var(--space-4); }
.sidebar .controls { flex-direction: column; align-items: stretch; }
.sidebar .wide { flex: none; }
.sidebar .group.group > div { align-items: baseline; }
.sidebar .group > div > label, .sidebar .group > div > span:first-child { flex: none; width: 7.5rem; }
.sidebar .group > div > button { flex: 1 1 auto; }
/* The filters popover's field: its chips beside the label, with Add filter or Edit filters under them. */
.sidebar .filters.filters > div { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: var(--space-2); }
.sidebar .filters > div > :not(:first-child) { grid-column: 2; }
@media (min-width: 45rem) {
.sidebar { grid-template-columns: 20rem minmax(0, 1fr); grid-template-rows: repeat(2, auto) 1fr; align-items: start; column-gap: var(--space-6); }
.sidebar > :last-child { grid-column: 2; grid-row: 2 / -1; }
.sidebar > .head { grid-column: 1 / -1; }
}import { Quill } from '@quillsql/node';
const quill = new Quill({
privateKey: process.env.QUILL_PRIVATE_KEY,
databaseType: 'postgresql',
databaseConnectionString: process.env.DATABASE_URL,
});
// "authenticate" is your existing auth middleware.
app.post('/quill', authenticate, async (req, res) => {
const result = await quill.query({
tenants: [{ tenantField: 'organization_id', tenantIds: [req.user.organizationId] }],
metadata: req.body.metadata,
});
res.send(result);
});Sidebar with advanced filtering
import { useState } from 'react';
import { Chart, useReport, useReportQueryBuilder, type SetReportBuilderInput } from '@quillsql/react';
import { Table2 } from 'lucide-react';
import { MetricTable, type MetricRowsPage } from '../components/blocks/metric-explorer/metric-explorer';
import { Button } from '../components/button/button';
import { EmptyState } from '../components/empty-state/empty-state';
import { MultiSelect, Select, FilterBuilder } from '../components/filter-builder/filter-builder';
import { InlineEdit } from '../components/inline-edit/inline-edit';
import styles from './ReportBuilder.module.css';
import { ReportChat } from './ReportChat';
import chatStyles from './ReportChat.module.css';
const DEFAULT_REPORT_ID = '6af3445c802380dce4bba1ba';
const ROWS_PER_PAGE = 6;
/**
* The sidebar report builder with its filters as one more control of the query: a Filters field whose chips open
* Quill's filter editor in a popover. `useReportQueryBuilder` drafts the filters, and Apply hands them to `setFilters`.
*/
export function ReportBuilderSidebarAdvanced({ endpoint }: { endpoint: string }) {
// The report the chat last built, else the default one.
const [openReportId, setOpenReportId] = useState(DEFAULT_REPORT_ID);
const report = useReport(openReportId, {
destinationDashboardName: 'Metric explorer',
showTableNames: false,
initialPagination: { pageIndex: 0, pageSize: ROWS_PER_PAGE },
});
const { reportId, chart, loading, chartLoading, table, tableLoading, setReport, setFilters } = report;
const queryBuilder = useReportQueryBuilder({ reportId, filters: report.filters, queryBuilderProps: report.filterQueryBuilderProps, onApply: setFilters });
const busy = chartLoading || !reportId;
const isTable = report.chartType === 'table';
const page: MetricRowsPage = {
columns: table.columns,
rows: table.rows,
page: table.pagination.pageIndex + 1, pageCount: Math.max(0, table.getPageCount()), rowCount: table.getRowCount(),
loading: loading || tableLoading, onPageChange: (next) => table.setPageIndex(next - 1),
};
return (
<div className={chatStyles.layout}>
<section className={`${styles.root} ${styles.sidebar}`} aria-label="Report builder">
<header className={styles.head}>
<InlineEdit as="h2" className={styles.name} label="Report name" placeholder="Untitled report" value={report.name} onSave={(name) => setReport({ name })} />
<Button size="sm" disabled={busy || loading}>Add to dashboard</Button>
</header>
<div className={styles.controls}>
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Datasources" placeholder="Select tables"
value={report.datasources} options={report.datasourceOptions} disabled={!report.datasourceOptions.length} onChange={(datasources) => setReport({ datasources })} />
<Select className={styles.group} label="Group rows by" value={report.groupRowsBy} options={[{ value: '', label: 'None' }, ...report.groupRowsByOptions]}
disabled={busy} onChange={(groupRowsBy) => setReport({ groupRowsBy })} />
<Select className={styles.group} label="Group columns by" value={report.groupColumnsBy} options={[{ value: '', label: 'None' }, ...report.groupColumnsByOptions]}
disabled={busy || !report.groupRowsBy} onChange={(groupColumnsBy) => setReport({ groupColumnsBy, showLegend: !!groupColumnsBy })} />
<Select className={styles.group} label="Sort by" value={report.sort} options={[{ value: '', label: 'None' }, ...report.sortOptions]}
disabled={busy} onChange={(sort) => setReport({ sort })} />
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Aggregations" placeholder="Select measures"
value={report.aggregations} options={report.aggregationOptions} disabled={busy} onChange={(aggregations) => setReport({ aggregations })} />
{reportId && (
<div className={`${styles.group} ${styles.filters}`}>
<FilterBuilder disabled={busy} filters={report.filters} queryBuilder={queryBuilder}
filterUniqueValuesLoading={report.filterUniqueValuesLoading} onFiltersChange={setFilters} />
</div>
)}
</div>
{reportId && (
<div className={styles.controls}>
<Select className={styles.group} label="Chart type" value={report.chartType} disabled={busy}
options={report.chartTypeOptions.map((o) => ({ ...o, label: o.label[0].toUpperCase() + o.label.slice(1) }))}
onChange={(v) => setReport({ chartType: v as SetReportBuilderInput['chartType'] })} />
<Select className={styles.group} label="Chart sort" value={report.chartSort} options={[{ value: '', label: 'No sorting' }, ...report.chartSortOptions]}
disabled={busy || isTable} onChange={(chartSort) => setReport({ chartSort })} />
{report.dateBucketOptions.length > 0 && (
<Select className={styles.group} label="Date bucket" value={report.dateBucket} options={report.dateBucketOptions} disabled={busy}
onChange={(v) => setReport({ dateBucket: v as SetReportBuilderInput['dateBucket'] })} />
)}
{!isTable && (
<>
<Select className={styles.group} label="X-axis" value={report.xAxis.field} options={report.xAxisOptions} disabled={busy}
onChange={(field) => setReport({ xAxis: { field } })} />
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Y-axis" placeholder="Select fields"
value={report.yAxis.fields.map((f) => f.field)} options={report.yAxisOptions} disabled={busy}
onChange={(next) => next.length && setReport({ yAxis: { fields: [...report.yAxis.fields.filter((f) => next.includes(f.field)), ...next.filter((field) => !report.yAxis.fields.some((f) => f.field === field)).map((field) => ({ field }))] } })} />
</>
)}
<MultiSelect className={`${styles.group} ${styles.wide}`} label="Columns" placeholder="Select columns"
value={report.columns.map((c) => c.value)} options={report.columnOptions}
disabled={busy || report.columnStructureEditsLocked} onChange={(next) => report.columnActions.replace(next.map((field) => ({ field })))} />
</div>
)}
{reportId ? (
<div className={styles.views}>
<Chart chart={chart} chartLoading={loading || busy}
containerStyle={{ width: '100%', height: '100%', minHeight: 260, contain: 'size' }} />
<MetricTable table={page} rowsPerPage={ROWS_PER_PAGE} caption={report.name || 'Report rows'} />
</div>
) : (
<EmptyState icon={<Table2 size={24} strokeWidth={1.75} />} title="No datasource yet" description="Pick one or more tables in Datasources to start a report." />
)}
</section>
<ReportChat endpoint={endpoint} state={report.reportBuilderState} onReport={setOpenReportId} />
</div>
);
}.root { box-sizing: border-box; display: grid; gap: var(--space-4); width: min(100%, 1100px); min-width: 0; margin-inline: auto; padding: var(--space-4) var(--space-5) var(--space-5); border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--foreground); font-family: var(--font-body); font-size: var(--text-sm); letter-spacing: var(--tracking-body); line-height: var(--leading-body); }
.root > * { min-width: 0; --radius-control: 9px; }
.head { --control-height-sm: 32px; display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3) var(--space-4); }
.head > :first-child { flex: 1 1 16rem; }
.head .name[data-variant] { --size: var(--text-base); }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-4); }
.controls > * { min-width: 0; }
.group.group > div { display: flex; align-items: center; gap: var(--space-2); }
.group > div > label, .group > div > span:first-child { color: var(--text-secondary); font-size: 13px; font-weight: 400; white-space: nowrap; }
.group > div > div { flex: 1 1 auto; min-width: 0; }
.wide { flex: 0 1 15rem; }
.viewSwitch { border-radius: 9px; }
.viewSwitch button { min-height: 24px; border-radius: 6px; padding: 0 10px; font-size: 13px; }
/* Sidebar: the controls in a column, the sentence, chart and rows beside them; narrow, the column sits above. */
.main { display: grid; gap: var(--space-4); align-content: start; }
.views { display: grid; grid-template-columns: minmax(0, 1fr); grid-auto-rows: 1fr; gap: var(--space-4); }
.sidebar .controls { flex-direction: column; align-items: stretch; }
.sidebar .wide { flex: none; }
.sidebar .group.group > div { align-items: baseline; }
.sidebar .group > div > label, .sidebar .group > div > span:first-child { flex: none; width: 7.5rem; }
.sidebar .group > div > button { flex: 1 1 auto; }
/* The filters popover's field: its chips beside the label, with Add filter or Edit filters under them. */
.sidebar .filters.filters > div { display: grid; grid-template-columns: 7.5rem minmax(0, 1fr); gap: var(--space-2); }
.sidebar .filters > div > :not(:first-child) { grid-column: 2; }
@media (min-width: 45rem) {
.sidebar { grid-template-columns: 20rem minmax(0, 1fr); grid-template-rows: repeat(2, auto) 1fr; align-items: start; column-gap: var(--space-6); }
.sidebar > :last-child { grid-column: 2; grid-row: 2 / -1; }
.sidebar > .head { grid-column: 1 / -1; }
}import { Quill } from '@quillsql/node';
const quill = new Quill({
privateKey: process.env.QUILL_PRIVATE_KEY,
databaseType: 'postgresql',
databaseConnectionString: process.env.DATABASE_URL,
});
// "authenticate" is your existing auth middleware.
app.post('/quill', authenticate, async (req, res) => {
const result = await quill.query({
tenants: [{ tenantField: 'organization_id', tenantIds: [req.user.organizationId] }],
metadata: req.body.metadata,
});
res.send(result);
});