@@ -343,32 +343,55 @@ def get(batch_name: str, start_index: int):
343343
344344
345345@rt ("/batch/{batch_name}/search" )
346- def post (batch_name : str , search : str = "" ):
346+ def get (batch_name : str , search : str = "" ):
347347 """
348348 Search for a given batch name and search string.
349349 """
350350 import re
351351
352+ # Store the search term in state
353+ app .state .search_term [batch_name ] = search
354+
355+ # Ensure we have stats for this batch
356+ if batch_name not in app .state .stats_cache :
357+ app .state .calculate_metric_stats (batch_name )
358+
352359 metric_stats = app .state .stats_cache [batch_name ]
353360 try :
354361 pattern = re .compile (search , re .IGNORECASE ) if search else None
355- filtered_stats = [
356- stat
357- for stat in metric_stats
362+
363+ # Keep track of original indices while filtering
364+ filtered_stats_with_indices = [
365+ (i , stat ) # Keep original index with the stat
366+ for i , stat in enumerate (metric_stats )
358367 if not pattern or pattern .search (stat ["metric_name" ])
359368 ]
360- placeholders = []
361- for i , stat in enumerate (filtered_stats ):
362- placeholders .append (
369+
370+ # Return empty state if no results
371+ if not filtered_stats_with_indices :
372+ return Div (
373+ P ("No matching metrics found" , cls = "text-muted-foreground p-4 text-center" ),
374+ id = "charts-grid" ,
375+ )
376+
377+ # Create chart placeholders using original indices
378+ return Div (
379+ * [
363380 ChartManager .create_chart_placeholder (
364- stat ["metric_name" ], i , batch_name
381+ stat ["metric_name" ],
382+ original_index , # Use the original index instead of enumeration
383+ batch_name
365384 )
366- )
367- return (
368- Div (* placeholders ) if placeholders else Div (P ("No matching metrics found" ))
385+ for original_index , stat in filtered_stats_with_indices
386+ ],
387+ id = "charts-grid" ,
388+ cls = f"grid grid-cols-{ 2 if app .state .two_columns else 1 } gap-4"
369389 )
370390 except re .error :
371- return Div (P ("Invalid search pattern" ))
391+ return Div (
392+ P ("Invalid search pattern" , cls = "text-red-500 p-4 text-center" ),
393+ id = "charts-grid" ,
394+ )
372395
373396
374397@rt ("/batch/{batch_name}/update-n" )
0 commit comments