1
1
import { AppBar , Paper , Button , Stack , Alert , Snackbar } from "@mui/material" ;
2
-
3
2
import PlayCircleFilledWhiteIcon from "@mui/icons-material/PlayCircleFilledWhite" ;
4
3
import DataObjectIcon from "@mui/icons-material/DataObject" ;
4
+ import DatabaseIcon from "@mui/icons-material/Storage" ; // New icon for DuckDB
5
5
import GitHubIcon from "@mui/icons-material/GitHub" ;
6
6
import IconButton from "@mui/material/IconButton" ;
7
7
import "../../styles/Home.module.css" ;
@@ -14,13 +14,14 @@ import { useQueryContext } from "../../contexts/queryContext/useQueryContext";
14
14
import MuiAlert , { AlertProps } from "@mui/material/Alert" ;
15
15
import { AddUrlButton } from "./add-url-button" ;
16
16
import { AlertMessage } from "./alert" ;
17
- import { fetchQuery } from "../../fetch" ;
17
+ import { fetchQuery , fetchDuckDBQuery } from "../../fetch" ; // Import new fetch function
18
18
19
19
const Header = ( ) => {
20
20
const { query, setQueryResults, setQueryRunning, queryRunning, serverUrl } =
21
21
useQueryContext ( ) ;
22
22
const [ errorMessage , setErrorMessage ] = useState ( "" ) ;
23
23
const [ queryError , setQueryError ] = useState ( false ) ;
24
+
24
25
const handleToggle = async ( dts = false ) => {
25
26
setQueryRunning ( true ) ;
26
27
try {
@@ -40,77 +41,55 @@ const Header = () => {
40
41
}
41
42
} ;
42
43
43
- const handleClose = (
44
- _event ?: React . SyntheticEvent | Event ,
45
- reason ?: string
46
- ) => {
44
+ // New function for handling DuckDB query execution
45
+ const handleDuckDBQuery = async ( ) => {
46
+ setQueryRunning ( true ) ;
47
+ try {
48
+ const response = await fetchDuckDBQuery ( ) ;
49
+ setQueryRunning ( false ) ;
50
+
51
+ const resJson = await response . json ( ) ;
52
+ if ( response . status !== 200 ) {
53
+ setErrorMessage ( resJson . error ) ;
54
+ setQueryError ( true ) ;
55
+ return ;
56
+ }
57
+ setQueryResults ( resJson ) ;
58
+ } catch ( error ) {
59
+ console . log ( "error is %o" , error ) ;
60
+ setQueryRunning ( false ) ;
61
+ }
62
+ } ;
63
+
64
+ const handleClose = ( _event ?: React . SyntheticEvent | Event , reason ?: string ) => {
47
65
if ( reason === "clickaway" ) {
48
66
return ;
49
67
}
50
-
51
68
setQueryError ( false ) ;
52
69
} ;
53
- const QueryButtonText = "Run Query" ;
54
- const TypeButtonText = "Get Types" ;
55
70
56
71
return (
57
72
< >
58
- < AlertMessage
59
- open = { queryError }
60
- handleClose = { handleClose }
61
- severity = "error"
62
- errorMessage = { errorMessage }
63
- />
64
- < Backdrop
65
- className = "w-screen ml-0"
66
- sx = { { color : "#fff" , zIndex : ( theme ) => theme . zIndex . drawer + 1 } }
67
- open = { queryRunning }
68
- >
73
+ < AlertMessage open = { queryError } handleClose = { handleClose } severity = "error" errorMessage = { errorMessage } />
74
+ < Backdrop className = "w-screen ml-0" sx = { { color : "#fff" , zIndex : ( theme ) => theme . zIndex . drawer + 1 } } open = { queryRunning } >
69
75
< CircularProgress color = "inherit" />
70
76
</ Backdrop >
71
77
< div className = "header-left-group" >
72
- < div className = "flex-col col-span-1 tablet:col-span-2 mobile:col-span-2 justify-center pt-2 pr-2" >
78
+ < div className = "flex-col col-span-1 tablet:col-span-2 mobile:col-span-2 justify-center pt-2 pr-2" >
73
79
< Image alt = "logo" src = "/logo-original.svg" width = { 162 } height = { 32 } />
74
80
</ div >
75
81
< div className = "header-left-stack" >
76
- < Button
77
- onClick = { async ( ) => {
78
- await handleToggle ( ) ;
79
- } }
80
- variant = "outlined"
81
- className = "button-primary"
82
- startIcon = { < PlayCircleFilledWhiteIcon /> }
83
- >
84
- { QueryButtonText }
82
+ < Button onClick = { async ( ) => await handleToggle ( ) } variant = "outlined" className = "button-primary" startIcon = { < PlayCircleFilledWhiteIcon /> } >
83
+ Run Query
84
+ </ Button >
85
+ < Button onClick = { async ( ) => await handleDuckDBQuery ( ) } variant = "outlined" className = "button-primary" startIcon = { < DatabaseIcon /> } >
86
+ Run DuckDB Query
85
87
</ Button >
86
- < IconButton
87
- onClick = { async ( ) => {
88
- await handleToggle ( ) ;
89
- } }
90
- className = "icon-button-primary"
91
- >
92
- < PlayCircleFilledWhiteIcon />
93
- </ IconButton >
94
- < Button
95
- variant = "outlined"
96
- className = "button-primary"
97
- startIcon = { < DataObjectIcon /> }
98
- onClick = { async ( ) => {
99
- await handleToggle ( true ) ;
100
- } }
101
- >
102
- { TypeButtonText }
88
+ < Button variant = "outlined" className = "button-primary" startIcon = { < DataObjectIcon /> } onClick = { async ( ) => await handleToggle ( true ) } >
89
+ Get Types
103
90
</ Button >
104
- < IconButton
105
- onClick = { async ( ) => {
106
- await handleToggle ( true ) ;
107
- } }
108
- className = "icon-button-primary"
109
- >
110
- < DataObjectIcon />
111
- </ IconButton >
112
91
</ div >
113
- < div className = "col-start-8 mobile:col-start-9 col-span-2 mobile:col-span-1 regular:col-start-7 regular:col-span-3 flex justify-end space-x-2 mobile:space-x-0 items-center" >
92
+ < div className = "col-start-8 mobile:col-start-9 col-span-2 mobile:col-span-1 regular:col-start-7 regular:col-span-3 flex justify-end space-x-2 mobile:space-x-0 items-center" >
114
93
< AddUrlButton />
115
94
< a href = "https://github.com/stackql/stackql-playground" >
116
95
< IconButton aria-label = "GitHub repository" >
0 commit comments