From b095091aad50f8e984af960deb9b0ccf0f321127 Mon Sep 17 00:00:00 2001 From: Aditya Vikram Singh <247195684+avs-io@users.noreply.github.com> Date: Sat, 22 Aug 2026 23:46:46 +0530 Subject: [PATCH] fix(desktop): thread PR-tab period through App Empty copy was defaulting to Today because App never passed the selected period. Labels now share PERIOD_LABELS; the wider hint queries Lifetime. --- app/renderer/App.test.tsx | 2 +- app/renderer/App.tsx | 13 ++--------- app/renderer/lib/period.ts | 10 +++++++++ app/renderer/sections/PullRequests.test.tsx | 12 +++++------ app/renderer/sections/PullRequests.tsx | 24 +++++++-------------- 5 files changed, 27 insertions(+), 34 deletions(-) diff --git a/app/renderer/App.test.tsx b/app/renderer/App.test.tsx index 1e9f64b3..e45aab0f 100644 --- a/app/renderer/App.test.tsx +++ b/app/renderer/App.test.tsx @@ -268,7 +268,7 @@ describe('App shortcuts', () => { expect(await screen.findByText('No sessions in this range yet.')).toBeInTheDocument() fireEvent.keyDown(document, { key: '3', ...chord }) - expect(await screen.findByText(/PR links are captured as sessions are parsed/)).toBeInTheDocument() + expect(await screen.findByText(/No sessions in Last 30 days mentioned a pull request URL/)).toBeInTheDocument() fireEvent.keyDown(document, { key: '4', ...chord }) expect(await screen.findByText('Cost flow ยท model โ†’ project')).toBeInTheDocument() diff --git a/app/renderer/App.tsx b/app/renderer/App.tsx index 6262abbc..e72777b6 100644 --- a/app/renderer/App.tsx +++ b/app/renderer/App.tsx @@ -18,7 +18,7 @@ import { formatCompact, formatUsd, setActiveCurrency } from './lib/format' import { motionClass } from './lib/motion' import { codeburn } from './lib/ipc' import { isModifierChord, shortcutLabel } from './lib/platform' -import { localDateKey } from './lib/period' +import { localDateKey, PERIOD_LABELS } from './lib/period' import { persistRefreshValue, readRefreshValue, refreshValueToMs, RefreshCadenceContext, type RefreshCadence } from './lib/refreshCadence' import { OverviewContent } from './sections/Overview' import { OptimizeContent } from './sections/Optimize' @@ -118,15 +118,6 @@ const SECTION_TITLES: Record = { settings: 'Settings', } -const PERIOD_LABELS: Record = { - today: 'Today', - week: 'Last 7 days', - month: 'This month', - '30days': 'Last 30 days', - all: 'Last 6 months', - lifetime: 'Lifetime', -} - const STANDARD_PERIODS: Period[] = ['today', 'week', '30days', 'month', 'all', 'lifetime'] // Instant-switch memo key for an overview result. Shared by the overview poll @@ -565,7 +556,7 @@ function AppMain() { ) : section === 'sessions' ? ( ) : section === 'pullRequests' ? ( - + ) : section === 'spend' ? ( ) : section === 'optimize' ? ( diff --git a/app/renderer/lib/period.ts b/app/renderer/lib/period.ts index 01511ac6..c0c99205 100644 --- a/app/renderer/lib/period.ts +++ b/app/renderer/lib/period.ts @@ -1,5 +1,15 @@ import type { DailyHistoryEntry, Period } from './types' +/** Same words the desktop TopBar and empty states must use. `all` is last six months, not lifetime. */ +export const PERIOD_LABELS: Record = { + today: 'Today', + week: 'Last 7 days', + month: 'This month', + '30days': 'Last 30 days', + all: 'Last 6 months', + lifetime: 'Lifetime', +} + // The CLI emits `history.daily` as a SPARSE list of active days only (not a // backfilled calendar). Charts must zero-fill inactive days client-side to keep // the time axis honest; helpers here own that windowing. diff --git a/app/renderer/sections/PullRequests.test.tsx b/app/renderer/sections/PullRequests.test.tsx index 3a68e934..85cb4ebf 100644 --- a/app/renderer/sections/PullRequests.test.tsx +++ b/app/renderer/sections/PullRequests.test.tsx @@ -284,7 +284,7 @@ describe('PullRequests', () => { getOverview.mockResolvedValue(makePayload()) render() - expect(await screen.findByText(/No sessions in All mentioned a pull request URL/)).toBeInTheDocument() + expect(await screen.findByText(/No sessions in Lifetime mentioned a pull request URL/)).toBeInTheDocument() expect(screen.queryByRole('table')).toBeNull() }) @@ -292,19 +292,19 @@ describe('PullRequests', () => { getOverview.mockResolvedValue(makePayload({ rows: [], distinctCost: 0, distinctSessions: 0, attributedCost: 0, unattributedCost: 0 })) render() - expect(await screen.findByText(/No sessions in All mentioned a pull request URL/)).toBeInTheDocument() + expect(await screen.findByText(/No sessions in Lifetime mentioned a pull request URL/)).toBeInTheDocument() expect(screen.queryByRole('table')).toBeNull() }) - it('names Today and points at All when a wider window has rows', async () => { + it('names Today and points at Lifetime when a wider window has rows', async () => { getOverview.mockImplementation(async (period: string) => { - if (period === 'all') return makePayload(SAMPLE) + if (period === 'lifetime') return makePayload(SAMPLE) return makePayload() }) render() expect(await screen.findByText(/No sessions in Today mentioned a pull request URL/)).toBeInTheDocument() - expect(await screen.findByText(/All time has 2 pull requests/)).toBeInTheDocument() - expect(getOverview).toHaveBeenCalledWith('all', 'all') + expect(await screen.findByText(/Lifetime has 2 pull requests/)).toBeInTheDocument() + expect(getOverview).toHaveBeenCalledWith('lifetime', 'all') }) }) diff --git a/app/renderer/sections/PullRequests.tsx b/app/renderer/sections/PullRequests.tsx index 8589332f..a9f4a091 100644 --- a/app/renderer/sections/PullRequests.tsx +++ b/app/renderer/sections/PullRequests.tsx @@ -9,6 +9,7 @@ import { StaleBanner } from '../components/StaleBanner' import { type Polled, usePolled } from '../hooks/usePolled' import { formatDayShort, formatUsd } from '../lib/format' import { codeburn } from '../lib/ipc' +import { PERIOD_LABELS } from '../lib/period' import type { CliError, DateRange, MenubarPayload, Period } from '../lib/types' type PullRequests = NonNullable @@ -63,19 +64,10 @@ export function PullRequests({ period, provider, range = null }: { period: Perio return } -const PERIOD_LABEL: Record = { - today: 'Today', - week: 'This week', - '30days': 'Last 30 days', - month: 'This month', - all: 'All', - lifetime: 'All', -} - -export function PullRequestsContent({ overview, period = 'today', provider = 'all', range = null }: { +export function PullRequestsContent({ overview, period, provider, range = null }: { overview: Polled - period?: Period - provider?: string + period: Period + provider: string range?: DateRange | null }) { if (!overview.data) { @@ -113,11 +105,11 @@ function PullRequestsPage({ pullRequests, staleError, period, provider, range }: function PrEmptyNote({ period, provider, range }: { period: Period; provider: string; range: DateRange | null }) { const [widerCount, setWiderCount] = useState(null) - const canProbeWider = !range && period !== 'all' && period !== 'lifetime' + const canProbeWider = !range && period !== 'lifetime' useEffect(() => { if (!canProbeWider) return let cancelled = false - void codeburn.getOverview('all', provider).then(payload => { + void codeburn.getOverview('lifetime', provider).then(payload => { if (cancelled) return setWiderCount(payload.current.pullRequests?.rows.length ?? 0) }).catch(() => { @@ -126,9 +118,9 @@ function PrEmptyNote({ period, provider, range }: { period: Period; provider: st return () => { cancelled = true } }, [canProbeWider, provider]) - const periodLabel = PERIOD_LABEL[period] + const periodLabel = PERIOD_LABELS[period] const widerHint = widerCount && widerCount > 0 - ? ` All time has ${widerCount.toLocaleString('en-US')} pull requests โ€” switch the period control to All.` + ? ` Lifetime has ${widerCount.toLocaleString('en-US')} pull requests โ€” switch the period control to Life.` : '' return (