: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
fix(data-catalog): truncate long values in metric run results (#117170)
Sinan Kucukkoseler4c9b9bc1f91d
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 8be74cb8deaf..43001b83ea03 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2896,6 +2896,14 @@ snapshots:hash: v1.k794b7964.7e808d1acde79b48d8f6c2d7139a9a11e2c33e0579b69636176f4f3b06f0fd94.4U7X0_N-c7UsfP55hsEDM_-nKHMzZYtNczPj2K5penIcustomer-analytics-task-digest--tasks-modal--light:hash: v1.k794b7964.d699105ed3649edc2776b326c0b8417aaf3d6b22573537c1812e5cee2917f13a.yH78vgMSeg2K_yuHa4ej4U_5g6atJd_s4pbbMFhbVlA+ data-catalog-metric-run-result-cell--long-values-collapse--dark:+ hash: v1.k794b7964.dc188a898119faa5dc90aabb8b42f172657e8d18604c5cb4dfecd77f33dcca14.OkK0G4Kc9D5flwW3eKJ24FBFZcaNd7oEQUHyqqLXtqY+ data-catalog-metric-run-result-cell--long-values-collapse--light:+ hash: v1.k794b7964.3c93d03760586dc6ad29f5bbecc790ae71a32adb73b27b407451aff2d013be47.KGjBSg-Nc6WrGErPGI2lyf8Q9jWaU-TnJr5oBI63hbQ+ data-catalog-metric-run-result-cell--long-values-collapse-narrow--dark:+ hash: v1.k794b7964.31b0aad20412006cac1042289e42000bcf9d33eedd04b31660ed76046af9999b.f5qS7fn7tfv7TpUci6SBbLNi_kbaZg1VK0FE22kb5tw+ data-catalog-metric-run-result-cell--long-values-collapse-narrow--light:+ hash: v1.k794b7964.9aa8dcef35291699e28da4dddc121a72afe63c58234aacb2bde52bc664ce6eb6.I_bEwyXTBG0uz_Hq0wBLtozTigTmAS6yf0dInWvo6_Edata-catalog-metric-tests--empty--dark:hash: v1.k794b7964.8c5bed6e45ecc0ce83e4fcb37057c6d87aad0a974e8ed035b9fc9e67a8c1dbd9.jNr2vi0P9-nEfiRddJJjwFg4ZekchSpeyXxdxNfAF1Edata-catalog-metric-tests--empty--light:diff --git a/products/data_catalog/frontend/components/MetricDefinition.tsx b/products/data_catalog/frontend/components/MetricDefinition.tsxindex 11e4ddddb52e..f9810ad2e4fd 100644--- a/products/data_catalog/frontend/components/MetricDefinition.tsx+++ b/products/data_catalog/frontend/components/MetricDefinition.tsx@@ -13,6 +13,7 @@ import { METRIC_MARKDOWN_MAX_LENGTH } from '../common'import { definitionField } from '../dataCatalogMetricSceneLogic'import type { DataCatalogMetricApi } from '../generated/api.schemas'import { MetricMarkdownEditorField } from './MetricMarkdownEditorField'+import { ResultCell } from './ResultCell'import { RunMetricWithAIButton } from './RunMetricWithAIButton'import { Section } from './Section'@@ -280,7 +281,7 @@ function ResultsTable({ results }: { results: unknown }): JSX.Element {columns={keys.map((columnKey) => ({title: columnKey,key: columnKey,- render: (_: unknown, row: Record<string, unknown>) => formatCell(row[columnKey]),+ render: (_: unknown, row: Record<string, unknown>) => <ResultCell value={row[columnKey]} />,}))}size="small"/>@@ -288,10 +289,3 @@ function ResultsTable({ results }: { results: unknown }): JSX.Element {}return <CodeSnippet language={Language.JSON}>{JSON.stringify(results, null, 2)}</CodeSnippet>}--function formatCell(value: unknown): string {- if (value == null) {- return ''- }- return typeof value === 'object' ? JSON.stringify(value) : String(value)-}diff --git a/products/data_catalog/frontend/components/ResultCell.stories.tsx b/products/data_catalog/frontend/components/ResultCell.stories.tsxnew file mode 100644index 000000000000..be3be7a6ce99--- /dev/null+++ b/products/data_catalog/frontend/components/ResultCell.stories.tsx@@ -0,0 +1,57 @@+import type { Meta, StoryObj } from '@storybook/react'++import type { DataCatalogMetricApi } from '../generated/api.schemas'+import { MetricDefinition } from './MetricDefinition'++interface StoryProps {+ narrow?: boolean+}++const days = Array.from({ length: 31 }, (_, index) => `2026-09-${String(index + 1).padStart(2, '0')}`)+const row = {+ data: days.map((_, index) => 100 + ((index * 37) % 300)),+ days,+ count: 8247,+ label: 'example event',+ description: 'Counts every example event that a person sends from the web app, excluding internal test accounts',+ filter: { insight: 'TRENDS', interval: 'day', date_from: '2026-09-01', display: 'ActionsLineGraph' },+}++const metric = {+ id: 'metric-1',+ name: 'example_events',+ definition_kind: 'TrendsQuery',+ definition: { kind: 'TrendsQuery', series: [{ kind: 'EventsNode', event: 'example event' }] },+ status: 'approved',+} as unknown as DataCatalogMetricApi++const meta: Meta<StoryProps> = {+ title: 'Data catalog/Metric run result cell',+ parameters: { viewMode: 'story', testOptions: { waitForSelector: '.react-json-view' } },+ render: ({ narrow }) => (+ <div className={narrow ? 'w-130' : undefined}>+ <MetricDefinition+ metric={metric}+ editingDefinition={false}+ draftMarkdown=""+ saving={false}+ runResult={{ results: [row, { ...row, label: 'second event', count: 12 }] }}+ runResultLoading={false}+ onDraftMarkdown={() => {}}+ onEdit={() => {}}+ onStartEditingMarkdown={() => {}}+ onSaveMarkdown={() => {}}+ onRun={() => {}}+ onRunWithAI={() => {}}+ />+ </div>+ ),+}++export default meta++type Story = StoryObj<StoryProps>++export const LongValuesCollapse: Story = {}++export const LongValuesCollapseNarrow: Story = { args: { narrow: true } }diff --git a/products/data_catalog/frontend/components/ResultCell.tsx b/products/data_catalog/frontend/components/ResultCell.tsxnew file mode 100644index 000000000000..dc2ddf5b6c7c--- /dev/null+++ b/products/data_catalog/frontend/components/ResultCell.tsx@@ -0,0 +1,28 @@+import { Tooltip } from '@posthog/lemon-ui'++import { JSONViewer } from 'lib/components/JSONViewer'++// A trends row carries whole series (`data`, `days`, `filter`), so long values collapse to keep each row one line.+const INLINE_VALUE_MAX_LENGTH = 60++export function ResultCell({ value }: { value: unknown }): JSX.Element | null {+ if (value == null) {+ return null+ }+ const text = typeof value === 'object' ? JSON.stringify(value) : String(value)+ if (text.length <= INLINE_VALUE_MAX_LENGTH) {+ return <>{text}</>+ }+ if (typeof value === 'object') {+ return (+ <div className="w-max max-w-120 overflow-x-auto">+ <JSONViewer src={value} collapsed displayObjectSize />+ </div>+ )+ }+ return (+ <Tooltip title={text}>+ <span className="block max-w-80 truncate">{text}</span>+ </Tooltip>+ )+}diff --git a/products/data_catalog/frontend/components/metricDefinition.test.tsx b/products/data_catalog/frontend/components/metricDefinition.test.tsxindex e338d74ba0c6..fc402c3bd6b0 100644--- a/products/data_catalog/frontend/components/metricDefinition.test.tsx+++ b/products/data_catalog/frontend/components/metricDefinition.test.tsx@@ -5,7 +5,7 @@ import { cleanup, render, screen } from '@testing-library/react'import { initKeaTests } from '~/test/init'import type { DataCatalogMetricApi } from '../generated/api.schemas'-import { MetricDefinition } from './MetricDefinition'+import { DataCatalogMetricRunResult, MetricDefinition } from './MetricDefinition'const SOURCE_INSIGHT_ACTION = 'View source insight'@@ -24,14 +24,14 @@ function buildMetric(overrides: Partial<DataCatalogMetricApi> = {}): DataCatalog} as DataCatalogMetricApi}-function renderDefinition(metric: DataCatalogMetricApi): void {+function renderDefinition(metric: DataCatalogMetricApi, runResult: DataCatalogMetricRunResult | null = null): void {render(<MetricDefinitionmetric={metric}editingDefinition={false}draftMarkdown=""saving={false}- runResult={null}+ runResult={runResult}runResultLoading={false}onDraftMarkdown={jest.fn()}onEdit={jest.fn()}@@ -70,4 +70,12 @@ describe('MetricDefinition', () => {expect(screen.queryByText(SOURCE_INSIGHT_ACTION)).not.toBeInTheDocument()expect(screen.getByText('View definition')).toBeInTheDocument()})++ it('keeps long result values out of the table cell', () => {+ const days = Array.from({ length: 31 }, (_, index) => `2026-01-${String(index + 1).padStart(2, '0')}`)+ renderDefinition(buildMetric(), { results: [{ days, count: 42 }] })++ expect(screen.getByText('42')).toBeInTheDocument()+ expect(screen.queryByText(JSON.stringify(days))).not.toBeInTheDocument()+ })})