Skip to content

Commit 9dde8f8

Browse files
authored
feat(webui): Add guided query mode button; Add a temporary env var to enable the guided query mode. (#1276)
1 parent f91f98c commit 9dde8f8

File tree

9 files changed

+162
-6
lines changed

9 files changed

+162
-6
lines changed

components/webui/client/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
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",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.sqlInterfaceButton {
2+
width: 100px;
3+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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;

components/webui/client/src/pages/SearchPage/SearchControls/index.module.css

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@
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
}

components/webui/client/src/pages/SearchPage/SearchControls/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
} from "../../../config";
77
import Dataset from "./Dataset";
88
import styles from "./index.module.css";
9+
import SqlInterfaceButton from "./Presto/SqlInterfaceButton";
910
import SqlQueryInput from "./Presto/SqlQueryInput";
1011
import SqlSearchButton from "./Presto/SqlSearchButton";
1112
import QueryInput from "./QueryInput";
@@ -29,6 +30,10 @@ const handleSubmit = (ev: React.FormEvent<HTMLFormElement>) => {
2930
* @return
3031
*/
3132
const 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
)}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

0 commit comments

Comments
 (0)