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.
This commit is contained in:
Aditya Vikram Singh 2026-08-22 23:46:46 +05:30
parent 7b802f4dd0
commit b095091aad
5 changed files with 27 additions and 34 deletions

View file

@ -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()

View file

@ -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<Section, string> = {
settings: 'Settings',
}
const PERIOD_LABELS: Record<Period, string> = {
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' ? (
<Sessions period={period} provider={provider} range={customRange} refreshToken={refreshToken} detectedProviders={detectedProviders} onProviderChange={onProviderSelect} ready={ready} />
) : section === 'pullRequests' ? (
<PullRequestsContent overview={overview} />
<PullRequestsContent overview={overview} period={period} provider={provider} range={customRange} />
) : section === 'spend' ? (
<SpendContent period={period} provider={provider} range={customRange} overview={overview} refreshToken={refreshToken} ready={ready} />
) : section === 'optimize' ? (

View file

@ -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<Period, string> = {
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.

View file

@ -284,7 +284,7 @@ describe('PullRequests', () => {
getOverview.mockResolvedValue(makePayload())
render(<PullRequests period="lifetime" provider="all" />)
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(<PullRequests period="lifetime" provider="all" />)
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(<PullRequests period="today" provider="all" />)
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')
})
})

View file

@ -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<MenubarPayload['current']['pullRequests']>
@ -63,19 +64,10 @@ export function PullRequests({ period, provider, range = null }: { period: Perio
return <PullRequestsContent key={`${period}|${provider}|${range?.from ?? ''}|${range?.to ?? ''}`} overview={overview} period={period} provider={provider} range={range} />
}
const PERIOD_LABEL: Record<Period, string> = {
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<MenubarPayload>
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<number | null>(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 (
<EmptyNote>