Skip to content

Commit ae45194

Browse files
committed
[Feature] Replace Query Textarea by MonacoEdiotr
Signed-off-by: Kent Huang <kent@infuseai.io>
1 parent 1fcf126 commit ae45194

5 files changed

Lines changed: 93 additions & 17 deletions

File tree

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ indent_style = space
1616
indent_size = 4
1717

1818
# 2 space indentation
19-
[*.{js,json,y{a,}ml,html,cwl}]
19+
[*.{js,json,y{a,}ml,html,cwl,tsx}]
2020
indent_style = space
2121
indent_size = 2
2222

2323
[*.{md,Rmd,rst}]
2424
trim_trailing_whitespace = false
2525
indent_style = space
26-
indent_size = 2
26+
indent_size = 2

js/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
"@chakra-ui/react": "^2.8.1",
1919
"@emotion/react": "^11.11.1",
2020
"@emotion/styled": "^11.11.0",
21+
"@monaco-editor/react": "^4.6.0",
2122
"axios": "^1.6.0",
2223
"dagre": "^0.8.5",
2324
"framer-motion": "^10.16.4",
2425
"lodash": "^4.17.21",
26+
"monaco-editor": "^0.44.0",
2527
"next": "14.0.1",
2628
"react": "^18",
2729
"react-data-grid": "7.0.0-beta.40",

js/pnpm-lock.yaml

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/src/components/query/QueryView.tsx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import axios, { AxiosError } from "axios";
55
import { DataFrame, queryDiff } from "@/components/query/query";
66
import { PUBLIC_API_URL } from "../../lib/const";
77
import { Box, Button, Flex, Textarea } from "@chakra-ui/react";
8+
import SqlEditor from "./SqlEditor";
89

910
interface QueryViewDataGridProps {
1011
loading: boolean;
@@ -48,7 +49,7 @@ const QueryViewDataGrid = ({
4849
};
4950

5051
const QueryView = () => {
51-
const [query, setQuery] = useState('select * from {{ ref("mymodel") }}');
52+
const [query, setQuery] = useState('-- Enter your SQL query here ---\nselect * from {{ ref("mymodel") }}');
5253

5354
const [loading, setLoading] = useState(false);
5455
const [error, setError] = useState<string>();
@@ -128,21 +129,19 @@ const QueryView = () => {
128129
Run
129130
</Button>
130131
</Flex>
131-
<Textarea
132-
flex="1"
133-
height="200px"
134-
value={query}
135-
onChange={(e) => setQuery(e.target.value)}
136-
onKeyDown={(e) => {
137-
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
138-
executeQuery();
139-
e.preventDefault();
140-
}
141-
}}
142-
placeholder="Enter your SQL query here"
143-
rows={20}
132+
<Box
133+
flex='1'
134+
border={'1px solid #CBD5E0'}
135+
height='200px'
144136
style={{ width: "100%" }}
145-
/>
137+
>
138+
<SqlEditor
139+
language="sql"
140+
theme="vs"
141+
value={query}
142+
onChange={(value) => setQuery(value)}
143+
/>
144+
</Box>
146145
<Box backgroundColor="gray.100" height="50vh">
147146
<QueryViewDataGrid
148147
loading={loading}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import MonacoEditor from '@monaco-editor/react';
3+
4+
5+
interface SqlEditorProps {
6+
language?: string;
7+
theme?: string;
8+
value: string;
9+
onChange: (e: any) => void;
10+
}
11+
12+
const SqlEditor: React.FC<SqlEditorProps> = ({ value, onChange, ...props}: SqlEditorProps) => {
13+
const handleEditorChange = (value: string | undefined) => {
14+
if (value !== undefined) {
15+
onChange(value);
16+
}
17+
};
18+
19+
return (
20+
<MonacoEditor
21+
language={props.language || "sql"}
22+
theme={props.theme || "vs"}
23+
defaultValue={value}
24+
onChange={handleEditorChange}
25+
options={{
26+
tabSize: 2,
27+
fontSize: 16,
28+
lineNumbers: "off",
29+
automaticLayout: true,
30+
minimap: { enabled: false },
31+
wordWrap: "on",
32+
wrappingIndent: 'indent',
33+
// Additional options as needed
34+
}}
35+
/>
36+
);
37+
};
38+
39+
export default SqlEditor;

0 commit comments

Comments
 (0)