You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(insights): sort the metric breakdown drawer's prompts list by current value (Cur) descending #316
In /dashboard/insights, clicking a metric card (e.g. Mentions) opens the metric breakdown drawer (_metric-breakdown-sheet.tsx). On the Prompts tab, the list should be ordered by the Cur (current value) column descending — highest current value at the top.
Current behavior
The table renders the rows in the order it receives them, and that order is ascending by delta (biggest drop first), not by current value. The sort is applied once in the data builder, getMetricBreakdown in web/src/lib/actions/tracking.ts:
rows.sort((a,b)=>a.delta-b.delta);// ascending by delta — byPrompt[0] = largest drop
So a prompt with a high current mention count can appear far down the list if its delta is small/positive.
Why the fix belongs in the view, not the data builder
The delta-ascending order is intentionally relied on by the drawer's "biggest driver" sentence (TopContributorLine), which reads data.byPrompt[0] (largest drop) and data.byPrompt[data.byPrompt.length - 1] (largest gain). Re-sorting the shared array in getMetricBreakdown would silently break that attribution. So the display order should be changed in the sheet, leaving the action's array order intact.
Proposed change
In _metric-breakdown-sheet.tsx, sort the rows by cur descending for display — e.g. in BreakdownTable (or where pickRows() returns), map over a sorted copy ([...rows].sort((a, b) => b.cur - a.cur)) so the table shows highest current value first. Leave getMetricBreakdown's ordering untouched so TopContributorLine still works.
Primary target: the Prompts tab (the user's request).
Since the table is shared, applying the same cur-descending sort to the Platforms / Topics tabs is fine and keeps the three tabs consistent.
Optional: a stable tiebreak for equal cur (e.g. by delta desc or label) to keep ordering deterministic.
Acceptance criteria
In the breakdown drawer's Prompts tab, rows are ordered by the Cur column from highest to lowest.
The "biggest driver" sentence at the top of the drawer is unchanged (still names the largest drop/gain correctly).
No change to the underlying data or to getMetricBreakdown's returned order.
(If applied) Platforms and Topics tabs follow the same Cur-descending order.
Notes
View-only change; no data, schema, or server changes.
Activity