: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(insights): keep home sample labels inside cards (#116910)
Daniel Parkere9f815a9ced9
diff --git a/docs/published/handbook/engineering/conventions/frontend-coding.md b/docs/published/handbook/engineering/conventions/frontend-coding.mdindex 47de6f8fc0d5..da723bd7a320 100644--- a/docs/published/handbook/engineering/conventions/frontend-coding.md+++ b/docs/published/handbook/engineering/conventions/frontend-coding.md@@ -40,7 +40,7 @@ Hence the explicit separation between the data and view layers.- Reach for an existing design-system component (Lemon/quill) before hand-rolling markup — reuse is how new UI stays on-brand. When you genuinely need a custom component, build it from the system's tokens and primitives and match the surrounding scene's density; avoid the generic AI-generated look (purple gradients, glassmorphism, gradient text, icon-tile card grids, decorative motion).- Before building new UI, read a few comparable scenes or components and model yours on the ones that follow these conventions. The codebase contains legacy that predates them — an existing violation is not license to repeat it. Conventions outrank precedent, and compliant precedent outranks invention.- Extract a shared component once the same shape appears in several places and the call sites read as content, not markup. Keep new generics next to the feature that uses them, and promote to `lib/` only when a second feature needs them. Don't build wrappers with a single consumer, and don't add boolean variant props so one caller can switch half the component off — that's two components.- - Analytics overview cards in the LemonUI web app share `lib/components/AnalyticsMetricCard/AnalyticsMetricCard`. It wraps the chart library metric content with a consistent surface and loading, error, and empty states. Supply `data` and `theme` for a sparkline, `showChange` for comparisons, and `onClick` for a native button with a navigation chevron. `selected` highlights a card that controls the displayed chart and removes the navigation chevron. The hover border and focus ring show that the card is interactive. Quill surfaces can compose `Metric` with `Card` instead.+ - Analytics overview cards in the LemonUI web app share `lib/components/AnalyticsMetricCard/AnalyticsMetricCard`. It wraps the chart library metric content with a consistent surface and loading, error, and empty states. Supply `data` and `theme` for a sparkline, `showChange` for comparisons, and `onClick` for a native button with a navigation chevron. `selected` highlights a card that controls the displayed chart and removes the navigation chevron. The hover border and focus ring show that the card is interactive. For sample metrics, put `SampleDataTag` inside the card with `adornment`. Put the same tag in chart headers. Keep the cards outside `SampleDataState`, which animates its content. Quill surfaces can compose `Metric` with `Card` instead.- Interactive elements are real `<button>`/`<a>` elements (`LemonButton` renders one) — never `onClick` on a `<div>`.- With `focusBasedKeyboardNavigation` enabled, `LemonMenu` moves focus between its trigger and menu items with the arrow keys, including after the menu reopens. Custom triggers must forward `onFocus` and `onKeyDown` to preserve keyboard navigation and focus return.- Loading, empty, and error are three different screens. Never show an empty state from data that hasn't resolved yet — branch on the loading state first.diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex ad4da97c4f3e..30e9bf31cfba 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -2536,6 +2536,10 @@ snapshots:hash: v1.k794b7964.5f13bf50d33b9d3257d8a93eea04dc06edfc31a86ac947e74fc7f32ff23750da.vV-ots4x1jS78n1arxGnPxkVZ2x3hiQSekk9XBwvvdocomponents-sample-data-state--wizard-installing--light:hash: v1.k794b7964.2052c49beff2e0a5c5c533ae05c73bacc2619a04053b4529acf93574160c3a66.sTXp62J02o4EVCFfSt9_QV7YwS6UN87FpVxkPGrmZ3o+ components-sample-data-tag--default--dark:+ hash: v1.k794b7964.59c7a8b6d1d563565a9f3efa7c9bac27a87225ec9bee0021e0b80e5420783056.9w3awIuhlR02uWkYgTVenAzkCRqWD4s20qdlLzfmwnw+ components-sample-data-tag--default--light:+ hash: v1.k794b7964.8ebad648dbf23b4ccf50c7b2543d02e9429c2f5c67446cee8823fc06fc98a97d.MSu4A4yz_nNpo8sN007sucqXSdbb7pJQExT5Z2ki0Yscomponents-search--default--dark:hash: v1.k794b7964.da49a8420c703e68e52fc9091f69cbe6f9b145bbdae11bef03d31e3523168cac.iQUGfMwL8k8_L-SfZAShZ6S6gLXnlrhUWMVZf01c16Mcomponents-search--default--light:@@ -13523,9 +13527,9 @@ snapshots:scenes-app-product-analytics-home-dashboard-starter--with-custom-dashboard--light:hash: v1.k794b7964.3955f90c8826d28cbc8ea87ae21c2736e2ff3b67999586e1901969a2a11a7acb.YjXt5UQ0a2xK9iFx0IGxA9lIQFU4q66REMcDhWsHAXsscenes-app-product-analytics-home-overview--before-ingestion--dark:- hash: v1.k794b7964.48b65f3dbe882c551df657d0b9a78332819528de6691037310e456bdf6e0b71a.JmauGDlQzy9IlkbJbj6jdII20poToLzHc7PUreuu7hc+ hash: v1.k794b7964.c9c3a3bcad0d8d6b1978454f6b7425e931171755e46d4422f9483a3f3e9d7066.OrUa2KPTzEeViZagRu3IMyexInpaS4_kRvrSd1LnKmkscenes-app-product-analytics-home-overview--before-ingestion--light:- hash: v1.k794b7964.2321ed939beecdb0220b228d4adf80ec5bd5cd0a2317116c7a32c503dacb1dcd.r7oXDGw5c-_yRvT4Q66seo1sfW7h1e_GZY9NK5VYANM+ hash: v1.k794b7964.dbfafea3a0fa32deb41e802b69cff725b8851cec68293425419d719b1b37833b.MIpMguoTmAH-TuOqNYcoRIWvP6gO_22SHLcL6CDk_Mcscenes-app-product-analytics-home-overview--empty--dark:hash: v1.k794b7964.803d51407dca494e41d04f4cb5fb324abd193b22d9cad2b60b92087ec1bf76b5.nESq7Ay6ngu1UriAYHASMUKdnt6lU8FQZwgXkFcizKwscenes-app-product-analytics-home-overview--empty--light:diff --git a/frontend/src/scenes/insights/EmptyStates/SampleDataState.tsx b/frontend/src/scenes/insights/EmptyStates/SampleDataState.tsxindex 19bc5a19e16e..fb5eb5f47535 100644--- a/frontend/src/scenes/insights/EmptyStates/SampleDataState.tsx+++ b/frontend/src/scenes/insights/EmptyStates/SampleDataState.tsx@@ -17,12 +17,13 @@ import type {import { useChartTheme } from 'lib/charts/hooks'import { CommandBlock } from 'lib/components/CommandBlock/CommandBlock'-import { Link } from 'lib/lemon-ui/Link'import { inStorybook, inStorybookTestRunner } from 'lib/utils/dom'import { humanFriendlyNumber } from 'lib/utils/numbers'import { setupWizardStatusLogic } from 'scenes/onboarding/shared/setupWizardStatusLogic'import { useWizardCommand } from 'scenes/onboarding/shared/useWizardCommand'+import { SampleDataTag } from './SampleDataTag'+export type SampleDataVariant = 'line' | 'bar' | 'pie' | 'proportionBar' | 'funnel' | 'number' | 'table'const WEEK_LABELS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']@@ -139,47 +140,6 @@ function SampleChart({ variant }: { variant: Exclude<SampleDataVariant, 'number')}-function SampleDataTooltipContent(): JSX.Element {- const { setupStatus } = useValues(setupWizardStatusLogic)-- return (- <div className="max-w-72 space-y-1.5 p-0.5">- <div className="font-semibold">This is sample data</div>- <p className="m-0">- This project hasn't received any events yet - you'll see your real data here as soon as events start- coming in.- </p>- {setupStatus?.kind === 'installing' &&- (setupStatus.mode === 'cloud' ? (- <p className="m-0">- The setup wizard is installing PostHog in your codebase. Once it's done, it will open a pull- request for you to merge.- </p>- ) : (- <p className="m-0">- The setup wizard is installing PostHog in your codebase. You'll see real data here soon after- it's done.- </p>- ))}- {setupStatus?.kind === 'pull_request' &&- (setupStatus.pullRequest.merged ? (- <p className="m-0">- Your setup pull request is merged. Once the updated code is live and sending events, this chart- will fill in automatically.- </p>- ) : (- <p className="m-0">- Your setup pull request hasn't been merged yet -{' '}- <Link to={setupStatus.pullRequest.url} target="_blank" targetBlankIcon>- merge it- </Link>{' '}- to start sending events.- </p>- ))}- </div>- )-}-/** Obviously-fake placeholder chart shown instead of an empty state before a project has ingested any events. */export function SampleDataState({variant = 'line',@@ -262,11 +222,7 @@ export function SampleDataState({</span></Tooltip>)}- <Tooltip title={<SampleDataTooltipContent />} interactive delayMs={100} placement="bottom">- <LemonTag className="cursor-help" type="muted">- Sample data- </LemonTag>- </Tooltip>+ <SampleDataTag /></div><div className={clsx('SampleDataState__viz', children && 'SampleDataState__viz--custom')}>{children ??diff --git a/frontend/src/scenes/insights/EmptyStates/SampleDataTag.stories.tsx b/frontend/src/scenes/insights/EmptyStates/SampleDataTag.stories.tsxnew file mode 100644index 000000000000..d3473e71acac--- /dev/null+++ b/frontend/src/scenes/insights/EmptyStates/SampleDataTag.stories.tsx@@ -0,0 +1,13 @@+import type { Meta, StoryObj } from '@storybook/react'++import { SampleDataTag } from './SampleDataTag'++const meta: Meta<typeof SampleDataTag> = {+ component: SampleDataTag,+ title: 'Components/Sample Data Tag',+}+export default meta++type Story = StoryObj<typeof SampleDataTag>++export const Default: Story = {}diff --git a/frontend/src/scenes/insights/EmptyStates/SampleDataTag.tsx b/frontend/src/scenes/insights/EmptyStates/SampleDataTag.tsxnew file mode 100644index 000000000000..5b56a2b7b386--- /dev/null+++ b/frontend/src/scenes/insights/EmptyStates/SampleDataTag.tsx@@ -0,0 +1,54 @@+import { useValues } from 'kea'++import { LemonTag, Tooltip } from '@posthog/lemon-ui'++import { Link } from 'lib/lemon-ui/Link'+import { setupWizardStatusLogic } from 'scenes/onboarding/shared/setupWizardStatusLogic'++export function SampleDataTag(): JSX.Element {+ const { setupStatus } = useValues(setupWizardStatusLogic)++ const content = (+ <div className="max-w-72 space-y-1.5 p-0.5">+ <div className="font-semibold">This is sample data</div>+ <p className="m-0">+ This project hasn't received any events yet - you'll see your real data here as soon as events start+ coming in.+ </p>+ {setupStatus?.kind === 'installing' &&+ (setupStatus.mode === 'cloud' ? (+ <p className="m-0">+ The setup wizard is installing PostHog in your codebase. Once it's done, it will open a pull+ request for you to merge.+ </p>+ ) : (+ <p className="m-0">+ The setup wizard is installing PostHog in your codebase. You'll see real data here soon after+ it's done.+ </p>+ ))}+ {setupStatus?.kind === 'pull_request' &&+ (setupStatus.pullRequest.merged ? (+ <p className="m-0">+ Your setup pull request is merged. Once the updated code is live and sending events, this chart+ will fill in automatically.+ </p>+ ) : (+ <p className="m-0">+ Your setup pull request hasn't been merged yet -{' '}+ <Link to={setupStatus.pullRequest.url} target="_blank" targetBlankIcon>+ merge it+ </Link>{' '}+ to start sending events.+ </p>+ ))}+ </div>+ )+ return (+ <Tooltip title={content} interactive delayMs={100} placement="bottom">+ <LemonTag data-attr="insight-sample-data-tag" className="cursor-help" type="muted">+ Sample data+ </LemonTag>+ </Tooltip>+ )+}diff --git a/products/product_analytics/frontend/insights/home/HomeTabChartCard.tsx b/products/product_analytics/frontend/insights/home/HomeTabChartCard.tsxindex 541b429585d6..b1001791a1d3 100644--- a/products/product_analytics/frontend/insights/home/HomeTabChartCard.tsx+++ b/products/product_analytics/frontend/insights/home/HomeTabChartCard.tsx@@ -7,8 +7,8 @@ import { IconInfo } from '@posthog/icons'import { LemonButton, LemonCard } from '@posthog/lemon-ui'import { Tooltip } from 'lib/lemon-ui/Tooltip'-import { SampleDataState } from 'scenes/insights/EmptyStates/SampleDataState'import { sampleDataStateLogic } from 'scenes/insights/EmptyStates/sampleDataStateLogic'+import { SampleDataTag } from 'scenes/insights/EmptyStates/SampleDataTag'import { teamLogic } from 'scenes/teamLogic'import { Query } from '~/queries/Query/Query'@@ -65,6 +65,7 @@ export function HomeTabChartCard({ option, size, control, source }: HomeTabChart)}</div><div className="flex flex-wrap items-center gap-1">+ {sampleData && <SampleDataTag />}{control}<LemonButtontype="tertiary"@@ -83,7 +84,7 @@ export function HomeTabChartCard({ option, size, control, source }: HomeTabChart<divclassName={`HomeTabDefaultChart HomeTabChartCard__visualization HomeTabChartCard__visualization--${size}`}>- {sampleData ? <SampleDataState>{chart}</SampleDataState> : chart}+ {chart}</div></LemonCard>)diff --git a/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx b/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsxindex e8e1e8676492..ead9633f8041 100644--- a/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx+++ b/products/product_analytics/frontend/insights/home/HomeTabDefault.test.tsx@@ -172,7 +172,7 @@ describe('HomeTabDefault query reuse', () => {const { container } = render(<HomeTabDefault />)await waitFor(() =>- expect(container.querySelectorAll('[data-attr="insight-sample-data-state"]')).toHaveLength(11)+ expect(container.querySelectorAll('[data-attr="insight-sample-data-tag"]')).toHaveLength(11))for (const tile of container.querySelectorAll('[data-attr^="home-tab-metric-"]')) {expect(tile).toHaveAttribute('aria-busy', 'false')@@ -189,7 +189,7 @@ describe('HomeTabDefault query reuse', () => {})await waitFor(() => expect(mockedQuery).toHaveBeenCalledTimes(14))- expect(container.querySelector('[data-attr="insight-sample-data-state"]')).toBeNull()+ expect(container.querySelector('[data-attr="insight-sample-data-tag"]')).toBeNull()await waitFor(() =>expect(within(screen.getByLabelText('Sessions', { selector: 'button' })).getByText('10')diff --git a/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx b/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsxindex 327800fd648c..efdaf213da19 100644--- a/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx+++ b/products/product_analytics/frontend/insights/home/HomeTabStatTile.tsx@@ -6,8 +6,8 @@ import { AnalyticsMetricCard } from 'lib/components/AnalyticsMetricCard/Analyticimport { Tooltip } from 'lib/lemon-ui/Tooltip'import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'import { formatBucketLabel } from 'lib/utils/timeBuckets'-import { SampleDataState } from 'scenes/insights/EmptyStates/SampleDataState'import { sampleDataStateLogic } from 'scenes/insights/EmptyStates/sampleDataStateLogic'+import { SampleDataTag } from 'scenes/insights/EmptyStates/SampleDataTag'import { teamLogic } from 'scenes/teamLogic'import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'@@ -101,9 +101,16 @@ export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabSt? 'No previous period data': `vs. ${formatItem(previousValue, stat.kind)} prior`- const card = (+ return (<AnalyticsMetricCardclassName="h-full w-full"+ adornment={+ shouldShowSampleData ? (+ <div className="flex justify-end px-3 pb-3">+ <SampleDataTag />+ </div>+ ) : undefined+ }title={label}ariaLabel={stat.title}onClick={onSelect}@@ -127,6 +134,4 @@ export function HomeTabStatTile({ stat, compare, selected, onSelect }: HomeTabStrestingSubtitle={<span translate="no">{subtitle}</span>}/>)-- return shouldShowSampleData ? <SampleDataState>{card}</SampleDataState> : card}