@@ -57,24 +57,16 @@ let headers = [
5757 ("Access-Control-Allow-Methods" , "GET, POST, PUT, DELETE, OPTIONS" )
5858] |> Header . of_list;
5959
60- let rev_arr = (array) => array |> Array . to_list |> List . rev |> Array . of_list;
61-
6260[@ react . component ]
63- let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
64-
65- let (value , setValue ) = React . useState(_ => parameters |> ParameterUtils . concat_parameter_list);
61+ let make = (~goblint_path, ~inputValue, ~setInputValue, ~disableRun, ~setDisableRun, ~inputState, ~setInputState, ~sortDesc, ~setSortDesc, ~history, ~setHistory) => {
6662 // Linked to cancelation, see reasons below in on_cancel() for why it is commented out
6763 // let (disableCancel, setDisableCancel) = React.useState(_ => true);
68- let (disableRun , setDisableRun ) = React . useState(_ => false );
69- let (inputState , setInputState ) = React . useState(_ => Ok );
70- let (sortDesc , setSortDesc ) = React . useState(_ => true );
71-
64+
7265 React . useEffect1(() => {
7366 None
74- }, [| value |] );
67+ }, [| inputValue |] );
7568
7669 React . useEffect1(() => {
77- setHistory(_ => history |> rev_arr);
7870 None
7971 }, [| sortDesc|] );
8072
@@ -111,8 +103,8 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
111103 }
112104 }
113105
114- let react_on_input = (parameter_list, is_malformed, value ) => {
115- let input_state = is_input_invalid(parameter_list, is_malformed, value );
106+ let react_on_input = (parameter_list, is_malformed, inputValue ) => {
107+ let input_state = is_input_invalid(parameter_list, is_malformed, inputValue );
116108 setInputState(_ => input_state);
117109
118110 let isInvalid = ! is_ok(input_state)
@@ -121,60 +113,40 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
121113 isInvalid
122114 }
123115
124- let on_change = (new_value ) => {
116+ let on_change = (new_inputValue ) => {
125117 let (tuple_parameter_list , is_malformed ) =
126- new_value
118+ new_inputValue
127119 |> ParameterUtils . construct_parameters
128120 |> ((p, b)) => (p |> ParameterUtils . tuples_from_parameters, b);
129121
130- let _ = react_on_input(tuple_parameter_list, is_malformed, new_value );
131- setValue (_ => new_value );
122+ let _ = react_on_input(tuple_parameter_list, is_malformed, new_inputValue );
123+ setInputValue (_ => new_inputValue );
132124 };
133125
134126 let on_submit = () => {
135127 let (parameter_list , tuple_parameter_list , is_malformed ) =
136- value
128+ inputValue
137129 |> ParameterUtils . construct_parameters
138130 |> ((p, b)) => (p, p |> ParameterUtils . tuples_from_parameters, b);
139131
140132 // To prevent invalid default input to be executed, with i.e. blacklisted options, we check the input value first
141- let isInvalid = react_on_input(tuple_parameter_list, is_malformed, value );
133+ let isInvalid = react_on_input(tuple_parameter_list, is_malformed, inputValue );
142134
143135 if (! isInvalid) {
144136 let time = Time . get_local_time() ;
145137 let element = (parameter_list, time, Executing );
146138
147- let new_history = if (sortDesc) {
148- history |> Array . append([| element|] )
149- } else {
150- [| element|] |> Array . append(history)
151- };
139+ let new_history = List . cons(element, history);
152140
153141 setHistory(_ => new_history);
154142 // setDisableCancel(_ => false);
155143
156144 let modify_history = (result: paramState ): unit => {
157- let lastIndex = Array . length(new_history) - 1 ;
158- // This tuple is used to calculate where to update the last added history/parameter element
159- let (index , startIndex , endIndex ) = if (sortDesc) {
160- (0 , 1 , lastIndex)
161- } else {
162- (lastIndex, 0 , lastIndex)
163- };
164-
165- let pickedElem = index |> Array . get(new_history);
145+ let pickedElem = new_history |> List . hd;
166146
167147 if (pickedElem == element) {
168- let intermediateHistory = endIndex |> Array . sub(new_history, startIndex);
169-
170- let new_element = (parameter_list, time, result);
171-
172- let new_history = if (sortDesc) {
173- intermediateHistory |> Array . append([| new_element|] )
174- } else {
175- [| new_element|] |> Array . append(intermediateHistory)
176- };
177-
148+ let intermediateHistory = new_history |> List . tl;
149+ let new_history = List . cons(((parameter_list, time, result)), intermediateHistory);
178150 setHistory(_ => new_history);
179151 // setDisableCancel(_ => true);
180152 }
@@ -258,13 +230,10 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
258230
259231 // This cancel function is here in case it will be implemented in the http-server, not far fetched.
260232 /* let on_cancel = () => {
261- let lastElemIndex = Array.length(history) - 1;
262- let (param, time, _) = Array.get(history, lastElemIndex);
263-
264- let intermediateHistory = Array.sub(history, 0, lastElemIndex);
265- let new_history = Array.append(intermediateHistory, [|(param, time, Canceled)|]);
233+ let (param, time, _) = history |> List.hd;
234+ let intermediateHistory = history |> List.tl;
235+ let new_history = List.cons(((param, time, Canceled)), intermediateHistory);
266236 setHistory(_ => new_history);
267-
268237 setDisableCancel(_ => true);
269238 };*/
270239
@@ -273,8 +242,16 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
273242 {"Run" |> React . string}
274243 </Button >;
275244
276- let map_history_entry_to_list_entry = (arr) => {
277- arr |> Array . mapi((i, (parameter_grouping, time, paramState)) =>
245+ let map_history_entry_to_list_entry = (history) => {
246+ history
247+ |> (history) => {
248+ if (! sortDesc) {
249+ history |> List . rev
250+ } else {
251+ history
252+ }
253+ }
254+ |> List . mapi((i, (parameter_grouping, time, paramState)) =>
278255 {<li key= {"params_" ++ string_of_int(i)} className= "list-group-item" >
279256 <div className= "container text-center" >
280257 <div className= "row" >
@@ -319,8 +296,8 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
319296 {switch inputState {
320297 | Malformed
321298 | Blacklisted
322- | Empty => <Input class_= [ "form-control" , "is-invalid" ] value on_change on_submit key= "tooltip_path" /* id=input_id style={ReactDOM.Style.make(~maxWidth="100%", ())} */ />
323- | Ok => <Input value on_change on_submit key= "tooltip_path" /* id=input_id*/ />;
299+ | Empty => <Input class_= [ "form-control" , "is-invalid" ] value= inputValue on_change on_submit key= "tooltip_path" />
300+ | Ok => <Input value= inputValue on_change on_submit key= "tooltip_path" /* id=input_id*/ />;
324301 }}
325302 {switch inputState {
326303 | Ok => React . null;
@@ -355,7 +332,7 @@ let make = (~goblint_path, ~parameters, ~history, ~setHistory) => {
355332 </div >
356333 </div >
357334 </li >}
358- {list_elements |> Array . to_list |> React . list}
335+ {list_elements |> React . list}
359336 </ol >
360337 </div >
361338 </div >
0 commit comments