@@ -31,6 +31,7 @@ export default function Dashboard() {
3131 const [ maintenanceStats , setMaintenanceStats ] = useState < any > ( { } )
3232 const [ systemHealth , setSystemHealth ] = useState < any > ( { } )
3333 const [ backendHealth , setBackendHealth ] = useState < any > ( { } )
34+ const [ queryLoadPeriod , setQueryLoadPeriod ] = useState ( "24" )
3435
3536 useEffect ( ( ) => {
3637 fetchDashboardData ( )
@@ -41,7 +42,7 @@ export default function Dashboard() {
4142 clearInterval ( dataInterval )
4243 clearInterval ( healthInterval )
4344 }
44- } , [ ] )
45+ } , [ queryLoadPeriod ] )
4546
4647 const fetchDashboardData = async ( ) => {
4748 try {
@@ -100,28 +101,33 @@ export default function Dashboard() {
100101 }
101102
102103 // Fetch sector timeline
103- const timelineRes = await fetch ( `${ API_BASE_URL } /dashboard/sectors/timeline?hours=24 ` , {
104+ const timelineRes = await fetch ( `${ API_BASE_URL } /dashboard/sectors/timeline?hours=${ queryLoadPeriod } ` , {
104105 headers : getHeaders ( )
105106 } )
106107 if ( timelineRes . ok ) {
107108 const timeline = await timelineRes . json ( )
108109 const grouped : Record < string , any > = { }
109110
110111 timeline . timeline ?. forEach ( ( item : any ) => {
111- if ( ! grouped [ item . hour ] ) {
112- grouped [ item . hour ] = { hour : item . hour }
112+ // Use sort_key for grouping to distinguish same hours on different days
113+ const key = item . sort_key || item . hour
114+ if ( ! grouped [ key ] ) {
115+ grouped [ key ] = { hour : item . hour , sort_key : key }
113116 }
114- grouped [ item . hour ] [ item . primary_sector ] = item . count
117+ grouped [ key ] [ item . primary_sector ] = item . count
115118 } )
116119
117- const chartData = Object . values ( grouped ) . map ( ( item : any ) => ( {
118- hour : item . hour ,
119- semantic : item . semantic || 0 ,
120- episodic : item . episodic || 0 ,
121- procedural : item . procedural || 0 ,
122- emotional : item . emotional || 0 ,
123- reflective : item . reflective || 0 ,
124- } ) )
120+ // Explicitly sort by sort_key for proper chronological ordering
121+ const chartData = Object . values ( grouped )
122+ . sort ( ( a : any , b : any ) => ( a . sort_key || a . hour ) . localeCompare ( b . sort_key || b . hour ) )
123+ . map ( ( item : any ) => ( {
124+ hour : item . hour ,
125+ semantic : item . semantic || 0 ,
126+ episodic : item . episodic || 0 ,
127+ procedural : item . procedural || 0 ,
128+ emotional : item . emotional || 0 ,
129+ reflective : item . reflective || 0 ,
130+ } ) )
125131
126132 setQpsData ( chartData )
127133 }
@@ -272,10 +278,14 @@ export default function Dashboard() {
272278 < div className = "flex items-center justify-between mb-4" >
273279 < h2 className = "text-xl font-semibold text-[#f4f4f5]" > Memory Query Load</ h2 >
274280 < div className = "flex gap-2" >
275- < select className = "rounded-xl p-2 pl-4 border border-stone-800 bg-stone-950 hover:bg-stone-900/50 hover:text-stone-300 text-sm font-medium text-stone-400 outline-none cursor-pointer transition-colors" >
276- < option className = "bg-stone-950" > 24 hours</ option >
277- < option className = "bg-stone-950" > 7 days</ option >
278- < option className = "bg-stone-950" > 30 days</ option >
281+ < select
282+ value = { queryLoadPeriod }
283+ onChange = { ( e ) => setQueryLoadPeriod ( e . target . value ) }
284+ className = "rounded-xl p-2 pl-4 border border-stone-800 bg-stone-950 hover:bg-stone-900/50 hover:text-stone-300 text-sm font-medium text-stone-400 outline-none cursor-pointer transition-colors"
285+ >
286+ < option value = "24" className = "bg-stone-950" > 24 hours</ option >
287+ < option value = "168" className = "bg-stone-950" > 7 days</ option >
288+ < option value = "720" className = "bg-stone-950" > 30 days</ option >
279289 </ select >
280290 </ div >
281291 </ div >
0 commit comments