Skip to content

Commit 73cdfa8

Browse files
committed
Fix non-permanent state of history table after switching tabs
1 parent 16a2a1c commit 73cdfa8

File tree

5 files changed

+59
-38
lines changed

5 files changed

+59
-38
lines changed

src/Main.re

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ let make = (~cil, ~goblint, ~warnings, ~meta, ~stats, ~file_loc) => {
4848
[|state.display|],
4949
);
5050

51+
let parameters = state |> ParameterUtils.getParameters;
52+
Util.log(parameters);
53+
54+
let destructuredParameters = parameters |> ParameterUtils.concatParameters;
55+
let (history, setHistory) = React.useState(_ => [|(destructuredParameters, Time.getLocalTime(), ParameterView.Executed)|]);
56+
57+
React.useEffect1(() => {
58+
None
59+
}, [|history|]);
60+
5161
<div className="container-fluid">
5262
<header className="navbar navbar-dark fixed-top bg-dark flex-md-nowrap shadow p-1">
5363
<div className="navbar-brand mx-2" >{React.string("Gobview")}</div>
@@ -66,7 +76,7 @@ let make = (~cil, ~goblint, ~warnings, ~meta, ~stats, ~file_loc) => {
6676
| None => <div className="content d-flex flex-column h-75 overflow-auto p-4" />
6777
| Some(f) => <Content state display=f dispatch />
6878
}}
69-
<Panel state dispatch />
79+
<Panel state dispatch parameters={destructuredParameters} history setHistory />
7080
</div>
7181
<div className="col-3 border-start overflow-auto py-2 h-100">
7282
<SidebarRight

src/ui/panel/Panel.re

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,7 @@ let make_nav_pills = (current, dispatch) => {
3131
};
3232

3333
[@react.component]
34-
let make = (~state, ~dispatch) => {
35-
let parameters =
36-
switch (Yojson.Safe.Util.member("command", state.meta)) {
37-
| `String(command) => command
38-
| _ => ""
39-
};
34+
let make = (~state, ~dispatch, ~parameters, ~history, ~setHistory) => {
4035

4136
let locations = (state.goblint)#dead_locations;
4237

@@ -46,7 +41,7 @@ let make = (~state, ~dispatch) => {
4641
| Some(Warnings) => <WarningView warnings={state.warnings} dispatch />
4742
| Some(DeadCode) => <DeadCodeView locations dispatch />
4843
| Some(Statistics) => <GvStatisticsView stats={state.stats} />
49-
| Some(Parameters) => <ParameterView parameters />
44+
| Some(Parameters) => <ParameterView parameters history setHistory />
5045
| _ => React.null
5146
};
5247

src/ui/panel/ParameterView.re

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
open Unix
21
//open Lwt
32
//open Cohttp
43
//open Cohttp_lwt_unix
@@ -8,37 +7,12 @@ module ReactDOM = React.Dom
87

98
type paramState = Executed | Executing | Canceled | Error;
109

11-
// TODO FIX BUG: make param history permanently available until GobView is closed again => clear afterwards
1210
[@react.component]
13-
let make = (~parameters) => {
14-
15-
let initParams =
16-
parameters
17-
|> String.split_on_char(' ')
18-
|> List.map((s) => { String.sub(s, 1, String.length(s)-2)})
19-
|> String.concat(" ");
20-
21-
let timeToString = (time) => {
22-
string_of_int(time.tm_min)
23-
|> String.cat(":")
24-
|> String.cat(string_of_int(time.tm_hour))
25-
|> String.cat(" ");
26-
}
27-
28-
let getLocalTime = () => {
29-
Unix.time()
30-
|> Unix.localtime
31-
|> timeToString;
32-
}
11+
let make = (~parameters, ~history, ~setHistory) => {
3312

34-
let (history, setHistory) = React.useState(_ => [|(initParams, getLocalTime(), Executed)|]);
35-
let (value, setValue) = React.useState(_ => initParams);
13+
let (value, setValue) = React.useState(_ => parameters);
3614
let (disableCancel, setDisableCancel) = React.useState(_ => true);
3715

38-
React.useEffect1(() => {
39-
None
40-
}, [|history|]);
41-
4216
React.useEffect1(() => {
4317
None
4418
}, [|value|]);
@@ -48,7 +22,7 @@ let make = (~parameters) => {
4822
};
4923

5024
let on_submit = () => {
51-
let newHistory = Array.append(history, [|(value, getLocalTime(), Executing)|])
25+
let newHistory = Array.append(history, [|(value, Time.getLocalTime(), Executing)|])
5226
setHistory(_ => newHistory)
5327

5428
// TODO transform param string with "' '" seperation mask
@@ -101,7 +75,7 @@ let make = (~parameters) => {
10175
)
10276
};
10377

104-
let list_elements = map_history_entry_to_list_entry(history);
78+
let list_elements = history |> map_history_entry_to_list_entry;
10579

10680
<div>
10781
<div className="input-group mb-2">

src/utils/ParameterUtils.re

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
open State
2+
3+
let concatParameters = (parameters) => {
4+
parameters
5+
|> String.split_on_char(' ')
6+
|> List.map((s) => { String.sub(s, 1, String.length(s)-2)})
7+
|> String.concat(" ")
8+
};
9+
10+
let getParameters = (state) => {
11+
switch (Yojson.Safe.Util.member("command", state.meta)) {
12+
| `String(command) => command
13+
| _ => ""
14+
}
15+
};
16+
17+
let constructParameters = (parameters) => {
18+
parameters
19+
|> String.split_on_char(' ')
20+
|> List.map((s) => "'" |> String.cat(s) |> String.cat("'"))
21+
}

src/utils/Time.re

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
open Unix
2+
3+
let timeToString = (time) => {
4+
let rawMinutes = string_of_int(time.tm_min);
5+
let minutes = if (String.length(rawMinutes) == 1) {
6+
"0"
7+
} else {
8+
""
9+
} ++ rawMinutes;
10+
11+
minutes
12+
|> String.cat(":")
13+
|> String.cat(string_of_int(time.tm_hour))
14+
|> String.cat(" ");
15+
};
16+
17+
let getLocalTime = () => {
18+
Unix.time()
19+
|> Unix.localtime
20+
|> timeToString;
21+
};

0 commit comments

Comments
 (0)