Skip to content

Commit 0a57205

Browse files
committed
added explanations in NullClosure
1 parent 7775fa6 commit 0a57205

File tree

2 files changed

+122
-64
lines changed

2 files changed

+122
-64
lines changed

src/features/components/minimzeDfa/MinimizedDfa.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,6 @@ export const MinimizedDfa = (props: MinimizedDfaProps) => {
7575

7676
const [open, setOpen] = useState(1);
7777

78-
const handleSnackbarClose = (
79-
event: React.SyntheticEvent | Event,
80-
reason?: string
81-
) => {
82-
if (reason === "clickaway") {
83-
return;
84-
}
85-
setOpenSnackbar(false);
86-
};
87-
8878
useEffect(() => {
8979
setMinimizedDfaRows(dataContext?.rows);
9080
setMinimizedDfaStates(props?.states);
@@ -147,6 +137,16 @@ export const MinimizedDfa = (props: MinimizedDfaProps) => {
147137
}
148138
}, [isPlaying, displayStep, mergeStep]);
149139

140+
const handleSnackbarClose = (
141+
event: React.SyntheticEvent | Event,
142+
reason?: string
143+
) => {
144+
if (reason === "clickaway") {
145+
return;
146+
}
147+
setOpenSnackbar(false);
148+
};
149+
150150
const handleUpdateData = () => {
151151
console.log("MinimizedDfa handleUpdateData: stepNumber: ", displayStep);
152152
if (displayStep === 0) {

src/features/components/nfaToDfa/NullClosure.tsx

Lines changed: 112 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
Alert,
23
Box,
34
Button,
45
ButtonGroup,
@@ -8,6 +9,7 @@ import {
89
MenuItem,
910
Select,
1011
SelectChangeEvent,
12+
Snackbar,
1113
} from "@mui/material";
1214
import { GridColumns } from "@mui/x-data-grid";
1315
import { useContext, useEffect, useState } from "react";
@@ -78,57 +80,88 @@ export const NullClosure = (props: NullClosureProps) => {
7880

7981
const [open, setOpen] = useState(1);
8082

83+
const [showExplanation, setShowExplanation] = useState(false);
84+
const [openSnackbar, setOpenSnackbar] = useState(false);
85+
const [snackbarMessage, setSnackbarMessage] = useState("");
86+
8187
// populate props rows in null closure table one by one with null closure states and transitions according to specified duration and isPlaying
8288
useEffect(() => {
83-
console.log(
84-
"NullClosure useEffect, isPlaying, duration: ",
85-
isPlaying,
86-
duration
87-
);
8889
if (isPlaying) {
8990
let timer = setTimeout(() => {
90-
console.log("inside set timeout, index", index);
91-
const rowIndex = Math.floor(index / numberOfColumns);
92-
console.log(
93-
"before handleUpdateData: index, rowIndex: ",
94-
index,
95-
rowIndex,
96-
props.rows.length
97-
);
91+
if (!showExplanation) {
92+
const rowIndex = Math.floor(index / numberOfColumns);
9893

99-
handleUpdateData(
100-
rowIndex,
101-
props.rows.slice(0, rowIndex),
102-
props.states.slice(0, rowIndex),
103-
props.transitions
104-
);
94+
handleUpdateData(
95+
rowIndex,
96+
props.rows.slice(0, rowIndex),
97+
props.states.slice(0, rowIndex),
98+
props.transitions
99+
);
105100

106-
// stop if all rows have been displayed i.e., if rowIndex equals rows length and last row's null column has been displayed
107-
// index === props.rows.length * numberOfColumns + props.states.length - 1;
108-
if (
109-
rowIndex === props.rows.length &&
110-
index % numberOfColumns === numberOfColumns - 1
111-
) {
112-
setIsComplete(true);
113-
setIsPlaying(false);
114-
} else index++;
101+
// stop if all rows have been displayed
102+
if (rowIndex > props.rows.length && index % numberOfColumns === 0) {
103+
setIsComplete(true);
104+
setIsPlaying(false);
105+
handleExplanation();
106+
}
107+
index++;
108+
} else handleExplanation();
115109
}, duration * 1000);
116110
return () => clearTimeout(timer);
117111
}
118-
}, [props, nullClosureRows, isPlaying]);
112+
}, [props, nullClosureRows, isPlaying, showExplanation]);
113+
114+
const handleExplanation = () => {
115+
if (index % numberOfColumns === 0)
116+
setSnackbarMessage(
117+
`Added null closure of ${dataContext?.rows?.[
118+
nullClosureRowId - 1
119+
]?.state?.replaceAll(
120+
NullClosureStateId,
121+
""
122+
)} i.e., ${dataContext?.rows?.[nullClosureRowId - 1]?.state?.replaceAll(
123+
NullClosureStateId,
124+
""
125+
)} itself` +
126+
(dataContext?.rows?.[nullClosureRowId - 1]?.nul !== ""
127+
? ` and its null transition ${dataContext?.rows?.[
128+
nullClosureRowId - 1
129+
]?.nul
130+
?.split(", ")
131+
?.filter(
132+
(s) => s !== dataContext?.rows?.[nullClosureRowId - 1]?.state
133+
)
134+
?.join(", ")
135+
?.replaceAll(NullClosureStateId, "")}.`
136+
: " only.")
137+
);
138+
else
139+
setSnackbarMessage(
140+
`Added state ${nullClosureRows?.[
141+
nullClosureRowId - 1
142+
]?.state?.replaceAll(NullClosureStateId, "")}.`
143+
);
144+
145+
setOpenSnackbar(true);
146+
setShowExplanation(false);
147+
};
148+
149+
const handleSnackbarClose = (
150+
event: React.SyntheticEvent | Event,
151+
reason?: string
152+
) => {
153+
if (reason === "clickaway") {
154+
return;
155+
}
156+
setOpenSnackbar(false);
157+
};
119158

120159
const handleUpdateData = (
121160
rowIndex: number,
122161
rows: RowModel[],
123162
states: DraggableStateModel[],
124163
transitions: TransitionModel[]
125164
) => {
126-
console.log(
127-
"handleUpdateData, rowIndex, index, rows: ",
128-
rowIndex,
129-
index,
130-
rows
131-
);
132165
setNullClosureRowId(rowIndex);
133166
// copy all null transitions for each row and paste them in the null column alongwith state name
134167
setNullClosureRows(
@@ -172,6 +205,7 @@ export const NullClosure = (props: NullClosureProps) => {
172205
};
173206
})
174207
);
208+
setShowExplanation(true);
175209
};
176210

177211
const handleDurationChange = (event: SelectChangeEvent) => {
@@ -196,27 +230,31 @@ export const NullClosure = (props: NullClosureProps) => {
196230

197231
const showNextRow = () => {
198232
console.log("NullClosure show next row, index: ", index);
199-
const rowIndex = Math.floor(index / numberOfColumns);
200-
if (isComplete) {
201-
setIsReady(true);
202-
props.setRows(nullClosureRows);
203-
props.setStates(nullClosureStates);
204-
props.setTransitions(nullClosureTransitions);
205-
props.setIsNullClosureTableComplete(true);
206-
}
233+
if (!showExplanation) {
234+
const rowIndex = Math.floor(index / numberOfColumns);
235+
if (isComplete) {
236+
setIsReady(true);
237+
props.setRows(nullClosureRows);
238+
props.setStates(nullClosureStates);
239+
props.setTransitions(nullClosureTransitions);
240+
props.setIsNullClosureTableComplete(true);
241+
}
207242

208-
handleUpdateData(
209-
rowIndex,
210-
props.rows.slice(0, rowIndex),
211-
props.states.slice(0, rowIndex),
212-
props.transitions
213-
);
243+
handleUpdateData(
244+
rowIndex,
245+
props.rows.slice(0, rowIndex),
246+
props.states.slice(0, rowIndex),
247+
props.transitions
248+
);
214249

215-
// stop if all rows have been displayed i.e., if rowIndex equals rows length and last row's null column has been displayed
216-
if (rowIndex === props.rows.length && index % numberOfColumns !== 0) {
217-
setIsComplete(true);
218-
setIsPlaying(false);
219-
} else index++;
250+
// stop if all rows have been displayed
251+
if (rowIndex > props.rows.length && index % numberOfColumns === 0) {
252+
setIsComplete(true);
253+
setIsPlaying(false);
254+
handleExplanation();
255+
}
256+
index++;
257+
} else handleExplanation();
220258
};
221259

222260
const transitionTableProps: ToolsTransitionTableProps = {
@@ -259,6 +297,26 @@ export const NullClosure = (props: NullClosureProps) => {
259297
return (
260298
<>
261299
<Box sx={{ display: "flex", m: 1, mt: 5 }}>
300+
<Snackbar
301+
open={openSnackbar}
302+
autoHideDuration={
303+
isPlaying ? duration * 1000 : duration * 1000 * 1000
304+
}
305+
onClose={handleSnackbarClose}
306+
anchorOrigin={{
307+
vertical: "bottom",
308+
horizontal: "center",
309+
}}
310+
>
311+
<Alert
312+
onClose={handleSnackbarClose}
313+
severity="info"
314+
sx={{ width: "100%" }}
315+
>
316+
{snackbarMessage}
317+
</Alert>
318+
</Snackbar>
319+
262320
<AppBarAndDrawer {...appBarAndDrawerProps} />
263321

264322
<MainContent open={open} sx={{ paddingBottom: 12 }}>

0 commit comments

Comments
 (0)