: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
feat(insights): migrate the metric insight to the composable quill Metric (#70220)
Sam Penningtona60981ac010e
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex c00b7a6d18b4..5f20932e40ec 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2733,9 +2733,9 @@ snapshots:insights-insightstable--sql-breakdown--light:hash: v1.k794b7964.710a5fa22da7eff24e97e754426977214d9cdb9fd0252415534110bc7d9bbf95.EmqhUt-YOAWJV1nbFZ2BA-Let9QcaeDgslu9bcPR_mEinsights-metric--default--dark:- hash: v1.k794b7964.1cebe69afb359b708a6769148047246697c99e189310fe55272267130c647782.QYAUjI9RJ3FeBPlsStBw2DGM5gMlabSChpozM9kc48w+ hash: v1.k794b7964.bdc893ac78b0c99cb12fe2d3fa70346f932cccab0ae49df0d8e47e4740224266.KsZ8mkjoktS-Fzlo_tl1EQBX5t3-L0MWAbrR6yO2yCoinsights-metric--default--light:- hash: v1.k794b7964.f3d7a94051dbeb60fc73755c1f3f96e06db2c7b240a4c9226e153db9d9152403.2nDJVbZQAVhYH4dlA12MNwqdLbHYRdEDFHLUGtFkplY+ hash: v1.k794b7964.48725db2ac1e33838b543ca02ec02a9531421ae1b72a906e08769203b062878a.FYtwisigBj0inQ6P1fYQm_mYSl94iSjrfM-o0EKI8S8insights-paths--edit-scene--dark:hash: v1.k794b7964.c10a62416e61fe00c19684959755b06e2a88c87594a1d290d11c9fadcd78fc83.I3vjwPG_Juw_6WMzb3VYtPeeLkGEC6997iPSmY8EbQsinsights-paths--edit-scene--light:diff --git a/frontend/src/scenes/insights/views/Metric/Metric.stories.tsx b/frontend/src/scenes/insights/views/Metric/Metric.stories.tsxindex 755432a67636..b9f9aee018ca 100644--- a/frontend/src/scenes/insights/views/Metric/Metric.stories.tsx+++ b/frontend/src/scenes/insights/views/Metric/Metric.stories.tsx@@ -5,13 +5,13 @@ import { InsightVizStory } from 'scenes/insights/__mocks__/createInsightVizStoryimport __trendsMetric from '~/mocks/fixtures/api/projects/team_id/insights/trendsMetric.json'-import { Metric } from './Metric'+import { MetricCard } from './Metric'type Story = StoryObj<{}>const meta: Meta = {title: 'Insights/Metric',- component: Metric,+ component: MetricCard,parameters: {layout: 'centered',mockDate: '2022-04-01',diff --git a/frontend/src/scenes/insights/views/Metric/Metric.tsx b/frontend/src/scenes/insights/views/Metric/Metric.tsxindex b58b12e5255d..e33fac88ba18 100644--- a/frontend/src/scenes/insights/views/Metric/Metric.tsx+++ b/frontend/src/scenes/insights/views/Metric/Metric.tsx@@ -1,7 +1,15 @@import clsx from 'clsx'import { useValues } from 'kea'-import { MetricCard, useChartTheme } from '@posthog/quill-charts'+import { useChartTheme } from '@posthog/quill-charts'+import {+ Metric,+ MetricDelta,+ MetricHeader,+ MetricSparkline,+ MetricSubtitle,+ MetricValue,+} from '@posthog/quill-components/metric'import { dayjs } from 'lib/dayjs'import { hexToRGBA } from 'lib/utils/colors'@@ -37,7 +45,7 @@ const makeChangeColor = (hex: string): { background: string; foreground: stringforeground: hex,})-export function Metric({ inCardView }: ChartParams): JSX.Element {+export function MetricCard({ inCardView }: ChartParams): JSX.Element {const { insightProps } = useValues(insightLogic)const { insightData, trendsFilter, interval } = useValues(insightVizDataLogic(insightProps))const { incompletenessOffsetFromEnd } = useValues(trendsDataLogic(insightProps))@@ -89,14 +97,10 @@ export function Metric({ inCardView }: ChartParams): JSX.Element {return (<div className={clsx('Metric ph-no-capture flex flex-col w-full p-2', inCardView && 'flex-1')}>- <MetricCard- className={inCardView ? 'flex-1' : undefined}+ <Metric+ className={clsx('px-0', inCardView && 'flex-1')}sparklineFill={inCardView}- // No title — the insight/card header already shows the name.- title={null}value={headlineValue}- changeSize="md"- changeInlinechange={change}changeTooltip={changeTooltip}hoverChangeFromPreviousPoint@@ -112,9 +116,16 @@ export function Metric({ inCardView }: ChartParams): JSX.Element {}sparklineDashedFromIndex={dashedFromIndex}sparklineHeight={120}- sparklineClassName="mt-4 -mx-2"dataAttr="metric-value"- />+ >+ {/* No title — the insight/card header already shows the name; the pill sits inline. */}+ <MetricHeader className="items-center">+ <MetricValue />+ <MetricDelta className="h-auto gap-1 px-2.5 py-1 text-sm [&>svg]:size-3!" />+ </MetricHeader>+ <MetricSubtitle className="mt-1" />+ <MetricSparkline className="mt-4 -mx-2 -mb-2" />+ </Metric></div>)}diff --git a/frontend/src/scenes/trends/Trends.tsx b/frontend/src/scenes/trends/Trends.tsxindex d4a965ec8d17..0ca82c69d17d 100644--- a/frontend/src/scenes/trends/Trends.tsx+++ b/frontend/src/scenes/trends/Trends.tsx@@ -8,7 +8,7 @@ import { lazyWithRetry } from 'lib/utils/retryImport'import { insightLogic } from 'scenes/insights/insightLogic'import { BoldNumber } from 'scenes/insights/views/BoldNumber'import { InsightsTable } from 'scenes/insights/views/InsightsTable/InsightsTable'-import { Metric } from 'scenes/insights/views/Metric/Metric'+import { MetricCard } from 'scenes/insights/views/Metric/Metric'import { InsightVizNode } from '~/queries/schema/schema-general'import { QueryContext } from '~/queries/types'@@ -116,7 +116,7 @@ export function TrendInsight({ view, context, embedded, inSharedMode, editMode }return <BoldNumber {...commonProps} />}if (display === ChartDisplayType.Metric) {- return <Metric {...commonProps} />+ return <MetricCard {...commonProps} />}if (display === ChartDisplayType.ActionsTable) {return (