File tree Expand file tree Collapse file tree 9 files changed +162
-6
lines changed
Presto/SqlInterfaceButton Expand file tree Collapse file tree 9 files changed +162
-6
lines changed Original file line number Diff line number Diff line change 77 "build" : " tsc -b && vite build" ,
88 "lint:check" : " eslint" ,
99 "lint:fix" : " eslint --fix" ,
10- "start" : " vite"
10+ "start" : " vite" ,
11+ "guided" : " VITE_GUIDED_DEV=true npm run start"
1112 },
1213 "author" :
" YScope Inc. <[email protected] >" ,
1314 "license" : " Apache-2.0" ,
Original file line number Diff line number Diff line change 1+ import { EditOutlined } from "@ant-design/icons" ;
2+ import { Button } from "antd" ;
3+
4+ import usePrestoSearchState from "../../../../SearchState/Presto" ;
5+ import { PRESTO_SQL_INTERFACE } from "../../../../SearchState/Presto/typings" ;
6+
7+
8+ /**
9+ * Renders a button to switch to Freeform SQL interface.
10+ *
11+ * @return
12+ */
13+ const FreeformButton = ( ) => {
14+ const setSqlInterface = usePrestoSearchState ( ( state ) => state . setSqlInterface ) ;
15+
16+ const handleClick = ( ) => {
17+ setSqlInterface ( PRESTO_SQL_INTERFACE . FREEFORM ) ;
18+ } ;
19+
20+ return (
21+ < Button
22+ block = { true }
23+ color = { "default" }
24+ icon = { < EditOutlined /> }
25+ size = { "middle" }
26+ variant = { "filled" }
27+ onClick = { handleClick }
28+ >
29+ Freeform
30+ </ Button >
31+ ) ;
32+ } ;
33+
34+
35+ export default FreeformButton ;
Original file line number Diff line number Diff line change 1+ import { AppstoreOutlined } from "@ant-design/icons" ;
2+ import { Button } from "antd" ;
3+
4+ import usePrestoSearchState from "../../../../SearchState/Presto" ;
5+ import { PRESTO_SQL_INTERFACE } from "../../../../SearchState/Presto/typings" ;
6+
7+
8+ /**
9+ * Renders a button to switch to Guided SQL interface.
10+ *
11+ * @return
12+ */
13+ const GuidedButton = ( ) => {
14+ const setSqlInterface = usePrestoSearchState ( ( state ) => state . setSqlInterface ) ;
15+
16+ const handleClick = ( ) => {
17+ setSqlInterface ( PRESTO_SQL_INTERFACE . GUIDED ) ;
18+ } ;
19+
20+ return (
21+ < Button
22+ block = { true }
23+ color = { "default" }
24+ icon = { < AppstoreOutlined /> }
25+ size = { "middle" }
26+ variant = { "filled" }
27+ onClick = { handleClick }
28+ >
29+ Guided
30+ </ Button >
31+ ) ;
32+ } ;
33+
34+ export default GuidedButton ;
Original file line number Diff line number Diff line change 1+ .sqlInterfaceButton {
2+ width : 100px ;
3+ }
Original file line number Diff line number Diff line change 1+ import usePrestoSearchState from "../../../SearchState/Presto" ;
2+ import { PRESTO_SQL_INTERFACE } from "../../../SearchState/Presto/typings" ;
3+ import FreeformButton from "./FreeformButton" ;
4+ import GuidedButton from "./GuidedButton" ;
5+ import styles from "./index.module.css" ;
6+
7+
8+ /**
9+ * Renders the button to switch Presto SQL interface.
10+ *
11+ * @return
12+ */
13+ const SqlInterfaceButton = ( ) => {
14+ const sqlInterface = usePrestoSearchState ( ( state ) => state . sqlInterface ) ;
15+
16+ return (
17+ < div className = { styles [ "sqlInterfaceButton" ] } >
18+ { sqlInterface === PRESTO_SQL_INTERFACE . GUIDED ?
19+ < FreeformButton /> :
20+ < GuidedButton /> }
21+ </ div >
22+ ) ;
23+ } ;
24+
25+ export default SqlInterfaceButton ;
Original file line number Diff line number Diff line change 99 gap : 10px ;
1010}
1111
12- .buttonAndStatusRow {
12+ .status {
13+ margin-left : 2px ;
14+ }
15+
16+ .statusAndButtonsRow {
1317 display : flex;
1418 align-items : flex-start;
1519 justify-content : space-between;
1620 gap : 10px ;
1721}
1822
19- .status {
20- margin-left : 2px ;
23+ .buttons {
24+ display : flex;
25+ flex-direction : row;
26+ gap : 5px ;
2127}
Original file line number Diff line number Diff line change 66} from "../../../config" ;
77import Dataset from "./Dataset" ;
88import styles from "./index.module.css" ;
9+ import SqlInterfaceButton from "./Presto/SqlInterfaceButton" ;
910import SqlQueryInput from "./Presto/SqlQueryInput" ;
1011import SqlSearchButton from "./Presto/SqlSearchButton" ;
1112import QueryInput from "./QueryInput" ;
@@ -29,6 +30,10 @@ const handleSubmit = (ev: React.FormEvent<HTMLFormElement>) => {
2930 * @return
3031 */
3132const SearchControls = ( ) => {
33+ /* eslint-disable-next-line no-warning-comments */
34+ // TODO: Remove flag and related logic when the new guide UI is fully implemented.
35+ const isGuidedEnabled = "true" === import . meta. env [ `VITE_GUIDED_DEV` ] ;
36+
3237 return (
3338 < form onSubmit = { handleSubmit } >
3439 { SETTINGS_QUERY_ENGINE !== CLP_QUERY_ENGINES . PRESTO ?
@@ -48,11 +53,14 @@ const SearchControls = () => {
4853 (
4954 < div className = { styles [ "searchControlsContainer" ] } >
5055 < SqlQueryInput />
51- < div className = { styles [ "buttonAndStatusRow " ] } >
56+ < div className = { styles [ "statusAndButtonsRow " ] } >
5257 < div className = { styles [ "status" ] } >
5358 < QueryStatus />
5459 </ div >
55- < SqlSearchButton />
60+ < div className = { styles [ "buttons" ] } >
61+ { isGuidedEnabled && < SqlInterfaceButton /> }
62+ < SqlSearchButton />
63+ </ div >
5664 </ div >
5765 </ div >
5866 ) }
Original file line number Diff line number Diff line change 1+ import { create } from "zustand" ;
2+
3+ import { PRESTO_SQL_INTERFACE } from "./typings" ;
4+
5+
6+ /**
7+ * Default values of the Presto search state.
8+ */
9+ const PRESTO_SEARCH_STATE_DEFAULT = Object . freeze ( {
10+ sqlInterface : PRESTO_SQL_INTERFACE . FREEFORM ,
11+ } ) ;
12+
13+ interface PrestoSearchState {
14+ /**
15+ * Presto SQL interface.
16+ */
17+ sqlInterface : PRESTO_SQL_INTERFACE ;
18+
19+ setSqlInterface : ( iface : PRESTO_SQL_INTERFACE ) => void ;
20+ }
21+
22+ const usePrestoSearchState = create < PrestoSearchState > ( ( set ) => ( {
23+ ...PRESTO_SEARCH_STATE_DEFAULT ,
24+ setSqlInterface : ( iface ) => {
25+ set ( { sqlInterface : iface } ) ;
26+ } ,
27+ } ) ) ;
28+
29+ export { PRESTO_SEARCH_STATE_DEFAULT } ;
30+ export default usePrestoSearchState ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Presto SQL interface types.
3+ */
4+ export enum PRESTO_SQL_INTERFACE {
5+ /**
6+ * Guided interface with limited SQL dialect.
7+ */
8+ GUIDED = "guided" ,
9+
10+ /**
11+ * Freeform interface with SQL editor.
12+ */
13+ FREEFORM = "freeform" ,
14+ }
You can’t perform that action at this time.
0 commit comments