Skip to content

Commit 7d5e40e

Browse files
authored
Add retry button for error page (#85)
* Add retry button for error page * Add requested changes in PR * Adjust value assignment * Add only one default function parameter
1 parent 1dd1203 commit 7d5e40e

File tree

1 file changed

+33
-25
lines changed

1 file changed

+33
-25
lines changed

feedingwebapp/src/Pages/Home/MealStates/RobotMotion.jsx

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,16 @@ const RobotMotion = (props) => {
242242
* @param {flexSizeOuter} - flexbox percentage for parent element rendering everything
243243
* @param {flexSizeTextInner} - flexbox percentage for child element rendering text
244244
* @param {flexSizeVisualInner} - flexbox percentage for child element rendering visual
245-
* @param {progress} - progress proportion; if null progress bar not shown
246245
* @param {text} - action status text
247246
* @param {showTime} - indicates if elapsed time needs to be shown
248247
* @param {time} - calculated elapsed time, 0 if time not available
248+
* @param {progress} - progress proportion; if null progress bar not shown
249+
* @param {retry} - indicates if retry needed for error
249250
*
250251
* @returns {JSX.Element} the action status text, progress bar or blank view
251252
*/
252253
const actionStatusTextAndVisual = useCallback(
253-
(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress) => {
254+
(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress, retry = false) => {
254255
return (
255256
<>
256257
<View style={{ flex: flexSizeOuter, flexDirection: dimension, alignItems: 'center', justifyContent: 'center', width: '100%' }}>
@@ -260,6 +261,22 @@ const RobotMotion = (props) => {
260261
</p>
261262
<p style={{ fontSize: motionTextFontSize }}>{text}</p>
262263
{showTime ? <p style={{ fontSize: motionTextFontSize }}>&nbsp;&nbsp;Elapsed Time: {time} sec</p> : <></>}
264+
{retry ? (
265+
<Button
266+
variant='warning'
267+
className='mx-2 btn-huge'
268+
size='lg'
269+
onClick={resumeCallback}
270+
style={{
271+
width: '90%',
272+
height: '20%'
273+
}}
274+
>
275+
<h5 style={{ textAlign: 'center', fontSize: motionTextFontSize }}>Retry</h5>
276+
</Button>
277+
) : (
278+
<></>
279+
)}
263280
</View>
264281
<View
265282
style={{
@@ -276,7 +293,7 @@ const RobotMotion = (props) => {
276293
</>
277294
)
278295
},
279-
[dimension, props.waitingText, motionTextFontSize, waitingTextFontSize]
296+
[dimension, props.waitingText, motionTextFontSize, waitingTextFontSize, resumeCallback]
280297
)
281298

282299
/**
@@ -288,39 +305,36 @@ const RobotMotion = (props) => {
288305
(actionStatus, flexSizeOuter) => {
289306
let flexSizeTextInner = 1
290307
let flexSizeVisualInner = 1
291-
let text
292-
let time
293-
let showTime
308+
let text = 'Robot is paused'
309+
let showTime = false
310+
let time = 0
311+
let progress = null
294312
switch (actionStatus.actionStatus) {
295313
case ROS_ACTION_STATUS_EXECUTE:
296314
if (actionStatus.feedback) {
297-
let progress = 1 - actionStatus.feedback.motion_curr_distance / actionStatus.feedback.motion_initial_distance
298315
if (!actionStatus.feedback.is_planning) {
299316
let moving_elapsed_time = actionStatus.feedback.motion_time.sec + actionStatus.feedback.motion_time.nanosec / 10 ** 9
300317
text = 'Robot is moving...'
301318
time = Math.round(moving_elapsed_time * 100) / 100
302319
showTime = true
320+
progress = 1 - actionStatus.feedback.motion_curr_distance / actionStatus.feedback.motion_initial_distance
303321
// Calling CircleProgessBar component to visualize robot motion of moving
304322
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress)}</>
305323
} else {
306324
let planning_elapsed_time = actionStatus.feedback.planning_time.sec + actionStatus.feedback.planning_time.nanosec / 10 ** 9
307325
text = 'Robot is thinking...'
308326
time = Math.round(planning_elapsed_time * 100) / 100
309327
showTime = true
310-
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
328+
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress)}</>
311329
}
312330
} else {
313331
// If you haven't gotten feedback yet, assume the robot is planning
314332
text = 'Robot is thinking...'
315-
time = 0
316-
showTime = false
317-
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
333+
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress)}</>
318334
}
319335
case ROS_ACTION_STATUS_SUCCEED:
320336
text = 'Robot has finished'
321-
time = 0
322-
showTime = false
323-
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
337+
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress)}</>
324338
case ROS_ACTION_STATUS_ABORT:
325339
/**
326340
* TODO: Just displaying that the robot faced an error is not useful
@@ -329,20 +343,14 @@ const RobotMotion = (props) => {
329343
* users on how to troubleshoot/fix it.
330344
*/
331345
text = 'Robot encountered an error'
332-
time = 0
333-
showTime = false
334-
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
346+
return (
347+
<>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress, true)}</>
348+
)
335349
case ROS_ACTION_STATUS_CANCELED:
336-
text = 'Robot is paused'
337-
time = 0
338-
showTime = false
339-
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
350+
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress)}</>
340351
default:
341352
if (paused) {
342-
text = 'Robot is paused'
343-
time = 0
344-
showTime = false
345-
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, null)}</>
353+
return <>{actionStatusTextAndVisual(flexSizeOuter, flexSizeTextInner, flexSizeVisualInner, text, showTime, time, progress)}</>
346354
} else {
347355
return (
348356
<View

0 commit comments

Comments
 (0)