: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(mcp-analytics): dash the in-progress bucket on the KPI sparklines (#75889)
Georgis Andonisac4739c33759
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex fb4ed44be54b..009a3d4ca0ce 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -6502,6 +6502,10 @@ snapshots:hash: v1.k794b7964.c43bf4fc139c60f91e2bbe9f160077ebe7678b23bfbb86cc23ffb7e610cf510a.cYi4muc-vdYm66DM_ooUC9daJDJ7FJlH9dgETasyR68scenes-app-mcp-analytics-dashboard-cards--key-metrics--light:hash: v1.k794b7964.e44175ae2c238669a74dd8aec65a9a30e46a9bb1f7f75065d9f5a6c95e4d226b.PMsDqcVriwdb3Q7xvz70gU_edbqDUiMp-o5p_vdn7SI+ scenes-app-mcp-analytics-dashboard-cards--key-metrics-in-progress-bucket--dark:+ hash: v1.k794b7964.e2688d6015e59ab3c4591b183f0dfc5f63b664c884c0c84da49dad113b1b5ec6.3o0fDZhH1au5zqzAax1ESTjpZyuZoRto4W6bBJ2Cbfc+ scenes-app-mcp-analytics-dashboard-cards--key-metrics-in-progress-bucket--light:+ hash: v1.k794b7964.987a4b9f762bab3f88f39ea33fb0eca000d0e5f6aeb2c0a89e2979399f4d5797.ziZ_6D2TpdPk2pVJqrCMfEcmRufZDVVVqN51I5vIHgMscenes-app-mcp-analytics-dashboard-cards--share-by-harness--dark:hash: v1.k794b7964.a4f65ae92d92d3600674689dc61f5ba834aac470154fb26b82821cb17b12cada.vAYLkto1-GBp1WeHETUeB5R0Pljn-RwHDW9h3bib1KQscenes-app-mcp-analytics-dashboard-cards--share-by-harness--light:diff --git a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsxindex acf1b729d3a0..1b785abdc807 100644--- a/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx+++ b/products/mcp_analytics/frontend/MCPAnalyticsDashboardOverview.tsx@@ -31,6 +31,7 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {dailyActivity,activityRowsLoading,activityIncompleteTail,+ kpiIncompleteTail,toolDailySeries,toolDailyRowsLoading,toolRows,@@ -90,6 +91,7 @@ export function MCPAnalyticsDashboardOverview(): JSX.Element {kpisLoading={kpisLoading}usersLoading={usersLoading}theme={theme}+ incompleteTail={kpiIncompleteTail}/></section><section data-quill>diff --git a/products/mcp_analytics/frontend/dashboard/DashboardCards.stories.tsx b/products/mcp_analytics/frontend/dashboard/DashboardCards.stories.tsxindex 879da3488ccf..e90247b397b3 100644--- a/products/mcp_analytics/frontend/dashboard/DashboardCards.stories.tsx+++ b/products/mcp_analytics/frontend/dashboard/DashboardCards.stories.tsx@@ -155,6 +155,23 @@ export const KeyMetrics: Story = {kpisLoading={false}usersLoading={false}theme={buildTheme()}+ incompleteTail={false}+ />+ </div>+ ),+}++export const KeyMetricsInProgressBucket: Story = {+ render: () => (+ <div className="w-[960px]">+ <KpiTiles+ kpis={KPIS}+ users={metric(1840, 1655, [], 'up')}+ intentClusterCount={metric(6, 0, [], 'up')}+ kpisLoading={false}+ usersLoading={false}+ theme={buildTheme()}+ incompleteTail/></div>),diff --git a/products/mcp_analytics/frontend/dashboard/KpiTiles.tsx b/products/mcp_analytics/frontend/dashboard/KpiTiles.tsxindex 0e41c7ae651d..68ab287abd31 100644--- a/products/mcp_analytics/frontend/dashboard/KpiTiles.tsx+++ b/products/mcp_analytics/frontend/dashboard/KpiTiles.tsx@@ -21,8 +21,18 @@ interface TileSpec {subtitle?: string}-function KPITile({ tile, theme }: { tile: TileSpec; theme: ChartTheme }): JSX.Element {+function KPITile({+ tile,+ theme,+ incompleteTail,+}: {+ tile: TileSpec+ theme: ChartTheme+ incompleteTail: boolean+}): JSX.Element {const { metric } = tile+ // Tiles whose metric carries no sparkline (Users, Intent clusters) have no segment to dash.+ const dashedFromIndex = incompleteTail && metric.sparkline.length >= 2 ? metric.sparkline.length - 1 : undefinedreturn (<Link to={tile.href} subtle className="group/tile flex h-full">@@ -46,6 +56,7 @@ function KPITile({ tile, theme }: { tile: TileSpec; theme: ChartTheme }): JSX.ElhoverChangeFromPreviousPointrestingSubtitle={tile.subtitle ?? tile.summaryLabel}sparklineHeight={50}+ sparklineDashedFromIndex={dashedFromIndex}/></Link>)@@ -58,6 +69,7 @@ export function KpiTiles({kpisLoading,usersLoading,theme,+ incompleteTail,}: {kpis: KPIDatausers: KPIMetric@@ -65,6 +77,10 @@ export function KpiTiles({kpisLoading: booleanusersLoading: booleantheme: ChartTheme+ // When true, the sparklines' final point is the current in-progress interval — dash it so a+ // partial period doesn't read as a decline. Required rather than optional: an omitted prop+ // silently renders the partial bucket as settled data.+ incompleteTail: boolean}): JSX.Element {const tiles: TileSpec[] = [{@@ -135,7 +151,7 @@ export function KpiTiles({<div className="@container"><div className="grid grid-cols-2 gap-3 @xl:grid-cols-3 @6xl:grid-cols-6">{tiles.map((tile) => (- <KPITile key={tile.label} tile={tile} theme={theme} />+ <KPITile key={tile.label} tile={tile} theme={theme} incompleteTail={incompleteTail} />))}</div></div>diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.tsindex 463f721eda81..a4eacdde667d 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.test.ts@@ -24,6 +24,7 @@ import {type SessionRow,type ToolDailyRow,} from './mcpDashboardOverviewLogic'+import { BUCKET_FORMAT } from './timeBuckets'jest.mock('lib/api')jest.mock('./generated/api', () => ({@@ -391,6 +392,39 @@ describe('mcpDashboardOverviewLogic', () => {})})+ describe('kpiIncompleteTail', () => {+ beforeEach(() => {+ jest.clearAllMocks()+ initKeaTests()+ jest.spyOn(mockApi, 'query').mockResolvedValue({ results: [] })+ })++ // Reads the sparkline's own labels rather than the zero-filled axis: on a day with no calls+ // yet the KPI series stops at yesterday, which is settled, so dashing its last point would+ // mark a complete bucket as in progress.+ it('tracks the KPI sparkline labels, not the chart axis', async () => {+ const logic = mcpDashboardOverviewLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()++ const bucket = (daysAgo: number): string =>+ dayjs().tz(logic.values.timezone).subtract(daysAgo, 'day').startOf('day').format(BUCKET_FORMAT)+ const row = (daysAgo: number): BucketRow => ({+ bucket: bucket(daysAgo),+ sessions: 3,+ tool_calls: 30,+ errors: 1,+ p95: 100,+ })++ logic.actions.loadKPIsSuccess(buildKPIs([row(1), row(0)], bucket(1)))+ expect(logic.values.kpiIncompleteTail).toBe(true)++ logic.actions.loadKPIsSuccess(buildKPIs([row(3), row(2)], bucket(3)))+ expect(logic.values.kpiIncompleteTail).toBe(false)+ })+ })+describe('filter wiring', () => {beforeEach(() => {jest.clearAllMocks()diff --git a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.tsindex 1eef39ccdc31..9801102aaf83 100644--- a/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts+++ b/products/mcp_analytics/frontend/mcpDashboardOverviewLogic.ts@@ -406,6 +406,7 @@ export interface mcpDashboardOverviewLogicValues {harnessRowsLoading: booleanintentClusterCount: KPIMetricinterval: IntervalType+ kpiIncompleteTail: booleankpis: KPIDatakpisLoading: booleannotableSessions: NotableSession[]@@ -602,6 +603,7 @@ export interface mcpDashboardOverviewLogicMeta {interval: (dateFilter: DateFilter) => IntervalTypebucketKeys: (dateFilter: DateFilter, timezone: string, interval: IntervalType) => string[]activityIncompleteTail: (bucketKeys: string[], timezone: string, interval: IntervalType) => boolean+ kpiIncompleteTail: (kpis: KPIData, timezone: string, interval: IntervalType) => booleandailyActivity: (activityRows: ActivityRow[], bucketKeys: string[]) => DailyActivitytoolDailySeries: (toolDailyRows: ToolDailyRow[], bucketKeys: string[]) => ToolDailySeriesnotableSessions: (sessionRows: SessionRow[]) => NotableSession[]@@ -852,6 +854,13 @@ export const mcpDashboardOverviewLogic = kea<mcpDashboardOverviewLogicType>([(bucketKeys: string[], timezone: string, interval: IntervalType): boolean =>lastBucketIsInProgress(bucketKeys, timezone, interval),],+ // Read off the KPI sparkline's own labels, not `bucketKeys`: the sparkline is not zero-filled,+ // so on a day with no calls yet its last point is yesterday, which is settled.+ kpiIncompleteTail: [+ (s) => [s.kpis, s.timezone, s.interval],+ (kpis: KPIData, timezone: string, interval: IntervalType): boolean =>+ lastBucketIsInProgress(kpis.sessions.sparklineLabels, timezone, interval),+ ],dailyActivity: [(s) => [s.activityRows, s.bucketKeys],(rows: ActivityRow[], bucketKeys: string[]): DailyActivity => buildDailyActivity(rows, bucketKeys),