Skip to content

[P1] Implement missing CostDashboard UI elements (date filter, task breakdown, trend chart) #86

Description

@frankbria

Problem

CostDashboard component exists but is missing critical UI elements expected by E2E tests, causing 3 test failures.

Current State

  • CostDashboard component exists (web-ui/src/components/metrics/CostDashboard.tsx)
  • ✅ Metrics panel rendered in Dashboard (web-ui/src/components/Dashboard.tsx:519-524)
  • ❌ Missing: Date range filter
  • ❌ Missing: Task cost breakdown table
  • ❌ Missing: Cost trend chart

Failed Tests (3 total)

All in tests/e2e/test_metrics_ui.spec.ts:

  1. should filter metrics by date range (line 166)

    • Error: date-range-filter element not found
    • Expected: Date range picker with start/end date inputs
  2. should display cost per task (line 201)

    • Error: task-column-header element not found
    • Expected: Table with columns: Task, Cost, Tokens
  3. should display cost trend chart (line 281)

    • Error: trend-chart-data element not found
    • Expected: Line/area chart showing cost over time

Missing UI Components

1. Date Range Filter (Priority: High)

Required data-testid elements:

  • date-range-filter - Container div
  • start-date-input - Start date picker
  • end-date-input - End date picker
  • apply-filter-button - Apply button

Example Implementation:

<div data-testid="date-range-filter" className="mb-4">
  <label>Start Date</label>
  <input
    type="date"
    data-testid="start-date-input"
    value={startDate}
    onChange={handleStartDateChange}
  />
  
  <label>End Date</label>
  <input
    type="date"
    data-testid="end-date-input"
    value={endDate}
    onChange={handleEndDateChange}
  />
  
  <button data-testid="apply-filter-button" onClick={applyFilter}>
    Apply
  </button>
</div>

2. Task Cost Breakdown Table (Priority: High)

Required data-testid elements:

  • task-cost-table - Table container
  • task-column-header - "Task" header
  • cost-column-header - "Cost (USD)" header
  • tokens-column-header - "Tokens" header
  • task-row-{task_id} - Each task row

Data Source: /api/projects/{id}/metrics/costs endpoint

Example Implementation:

<table data-testid="task-cost-table" className="w-full">
  <thead>
    <tr>
      <th data-testid="task-column-header">Task</th>
      <th data-testid="cost-column-header">Cost (USD)</th>
      <th data-testid="tokens-column-header">Tokens</th>
    </tr>
  </thead>
  <tbody>
    {tasks.map(task => (
      <tr key={task.id} data-testid={`task-row-${task.id}`}>
        <td>{task.name}</td>
        <td>${task.cost.toFixed(2)}</td>
        <td>{task.tokens.toLocaleString()}</td>
      </tr>
    ))}
  </tbody>
</table>

3. Cost Trend Chart (Priority: Medium)

Required data-testid elements:

  • trend-chart - Chart container
  • trend-chart-data - Data visualization (SVG/Canvas)
  • chart-x-axis - X-axis (time labels)
  • chart-y-axis - Y-axis (cost labels)

Recommended Library: Recharts (already used in project?)

Example Implementation:

import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip } from 'recharts';

<div data-testid="trend-chart">
  <LineChart width={600} height={300} data={trendData}>
    <CartesianGrid strokeDasharray="3 3" />
    <XAxis dataKey="date" data-testid="chart-x-axis" />
    <YAxis data-testid="chart-y-axis" />
    <Tooltip />
    <Line
      type="monotone"
      dataKey="cost"
      stroke="#8884d8"
      data-testid="trend-chart-data"
    />
  </LineChart>
</div>

API Endpoints Required

Verify these endpoints exist and return correct data:

  1. GET /api/projects/{id}/metrics/costs

    • Returns: { total_cost_usd, by_agent[], by_model[], by_task[] }
  2. GET /api/projects/{id}/metrics/costs?start_date=YYYY-MM-DD&end_date=YYYY-MM-DD

    • Returns: Filtered cost data for date range
  3. GET /api/projects/{id}/metrics/trend

    • Returns: Time-series data [{ date, cost, tokens }]

Implementation Estimate

  • Date Range Filter: 30-45 minutes
  • Task Cost Table: 45-60 minutes
  • Cost Trend Chart: 60-90 minutes
  • Testing & Polish: 30 minutes
  • Total: 2.5-3.5 hours

Acceptance Criteria

  • Date range filter renders with data-testid attributes
  • Filtering by date updates metrics display
  • Task cost breakdown table shows all tasks with costs
  • Table columns have correct data-testid attributes
  • Cost trend chart displays historical cost data
  • Chart has data-testid attributes for testing
  • All 3 metrics UI tests pass

Files to Modify

  • web-ui/src/components/metrics/CostDashboard.tsx - Add all three components
  • web-ui/src/api/metrics.ts - Add API client functions (if missing)
  • web-ui/package.json - Add charting library if needed

Optional Enhancements

  • Export to CSV button
  • Toggle between daily/weekly/monthly aggregation
  • Hover tooltips on chart
  • Sortable table columns
  • Cost alerts/budgets

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions