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" ;
33import { useFormStyles } from "styles/form" ;
44import { MetricFormValues } from "../MetricForm.types" ;
55import Editor from "react-simple-code-editor" ;
66import { 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
119export 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 < / I n p u t L a b e l >
2426 < OutlinedInput
@@ -33,7 +35,7 @@ export const MetricFormStepSettings = () => {
3335 < / F o r m C o n t r o l >
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} < / F o r m H e l p e r T e x t >
6874 < / F o r m C o n t r o l >
6975 < FormControlLabel
7076 className = { classes . formControlCheckbox }
0 commit comments