@@ -3,8 +3,10 @@ import { useNumber } from '@/hooks/use-numer-formatter';
33import type { RouterOutputs } from '@/trpc/client' ;
44import { cn } from '@/utils/cn' ;
55import { getChartColor } from '@/utils/theme' ;
6+ import { getPreviousMetric } from '@openpanel/common' ;
67import { ChevronDown , ChevronRight } from 'lucide-react' ;
78import { useState } from 'react' ;
9+ import { PreviousDiffIndicatorPure } from '../common/previous-diff-indicator' ;
810import { Tables } from './chart' ;
911
1012interface BreakdownListProps {
@@ -48,10 +50,9 @@ export function BreakdownList({
4850 } ) ;
4951 } ;
5052
51- // Get the color index for a breakdown based on its position in the
52- // visible series list (so colors match the chart bars)
53- const getVisibleIndex = ( id : string ) => {
54- return visibleSeriesIds . indexOf ( id ) ;
53+ // Get the stable color index for a breakdown (position in full list, matches chart)
54+ const getStableColorIndex = ( id : string ) => {
55+ return allBreakdowns . findIndex ( ( b ) => b . id === id ) ;
5556 } ;
5657
5758 if ( allBreakdowns . length === 0 ) {
@@ -81,14 +82,12 @@ export function BreakdownList({
8182 { allBreakdowns . map ( ( item , index ) => {
8283 const isExpanded = expandedIds . has ( item . id ) ;
8384 const isVisible = visibleSeriesIds . includes ( item . id ) ;
84- const visibleIndex = getVisibleIndex ( item . id ) ;
85+ const stableColorIndex = getStableColorIndex ( item . id ) ;
8586 const previousItem = previousData [ index ] ?? null ;
8687 const hasBreakdownName =
8788 item . breakdowns && item . breakdowns . length > 0 ;
8889 const color =
89- isVisible && visibleIndex !== - 1
90- ? getChartColor ( visibleIndex )
91- : undefined ;
90+ stableColorIndex >= 0 ? getChartColor ( stableColorIndex ) : undefined ;
9291
9392 return (
9493 < div key = { item . id } className = "col" >
@@ -107,7 +106,7 @@ export function BreakdownList({
107106 className = "shrink-0"
108107 style = { {
109108 borderColor : color ,
110- backgroundColor : isVisible ? color : 'transparent' ,
109+ backgroundColor : isVisible && color ? color : 'transparent' ,
111110 } }
112111 />
113112 ) }
@@ -141,6 +140,14 @@ export function BreakdownList({
141140 '%' ,
142141 ) }
143142 </ div >
143+ { previousItem && (
144+ < PreviousDiffIndicatorPure
145+ { ...getPreviousMetric (
146+ item . lastStep . percent ,
147+ previousItem . lastStep . percent ,
148+ ) }
149+ />
150+ ) }
144151 </ div >
145152 < div className = "text-right row gap-2 items-center" >
146153 < div className = "text-muted-foreground text-sm" >
@@ -149,6 +156,14 @@ export function BreakdownList({
149156 < div className = "font-mono font-semibold text-sm" >
150157 { number . format ( item . lastStep . count ) }
151158 </ div >
159+ { previousItem && (
160+ < PreviousDiffIndicatorPure
161+ { ...getPreviousMetric (
162+ item . lastStep . count ,
163+ previousItem . lastStep . count ,
164+ ) }
165+ />
166+ ) }
152167 </ div >
153168 </ div >
154169 </ div >
@@ -160,6 +175,7 @@ export function BreakdownList({
160175 current : item ,
161176 previous : previousItem ,
162177 } }
178+ noTopBorderRadius
163179 />
164180 ) }
165181 </ div >
0 commit comments