feat: added reset experiment (in UI)
ref:N25B-400
This commit is contained in:
@@ -2,7 +2,8 @@ import React from 'react';
|
||||
import styles from './MonitoringPage.module.css';
|
||||
import useProgramStore from "../../utils/programStore.ts";
|
||||
import { GestureControls, SpeechPresets, DirectSpeechInput, StatusList, RobotConnected } from './MonitoringPageComponents.tsx';
|
||||
import { nextPhase, useExperimentLogger, useStatusLogger, pauseExperiment, playExperiment, resetExperiment, resetPhase, type ExperimentStreamData, type GoalUpdate, type TriggerUpdate, type CondNormsStateUpdate, type PhaseUpdate } from ".//MonitoringPageAPI.ts"
|
||||
import { nextPhase, useExperimentLogger, useStatusLogger, pauseExperiment, playExperiment, resetPhase, type ExperimentStreamData, type GoalUpdate, type TriggerUpdate, type CondNormsStateUpdate, type PhaseUpdate } from ".//MonitoringPageAPI.ts"
|
||||
import { graphReducer, runProgramm } from '../VisProgPage/VisProg.tsx';
|
||||
|
||||
import type { NormNodeData } from '../VisProgPage/visualProgrammingUI/nodes/NormNode.tsx';
|
||||
|
||||
@@ -39,6 +40,8 @@ const MonitoringPage: React.FC = () => {
|
||||
const getNormsInPhase = useProgramStore((s) => s.getNormsInPhase);
|
||||
const getGoalsInPhase = useProgramStore((s) => s.getGoalsInPhase);
|
||||
const getTriggersInPhase = useProgramStore((s) => s.getTriggersInPhase);
|
||||
const setProgramState = useProgramStore((state) => state.setProgramState);
|
||||
|
||||
|
||||
// Can be used to block actions until feedback from CB.
|
||||
const [loading, setLoading] = React.useState(false);
|
||||
@@ -134,6 +137,31 @@ const handleStatusUpdate = React.useCallback((data: any) => {
|
||||
//For pings that update conditional norms
|
||||
useStatusLogger(handleStatusUpdate);
|
||||
|
||||
const resetExperiment = React.useCallback(async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
const phases = graphReducer();
|
||||
setProgramState({ phases });
|
||||
|
||||
//reset monitoring page
|
||||
setActiveIds({}); //remove active items
|
||||
setPhaseIndex(0); //Go to first phase
|
||||
setGoalIndex(0); // Reset goal indicator
|
||||
setIsFinished(false); // Reset experiment done
|
||||
|
||||
//inform backend
|
||||
await runProgramm();
|
||||
|
||||
console.log("Experiment & UI successfully reset to start.");
|
||||
} catch (err) {
|
||||
console.error("Failed to reset program:", err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [graphReducer, setProgramState]);
|
||||
|
||||
|
||||
if (phaseIds.length === 0) {
|
||||
return <p className={styles.empty}>No program loaded.</p>;
|
||||
}
|
||||
@@ -223,9 +251,6 @@ const handleStatusUpdate = React.useCallback((data: any) => {
|
||||
case "nextPhase":
|
||||
await nextPhase();
|
||||
break;
|
||||
case "resetPhase":
|
||||
await resetPhase();
|
||||
break;
|
||||
case "resetExperiment":
|
||||
await resetExperiment();
|
||||
break;
|
||||
@@ -324,7 +349,7 @@ const handleStatusUpdate = React.useCallback((data: any) => {
|
||||
{/*Restart Experiment button*/}
|
||||
<button
|
||||
className={styles.restartExperiment}
|
||||
onClick={() => handleButton("resetExperiment")}
|
||||
onClick={() => resetExperiment()}
|
||||
disabled={loading}
|
||||
>
|
||||
⟲
|
||||
|
||||
Reference in New Issue
Block a user