Skip to content

: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.

fix(mobile): show full numbers in insight tables (#125830)

Chris Volzer8561de028d59
diff --git a/products/mobile/docs/VIEWS.md b/products/mobile/docs/VIEWS.md
index 1500de68c7f5..e0854e93bc9b 100644
--- a/products/mobile/docs/VIEWS.md
+++ b/products/mobile/docs/VIEWS.md
@@ -246,6 +246,7 @@ A SQL insight is a `DataVisualizationNode` with a `HogQLQuery` source. Its respo
- Bar rows keep the server's order, because the SQL orders them on purpose. The total is their sum.
- Formatting comes from `insightFormatting.ts`, so a value reads the same in the table, the chart tooltip and the bar list. A table column takes its `tableSettings.columns` formatting, else its `chartSettings.yAxis` formatting. A chart and a bar list take the first saved y axis entry's formatting as `snapshot.format`, else the first y column's own format. As on the web, a percent column is a fraction scaled by 100 everywhere: 0.25 reads 25% in the table, on the chart and as a big number.
- The table draws six rows on a tile and up to 500 rows (`SQL_TABLE_MAX_ROWS`) on the insight screen and full screen, because the rows are plain views, not a virtual list. Past that, the caption and the line under the rows say "First 500 of 5,000 rows". An empty result says "No rows", or "No rows for this range" when the result has a range.
+- Table columns widen to show complete formatted numbers and column names. Wider tables scroll horizontally. The first column stays pinned when it takes up no more than half the table's viewport; otherwise all columns scroll together.
- `capabilities.number` is true for a big number, `capabilities.chart` for a chart over time with a y column and at least one date, whose first y column a pin draws. A SQL insight has no "View people".
- `kindLabel` names the resolved display: "Table", "Line", "Bar", "Big number" or "Pie", else "SQL".
diff --git a/products/mobile/src/ui/chart/SqlTable.test.tsx b/products/mobile/src/ui/chart/SqlTable.test.tsx
index 90adb3570996..c154764078dd 100644
--- a/products/mobile/src/ui/chart/SqlTable.test.tsx
+++ b/products/mobile/src/ui/chart/SqlTable.test.tsx
@@ -1,4 +1,4 @@
-import { fireEvent, render, screen } from '@testing-library/react-native'
+import { act, fireEvent, render, screen } from '@testing-library/react-native'
import { useColorScheme } from 'react-native'
import { sqlPresentation } from '@/model/adapters/sqlVisualization'
@@ -11,7 +11,7 @@ jest.mock('react-native-worklets', () => jest.requireActual('react-native-workle
jest.mock('react-native-reanimated', () => jest.requireActual('react-native-reanimated/mock'))
jest.mock('@/lib/analytics', () => ({ track: jest.fn() }))
-const COLUMNS: SqlColumnView[] = [
+const COLUMNS: [SqlColumnView, SqlColumnView, SqlColumnView] = [
{ name: 'page', scalar: 'STRING', isNumerical: false, isDate: false, format: null },
{ name: 'views', scalar: 'INTEGER', isNumerical: true, isDate: false, format: null },
{
@@ -37,6 +37,7 @@ function table(rowCount: number, hasMore = false): SqlTableView {
describe('SqlTable', () => {
afterEach(() => {
+ jest.useRealTimers()
jest.mocked(useColorScheme).mockReturnValue('light')
})
@@ -100,6 +101,54 @@ describe('SqlTable', () => {
expect(screen.getByTestId('chart-table-row-0-pinned')).not.toHaveStyle(highlighted)
})
+ test.each(['last', 'first', 'only'] as const)(
+ 'fits a large number in the %s column and lets the user scroll to it',
+ (position) => {
+ jest.useFakeTimers()
+ const number = '9223372036854775807'
+ const textColumn = COLUMNS[0]
+ const numberColumn = COLUMNS[1]
+ const columns =
+ position === 'only'
+ ? [numberColumn]
+ : position === 'first'
+ ? [numberColumn, textColumn]
+ : [textColumn, numberColumn]
+ const rows = [columns.map((column) => (column.isNumerical ? number : 'Example'))]
+ const { rerender } = render(
+ <SqlTable table={{ columns, rows, hasMore: false }} label="Large values" testID="chart-table" />
+ )
+ fireEvent(screen.getByTestId('chart-table'), 'layout', { nativeEvent: { layout: { width: 240 } } })
+ expect(screen.getByTestId('chart-table-scroll')).toHaveProp('scrollEnabled', false)
+
+ const columnIndex = columns.findIndex((column) => column.isNumerical)
+ fireEvent(
+ screen.getByTestId(`chart-table-measure-${columnIndex}`, { includeHiddenElements: true }),
+ 'layout',
+ {
+ nativeEvent: { layout: { width: 300 } },
+ }
+ )
+ act(() => jest.runOnlyPendingTimers())
+
+ expect(screen.getByText(number)).toBeTruthy()
+ expect(screen.getByTestId('chart-table-scroll')).toHaveProp('scrollEnabled', true)
+ expect(screen.getByTestId('chart-table-scroll')).toHaveProp('showsHorizontalScrollIndicator', true)
+ if (position !== 'last') {
+ expect(screen.queryByTestId('chart-table-row-0-pinned')).toBeNull()
+ }
+
+ rerender(
+ <SqlTable
+ table={{ columns: columns.map((column) => ({ ...column })), rows, hasMore: false }}
+ label="Large values"
+ testID="chart-table"
+ />
+ )
+ expect(screen.getByTestId('chart-table-scroll')).toHaveProp('scrollEnabled', true)
+ }
+ )
+
test('draws a screen up to the row cap and says so under the rows', () => {
render(<SqlTable table={table(501)} label="Top pages" testID="chart-table" />)
diff --git a/products/mobile/src/ui/chart/SqlTable.tsx b/products/mobile/src/ui/chart/SqlTable.tsx
index 39d04004ef2e..0fc7a278b28f 100644
--- a/products/mobile/src/ui/chart/SqlTable.tsx
+++ b/products/mobile/src/ui/chart/SqlTable.tsx
@@ -1,4 +1,4 @@
-import { memo, type ReactElement, useCallback, useMemo, useState } from 'react'
+import { memo, type ReactElement, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import {
type LayoutChangeEvent,
ScrollView,
@@ -24,6 +24,7 @@ import type { ChartAccessibilityAction, ChartTrackingContext } from './types'
const HEAD_HEIGHT = 30
// Fixed, because the pinned column and the scrolling columns draw each row in separate stacks that must line up.
const ROW_HEIGHT = 36
+const CELL_PADDING = 6
interface SqlTableProps {
table: SqlTableView
@@ -65,17 +66,18 @@ interface ColumnStyle {
function columnStyles(
part: readonly SqlColumnView[],
+ widths: readonly number[],
fixed: boolean,
growText: boolean,
styles: SqlTableStyles
): ColumnStyle[] {
- return part.map((column) => {
+ return part.map((column, index) => {
const right = alignRight(column)
const box: ViewStyle = fixed
- ? { width: columnWidth(column) }
+ ? { width: widths[index] }
: // Text columns take the room left when the columns fit; numbers and dates stay at their minimum width.
- { flexBasis: columnWidth(column), flexGrow: growText && right ? 0 : 1, flexShrink: 0 }
- const text = right ? [styles.cellText, styles.right, styles.numeric] : [styles.cellText]
+ { flexBasis: widths[index], flexGrow: growText && right ? 0 : 1, flexShrink: 0 }
+ const text: TextStyle[] = right ? [styles.cellText, styles.right, styles.numeric] : [styles.cellText]
return {
box: [box, styles.cell],
text,
@@ -129,7 +131,7 @@ const SqlRow = memo(function SqlRow({
/**
* The rows of a SQL insight in the server's order. Columns share the width when they fit. When they do not, the first
- * column stays put and the others scroll sideways. A tap on a row highlights it across both parts.
+ * column stays put if it leaves room to scroll the others. A tap on a row highlights it across both parts.
*/
export function SqlTable({
table,
@@ -149,21 +151,61 @@ export function SqlTable({
// Only a tile has "+N more". A screen cut at the drawing cap says so in the footer and its caption.
const capped = maxRows === undefined && more > 0
const [width, setWidth] = useState(0)
+ const [measured, setMeasured] = useState<ReadonlyMap<string, number>>(() => new Map())
+ const pending = useRef(new Map<string, number>())
+ const measureFrame = useRef<number | null>(null)
+ useEffect(
+ () => () => {
+ if (measureFrame.current !== null) {
+ cancelAnimationFrame(measureFrame.current)
+ measureFrame.current = null
+ }
+ },
+ []
+ )
+ const onMeasure = useCallback(
+ (index: number, event: LayoutChangeEvent) => {
+ const column = columns[index]
+ if (!column) {
+ return
+ }
+ const measuredWidth = Math.ceil(event.nativeEvent.layout.width) + CELL_PADDING * 2
+ if (measuredWidth <= (pending.current.get(column.name) ?? columnWidth(column))) {
+ return
+ }
+ pending.current.set(column.name, measuredWidth)
+ // Headers and values measure separately; publish their widths together to keep the grid aligned.
+ if (measureFrame.current === null) {
+ measureFrame.current = requestAnimationFrame(() => {
+ measureFrame.current = null
+ setMeasured(new Map(pending.current))
+ })
+ }
+ },
+ [columns]
+ )
const shown = useMemo(() => {
const now = Date.now()
return rows
.slice(0, limit)
.map((row) => columns.map((column, index) => formatSqlCell(row[index] ?? null, column, now)))
}, [rows, columns, limit])
- const totalWidth = columns.reduce((sum, column) => sum + columnWidth(column), 0)
- const pinned = columns.length > 1 && width > 0 && totalWidth > width
+ const widths = useMemo(
+ () => columns.map((column) => Math.max(columnWidth(column), measured.get(column.name) ?? 0)),
+ [columns, measured]
+ )
+ const totalWidth = widths.reduce((sum, column) => sum + column, 0)
+ const overflowing = width > 0 && totalWidth > width
+ const firstWidth = widths[0] ?? 0
+ const pinned = columns.length > 1 && overflowing && firstWidth <= width / 2
const layout = useMemo(() => {
const growText = columns.some((column) => !alignRight(column))
+ const all = columnStyles(columns, widths, overflowing, growText, styles)
return {
- pinned: columnStyles(columns.slice(0, 1), true, growText, styles),
- scrolling: columnStyles(pinned ? columns.slice(1) : columns, pinned, growText, styles),
+ pinned: all.slice(0, 1),
+ scrolling: pinned ? all.slice(1) : all,
}
- }, [columns, pinned, styles])
+ }, [columns, widths, overflowing, pinned, styles])
// Each row's cells split once per layout, so the memoized rows get the same arrays on every render.
const parts = useMemo(
() => shown.map((row) => (pinned ? { pinned: row.slice(0, 1), scrolling: row.slice(1) } : { scrolling: row })),
@@ -208,9 +250,7 @@ export function SqlTable({
const first = columns[0]
const scrolling = pinned ? columns.slice(1) : columns
- // Inside a horizontal scroll view the rows size to their longest text, so the table takes the container's width
- // when the columns fit, and the scrolling columns keep their minimum widths when they do not.
- const tableWidth = pinned || width === 0 ? undefined : width
+ const tableWidth = Math.max(totalWidth, width) - (pinned ? firstWidth : 0)
const rowTestID = (index: number, suffix: string): string | undefined =>
testID ? `${testID}-row-${index}${suffix}` : undefined
const head = (column: SqlColumnView, style: ColumnStyle | undefined, key: string): ReactElement => (
@@ -229,9 +269,37 @@ export function SqlTable({
testID={testID}
{...a11y}
>
+ {/* A horizontal scroll view measures native text without wrapping it to the grid's current widths. */}
+ <ScrollView
+ horizontal
+ scrollEnabled={false}
+ pointerEvents="none"
+ accessible={false}
+ accessibilityElementsHidden
+ importantForAccessibility="no-hide-descendants"
+ style={styles.measurement}
+ >
+ {columns.map((column, index) => (
+ // biome-ignore lint/suspicious/noArrayIndexKey: columns have a fixed order within a table.
+ <View key={index}>
+ <Text style={styles.headText} onLayout={(event) => onMeasure(index, event)}>
+ {column.name}
+ </Text>
+ {column.isNumerical && (
+ <Text
+ style={[styles.cellText, styles.numeric]}
+ onLayout={(event) => onMeasure(index, event)}
+ testID={testID ? `${testID}-measure-${index}` : undefined}
+ >
+ {shown.map((row) => row[index] ?? '–').join('\n')}
+ </Text>
+ )}
+ </View>
+ ))}
+ </ScrollView>
<View style={styles.grid}>
{pinned && first ? (
- <View style={[styles.pinned, { width: columnWidth(first) }]}>
+ <View style={[styles.pinned, { width: firstWidth }]}>
<View style={styles.headRow}>{head(first, layout.pinned[0], 'pinned')}</View>
{parts.map((part, index) => (
<SqlRow
@@ -249,13 +317,13 @@ export function SqlTable({
) : null}
<ScrollView
horizontal
- scrollEnabled={pinned}
- showsHorizontalScrollIndicator={false}
+ scrollEnabled={overflowing}
+ showsHorizontalScrollIndicator
style={styles.scroll}
contentContainerStyle={styles.scrollContent}
testID={testID ? `${testID}-scroll` : undefined}
>
- <View style={[styles.table, tableWidth !== undefined && { width: tableWidth }]}>
+ <View style={[styles.table, { width: tableWidth }]}>
<View style={styles.headRow}>
{scrolling.map((column, at) => head(column, layout.scrolling[at], `${at}`))}
</View>
@@ -301,6 +369,13 @@ export function SqlTable({
type SqlTableStyles = ReturnType<typeof useStyles>
const useStyles = createStyles(({ colors }) => ({
+ measurement: {
+ position: 'absolute',
+ left: 0,
+ right: 0,
+ height: 1,
+ opacity: 0,
+ },
grid: {
flexDirection: 'row',
},
@@ -334,7 +409,7 @@ const useStyles = createStyles(({ colors }) => ({
},
cell: {
justifyContent: 'center',
- paddingHorizontal: 6,
+ paddingHorizontal: CELL_PADDING,
},
headText: {
fontSize: 11,