1111// See the License for the specific language governing permissions and
1212// limitations under the License.
1313
14- import { QueryDefinition } from '@perses-dev/core ' ;
14+ import { QueryDefinition } from '@perses-dev/spec ' ;
1515import { Box , Stack , Tab , Tabs } from '@mui/material' ;
1616import { DataQueriesProvider , MultiQueryEditor , useSuggestedStepMs } from '@perses-dev/plugin-system' ;
1717import { useExplorerManagerContext } from '@perses-dev/explore' ;
@@ -27,24 +27,22 @@ interface SQLExplorerQueryParams {
2727const PANEL_PREVIEW_HEIGHT = 700 ;
2828const FILTERED_QUERY_PLUGINS = [ 'SQLTimeSeriesQuery' ] ;
2929
30+ function toQueryDefinitions ( queries : QueryDefinition [ ] ) {
31+ return queries . map ( ( query ) => ( {
32+ kind : query . spec . plugin . kind ,
33+ spec : query . spec . plugin . spec ,
34+ } ) ) ;
35+ }
36+
3037function TimeSeriesPanel ( { queries } : { queries : QueryDefinition [ ] } ) : ReactElement {
3138 const { width, ref : boxRef } = useResizeObserver ( ) ;
3239 const height = PANEL_PREVIEW_HEIGHT ;
3340
3441 const suggestedStepMs = useSuggestedStepMs ( width ) ;
3542
36- const definitions = queries . length
37- ? queries . map ( ( query ) => {
38- return {
39- kind : query . spec . plugin . kind ,
40- spec : query . spec . plugin . spec ,
41- } ;
42- } )
43- : [ ] ;
44-
4543 return (
4644 < Box ref = { boxRef } height = { height } >
47- < DataQueriesProvider definitions = { definitions } options = { { suggestedStepMs, mode : 'range' } } >
45+ < DataQueriesProvider definitions = { toQueryDefinitions ( queries ) } options = { { suggestedStepMs, mode : 'range' } } >
4846 < Panel
4947 panelOptions = { {
5048 hideHeader : true ,
@@ -62,16 +60,9 @@ function TimeSeriesPanel({ queries }: { queries: QueryDefinition[] }): ReactElem
6260function DataTable ( { queries } : { queries : QueryDefinition [ ] } ) : ReactElement {
6361 const height = PANEL_PREVIEW_HEIGHT ;
6462
65- const definitions = queries . map ( ( query ) => {
66- return {
67- kind : query . spec . plugin . kind ,
68- spec : query . spec . plugin . spec ,
69- } ;
70- } ) ;
71-
7263 return (
7364 < Box height = { height } >
74- < DataQueriesProvider definitions = { definitions } options = { { mode : 'instant' } } >
65+ < DataQueriesProvider definitions = { toQueryDefinitions ( queries ) } options = { { mode : 'instant' } } >
7566 < Panel
7667 panelOptions = { {
7768 hideHeader : true ,
@@ -106,30 +97,15 @@ export function SQLExplorer(): ReactElement {
10697 < Tab value = "graph" label = "Graph" />
10798 </ Tabs >
10899 < Stack gap = { 1 } >
109- { tab === 'table' && (
110- < Stack >
111- < MultiQueryEditor
112- queryTypes = { [ 'TimeSeriesQuery' ] }
113- onChange = { ( state ) => setQueryDefinitions ( state ) }
114- queries = { queryDefinitions }
115- onQueryRun = { ( ) => setData ( { tab, queries : queryDefinitions } ) }
116- filteredQueryPlugins = { FILTERED_QUERY_PLUGINS }
117- />
118- < DataTable queries = { queries } />
119- </ Stack >
120- ) }
121- { tab === 'graph' && (
122- < Stack >
123- < MultiQueryEditor
124- queryTypes = { [ 'TimeSeriesQuery' ] }
125- onChange = { ( state ) => setQueryDefinitions ( state ) }
126- queries = { queryDefinitions }
127- onQueryRun = { ( ) => setData ( { tab, queries : queryDefinitions } ) }
128- filteredQueryPlugins = { FILTERED_QUERY_PLUGINS }
129- />
130- < TimeSeriesPanel queries = { queries } />
131- </ Stack >
132- ) }
100+ < MultiQueryEditor
101+ queryTypes = { [ 'TimeSeriesQuery' ] }
102+ onChange = { ( state ) => setQueryDefinitions ( state ) }
103+ queries = { queryDefinitions }
104+ onQueryRun = { ( ) => setData ( { tab, queries : queryDefinitions } ) }
105+ filteredQueryPlugins = { FILTERED_QUERY_PLUGINS }
106+ />
107+ { tab === 'table' && < DataTable queries = { queries } /> }
108+ { tab === 'graph' && < TimeSeriesPanel queries = { queries } /> }
133109 </ Stack >
134110 </ Stack >
135111 ) ;
0 commit comments