: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(today): show number titles while values load (#127513)
Shy Alter9b6abb84883d
diff --git a/frontend/src/scenes/project-homepage/today/Today.stories.tsx b/frontend/src/scenes/project-homepage/today/Today.stories.tsxindex 67e98495249b..fd43b7d5c1e8 100644--- a/frontend/src/scenes/project-homepage/today/Today.stories.tsx+++ b/frontend/src/scenes/project-homepage/today/Today.stories.tsx@@ -885,6 +885,7 @@ const meta: Meta = {'/api/projects/:team_id/dashboards/': { results: DASHBOARDS, count: DASHBOARDS.length },},post: {+ '/api/projects/:team_id/file_system/home_folder/': { id: 'home-folder', path: 'Home' },'/api/environments/:team_id/query/:kind/': reportMetricQueryHandler,'/api/projects/:team_id/signals/reports/:id/state/': (req) => [200,@@ -1316,3 +1317,104 @@ export const ListItemAppearanceDialog: Story = {await within(document.body).findByText('Edit list item appearance')},}++export const HomePulseLoading: Story = {+ decorators: [+ mswDecorator({+ get: {+ '/api/projects/:team_id/today/highlights/': {+ ...HIGHLIGHTS,+ status: 'computing',+ generated_at: null,+ pulse: [],+ items: [],+ },+ },+ }),+ ],+ parameters: { testOptions: { waitForLoadersToDisappear: false } },+}++export const HomePulsePartial: Story = {+ decorators: [+ mswDecorator({+ get: {+ '/api/projects/:team_id/today/highlights/': {+ ...HIGHLIGHTS,+ status: 'computing',+ pulse: HIGHLIGHTS.pulse.slice(0, 1),+ items: [],+ },+ },+ }),+ ],+ parameters: { testOptions: { waitForLoadersToDisappear: false } },+}++export const HomePulseTitlesLoading: Story = {+ decorators: [+ mswDecorator({+ get: {+ '/api/projects/:team_id/today/highlights/': {+ ...HIGHLIGHTS,+ status: 'computing',+ pulse: [],+ items: [],+ pulse_slots: HIGHLIGHTS.pulse.slice(0, 4).map((metric) => ({+ key: metric.key,+ name: metric.name,+ url: metric.url,+ interval: metric.interval,+ status: 'pending',+ })),+ },+ },+ }),+ ],+ parameters: { testOptions: { waitForLoadersToDisappear: false } },+}++export const HomePulseMixed: Story = {+ decorators: [+ mswDecorator({+ get: {+ '/api/projects/:team_id/today/highlights/': {+ ...HIGHLIGHTS,+ status: 'computing',+ pulse: HIGHLIGHTS.pulse.slice(0, 1),+ items: [],+ pulse_slots: HIGHLIGHTS.pulse.slice(0, 4).map((metric, i) => ({+ key: metric.key,+ name: metric.name,+ url: metric.url,+ interval: metric.interval,+ status: i === 0 ? 'ready' : 'pending',+ })),+ },+ },+ }),+ ],+ parameters: { testOptions: { waitForLoadersToDisappear: false } },+}++export const HomePulseEmptyAndError: Story = {+ decorators: [+ mswDecorator({+ get: {+ '/api/projects/:team_id/today/highlights/': {+ ...HIGHLIGHTS,+ status: 'ready',+ pulse: HIGHLIGHTS.pulse.slice(0, 2),+ items: [],+ pulse_slots: HIGHLIGHTS.pulse.slice(0, 4).map((metric, i) => ({+ key: metric.key,+ name: metric.name,+ url: metric.url,+ interval: metric.interval,+ status: i < 2 ? 'ready' : i === 2 ? 'empty' : 'error',+ })),+ },+ },+ }),+ ],+}diff --git a/frontend/src/scenes/project-homepage/today/TodayHomePage.test.tsx b/frontend/src/scenes/project-homepage/today/TodayHomePage.test.tsxindex 6fac754d4ccd..28b4a4fee1f7 100644--- a/frontend/src/scenes/project-homepage/today/TodayHomePage.test.tsx+++ b/frontend/src/scenes/project-homepage/today/TodayHomePage.test.tsx@@ -1,5 +1,10 @@-import { cleanup, render } from '@testing-library/react'+import '@testing-library/jest-dom'++import { cleanup, render, screen, within } from '@testing-library/react'import { useActions, useValues } from 'kea'+import type { ReactNode } from 'react'++import type { PulseSlotApi } from 'products/today/frontend/generated/api.schemas'import { TodayHomePage } from './TodayHomePage'import { todayLogic } from './todayLogic'@@ -11,9 +16,12 @@ jest.mock('./todayHighlightsLogic', () => ({ todayHighlightsLogic: {} }))jest.mock('./TodaySampleBanner', () => ({ TodaySampleBanner: () => null }))jest.mock('./TodayForYou', () => ({ TodayForYou: () => null }))jest.mock('./TodayRecents', () => ({ TodayRecents: () => null }))-jest.mock('./TodayPulse', () => ({ TodayPulse: () => null }))+jest.mock('./TodayPulseHoverCard', () => ({+ TodayPulseHoverCard: ({ children }: { children: ReactNode }) => <>{children}</>,+}))+jest.mock('./TodaySparkline', () => ({ TodaySparkline: () => null }))-describe('TodayHomePage load measurement', () => {+describe('TodayHomePage loading', () => {afterEach(cleanup)it('evaluates existing numbers when leaving sample mode', () => {@@ -51,4 +59,61 @@ describe('TodayHomePage load measurement', () => {expect(actions.pulseViewMounted).toHaveBeenLastCalledWith(false)expect(actions.pulseViewUpdated).toHaveBeenCalledTimes(1)})+ it('replaces only a completed number and keeps the other named loaders in place', () => {+ const metrics = ['Sign-ups', 'Payments', 'Active users', 'Uploads'].map((name, i) =>+ makePulseMetric({ key: `number:${i}`, name, value: i === 1 ? 0 : 120 })+ )+ const slots: PulseSlotApi[] = metrics.map((metric) => ({+ key: metric.key,+ name: metric.name,+ url: metric.url,+ interval: metric.interval,+ status: 'pending',+ }))+ const home = {+ greeting: 'Hello',+ now: Date.now(),+ isNewProject: false,+ recentObjects: [],+ returnFocusReportId: null,+ useSampleData: false,+ }+ const numbers = {+ currentProjectId: 1,+ highlights: makeHighlights({ status: 'computing', pulse_slots: slots }),+ highlightsLoading: false,+ highlightsFailed: false,+ highlightsPending: false,+ pulsePending: false,+ pulseTiles: [] as typeof metrics,+ pulseSlots: slots,+ }+ const actions = {+ setReturnFocusReportId: jest.fn(),+ pulseViewMounted: jest.fn(),+ pulseViewUpdated: jest.fn(),+ pulseViewUnmounted: jest.fn(),+ }+ jest.mocked(useValues).mockImplementation((logic) => (logic === todayLogic ? home : numbers))+ jest.mocked(useActions).mockImplementation(() => actions)+ const view = render(<TodayHomePage />)+ const list = screen.getByRole('list')+ const cards = within(list).getAllByRole('listitem')+ expect(cards.map((card) => card.getAttribute('aria-label'))).toEqual(+ metrics.map((metric) => `${metric.name}: Loading`)+ )+ expect(cards.every((card) => card.getAttribute('aria-busy') === 'true')).toBe(true)++ numbers.pulseTiles = [metrics[1]]+ numbers.pulseSlots = slots.map((slot, i) => ({ ...slot, status: i === 1 ? 'ready' : 'pending' }))+ view.rerender(<TodayHomePage />)++ expect(within(list).getAllByRole('listitem')).toEqual(cards)+ expect(within(cards[1]).getByText('0')).toBeVisible()+ expect(cards[1]).not.toHaveAttribute('aria-busy', 'true')+ expect([cards[0], cards[2], cards[3]].every((card) => card.getAttribute('aria-busy') === 'true')).toBe(true)+ expect(metrics.map((metric) => within(list).getByText(metric.name).textContent)).toEqual(+ metrics.map((metric) => metric.name)+ )+ })})diff --git a/frontend/src/scenes/project-homepage/today/TodayHomePage.tsx b/frontend/src/scenes/project-homepage/today/TodayHomePage.tsxindex ba3fd1c35231..8ddd6f4c59ec 100644--- a/frontend/src/scenes/project-homepage/today/TodayHomePage.tsx+++ b/frontend/src/scenes/project-homepage/today/TodayHomePage.tsx@@ -59,6 +59,7 @@ export function TodayHomePage(): JSX.Element {highlightsPending,pulsePending,pulseTiles,+ pulseSlots,} = useValues(todayHighlightsLogic)const { pulseViewMounted, pulseViewUpdated, pulseViewUnmounted } = useActions(todayHighlightsLogic)const rootRef = useRef<HTMLDivElement>(null)@@ -77,6 +78,7 @@ export function TodayHomePage(): JSX.Element {highlightsPending,pulsePending,pulseTiles,+ pulseSlots,pulseViewUpdated,currentProjectId,useSampleData,@@ -122,8 +124,8 @@ export function TodayHomePage(): JSX.Element {<div className="TodayHome__body">{pulsePending ? (<TodayPulseSkeleton />- ) : highlights && pulseTiles.length > 0 ? (- <TodayPulse metrics={pulseTiles} />+ ) : highlights && pulseSlots?.length > 0 ? (+ <TodayPulse metrics={pulseTiles} slots={pulseSlots} />) : highlights?.status === 'ready' ? (<Text size="sm" variant="muted" render={<p />} className="m-0">Key numbers show here when you or your team open a few trend insights.diff --git a/frontend/src/scenes/project-homepage/today/TodayPulse.tsx b/frontend/src/scenes/project-homepage/today/TodayPulse.tsxindex 4b7fb8d9e0e6..c706a7a4789c 100644--- a/frontend/src/scenes/project-homepage/today/TodayPulse.tsx+++ b/frontend/src/scenes/project-homepage/today/TodayPulse.tsx@@ -1,6 +1,8 @@import { useActions, useValues } from 'kea'import { type RefObject, Suspense, lazy, useLayoutEffect, useRef } from 'react'+import { Button, Skeleton, Text } from '@posthog/quill'+import { dayjs } from 'lib/dayjs'import { formatAggregationAxisValue } from 'lib/insights/aggregationAxisFormat'import { LinkPrimitive } from 'lib/lemon-ui/Link'@@ -10,7 +12,7 @@ import { teamLogic } from 'scenes/teamLogic'import type { CurrencyCode, TrendsFilter } from '~/queries/schema/schema-general'-import type { HighlightMetricApi } from 'products/today/frontend/generated/api.schemas'+import type { HighlightMetricApi, PulseSlotApi } from 'products/today/frontend/generated/api.schemas'import { TodayChange } from './TodayChange'import { todayHighlightsLogic } from './todayHighlightsLogic'@@ -91,15 +93,76 @@ function useSettleOnReorder(listRef: RefObject<HTMLUListElement>, order: string)}, [order, listRef])}-export function TodayPulse({ metrics }: { metrics: HighlightMetricApi[] }): JSX.Element {+export function TodayPulse({ metrics, slots }: { metrics: HighlightMetricApi[]; slots?: PulseSlotApi[] }): JSX.Element {+ const cards =+ slots ??+ metrics.map(+ (metric): PulseSlotApi => ({+ key: metric.key,+ name: metric.name,+ status: 'ready',+ url: metric.url,+ interval: metric.interval,+ })+ )+ const { highlightsLoading, highlights, highlightsFailed } = useValues(todayHighlightsLogic)const listRef = useRef<HTMLUListElement>(null)- useSettleOnReorder(listRef, metrics.map((tile) => tile.key).join('|'))+ useSettleOnReorder(listRef, cards.map((tile) => tile.key).join('|'))const { baseCurrency } = useValues(teamLogic)- const { pulseMetricOpened, pulseMetricPreviewed, hidePulseMetric, holdPulseOrder, releasePulseOrder } =+ const { pulseMetricOpened, pulseMetricPreviewed, hidePulseMetric, holdPulseOrder, releasePulseOrder, retryPulse } =useActions(todayHighlightsLogic)return (<ul ref={listRef} className="TodayPulse" aria-label="Key numbers, against the period before">- {metrics.map((metric, position) => {+ {cards.map((slot, position) => {+ const metric = metrics.find((metric) => metric.key === slot.key)+ if (!metric) {+ const loading = slot.status === 'pending'+ return (+ <li+ key={slot.key}+ data-pulse-key={slot.key}+ className="TodayPulse__metric"+ aria-busy={loading}+ aria-label={`${slot.name}: ${loading ? 'Loading' : slot.status === 'error' ? 'Could not load' : 'No data'}`}+ >+ {slot.url ? (+ <LinkPrimitive to={slot.url} className="TodayPulse__name">+ {slot.name}+ </LinkPrimitive>+ ) : (+ <span className="TodayPulse__name">{slot.name}</span>+ )}+ <span className="TodayPulse__row">+ {loading ? (+ <Skeleton className="inline-block h-5 w-24" />+ ) : (+ <Text size="sm" variant="muted">+ {slot.status === 'error' ? 'Could not load' : 'No data'}+ </Text>+ )}+ </span>+ <span className="TodayPulse__spark">+ {loading ? (+ <Skeleton className="h-3 w-full" />+ ) : slot.status === 'error' ? (+ <Button+ size="xs"+ variant="link-muted"+ className="-ms-2"+ disabled={+ highlightsLoading ||+ (!highlightsFailed && highlights?.status === 'computing')+ }+ onClick={retryPulse}+ >+ Retry+ </Button>+ ) : null}+ </span>+ </li>+ )+ }+const isInsight = metric.key.startsWith('insight:')const tone = isInsight ? 'neutral' : metricTone(metric.change_pct, metric.value)const formatValue = metric.value_format ? metricFormatter(metric, baseCurrency) : todayNumber@@ -132,7 +195,7 @@ export function TodayPulse({ metrics }: { metrics: HighlightMetricApi[] }): JSX.pulseMetricPreviewed(metric, position)holdPulseOrder(metric.key,- metrics.map((tile) => tile.key)+ cards.map((tile) => tile.key))} else {releasePulseOrder(metric.key)diff --git a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.ts b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.tsindex 3123b30513fe..400a5e9261e9 100644--- a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.ts+++ b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.test.ts@@ -4,6 +4,8 @@ import posthog from 'posthog-js'import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'+import * as todayApi from 'products/today/frontend/generated/api'+import { HIGHLIGHTS_POLL_MS, todayHighlightsLogic } from './todayHighlightsLogic'import { makeHighlightItem, makeHighlights, makePulseMetric } from './todayTestFixtures'@@ -324,4 +326,87 @@ describe('todayHighlightsLogic', () => {)logic.actions.pulseViewUnmounted()})+ it('shows titles in stable order and measures only visible ready numbers', async () => {+ const capture = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined)+ const metrics = ['slow', 'fast', 'empty', 'error'].map((key) => makePulseMetric({ key, name: key }))+ const slots = metrics.map((metric) => ({+ key: metric.key,+ name: metric.name,+ url: metric.url,+ interval: metric.interval,+ status: 'pending' as const,+ }))+ const pending = makeHighlights({ status: 'computing', pulse: [], pulse_slots: slots })+ highlightResponses = [[200, pending]]+ const logic = todayHighlightsLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ logic.actions.pulseViewMounted(false)+ logic.actions.pulseViewUpdated()+ expect(logic.values.pulsePending).toBe(false)+ expect(logic.values.pulseSlots.map((slot) => slot.name)).toEqual(['slow', 'fast', 'empty', 'error'])+ expect(logic.values.pulseTiles).toEqual([])+ expect(capture.mock.calls.some(([event]) => event === 'today pulse first number shown')).toBe(false)+ logic.actions.loadHighlightsSuccess({+ ...pending,+ pulse: [metrics[1]],+ pulse_slots: slots.map((slot, i) => ({ ...slot, status: i === 1 ? 'ready' : 'pending' })),+ })+ logic.actions.pulseViewUpdated()+ expect(logic.values.pulseSlots.map((slot) => slot.key)).toEqual(['slow', 'fast', 'empty', 'error'])+ expect(logic.values.pulseTiles).toEqual([metrics[1]])+ expect(capture).toHaveBeenCalledWith(+ 'today pulse first number shown',+ expect.objectContaining({+ number_count: 1,+ first_card_duration_ms: expect.any(Number),+ loading_mode: 'progressive',+ })+ )+ logic.actions.pulseViewUnmounted()+ })++ it('keeps ready values and stops pending loaders when a poll fails', async () => {+ const metric = makePulseMetric()+ const partial = makeHighlights({+ status: 'computing',+ pulse: [metric],+ pulse_slots: [+ { key: metric.key, name: metric.name, status: 'ready', url: metric.url, interval: metric.interval },+ { key: 'slow', name: 'Slow number', status: 'pending', url: null, interval: null },+ ],+ })+ highlightResponses = [[200, partial]]+ const logic = todayHighlightsLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ logic.actions.loadHighlightsFailure('Request failed')+ expect(logic.values.pulseTiles).toEqual([metric])+ expect(logic.values.pulseSlots[1].status).toBe('error')+ expect(logic.values.pulsePending).toBe(false)+ })+ it('sends only one refresh when retry is selected twice', async () => {+ const failed = makeHighlights({+ pulse: [],+ pulse_slots: [{ key: 'failed', name: 'Failed number', status: 'error', url: null, interval: null }],+ })+ highlightResponses = [[200, failed]]+ const logic = todayHighlightsLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ let finish: (value: typeof failed) => void = () => undefined+ const request = jest.spyOn(todayApi, 'todayHighlightsRetrieve').mockImplementation(+ () =>+ new Promise((resolve) => {+ finish = resolve+ })+ )+ logic.actions.retryPulse()+ logic.actions.retryPulse()+ expect(request).toHaveBeenCalledTimes(1)+ expect(request).toHaveBeenCalledWith(String(logic.values.currentProjectId), { refresh: true })+ finish(failed)+ await expectLogic(logic).toFinishAllListeners()+ request.mockRestore()+ })})diff --git a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.ts b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.tsindex 30c62ac3f51a..6dcdf65abdad 100644--- a/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.ts+++ b/frontend/src/scenes/project-homepage/today/todayHighlightsLogic.ts@@ -9,7 +9,12 @@ import { ApiError } from 'lib/api'import { teamLogic } from 'scenes/teamLogic'import { todayHighlightsRetrieve } from 'products/today/frontend/generated/api'-import type { HighlightItemApi, HighlightMetricApi, HighlightsApi } from 'products/today/frontend/generated/api.schemas'+import type {+ HighlightItemApi,+ HighlightMetricApi,+ HighlightsApi,+ PulseSlotApi,+} from 'products/today/frontend/generated/api.schemas'export const HIGHLIGHTS_POLL_MS = 2_000const HIGHLIGHTS_WAIT_MS = 2_000@@ -19,6 +24,9 @@ const PULSE_SLOW_MS = 30_000interface PulseLoad {id: stringstartedAt: number+ firstCardAt: number | null+ firstResponseAt: number | null+ loadingMode: 'progressive' | 'complete' | nullfirstNumberAt: number | nullrequestCount: numberresponseCount: number@@ -57,6 +65,10 @@ function capturePulseLoad(const payload = {load_id: load.id,duration_ms: Math.round(performance.now() - load.startedAt),+ first_card_duration_ms: load.firstCardAt === null ? null : Math.round(load.firstCardAt - load.startedAt),+ first_response_duration_ms:+ load.firstResponseAt === null ? null : Math.round(load.firstResponseAt - load.startedAt),+ loading_mode: load.loadingMode,first_number_duration_ms: load.firstNumberAt === null ? null : Math.round(load.firstNumberAt - load.startedAt),request_count: load.requestCount,response_count: load.responseCount,@@ -101,6 +113,7 @@ export interface todayHighlightsLogicValues {owner: string} | nullpulsePending: boolean+ pulseSlots: PulseSlotApi[]pulseTiles: HighlightMetricApi[]}@@ -134,7 +147,7 @@ export interface todayHighlightsLogicActions {keys: string[]owner: string}- loadHighlights: () => any+ loadHighlights: (refresh?: boolean) => booleanloadHighlightsFailure: (error: string,errorObject?: any@@ -144,10 +157,10 @@ export interface todayHighlightsLogicActions {}loadHighlightsSuccess: (highlights: HighlightsApi | null,- payload?: any+ payload?: boolean) => {highlights: HighlightsApi | null- payload?: any+ payload?: boolean}pulseMetricOpened: (metric: HighlightMetricApi,@@ -175,6 +188,9 @@ export interface todayHighlightsLogicActions {releasePulseOrder: (owner: string) => {owner: string}+ retryPulse: () => {+ value: true+ }setHiddenHighlights: (hidden: Record<string, string>) => {hidden: Record<string, string>}@@ -203,17 +219,28 @@ export interface todayHighlightsLogicActions {// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface todayHighlightsLogicMeta {__keaTypeGenInternalSelectorTypes: {- pulseTiles: (+ pulseSlots: (highlights: HighlightsApi | null,hiddenPulseMetrics: Record<string, true>,currentProjectId: number | string,pulseOrderHeld: {keys: string[]owner: string- } | null- ) => HighlightMetricApi[]- highlightsPending: (highlights: HighlightsApi | null, highlightsLoading: boolean) => boolean- pulsePending: (highlights: HighlightsApi | null, highlightsPending: boolean) => boolean+ } | null,+ highlightsFailed: boolean+ ) => PulseSlotApi[]+ pulseTiles: (highlights: HighlightsApi | null, pulseSlots: PulseSlotApi[]) => HighlightMetricApi[]+ highlightsPending: (+ highlights: HighlightsApi | null,+ highlightsLoading: boolean,+ highlightsFailed: boolean+ ) => boolean+ pulsePending: (+ highlights: HighlightsApi | null,+ highlightsPending: boolean,+ pulseSlots: PulseSlotApi[],+ highlightsFailed: boolean+ ) => booleandoneHighlightKeys: (highlights: HighlightsApi | null,hiddenHighlights: Record<string, string>,@@ -256,18 +283,21 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([releasePulseOrder: (owner: string) => ({ owner }),pulseViewMounted: (sample: boolean) => ({ sample }),pulseViewUpdated: true,+ retryPulse: true,pulseViewUnmounted: (documentDeparture: boolean = false) => ({ documentDeparture }),}),loaders(({ values }) => ({highlights: [null as HighlightsApi | null,{- loadHighlights: async (): Promise<HighlightsApi | null> => {+ loadHighlights: async (refresh: boolean = false): Promise<HighlightsApi | null> => {if (values.currentProjectId === null) {return null}try {- return await todayHighlightsRetrieve(String(values.currentProjectId))+ return refresh+ ? await todayHighlightsRetrieve(String(values.currentProjectId), { refresh: true })+ : await todayHighlightsRetrieve(String(values.currentProjectId))} catch (error) {if (error instanceof ApiError && error.status === 404) {return null@@ -312,42 +342,70 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([},],highlights: {- loadHighlightsFailure: () => null,+ loadHighlightsFailure: (state) => state,},}),selectors({- pulseTiles: [- (s) => [s.highlights, s.hiddenPulseMetrics, s.currentProjectId, s.pulseOrderHeld],+ pulseSlots: [+ (s) => [s.highlights, s.hiddenPulseMetrics, s.currentProjectId, s.pulseOrderHeld, s.highlightsFailed],(highlights: HighlightsApi | null,hiddenPulseMetrics: Record<string, true>,currentProjectId: number | string,- pulseOrderHeld: { owner: string; keys: string[] } | null- ): HighlightMetricApi[] => {- const tiles = (highlights?.pulse ?? [])- .filter((metric) => !hiddenPulseMetrics[hiddenHighlightKey(currentProjectId, metric.key)])+ pulseOrderHeld: { owner: string; keys: string[] } | null,+ highlightsFailed: boolean+ ): PulseSlotApi[] => {+ const slots: PulseSlotApi[] =+ highlights?.pulse_slots ??+ (highlights?.pulse ?? []).map((metric) => ({+ key: metric.key,+ name: metric.name,+ url: metric.url,+ interval: metric.interval,+ status: 'ready',+ }))+ const visible = slots+ .filter((slot) => !hiddenPulseMetrics[hiddenHighlightKey(currentProjectId, slot.key)]).slice(0, PULSE_TILES)+ .map(+ (slot): PulseSlotApi =>+ highlightsFailed && slot.status === 'pending' ? { ...slot, status: 'error' } : slot+ )if (!pulseOrderHeld) {- return tiles+ return visible}const held = pulseOrderHeld.keysconst place = (key: string): number => {const index = held.indexOf(key)return index === -1 ? held.length : index}- return [...tiles].sort((a, b) => place(a.key) - place(b.key))+ return [...visible].sort((a, b) => place(a.key) - place(b.key))},],+ pulseTiles: [+ (s) => [s.highlights, s.pulseSlots],+ (highlights: HighlightsApi | null, pulseSlots: PulseSlotApi[]): HighlightMetricApi[] =>+ pulseSlots.flatMap((slot) => highlights?.pulse.find((metric) => metric.key === slot.key) ?? []),+ ],highlightsPending: [- (s) => [s.highlights, s.highlightsLoading],- (highlights: HighlightsApi | null, highlightsLoading: boolean): boolean =>- highlights ? highlights.status === 'computing' && highlights.generated_at === null : highlightsLoading,+ (s) => [s.highlights, s.highlightsLoading, s.highlightsFailed],+ (highlights: HighlightsApi | null, highlightsLoading: boolean, highlightsFailed: boolean): boolean =>+ !highlightsFailed &&+ (highlights+ ? highlights.status === 'computing' && highlights.generated_at === null+ : highlightsLoading),],pulsePending: [- (s) => [s.highlights, s.highlightsPending],- // An older result with no tiles is not worth showing while a new one computes.- (highlights: HighlightsApi | null, highlightsPending: boolean): boolean =>- highlightsPending || (highlights?.status === 'computing' && highlights.pulse.length === 0),+ (s) => [s.highlights, s.highlightsPending, s.pulseSlots, s.highlightsFailed],+ (+ highlights: HighlightsApi | null,+ highlightsPending: boolean,+ pulseSlots: PulseSlotApi[],+ highlightsFailed: boolean+ ): boolean =>+ !highlightsFailed &&+ pulseSlots.length === 0 &&+ (highlightsPending || highlights?.status === 'computing'),],doneHighlightKeys: [(s) => [s.highlights, s.hiddenHighlights, s.highlightsHiddenNow, s.currentProjectId],@@ -384,6 +442,9 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([const load: PulseLoad = {id: uuidv4(),startedAt: performance.now(),+ firstCardAt: null,+ firstResponseAt: null,+ loadingMode: null,firstNumberAt: null,requestCount: values.highlightsLoading ? 1 : 0,responseCount: 0,@@ -444,6 +505,9 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([if (!load || load.finished) {return}+ if (values.pulseSlots.length > 0 && load.firstCardAt === null) {+ load.firstCardAt = performance.now()+ }const numberCount = values.highlightsPending ? 0 : values.pulseTiles.lengthif (numberCount > 0 && load.firstNumberAt === null) {load.firstNumberAt = performance.now()@@ -459,7 +523,11 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([load.finished = truecache.disposables.dispose('pulseLoadSlow')cache.disposables.dispose('pulseLoadVisibility')- capturePulseLoad('today pulse load finished', load, { outcome, number_count: numberCount })+ capturePulseLoad('today pulse load finished', load, {+ outcome,+ number_count: numberCount,+ pending_count: values.pulseSlots.filter((slot) => slot.status === 'pending').length,+ })}},pulseViewUnmounted: ({ documentDeparture }) => {@@ -571,10 +639,17 @@ export const todayHighlightsLogic = kea<todayHighlightsLogicType>([position,})},+ retryPulse: () => {+ if (!values.highlightsLoading && (values.highlightsFailed || values.highlights?.status !== 'computing')) {+ actions.loadHighlights(true)+ }+ },loadHighlightsSuccess: ({ highlights }) => {cache.highlightsUnavailable = highlights === nullconst load = cache.pulseLoad as PulseLoad | undefinedif (load && !load.finished) {+ load.firstResponseAt ??= performance.now()+ load.loadingMode = highlights?.pulse_slots == null ? 'complete' : 'progressive'load.responseCount += 1load.initialStatus ??= highlights?.status ?? null}diff --git a/frontend/src/scenes/project-homepage/today/todayLogic.test.ts b/frontend/src/scenes/project-homepage/today/todayLogic.test.tsindex 0f842f8e895f..fe7dc8936096 100644--- a/frontend/src/scenes/project-homepage/today/todayLogic.test.ts+++ b/frontend/src/scenes/project-homepage/today/todayLogic.test.ts@@ -475,6 +475,26 @@ describe('todayLogic', () => {})})+ it('stops the For you loader when a poll fails before any rows arrive', async () => {+ const pending = makeHighlights({ status: 'computing', generated_at: null, items: [], pulse: [] })+ highlightResponses = [[200, pending]]+ const logic = todayLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.forYouReady).toBe(false)+ expect(logic.values.forYouRows.rows).toEqual([])++ highlightResponses = [[500, { detail: 'Request failed' }]]+ await expectLogic(todayHighlightsLogic(), () => {+ todayHighlightsLogic.actions.loadHighlights()+ }).toDispatchActions(['loadHighlightsFailure'])++ expect(todayHighlightsLogic.values.highlights).toEqual(pending)+ expect(todayHighlightsLogic.values.highlightsPending).toBe(false)+ expect(logic.values.forYouReady).toBe(true)+ expect(logic.values.forYouFailedNote).toBe('Highlights didn’t load.')+ })+it('remembers the report to focus and the home scroll only while the person stays on Today', async () => {const logic = todayLogic()logic.mount()diff --git a/frontend/src/scenes/project-homepage/today/todayLogic.ts b/frontend/src/scenes/project-homepage/today/todayLogic.tsindex 3eb268806517..3d1d5c4e9fb1 100644--- a/frontend/src/scenes/project-homepage/today/todayLogic.ts+++ b/frontend/src/scenes/project-homepage/today/todayLogic.ts@@ -244,7 +244,7 @@ export interface todayLogicActions {currentTeam: TeamPublicType | nullpayload?: any} // teamLogic- loadHighlights: () => any // todayHighlightsLogic+ loadHighlights: (refresh?: boolean | undefined) => boolean // todayHighlightsLogicaskAi: (prompt: string,source: TodayAskSource,