mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-12-03 03:29:51 +00:00
feat(app): Sessions provider quick-filter + Spend project inline expand
- Sessions: All + per-provider logo buttons (detected, cost > 0) that drive the same app-level provider state as the top-bar dropdown, so the two controls can never disagree; aria-pressed group semantics - Spend By project: rows expand inline (single-open, aria-expanded, chevron rotation) to the project's sessions: date, top model, calls, currency-aware cost; date-only strings parsed at local noon so days never roll across time zones 194/194, typecheck + build green.
This commit is contained in:
parent
015a1a069a
commit
f8b2894b4e
7 changed files with 202 additions and 17 deletions
|
|
@ -196,7 +196,7 @@ export function App() {
|
|||
{section === 'overview' ? (
|
||||
<OverviewContent period={period} provider={provider} range={customRange} overview={overview} onNavigate={navigate} />
|
||||
) : section === 'sessions' ? (
|
||||
<Sessions period={period} provider={provider} range={customRange} refreshToken={refreshToken} />
|
||||
<Sessions period={period} provider={provider} range={customRange} refreshToken={refreshToken} detectedProviders={detectedProviders} onProviderChange={setProvider} />
|
||||
) : section === 'spend' ? (
|
||||
<SpendContent period={period} provider={provider} range={customRange} overview={overview} refreshToken={refreshToken} />
|
||||
) : section === 'optimize' ? (
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ export { seriesColorForModel } from '../lib/modelSeries'
|
|||
* title + sub line `.lx`, an optional right-aligned `.val`. When `onClick` is
|
||||
* provided the row becomes a keyboard-operable button and shows the trailing
|
||||
* chevron; without it the row is inert and the chevron is omitted (honest).
|
||||
* Pass `expanded` on an interactive row to reflect its open/closed state
|
||||
* (`aria-expanded`, which also rotates the chevron).
|
||||
*/
|
||||
export function ListRow({
|
||||
no,
|
||||
|
|
@ -16,6 +18,7 @@ export function ListRow({
|
|||
value,
|
||||
valueClass,
|
||||
onClick,
|
||||
expanded,
|
||||
}: {
|
||||
no?: ReactNode
|
||||
dotColor?: string
|
||||
|
|
@ -24,6 +27,7 @@ export function ListRow({
|
|||
value?: ReactNode
|
||||
valueClass?: string
|
||||
onClick?: () => void
|
||||
expanded?: boolean
|
||||
}) {
|
||||
const dot: CSSProperties | undefined = dotColor ? { background: dotColor } : undefined
|
||||
const interactive = onClick !== undefined
|
||||
|
|
@ -39,6 +43,7 @@ export function ListRow({
|
|||
<div
|
||||
className={interactive ? 'li li-clickable' : 'li'}
|
||||
{...(interactive ? { role: 'button', tabIndex: 0, onClick, onKeyDown } : {})}
|
||||
{...(interactive && expanded !== undefined ? { 'aria-expanded': expanded } : {})}
|
||||
>
|
||||
{no !== undefined && <span className="no">{no}</span>}
|
||||
{dotColor !== undefined && <span className="mdot" style={dot} />}
|
||||
|
|
|
|||
|
|
@ -229,4 +229,45 @@ describe('Sessions', () => {
|
|||
render(<Sessions period="week" provider="all" />)
|
||||
expect(await screen.findByText('No sessions in this range yet.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('lifts provider quick-filter clicks to the app callback with the internal id', async () => {
|
||||
const user = userEvent.setup()
|
||||
getSessions.mockResolvedValue(rows)
|
||||
const onProviderChange = vi.fn()
|
||||
const detected = [
|
||||
{ id: 'claude', label: 'Claude' },
|
||||
{ id: 'codex', label: 'Codex' },
|
||||
]
|
||||
render(<Sessions period="30days" provider="all" detectedProviders={detected} onProviderChange={onProviderChange} />)
|
||||
await screen.findByText('6 sessions · $21.93 · 4.2M tokens')
|
||||
|
||||
const filter = screen.getByRole('group', { name: /provider/i })
|
||||
expect(within(filter).getAllByRole('button')).toHaveLength(3)
|
||||
|
||||
await user.click(within(filter).getByRole('button', { name: 'Codex' }))
|
||||
expect(onProviderChange).toHaveBeenCalledWith('codex')
|
||||
|
||||
await user.click(within(filter).getByRole('button', { name: 'All' }))
|
||||
expect(onProviderChange).toHaveBeenLastCalledWith('all')
|
||||
})
|
||||
|
||||
it('renders quick-filter buttons only for cost>0 providers and presses the active one', async () => {
|
||||
getSessions.mockResolvedValue(rows)
|
||||
// Mirror App.tsx: detectedProviders are built by dropping cost=0 entries.
|
||||
const providerDetails = [
|
||||
{ id: 'claude', label: 'Claude', cost: 12 },
|
||||
{ id: 'codex', label: 'Codex', cost: 4 },
|
||||
{ id: 'gemini', label: 'Gemini', cost: 0 },
|
||||
]
|
||||
const detected = providerDetails.filter(p => p.cost > 0).map(({ id, label }) => ({ id, label }))
|
||||
render(<Sessions period="30days" provider="codex" detectedProviders={detected} onProviderChange={() => {}} />)
|
||||
await screen.findByText('6 sessions · $21.93 · 4.2M tokens')
|
||||
|
||||
const filter = screen.getByRole('group', { name: /provider/i })
|
||||
expect(within(filter).getByRole('button', { name: 'Claude' })).toBeInTheDocument()
|
||||
expect(within(filter).getByRole('button', { name: 'Codex' })).toBeInTheDocument()
|
||||
expect(within(filter).queryByRole('button', { name: 'Gemini' })).not.toBeInTheDocument()
|
||||
expect(within(filter).getByRole('button', { name: 'Codex' })).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(within(filter).getByRole('button', { name: 'All' })).toHaveAttribute('aria-pressed', 'false')
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { Fragment, useEffect, useMemo, useState } from 'react'
|
|||
import { CliErrorPanel } from '../components/CliErrorPanel'
|
||||
import { EmptyNote } from '../components/EmptyState'
|
||||
import { Panel } from '../components/Panel'
|
||||
import { ProviderLogo } from '../components/ProviderLogo'
|
||||
import { SegTabs } from '../components/SegTabs'
|
||||
import { StaleBanner } from '../components/StaleBanner'
|
||||
import { Stat } from '../components/Stat'
|
||||
|
|
@ -62,11 +63,15 @@ export function Sessions({
|
|||
provider,
|
||||
range = null,
|
||||
refreshToken = 0,
|
||||
detectedProviders = [],
|
||||
onProviderChange = () => {},
|
||||
}: {
|
||||
period: Period
|
||||
provider: string
|
||||
range?: DateRange | null
|
||||
refreshToken?: number
|
||||
detectedProviders?: Array<{ id: string; label: string }>
|
||||
onProviderChange?: (value: string) => void
|
||||
}) {
|
||||
const [selectedId, setSelectedId] = useState<string | null>(null)
|
||||
const [query, setQuery] = useState('')
|
||||
|
|
@ -158,6 +163,30 @@ export function Sessions({
|
|||
return (
|
||||
<div className="sessions-list-view">
|
||||
{report.error && <StaleBanner error={report.error} />}
|
||||
{detectedProviders.length > 0 && (
|
||||
<div className="seg session-provider-filter" role="group" aria-label="Filter sessions by provider">
|
||||
<button
|
||||
type="button"
|
||||
className={provider === 'all' ? 'on' : undefined}
|
||||
aria-pressed={provider === 'all'}
|
||||
onClick={() => onProviderChange('all')}
|
||||
>
|
||||
All
|
||||
</button>
|
||||
{detectedProviders.map(entry => (
|
||||
<button
|
||||
key={entry.id}
|
||||
type="button"
|
||||
className={provider === entry.id ? 'on' : undefined}
|
||||
aria-pressed={provider === entry.id}
|
||||
onClick={() => onProviderChange(entry.id)}
|
||||
>
|
||||
<ProviderLogo provider={entry.id} size={14} />
|
||||
{entry.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="sessions-toolbar">
|
||||
<input
|
||||
className="sessions-search"
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
// @vitest-environment jsdom
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { render, screen, within } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import type { MenubarPayload, SpendFlow } from '../lib/types'
|
||||
|
|
@ -328,4 +329,58 @@ describe('Spend', () => {
|
|||
const otherNode = container.querySelector('[data-testid="sankey-node"][data-node-id="__other__"]')
|
||||
expect(otherNode?.getAttribute('fill')).toBe('var(--s-other)')
|
||||
})
|
||||
|
||||
it('expands a project row inline to reveal its sessions, one open row at a time', async () => {
|
||||
const user = userEvent.setup()
|
||||
const payload = makePayload(new Date())
|
||||
payload.current.topProjects[0].sessionDetails = [
|
||||
{
|
||||
cost: 120.5, savingsUSD: 0, calls: 40, inputTokens: 0, outputTokens: 0, date: '2026-07-09',
|
||||
models: [
|
||||
{ name: 'claude-opus-4', cost: 100, savingsUSD: 0 },
|
||||
{ name: 'claude-haiku-4', cost: 20.5, savingsUSD: 0 },
|
||||
],
|
||||
},
|
||||
{
|
||||
cost: 44.25, savingsUSD: 0, calls: 12, inputTokens: 0, outputTokens: 0, date: '2026-07-05',
|
||||
models: [{ name: 'gpt-5.5-codex', cost: 44.25, savingsUSD: 0 }],
|
||||
},
|
||||
]
|
||||
payload.current.topProjects[1].sessionDetails = [
|
||||
{
|
||||
cost: 9.9, savingsUSD: 0, calls: 3, inputTokens: 0, outputTokens: 0, date: '2026-07-02',
|
||||
models: [{ name: 'claude-sonnet-5', cost: 9.9, savingsUSD: 0 }],
|
||||
},
|
||||
]
|
||||
getOverview.mockResolvedValue(payload)
|
||||
getSpendFlow.mockResolvedValue(makeFlow())
|
||||
|
||||
render(<Spend period="week" provider="all" />)
|
||||
|
||||
const first = await screen.findByRole('button', { name: /codeburn/ })
|
||||
const second = screen.getByRole('button', { name: /agentseal-dash/ })
|
||||
expect(first).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(screen.queryByRole('region', { name: 'codeburn sessions' })).not.toBeInTheDocument()
|
||||
|
||||
await user.click(first)
|
||||
expect(first).toHaveAttribute('aria-expanded', 'true')
|
||||
const detail = screen.getByRole('region', { name: 'codeburn sessions' })
|
||||
expect(within(detail).getByText('Jul 9')).toBeInTheDocument()
|
||||
expect(within(detail).getByText('$120.50')).toBeInTheDocument()
|
||||
expect(within(detail).getByText('claude-opus-4')).toBeInTheDocument()
|
||||
expect(within(detail).getByText('Jul 5')).toBeInTheDocument()
|
||||
expect(within(detail).getByText('$44.25')).toBeInTheDocument()
|
||||
|
||||
// Expanding another project collapses the first (single open row).
|
||||
await user.click(second)
|
||||
expect(second).toHaveAttribute('aria-expanded', 'true')
|
||||
expect(first).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(screen.queryByRole('region', { name: 'codeburn sessions' })).not.toBeInTheDocument()
|
||||
expect(within(screen.getByRole('region', { name: 'agentseal-dash sessions' })).getByText('$9.90')).toBeInTheDocument()
|
||||
|
||||
// Clicking the open row collapses it in place.
|
||||
await user.click(second)
|
||||
expect(second).toHaveAttribute('aria-expanded', 'false')
|
||||
expect(screen.queryByRole('region', { name: 'agentseal-dash sessions' })).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { Fragment, useState } from 'react'
|
||||
|
||||
import { CliErrorPanel, CliErrorText } from '../components/CliErrorPanel'
|
||||
import { EmptyNote } from '../components/EmptyState'
|
||||
import { ListRow } from '../components/ListRow'
|
||||
|
|
@ -11,6 +13,14 @@ import { codeburn } from '../lib/ipc'
|
|||
import { contiguousDailyWindow, localDateKey } from '../lib/period'
|
||||
import type { CliError, DateRange, MenubarPayload, Period, SpendFlow } from '../lib/types'
|
||||
|
||||
type Project = MenubarPayload['current']['topProjects'][number]
|
||||
|
||||
/** Date-only CLI strings ("2026-07-11") formatted at local noon so the calendar day never rolls across time zones. */
|
||||
function formatProjectDay(date: string): string {
|
||||
const d = new Date(`${date}T12:00:00`)
|
||||
return Number.isNaN(d.getTime()) ? '—' : d.toLocaleDateString('en-US', { month: 'short', day: 'numeric' })
|
||||
}
|
||||
|
||||
const SPEND_CHART_DAYS = 15
|
||||
|
||||
function providerLabel(provider: string): string {
|
||||
|
|
@ -140,21 +150,7 @@ function SpendPage({
|
|||
<Panel title="Daily spend by model" className="spend-chart-panel">
|
||||
{chartHasSpend ? <StackedBars daily={chartDaily} fallbackLabel={providerLabel(provider)} /> : <EmptyNote>No model spend in this range yet.</EmptyNote>}
|
||||
</Panel>
|
||||
<Panel title="By project" right={projects.length ? `top ${projects.length}` : undefined} className="spend-scroll">
|
||||
{projects.length ? (
|
||||
projects.map((project, i) => (
|
||||
<ListRow
|
||||
key={project.name}
|
||||
no={String(i + 1).padStart(2, '0')}
|
||||
title={project.name}
|
||||
sub={`${project.sessions.toLocaleString('en-US')} ${project.sessions === 1 ? 'session' : 'sessions'}`}
|
||||
value={formatUsd(project.cost)}
|
||||
/>
|
||||
))
|
||||
) : (
|
||||
<EmptyNote>No project spend in this range yet.</EmptyNote>
|
||||
)}
|
||||
</Panel>
|
||||
<ProjectBreakdown projects={projects} />
|
||||
</div>
|
||||
|
||||
<Panel title="Cost flow · model → project" right="model → project flow for this range" bodyStyle={{ overflowX: 'auto' }}>
|
||||
|
|
@ -178,6 +174,50 @@ function SpendPage({
|
|||
)
|
||||
}
|
||||
|
||||
function ProjectBreakdown({ projects }: { projects: Project[] }) {
|
||||
const [expanded, setExpanded] = useState<string | null>(null)
|
||||
|
||||
return (
|
||||
<Panel title="By project" right={projects.length ? `top ${projects.length}` : undefined} className="spend-scroll">
|
||||
{projects.length ? (
|
||||
projects.map((project, i) => {
|
||||
const open = expanded === project.name
|
||||
return (
|
||||
<Fragment key={project.name}>
|
||||
<ListRow
|
||||
no={String(i + 1).padStart(2, '0')}
|
||||
title={project.name}
|
||||
sub={`${project.sessions.toLocaleString('en-US')} ${project.sessions === 1 ? 'session' : 'sessions'}`}
|
||||
value={formatUsd(project.cost)}
|
||||
expanded={open}
|
||||
onClick={() => setExpanded(current => current === project.name ? null : project.name)}
|
||||
/>
|
||||
{open && (
|
||||
<div className="spend-proj-detail" role="region" aria-label={`${project.name} sessions`}>
|
||||
{project.sessionDetails.length ? (
|
||||
project.sessionDetails.map((session, j) => (
|
||||
<div className="spend-proj-session" key={`${session.date}-${j}`}>
|
||||
<span className="sps-date">{formatProjectDay(session.date)}</span>
|
||||
<span className="sps-model">{session.models[0]?.name ?? '—'}</span>
|
||||
<span className="sps-calls">{session.calls.toLocaleString('en-US')} calls</span>
|
||||
<span className="sps-cost">{formatUsd(session.cost)}</span>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<div className="spend-proj-empty">No session detail for this project.</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Fragment>
|
||||
)
|
||||
})
|
||||
) : (
|
||||
<EmptyNote>No project spend in this range yet.</EmptyNote>
|
||||
)}
|
||||
</Panel>
|
||||
)
|
||||
}
|
||||
|
||||
function RowsPanel({
|
||||
title,
|
||||
rows,
|
||||
|
|
|
|||
|
|
@ -402,6 +402,16 @@ td:first-child { font-size: var(--fs-body); font-weight: var(--fw-body); }
|
|||
.li-clickable { cursor: pointer; border-radius: 7px; }
|
||||
.li-clickable:hover, .li-clickable:focus-visible { background: var(--hover); outline: none; }
|
||||
.li-clickable:focus-visible { box-shadow: inset 0 0 0 1px var(--accent); }
|
||||
.li .chev { transition: transform 140ms ease; }
|
||||
.li-clickable[aria-expanded="true"] .chev { transform: rotate(90deg); }
|
||||
|
||||
/* Spend: a project row's inline session sub-list (indented, TUI-style). */
|
||||
.spend-proj-detail { display: flex; flex-direction: column; padding: 2px 0 8px 27px; }
|
||||
.spend-proj-session { display: grid; grid-template-columns: 54px minmax(0, 1fr) auto auto; align-items: baseline; column-gap: 10px; padding: 4px 0; font-size: 11px; color: var(--mut); font-variant-numeric: tabular-nums; }
|
||||
.spend-proj-session + .spend-proj-session { border-top: 1px solid var(--line2); }
|
||||
.spend-proj-session .sps-model { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
|
||||
.spend-proj-session .sps-cost { color: var(--ink); font-family: var(--mono); }
|
||||
.spend-proj-empty { padding: 4px 0 8px 27px; font-size: 11px; color: var(--mut2); }
|
||||
|
||||
/* Models: grouped task lens. */
|
||||
.models-by-task { min-width: 660px; }
|
||||
|
|
@ -661,6 +671,11 @@ td:first-child { font-size: var(--fs-body); font-weight: var(--fw-body); }
|
|||
/* Sessions */
|
||||
.sessions-list-view { display: flex; width: 100%; flex-direction: column; gap: 10px; }
|
||||
.sessions-toolbar { display: flex; align-items: center; align-self: flex-start; flex-wrap: wrap; gap: 8px; }
|
||||
.session-provider-filter { align-self: flex-start; flex-wrap: wrap; }
|
||||
.session-provider-filter button { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 5px; background: transparent; padding: 4px 9px; font: inherit; font-size: 11.5px; color: var(--mut); white-space: nowrap; cursor: pointer; }
|
||||
.session-provider-filter button:hover { color: var(--ink); }
|
||||
.session-provider-filter button.on { color: var(--ink); font-weight: 560; }
|
||||
.session-provider-filter button:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }
|
||||
.sessions-search { min-width: 240px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); color: var(--ink); font: inherit; font-size: 12px; }
|
||||
.sessions-search::placeholder { color: var(--mut2); }
|
||||
.sessions-search:focus-visible { border-color: var(--accent); outline: 1px solid var(--accent); outline-offset: 1px; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue