@@ -16,27 +16,35 @@ export const ErrorDomain = ({onSave}) => {
1616 let has_empirical = "empirical_error" in errorDomain ;
1717 let has_algorithmic = "algorithmic_error" in errorDomain ;
1818 const [ jsonErrors , setJsonErrors ] = useState ( "" ) ;
19- const [ algorithmic_error , setAlgo ] = useState ( has_algorithmic ? errorDomain . algorithmic_error : { } )
20- const [ empirical_error , setEmp ] = useState ( has_empirical ? errorDomain . empirical_error : { } )
19+ const [ algorithmic_error , setAlgo ] = useState ( has_algorithmic ? errorDomain . algorithmic_error : { algorithmic_error : "null" } )
20+ const [ empirical_error , setEmp ] = useState ( has_empirical ? errorDomain . empirical_error : { empirical_error : "null" } )
2121
2222 const setInput = ( target ) => {
23- setWriting ( true )
24- dispatch ( writingBco ( true ) )
23+ setWriting ( true ) ;
24+ dispatch ( writingBco ( true ) ) ;
2525 let holder = { } ;
2626 try {
27- holder = JSON . parse ( target . value ) ;
28- setJsonErrors ( "" )
27+ if ( target . value . trim ( ) === "" ) {
28+ holder = target . id === "algorithmic"
29+ ? { algorithmic_error : "null" }
30+ : { empirical_error : "null" } ;
31+ } else {
32+ holder = JSON . parse ( target . value ) ;
33+ }
34+ setJsonErrors ( "" ) ;
2935 } catch ( e ) {
30- setJsonErrors ( e )
31- console . log ( "Caught: " + e . message )
36+ setJsonErrors ( e ) ;
37+ console . log ( "Caught: " + e . message ) ;
3238 }
39+
3340 if ( target . id === "algorithmic" ) {
3441 setAlgo ( holder ) ;
3542 }
3643 if ( target . id === "empirical" ) {
3744 setEmp ( holder ) ;
3845 }
3946 } ;
47+
4048
4149 const defaultAlgorithmicError = `{
4250 "algorithmic_error": "null"
@@ -75,16 +83,31 @@ export const ErrorDomain = ({onSave}) => {
7583 }
7684 action = {
7785 < Button
78- disabled = { jsonErrors !== "" || ! writing }
79- variant = "contained"
80- color = "primary"
81- onClick = { ( ) => {
82- dispatch ( updateErrorDomain ( { empirical_error, algorithmic_error} ) )
83- dispatch ( updateModified ( ) )
84- dispatch ( writingBco ( false ) )
85- onSave ( )
86- } }
87- > Next </ Button >
86+ disabled = { jsonErrors !== "" || ! writing }
87+ variant = "contained"
88+ color = "primary"
89+ onClick = { ( ) => {
90+ const finalAlgorithmic =
91+ algorithmic_error ?. algorithmic_error !== undefined
92+ ? algorithmic_error
93+ : { algorithmic_error : "null" } ;
94+
95+ const finalEmpirical =
96+ empirical_error ?. empirical_error !== undefined
97+ ? empirical_error
98+ : { empirical_error : "null" } ;
99+
100+ dispatch ( updateErrorDomain ( {
101+ algorithmic_error : finalAlgorithmic ,
102+ empirical_error : finalEmpirical
103+ } ) ) ;
104+ dispatch ( updateModified ( ) ) ;
105+ dispatch ( writingBco ( false ) ) ;
106+ onSave ( ) ;
107+ } }
108+ >
109+ Next
110+ </ Button >
88111 }
89112 />
90113 < CardContent >
0 commit comments