Skip to content

Commit 5c7595d

Browse files
fix: update SQL editor
1 parent 7ed1a40 commit 5c7595d

4 files changed

Lines changed: 49 additions & 35 deletions

File tree

internal/webui/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import { privateRoutes, publicRoutes } from "layout/Routes";
1313

1414
import { AppBar } from "./layout/AppBar";
1515

16+
import "prismjs/components/prism-sql";
17+
import "prismjs/themes/prism.css";
18+
1619
const mdTheme = createTheme();
1720

1821
export default function App() {

internal/webui/src/containers/MetricFormDialog/components/MetricForm/components/MetricFormStepSQL.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
import { FormControl, FormHelperText, InputLabel, OutlinedInput } from "@mui/material";
2-
import { useFormContext } from "react-hook-form";
1+
import { FormControl, FormHelperText, InputLabel, OutlinedInput, useTheme } from "@mui/material";
2+
import { Controller, useFormContext } from "react-hook-form";
33
import { useFormStyles } from "styles/form";
44
import { MetricFormValues } from "../MetricForm.types";
55
import Editor from "react-simple-code-editor";
66
import { highlight, languages } from "prismjs";
7-
import "prismjs/components/prism-sql";
8-
import "prismjs/themes/prism.css";
9-
import { Controller } from "react-hook-form";
7+
108

119

1210
export const MetricFormStepSQL = () => {
1311
const { control, formState: { errors } } = useFormContext<MetricFormValues>();
1412
const { classes, cx } = useFormStyles();
13+
const theme = useTheme();
1514

1615
const hasError = !!errors.SQLs;
1716
const errorMessage = errors.SQLs?.message;
@@ -22,6 +21,7 @@ export const MetricFormStepSQL = () => {
2221
className={cx(classes.formControlInput, classes.widthFull)}
2322
error={hasError}
2423
variant="outlined"
24+
aria-describedby="SQLs-error"
2525
>
2626
<InputLabel
2727
shrink
@@ -37,18 +37,22 @@ export const MetricFormStepSQL = () => {
3737
<Editor
3838
value={field.value ?? ""}
3939
onValueChange={field.onChange}
40+
onBlur={field.onBlur}
4041
highlight={(code) => highlight(code, languages.sql, "sql")}
4142
padding={12}
42-
id="SQLs"
43+
id="InitSQL"
44+
aria-describedby="InitSQL-error"
4345
style={{
4446
fontFamily: "'Fira Code', 'Consolas', monospace",
4547
fontSize: "0.75rem",
4648
lineHeight: 1.6,
4749
minHeight: "240px",
48-
border: hasError ? "1px solid #d32f2f" : "1px solid rgba(0,0,0,0.23)",
4950
borderRadius: "4px",
50-
backgroundColor: "#fafafa",
51-
color: "#333",
51+
backgroundColor: theme.palette.background.paper,
52+
color: theme.palette.text.primary,
53+
border: hasError
54+
? `1px solid ${theme.palette.error.main}`
55+
: `1px solid ${theme.palette.divider}`,
5256
}}
5357
/>
5458
)}

internal/webui/src/containers/MetricFormDialog/components/MetricForm/components/MetricFormStepSettings.tsx

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
import { Checkbox, FormControl, FormControlLabel, FormHelperText, InputLabel, OutlinedInput } from "@mui/material";
2-
import { useController, useFormContext } from "react-hook-form";
1+
import { Checkbox, FormControl, FormControlLabel, FormHelperText, InputLabel, OutlinedInput, useTheme } from "@mui/material";
2+
import { Controller, useController, useFormContext } from "react-hook-form";
33
import { useFormStyles } from "styles/form";
44
import { MetricFormValues } from "../MetricForm.types";
55
import Editor from "react-simple-code-editor";
66
import { highlight, languages } from "prismjs";
7-
import "prismjs/components/prism-sql";
8-
import "prismjs/themes/prism.css";
9-
import { Controller } from "react-hook-form";
7+
108

119
export const MetricFormStepSettings = () => {
12-
const { register, control } = useFormContext<MetricFormValues>();
10+
const { register, control, formState: { errors }, } = useFormContext<MetricFormValues>();
1311
const { classes, cx } = useFormStyles();
14-
12+
const theme = useTheme();
13+
const hasError = !!errors.SQLs;
14+
const errorMessage = errors.SQLs?.message;
1515
const { field: instanceLevelField } = useController({ name: "IsInstanceLevel", control });
1616

1717
return (
1818
<div className={classes.form}>
1919
<FormControl
2020
className={cx(classes.formControlInput, classes.widthDefault)}
2121
variant="outlined"
22+
error={hasError}
23+
aria-describedby="InitSQL-error"
2224
>
2325
<InputLabel htmlFor="Gauges">Gauges</InputLabel>
2426
<OutlinedInput
@@ -33,7 +35,7 @@ export const MetricFormStepSettings = () => {
3335
</FormControl>
3436
<FormControl
3537
className={cx(classes.formControlInput, classes.widthFull)}
36-
variant="outlined"
38+
variant="outlined"
3739
>
3840
<InputLabel
3941
shrink
@@ -46,25 +48,29 @@ export const MetricFormStepSettings = () => {
4648
name="InitSQL"
4749
control={control}
4850
render={({ field }) => (
49-
<Editor
50-
value={field.value ?? ""}
51-
onValueChange={field.onChange}
52-
highlight={(code) => highlight(code, languages.sql, "sql")}
53-
padding={12}
54-
id="InitSQL"
55-
style={{
56-
fontFamily: "'Fira Code', 'Consolas', monospace",
57-
fontSize: "0.75rem",
58-
lineHeight: 1.6,
59-
minHeight: "120px",
60-
border: "1px solid rgba(0,0,0,0.23)",
61-
borderRadius: "4px",
62-
backgroundColor: "#fafafa",
63-
color: "#333",
64-
}}
65-
/>
66-
)}
51+
<Editor
52+
value={field.value ?? ""}
53+
onValueChange={field.onChange}
54+
onBlur={field.onBlur}
55+
highlight={(code) => highlight(code, languages.sql, "sql")}
56+
padding={12}
57+
id="InitSQL"
58+
style={{
59+
fontFamily: "'Fira Code', 'Consolas', monospace",
60+
fontSize: "0.75rem",
61+
lineHeight: 1.6,
62+
minHeight: "120px",
63+
borderRadius: "4px",
64+
backgroundColor: theme.palette.background.paper,
65+
color: theme.palette.text.primary,
66+
border: hasError
67+
? `1px solid ${theme.palette.error.main}`
68+
: `1px solid ${theme.palette.divider}`,
69+
}}
70+
/>
71+
)}
6772
/>
73+
<FormHelperText id="InitSQL-error">{errorMessage}</FormHelperText>
6874
</FormControl>
6975
<FormControlLabel
7076
className={classes.formControlCheckbox}

internal/webui/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"resolveJsonModule": true,
2626
"isolatedModules": true,
2727
"noEmit": true,
28+
"ignoreDeprecations": "6.0",
2829
"downlevelIteration": true,
2930
"noFallthroughCasesInSwitch": true,
3031
"jsx": "react-jsx"

0 commit comments

Comments
 (0)