:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(quill): adopt new Quill Table components in MCP apps (#61118)
Rafael Audibert12d443888c86
diff --git a/services/mcp/src/ui-apps/components/PathsVisualizer.tsx b/services/mcp/src/ui-apps/components/PathsVisualizer.tsxindex 8d3653c46bd4..0df25396faa1 100644--- a/services/mcp/src/ui-apps/components/PathsVisualizer.tsx+++ b/services/mcp/src/ui-apps/components/PathsVisualizer.tsx@@ -1,12 +1,25 @@import type { ReactElement } from 'react'import { emptyStateIllustration } from '@posthog/mcp-ui'-import { Empty, EmptyDescription, EmptyHeader, EmptyMedia } from '@posthog/quill'+import { DataTable, type DataTableProps, Empty, EmptyDescription, EmptyHeader, EmptyMedia } from '@posthog/quill'-import { DataTable } from './charts'import type { PathsVisualizerProps } from './types'import { formatDuration, formatNumber } from './utils'+// Edges are sorted by user count and the busiest paths lead, so a truncated+// view stays meaningful; columns are non-sortable to match.+const MAX_ROWS = 20++function formatCellValue(value: unknown): string {+ if (value === null || value === undefined) {+ return '-'+ }+ if (typeof value === 'number') {+ return formatNumber(value)+ }+ return String(value)+}+/** Node keys are `<stepIndex>_<value>`; split into the step number and the path/value. */function parseNode(key: string): { step: number; path: string } {const sep = key.indexOf('_')@@ -47,11 +60,26 @@ export function PathsVisualizer({ results }: PathsVisualizerProps): ReactElement]})+ const displayRows = rows.slice(0, MAX_ROWS)+ const hasMore = displayRows.length < rows.length+ const tableColumns: DataTableProps<unknown[], unknown>['columns'] = columns.map((col, colIndex) => ({+ id: String(colIndex),+ header: col,+ accessorFn: (row: unknown[]) => row[colIndex],+ enableSorting: false,+ cell: (info: { getValue: () => unknown }) => formatCellValue(info.getValue()),+ }))+const topUsers = sorted[0]?.value ?? 0return (<div>- <DataTable columns={columns} rows={rows} />+ <DataTable columns={tableColumns} data={displayRows} className="rounded-lg border" />+ {hasMore && (+ <span className="mt-2 block text-center text-xs text-muted-foreground">+ Showing {displayRows.length} of {rows.length} transitions+ </span>+ )}<div className="mt-4 rounded-md bg-muted/50 p-3 text-sm text-muted-foreground"><strong className="text-foreground">{formatNumber(edges.length)}</strong> path transitiondiff --git a/services/mcp/src/ui-apps/components/TableVisualizer.tsx b/services/mcp/src/ui-apps/components/TableVisualizer.tsxindex ab76c2120d57..9e68511ddcaa 100644--- a/services/mcp/src/ui-apps/components/TableVisualizer.tsx+++ b/services/mcp/src/ui-apps/components/TableVisualizer.tsx@@ -1,8 +1,32 @@import type { ReactElement } from 'react'-import { BigNumber, DataTable, LineChart, type Series } from './charts'+import { emptyStateIllustration } from '@posthog/mcp-ui'+import { DataTable, type DataTableProps, Empty, EmptyDescription, EmptyHeader, EmptyMedia } from '@posthog/quill'++import { formatNumber } from './utils'+import { BigNumber, LineChart, type Series } from './charts'import type { TableVisualizerProps } from './types'+// Query results are truncated client-side; sorting a truncated view would+// mislead, so columns are non-sortable.+const MAX_ROWS = 20++function formatCellValue(value: unknown): string {+ if (value === null || value === undefined) {+ return '-'+ }+ if (typeof value === 'number') {+ return formatNumber(value)+ }+ if (typeof value === 'boolean') {+ return value ? 'true' : 'false'+ }+ if (typeof value === 'object') {+ return JSON.stringify(value)+ }+ return String(value)+}+const DATE_PATTERNS = [/^\d{4}-\d{2}-\d{2}/, // 2024-01-15 or 2024-01-15T.../^\d{4}\/\d{2}\/\d{2}/, // 2024/01/15@@ -117,5 +141,37 @@ export function TableVisualizer({ results }: TableVisualizerProps): ReactElementreturn <LineChart series={series} labels={labels} maxValue={maxValue} showLegend={false} />}- return <DataTable columns={columns} rows={rows} />+ if (rows.length === 0) {+ return (+ <Empty>+ <EmptyHeader>+ <EmptyMedia>{emptyStateIllustration('table')}</EmptyMedia>+ <EmptyDescription>+ {columns.length === 0 ? 'No rows to display' : 'Query returned no rows'}+ </EmptyDescription>+ </EmptyHeader>+ </Empty>+ )+ }++ const displayRows = rows.slice(0, MAX_ROWS)+ const hasMore = displayRows.length < rows.length+ const tableColumns: DataTableProps<unknown[], unknown>['columns'] = columns.map((col, colIndex) => ({+ id: String(colIndex),+ header: col,+ accessorFn: (row: unknown[]) => row[colIndex],+ enableSorting: false,+ cell: (info: { getValue: () => unknown }) => formatCellValue(info.getValue()),+ }))++ return (+ <div className="flex flex-col gap-2">+ <DataTable columns={tableColumns} data={displayRows} />+ {hasMore && (+ <span className="text-center text-xs text-muted-foreground">+ Showing {displayRows.length} of {rows.length}+ rows+ </span>+ )}+ </div>+ )}diff --git a/services/mcp/src/ui-apps/components/charts/DataTable.tsx b/services/mcp/src/ui-apps/components/charts/DataTable.tsxdeleted file mode 100644index 8bf8008526de..000000000000--- a/services/mcp/src/ui-apps/components/charts/DataTable.tsx+++ /dev/null@@ -1,151 +0,0 @@-import type { ReactElement } from 'react'--import { emptyStateIllustration } from '@posthog/mcp-ui'-import { Empty, EmptyDescription, EmptyHeader, EmptyMedia } from '@posthog/quill'--import { formatNumber } from '../utils'--// TODO(quill): same blocker as `lib/DataTable.tsx` — Quill ships no `Table`-// primitive. This is the chart-results variant: a fixed-height query-result-// table with a chart-style empty illustration. It would also collapse into a-// future Quill `Table` once the primitive lands; until then it stays-// distinct from `lib/DataTable.tsx` because it has different defaults-// (smaller cell width, max-row truncation, illustrated empty state).--const MAX_ROWS = 20-const MAX_CELL_WIDTH = 200--function formatCellValue(value: unknown): string {- if (value === null || value === undefined) {- return '-'- }- if (typeof value === 'number') {- return formatNumber(value)- }- if (typeof value === 'boolean') {- return value ? 'true' : 'false'- }- if (typeof value === 'object') {- return JSON.stringify(value)- }- return String(value)-}--export interface DataTableProps {- columns: string[]- rows: unknown[][]- maxRows?: number-}--export function DataTable({ columns, rows, maxRows = MAX_ROWS }: DataTableProps): ReactElement {- const displayRows = rows.slice(0, maxRows)- const hasMore = displayRows.length < rows.length-- if (columns.length === 0 && rows.length === 0) {- return (- <Empty>- <EmptyHeader>- <EmptyMedia>{emptyStateIllustration('table')}</EmptyMedia>- <EmptyDescription>No rows to display</EmptyDescription>- </EmptyHeader>- </Empty>- )- }-- if (rows.length === 0) {- return (- <Empty>- <EmptyHeader>- <EmptyMedia>{emptyStateIllustration('table')}</EmptyMedia>- <EmptyDescription>Query returned no rows</EmptyDescription>- </EmptyHeader>- </Empty>- )- }-- return (- <div style={{ overflowX: 'auto' }}>- <table- style={{- width: '100%',- borderCollapse: 'collapse',- fontSize: '0.8125rem',- }}- >- <thead>- <tr>- {columns.map((col, i) => (- <th- key={i}- style={{- padding: '0.5rem 0.75rem',- textAlign: 'left',- fontWeight: 600,- color: 'var(--color-text-primary, #101828)',- borderBottom: '2px solid var(--color-border-primary, #e5e7eb)',- backgroundColor: 'var(--color-background-secondary, #f9fafb)',- maxWidth: `${MAX_CELL_WIDTH}px`,- overflow: 'hidden',- textOverflow: 'ellipsis',- whiteSpace: 'nowrap',- }}- title={col}- >- {col}- </th>- ))}- </tr>- </thead>- <tbody>- {displayRows.map((row, rowIndex) => (- <tr- key={rowIndex}- style={{- backgroundColor:- rowIndex % 2 === 0- ? 'var(--color-background-primary, #fff)'- : 'var(--color-background-secondary, #f9fafb)',- }}- >- {columns.map((_, colIndex) => {- const value = row[colIndex]- const formatted = formatCellValue(value)- return (- <td- key={colIndex}- style={{- padding: '0.5rem 0.75rem',- color: 'var(--color-text-primary, #101828)',- borderBottom: '1px solid var(--color-border-primary, #e5e7eb)',- maxWidth: `${MAX_CELL_WIDTH}px`,- overflow: 'hidden',- textOverflow: 'ellipsis',- whiteSpace: 'nowrap',- }}- title={formatted}- >- {formatted}- </td>- )- })}- </tr>- ))}- </tbody>- </table>-- {hasMore && (- <div- style={{- padding: '0.75rem',- textAlign: 'center',- color: 'var(--color-text-secondary, #6b7280)',- fontSize: '0.8125rem',- borderTop: '1px solid var(--color-border-primary, #e5e7eb)',- }}- >- Showing {displayRows.length} of {rows.length}+ rows- </div>- )}- </div>- )-}diff --git a/services/mcp/src/ui-apps/components/charts/index.ts b/services/mcp/src/ui-apps/components/charts/index.tsindex 925285129592..b17b642231fc 100644--- a/services/mcp/src/ui-apps/components/charts/index.ts+++ b/services/mcp/src/ui-apps/components/charts/index.ts@@ -2,5 +2,4 @@ export { BigNumber, type BigNumberProps } from './BigNumber'export { LineChart, type LineChartProps, type Series, type DataPoint } from './LineChart'export { BarChart, type BarChartProps } from './BarChart'export { HorizontalBarChart, type HorizontalBarChartProps, type HorizontalBar } from './HorizontalBarChart'-export { DataTable, type DataTableProps } from './DataTable'export { Select, type SelectProps, type SelectOption } from './Select'diff --git a/services/mcp/src/ui-apps/lib/DataTable.tsx b/services/mcp/src/ui-apps/lib/DataTable.tsxindex a275923be939..3b126ed58028 100644--- a/services/mcp/src/ui-apps/lib/DataTable.tsx+++ b/services/mcp/src/ui-apps/lib/DataTable.tsx@@ -1,36 +1,18 @@-import { ChevronLeft, ChevronRight } from 'lucide-react'-import { type ReactElement, type ReactNode, useCallback, useMemo, useState } from 'react'--// TODO(quill): delete this file once @posthog/quill ships a `DataTable` (or-// `Table` + `TableSort` + `TablePagination`) primitive. The prop shape below-// (`columns`, `data`, `pageSize`, `defaultSort`, `emptyMessage`) deliberately-// mirrors what we'd expect from a Quill primitive so migration is a single-// import swap.-//-// What's needed from Quill:-// - A `Table` primitive with semantic `<table>/<thead>/<tbody>` markup —-// accessibility relies on this and Quill currently ships no table-// primitive (only `Item`/`ItemGroup`, which is row-per-item, not-// row-of-columns). The data-density tradeoff is real: a 5-column metric-// table doesn't render usefully as Item cards.-// - Column-aware sorting wired to header click + ARIA-// (`aria-sort=ascending|descending|none`). Today we hand-roll the toggle-// between asc → desc → unsorted and the sort indicator glyphs.-// - Client-side pagination with a token-styled control (we currently-// compose `<Button variant="ghost" size="icon-xs">` + chevron icons-// inline; a Quill `Pagination` primitive would absorb this).-// - Empty state slot. We already route the "no data" branch through-// `<Empty><EmptyHeader><EmptyDescription>` so the visual matches Quill's-// primitive, but a real Quill `Table` could expose this directly via an-// `emptyMessage` / `emptyState` prop.-// - Built-in cell renderers (default text, number-localised,-// boolean/null sentinel) — currently in `defaultFormat()` below.-//-// Until then this file leans on Quill's `Button`, `Empty*`, `cn()` and-// design tokens (`bg-muted/50`, `text-muted-foreground`, `border-t`,-// `--text-sm`) so the visual language already matches what a future Quill-// primitive would ship.-import { Button, cn, Empty, EmptyDescription, EmptyHeader } from '@posthog/quill'+import { type ReactElement, type ReactNode, useMemo } from 'react'++// Thin adapter over Quill's `DataTable`: keeps the ergonomic+// `key`/`header`/`render`/`align`/`sortable` column shape (and default cell+// formatting) that list views read declaratively, and maps it onto Quill's+// `ColumnDef`. Quill handles pagination, per-column alignment, sorting, and the+// empty state; this layer only adapts the API and provides defaults.+import {+ cn,+ DataTable as QuillDataTable,+ type DataTableProps as QuillDataTableProps,+ Empty,+ EmptyDescription,+ EmptyHeader,+} from '@posthog/quill'export interface DataTableColumn<T> {key: string@@ -51,14 +33,9 @@ export interface DataTableProps<T> {type SortDirection = 'asc' | 'desc'-interface SortState {- key: string- direction: SortDirection-}-function defaultFormat(value: unknown): string {if (value === null || value === undefined) {- return '\u2014'+ return '—'}if (typeof value === 'number') {return value.toLocaleString()@@ -92,25 +69,6 @@ function compareValues(a: unknown, b: unknown): number {return String(a).localeCompare(String(b))}-const alignClasses = {- left: 'text-left',- center: 'text-center',- right: 'text-right',-} as const--function SortIcon({ direction, active }: { direction?: SortDirection | undefined; active: boolean }): ReactElement {- return (- <span- className={cn(- 'inline-flex ml-1',- active ? 'text-foreground' : 'text-muted-foreground opacity-0 group-hover/th:opacity-50'- )}- >- {direction === 'asc' ? '\u2191' : direction === 'desc' ? '\u2193' : '\u2195'}- </span>- )-}-export function DataTable<T extends object>({columns,data,@@ -119,144 +77,45 @@ export function DataTable<T extends object>({emptyMessage = 'No data',className,}: DataTableProps<T>): ReactElement {- const [sort, setSort] = useState<SortState | null>(defaultSort ?? null)- const [page, setPage] = useState(0)-- const handleSort = useCallback((key: string) => {- setSort((prev) => {- if (prev?.key !== key) {- return { key, direction: 'asc' }- }- if (prev.direction === 'asc') {- return { key, direction: 'desc' }- }- return null- })- setPage(0)- }, [])-+ // Quill's DataTable owns sorting from an empty initial state, so honour+ // `defaultSort` by pre-ordering the rows it receives.const sortedData = useMemo(() => {- if (!sort) {+ if (!defaultSort) {return data}return [...data].sort((a, b) => {- const cmp = compareValues(getValue(a, sort.key), getValue(b, sort.key))- return sort.direction === 'desc' ? -cmp : cmp+ const cmp = compareValues(getValue(a, defaultSort.key), getValue(b, defaultSort.key))+ return defaultSort.direction === 'desc' ? -cmp : cmp})- }, [data, sort])-- const totalPages = pageSize > 0 ? Math.max(1, Math.ceil(sortedData.length / pageSize)) : 1- // Clamp during render so an out-of-range `page` (e.g. parent passed a shorter `data`)- // can't render an empty body with no empty-state fallback.- const safePage = Math.min(page, totalPages - 1)- const pagedData = pageSize > 0 ? sortedData.slice(safePage * pageSize, (safePage + 1) * pageSize) : sortedData- const showPagination = pageSize > 0 && sortedData.length > pageSize-- if (data.length === 0) {- return (- <Empty className={cn('py-8', className)}>- <EmptyHeader>- <EmptyDescription>{emptyMessage}</EmptyDescription>- </EmptyHeader>- </Empty>- )- }+ }, [data, defaultSort])++ const quillColumns = useMemo<QuillDataTableProps<T, unknown>['columns']>(+ () =>+ columns.map((col): QuillDataTableProps<T, unknown>['columns'][number] => ({+ id: col.key,+ accessorFn: (row: T) => getValue(row, col.key),+ header: () => col.header,+ cell: (info: { getValue: () => unknown; row: { original: T } }) =>+ col.render ? col.render(info.row.original) : defaultFormat(info.getValue()),+ enableSorting: col.sortable ?? false,+ meta: { align: col.align },+ })),+ [columns]+ )return (- <div className={cn('overflow-hidden rounded-lg border', className)}>- <div className="overflow-x-auto">- <table className="w-full text-sm">- <thead>- <tr className="bg-muted/50">- {columns.map((col) => (- <th- key={col.key}- aria-sort={- col.sortable- ? sort?.key === col.key- ? sort.direction === 'asc'- ? 'ascending'- : 'descending'- : 'none'- : undefined- }- className={cn(- 'group/th px-3 py-2 font-medium text-muted-foreground',- 'max-w-[200px] truncate',- alignClasses[col.align ?? 'left'],- col.sortable && 'cursor-pointer select-none hover:text-foreground'- )}- title={typeof col.header === 'string' ? col.header : undefined}- onClick={col.sortable ? () => handleSort(col.key) : undefined}- >- {col.header}- {col.sortable && (- <SortIcon- direction={sort?.key === col.key ? sort.direction : undefined}- active={sort?.key === col.key}- />- )}- </th>- ))}- </tr>- </thead>- <tbody>- {pagedData.map((row, rowIndex) => (- <tr key={rowIndex} className={cn('border-t', rowIndex % 2 === 1 && 'bg-muted/25')}>- {columns.map((col) => {- const content = col.render ? col.render(row) : defaultFormat(getValue(row, col.key))- const title = typeof content === 'string' ? content : undefined-- return (- <td- key={col.key}- className={cn(- 'px-3 py-2 text-foreground',- 'max-w-[200px] truncate',- alignClasses[col.align ?? 'left']- )}- title={title}- >- {content}- </td>- )- })}- </tr>- ))}- </tbody>- </table>- </div>- {showPagination && (- <div className="flex items-center justify-between border-t px-3 py-2 text-xs text-muted-foreground">- <span>- {safePage * pageSize + 1}–{Math.min((safePage + 1) * pageSize, sortedData.length)} of{' '}- {sortedData.length}- </span>- <div className="flex items-center gap-1">- <Button- variant="ghost"- size="icon-xs"- onClick={() => setPage(Math.max(0, safePage - 1))}- disabled={safePage === 0}- aria-label="Previous page"- >- <ChevronLeft className="h-3.5 w-3.5" />- </Button>- <span className="px-1 tabular-nums">- {safePage + 1} / {totalPages}- </span>- <Button- variant="ghost"- size="icon-xs"- onClick={() => setPage(Math.min(totalPages - 1, safePage + 1))}- disabled={safePage >= totalPages - 1}- aria-label="Next page"- >- <ChevronRight className="h-3.5 w-3.5" />- </Button>- </div>- </div>- )}- </div>+ <QuillDataTable<T, unknown>+ columns={quillColumns}+ data={sortedData}+ className={cn('rounded-lg border', className)}+ {...(pageSize > 0 ? { pageSize } : {})}+ empty={+ <Empty className="py-8">+ <EmptyHeader>+ <EmptyDescription>{emptyMessage}</EmptyDescription>+ </EmptyHeader>+ </Empty>+ }+ />)}