@@ -72,6 +72,9 @@ const RESULT_OPTIONS_TITLES: Record<SectionID, string> = {
7272 } ,
7373} ;
7474
75+ const EXECUTE_SECTIONS : SectionID [ ] = [ 'result' , 'schema' , 'simplified' , 'stats' ] ;
76+ const EXPLAIN_SECTIONS : SectionID [ ] = [ 'schema' , 'json' , 'simplified' , 'ast' ] ;
77+
7578interface ExecuteResultProps {
7679 result : QueryResult ;
7780 resultType ?: QueryAction ;
@@ -105,23 +108,22 @@ export function QueryResultViewer({
105108 const { error, isLoading, queryId, data = { } } = result ;
106109 const { preparedPlan, simplifiedPlan, stats, resultSets, ast} = data ;
107110
111+ React . useEffect ( ( ) => {
112+ if ( resultType === 'execute' && ! EXECUTE_SECTIONS . includes ( activeSection ) ) {
113+ setActiveSection ( 'result' ) ;
114+ }
115+ if ( resultType === 'explain' && ! EXPLAIN_SECTIONS . includes ( activeSection ) ) {
116+ setActiveSection ( 'schema' ) ;
117+ }
118+ } , [ activeSection , resultType ] ) ;
119+
108120 const radioButtonOptions : ControlGroupOption < SectionID > [ ] = React . useMemo ( ( ) => {
109- const sections : SectionID [ ] = [ ] ;
121+ let sections : SectionID [ ] = [ ] ;
110122
111123 if ( isExecute ) {
112- sections . push ( 'result' ) ;
113-
114- if ( preparedPlan ) {
115- sections . push ( 'schema' ) ;
116- }
117- if ( simplifiedPlan ?. plan ) {
118- sections . push ( 'simplified' ) ;
119- }
120- if ( stats ) {
121- sections . push ( 'stats' ) ;
122- }
124+ sections = EXECUTE_SECTIONS ;
123125 } else if ( isExplain ) {
124- sections . push ( 'schema' , 'json' , 'simplified' , 'ast' ) ;
126+ sections = EXPLAIN_SECTIONS ;
125127 }
126128
127129 return sections . map ( ( section ) => {
@@ -130,7 +132,7 @@ export function QueryResultViewer({
130132 content : RESULT_OPTIONS_TITLES [ section ] ,
131133 } ;
132134 } ) ;
133- } , [ isExecute , isExplain , preparedPlan , simplifiedPlan ?. plan , stats ] ) ;
135+ } , [ isExecute , isExplain ] ) ;
134136
135137 React . useEffect ( ( ) => {
136138 return ( ) => {
@@ -214,8 +216,8 @@ export function QueryResultViewer({
214216 }
215217 return < QueryJSONViewer data = { preparedPlan ?. pristine } /> ;
216218 }
217- if ( activeSection === RESULT_OPTIONS_IDS . simplified && simplifiedPlan ?. plan ) {
218- if ( ! simplifiedPlan ?. plan ) {
219+ if ( activeSection === RESULT_OPTIONS_IDS . simplified ) {
220+ if ( ! simplifiedPlan ?. plan ?. length ) {
219221 return renderStubMessage ( ) ;
220222 }
221223 return < SimplifiedPlan plan = { simplifiedPlan . plan } /> ;
0 commit comments