Skip to content

Commit e27d62e

Browse files
author
Marco
committed
fix lint
1 parent b501260 commit e27d62e

File tree

6 files changed

+77
-50
lines changed

6 files changed

+77
-50
lines changed

components/webui/client/src/components/SqlEditor/index.tsx

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
1-
import {Editor, useMonaco, EditorProps} from "@monaco-editor/react";
21
import {useEffect} from "react";
3-
import { language as sqlLanguage } from 'monaco-editor/esm/vs/basic-languages/sql/sql.js';
42

5-
interface SqlEditorProps extends Omit<EditorProps, 'language'> {}
3+
import {
4+
Editor,
5+
EditorProps,
6+
useMonaco,
7+
} from "@monaco-editor/react";
8+
import {language as sqlLanguage} from "monaco-editor/esm/vs/basic-languages/sql/sql.js";
9+
10+
11+
type SqlEditorProps = Omit<EditorProps, "language">;
612

713
/**
814
* Monaco editor with highlighting and autocomplete for SQL syntax.
15+
*
16+
* @param props
17+
* @return
918
*/
1019
const SqlEditor = (props: SqlEditorProps) => {
1120
const monaco = useMonaco();
1221

1322

1423
useEffect(() => {
1524
if (null === monaco) {
16-
return;
25+
return () => {
26+
};
1727
}
18-
28+
1929
// Adds autocomplete suggestions for SQL keywords on editor load
20-
const provider = monaco.languages.registerCompletionItemProvider('sql', {
21-
provideCompletionItems: () => {
22-
const suggestions = sqlLanguage[`keywords`].map((keyword: string) => ({
23-
label: keyword,
30+
const provider = monaco.languages.registerCompletionItemProvider("sql", {
31+
provideCompletionItems: (model, position) => {
32+
const word = model.getWordUntilPosition(position);
33+
const range = {
34+
startLineNumber: position.lineNumber,
35+
endLineNumber: position.lineNumber,
36+
startColumn: word.startColumn,
37+
endColumn: word.endColumn,
38+
};
39+
const suggestions = sqlLanguage.keywords.map((keyword: string) => ({
40+
detail: "SQL Keyword",
41+
insertText: `${keyword} `,
2442
kind: monaco.languages.CompletionItemKind.Keyword,
25-
insertText: keyword + ' ',
26-
detail: 'SQL Keyword'
43+
label: keyword,
44+
range: range,
2745
}));
2846

29-
return { suggestions };
30-
}
47+
return {suggestions: suggestions};
48+
},
3149
});
3250

3351
return () => {
@@ -37,24 +55,22 @@ const SqlEditor = (props: SqlEditorProps) => {
3755

3856
return (
3957
<Editor
40-
language="sql"
58+
language={"sql"}
59+
4160
// Use white background while loading (default is grey) so transition to editor with
4261
// white background is less jarring.
43-
loading={
44-
<div style={{ backgroundColor: 'white', height: '100%', width: '100%' }}/>
45-
}
62+
loading={<div style={{backgroundColor: "white", height: "100%", width: "100%"}}/>}
4663
options={{
47-
minimap: { enabled: false },
64+
fontSize: 14,
4865
lineNumbers: "on",
4966
lineNumbersMinChars: 2,
67+
minimap: {enabled: false},
68+
overviewRulerBorder: false,
69+
placeholder: "Enter your SQL query",
5070
scrollBeyondLastLine: false,
5171
wordWrap: "on",
52-
placeholder: "Enter your SQL query",
53-
overviewRulerBorder: false,
54-
fontSize: 14,
5572
}}
56-
{...props}
57-
/>
73+
{...props}/>
5874
);
5975
};
6076

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
declare module 'monaco-editor/esm/vs/basic-languages/sql/sql.js' {
2-
import { languages } from 'monaco-editor/esm/vs/editor/editor.api';
3-
4-
export const language: languages.IMonarchLanguage;
1+
declare module "monaco-editor/esm/vs/basic-languages/sql/sql.js" {
2+
import {languages} from "monaco-editor/esm/vs/editor/editor.api";
3+
4+
5+
interface SqlLanguageDefinition extends languages.IMonarchLanguage {
6+
keywords: string[];
7+
}
8+
9+
export const language: SqlLanguageDefinition;
510
}

components/webui/client/src/config/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const STREAM_TYPE = CLP_STORAGE_ENGINES.CLP === SETTINGS_STORAGE_ENGINE ?
2828
"json";
2929

3030
export {
31-
CLP_STORAGE_ENGINES,
3231
CLP_QUERY_ENGINES,
33-
SETTINGS_STORAGE_ENGINE,
32+
CLP_STORAGE_ENGINES,
3433
SETTINGS_QUERY_ENGINE,
34+
SETTINGS_STORAGE_ENGINE,
3535
STREAM_TYPE,
3636
};

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import useSearchStore, {SEARCH_STATE_DEFAULT} from "../../../SearchState/index";
88
import styles from "../../SearchButton/SubmitButton/index.module.css";
99

10+
1011
/**
1112
* Renders a button to run the SQL query.
1213
*

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { useCallback } from "react";
1+
import {useCallback} from "react";
2+
23
import SqlEditor from "../../../../../components/SqlEditor";
34
import useSearchStore from "../../../SearchState/index";
45

6+
57
/**
68
* Renders SQL query input.
9+
*
10+
* @return
711
*/
812
const SqlQueryInput = () => {
913
const handleChange = useCallback((value: string | undefined) => {
@@ -13,9 +17,8 @@ const SqlQueryInput = () => {
1317

1418
return (
1519
<SqlEditor
16-
height="150px"
17-
onChange={handleChange}
18-
/>
20+
height={"150px"}
21+
onChange={handleChange}/>
1922
);
2023
};
2124

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import {
2-
CLP_STORAGE_ENGINES,
32
CLP_QUERY_ENGINES,
4-
SETTINGS_STORAGE_ENGINE,
3+
CLP_STORAGE_ENGINES,
54
SETTINGS_QUERY_ENGINE,
5+
SETTINGS_STORAGE_ENGINE,
66
} from "../../../config";
77
import Dataset from "./Dataset";
88
import styles from "./index.module.css";
9-
import QueryInput from "./QueryInput";
109
import RunButton from "./Presto/RunButton";
11-
import SearchButton from "./SearchButton";
1210
import SqlQueryInput from "./Presto/SqlQueryInput";
11+
import QueryInput from "./QueryInput";
12+
import SearchButton from "./SearchButton";
1313
import TimeRangeInput from "./TimeRangeInput";
1414

1515

@@ -31,19 +31,21 @@ const SearchControls = () => {
3131
return (
3232
<form onSubmit={handleSubmit}>
3333
<div className={styles["searchControlsContainer"]}>
34-
{SETTINGS_QUERY_ENGINE === CLP_QUERY_ENGINES.NATIVE ? (
35-
<>
36-
{CLP_STORAGE_ENGINES.CLP_S === SETTINGS_STORAGE_ENGINE && <Dataset/>}
37-
<QueryInput/>
38-
<TimeRangeInput/>
39-
<SearchButton/>
40-
</>
41-
) : (
42-
<>
43-
<SqlQueryInput/>
44-
<RunButton/>
45-
</>
46-
)}
34+
{SETTINGS_QUERY_ENGINE === CLP_QUERY_ENGINES.NATIVE ?
35+
(
36+
<>
37+
{CLP_STORAGE_ENGINES.CLP_S === SETTINGS_STORAGE_ENGINE && <Dataset/>}
38+
<QueryInput/>
39+
<TimeRangeInput/>
40+
<SearchButton/>
41+
</>
42+
) :
43+
(
44+
<>
45+
<SqlQueryInput/>
46+
<RunButton/>
47+
</>
48+
)}
4749
</div>
4850
</form>
4951
);

0 commit comments

Comments
 (0)