@@ -438,6 +438,25 @@ export const QueryPerformanceGrid = ({
438438 }
439439 } , [ handleKeyDown ] )
440440
441+ const isSelectQuery = ( query : string | undefined ) : boolean => {
442+ if ( ! query ) return false
443+ const formattedQuery = query . trim ( ) . toLowerCase ( )
444+ return (
445+ formattedQuery . startsWith ( 'select' ) ||
446+ formattedQuery . startsWith ( 'with pgrst_source' ) ||
447+ formattedQuery . startsWith ( 'with pgrst_payload' )
448+ )
449+ }
450+
451+ useEffect ( ( ) => {
452+ if ( selectedRow !== undefined && view === 'suggestion' ) {
453+ const query = reportData [ selectedRow ] ?. query
454+ if ( ! isSelectQuery ( query ) ) {
455+ setView ( 'details' )
456+ }
457+ }
458+ } , [ selectedRow , view , reportData ] )
459+
441460 return (
442461 < div className = "relative flex flex-grow bg-alternative min-h-0" >
443462 < div ref = { dataGridContainerRef } className = "flex-1 min-w-0 overflow-x-auto" >
@@ -477,14 +496,12 @@ export const QueryPerformanceGrid = ({
477496 event . stopPropagation ( )
478497
479498 if ( typeof idx === 'number' && idx >= 0 ) {
480- // If onCurrentSelectQuery is provided, use the chart selection logic
481499 if ( onCurrentSelectQuery ) {
482500 const query = reportData [ idx ] ?. query
483501 if ( query ) {
484502 onCurrentSelectQuery ( query )
485503 }
486504 } else {
487- // Otherwise, open the detail panel
488505 setSelectedRow ( idx )
489506 const hasRecommendations = hasIndexRecommendations (
490507 reportData [ idx ] ?. index_advisor_result ,
@@ -553,12 +570,14 @@ export const QueryPerformanceGrid = ({
553570 >
554571 Query details
555572 </ TabsTrigger_Shadcn_ >
556- < TabsTrigger_Shadcn_
557- value = "suggestion"
558- className = "px-0 pb-0 data-[state=active]:bg-transparent !shadow-none"
559- >
560- Indexes
561- </ TabsTrigger_Shadcn_ >
573+ { selectedRow !== undefined && isSelectQuery ( reportData [ selectedRow ] ?. query ) && (
574+ < TabsTrigger_Shadcn_
575+ value = "suggestion"
576+ className = "px-0 pb-0 data-[state=active]:bg-transparent !shadow-none"
577+ >
578+ Indexes
579+ </ TabsTrigger_Shadcn_ >
580+ ) }
562581 </ TabsList_Shadcn_ >
563582 </ div >
564583
@@ -571,12 +590,14 @@ export const QueryPerformanceGrid = ({
571590 />
572591 ) }
573592 </ TabsContent_Shadcn_ >
574- < TabsContent_Shadcn_
575- value = "suggestion"
576- className = "mt-0 flex-grow min-h-0 overflow-y-auto"
577- >
578- { selectedRow !== undefined && < QueryIndexes selectedRow = { reportData [ selectedRow ] } /> }
579- </ TabsContent_Shadcn_ >
593+ { selectedRow !== undefined && isSelectQuery ( reportData [ selectedRow ] ?. query ) && (
594+ < TabsContent_Shadcn_
595+ value = "suggestion"
596+ className = "mt-0 flex-grow min-h-0 overflow-y-auto"
597+ >
598+ < QueryIndexes selectedRow = { reportData [ selectedRow ] } />
599+ </ TabsContent_Shadcn_ >
600+ ) }
580601 </ Tabs_Shadcn_ >
581602 </ SheetContent >
582603 </ Sheet >
0 commit comments