feat: add robot retraining logic
This commit is contained in:
@@ -35,7 +35,8 @@ import {
|
|||||||
Settings,
|
Settings,
|
||||||
Power,
|
Power,
|
||||||
ContentCopy,
|
ContentCopy,
|
||||||
MoreHoriz
|
MoreHoriz,
|
||||||
|
Refresh
|
||||||
} from "@mui/icons-material";
|
} from "@mui/icons-material";
|
||||||
import { useGlobalInfoStore } from "../../context/globalInfo";
|
import { useGlobalInfoStore } from "../../context/globalInfo";
|
||||||
import { checkRunsForRecording, deleteRecordingFromStorage, getStoredRecordings } from "../../api/storage";
|
import { checkRunsForRecording, deleteRecordingFromStorage, getStoredRecordings } from "../../api/storage";
|
||||||
@@ -117,6 +118,7 @@ const TableRowMemoized = memo(({ row, columns, handlers }: any) => {
|
|||||||
return (
|
return (
|
||||||
<MemoizedTableCell key={column.id} align={column.align}>
|
<MemoizedTableCell key={column.id} align={column.align}>
|
||||||
<MemoizedOptionsButton
|
<MemoizedOptionsButton
|
||||||
|
handleRetrain={() =>handlers.handleRetrainRobot(row.id, row.name)}
|
||||||
handleEdit={() => handlers.handleEditRobot(row.id, row.name, row.params || [])}
|
handleEdit={() => handlers.handleEditRobot(row.id, row.name, row.params || [])}
|
||||||
handleDuplicate={() => handlers.handleDuplicateRobot(row.id, row.name, row.params || [])}
|
handleDuplicate={() => handlers.handleDuplicateRobot(row.id, row.name, row.params || [])}
|
||||||
handleDelete={() => handlers.handleDelete(row.id)}
|
handleDelete={() => handlers.handleDelete(row.id)}
|
||||||
@@ -198,6 +200,17 @@ export const RecordingsTable = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.data && event.data.type === 'session-data-clear') {
|
||||||
|
window.sessionStorage.removeItem('browserId');
|
||||||
|
window.sessionStorage.removeItem('robotToRetrain');
|
||||||
|
window.sessionStorage.removeItem('robotName');
|
||||||
|
window.sessionStorage.removeItem('recordingUrl');
|
||||||
|
window.sessionStorage.removeItem('recordingSessionId');
|
||||||
|
window.sessionStorage.removeItem('pendingSessionData');
|
||||||
|
window.sessionStorage.removeItem('nextTabIsRecording');
|
||||||
|
window.sessionStorage.removeItem('initialUrl');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('message', handleMessage);
|
window.addEventListener('message', handleMessage);
|
||||||
@@ -303,6 +316,63 @@ export const RecordingsTable = ({
|
|||||||
setModalOpen(true);
|
setModalOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleRetrainRobot = useCallback(async (id: string, name: string) => {
|
||||||
|
const activeBrowserId = await getActiveBrowserId();
|
||||||
|
const robot = rows.find(row => row.id === id);
|
||||||
|
let targetUrl;
|
||||||
|
|
||||||
|
if (robot?.content?.workflow && robot.content.workflow.length > 0) {
|
||||||
|
// Get the last workflow item
|
||||||
|
const lastPair = robot.content.workflow[robot.content.workflow.length - 1];
|
||||||
|
|
||||||
|
if (lastPair?.what) {
|
||||||
|
if (Array.isArray(lastPair.what)) {
|
||||||
|
const gotoAction = lastPair.what.find(action =>
|
||||||
|
action && typeof action === 'object' && 'action' in action && action.action === "goto"
|
||||||
|
) as any;
|
||||||
|
|
||||||
|
if (gotoAction?.args?.[0]) {
|
||||||
|
targetUrl = gotoAction.args[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the URL in state and session storage
|
||||||
|
if (targetUrl) {
|
||||||
|
setInitialUrl(targetUrl);
|
||||||
|
setRecordingUrl(targetUrl);
|
||||||
|
window.sessionStorage.setItem('initialUrl', targetUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeBrowserId) {
|
||||||
|
setActiveBrowserId(activeBrowserId);
|
||||||
|
setWarningModalOpen(true);
|
||||||
|
} else {
|
||||||
|
// Pass the URL directly to avoid timing issues with state updates
|
||||||
|
startRetrainRecording(id, name, targetUrl);
|
||||||
|
}
|
||||||
|
}, [rows, setInitialUrl, setRecordingUrl]);
|
||||||
|
|
||||||
|
const startRetrainRecording = (id: string, name: string, url?: string) => {
|
||||||
|
setBrowserId('new-recording');
|
||||||
|
setRecordingName('');
|
||||||
|
setRecordingId('');
|
||||||
|
|
||||||
|
window.sessionStorage.setItem('browserId', 'new-recording');
|
||||||
|
window.sessionStorage.setItem('robotToRetrain', id);
|
||||||
|
window.sessionStorage.setItem('robotName', name);
|
||||||
|
|
||||||
|
window.sessionStorage.setItem('recordingUrl', url || recordingUrl);
|
||||||
|
|
||||||
|
const sessionId = Date.now().toString();
|
||||||
|
window.sessionStorage.setItem('recordingSessionId', sessionId);
|
||||||
|
|
||||||
|
window.openedRecordingWindow = window.open(`/recording-setup?session=${sessionId}`, '_blank');
|
||||||
|
|
||||||
|
window.sessionStorage.setItem('nextTabIsRecording', 'true');
|
||||||
|
};
|
||||||
|
|
||||||
const startRecording = () => {
|
const startRecording = () => {
|
||||||
setModalOpen(false);
|
setModalOpen(false);
|
||||||
|
|
||||||
@@ -381,6 +451,7 @@ export const RecordingsTable = ({
|
|||||||
handleSettingsRecording,
|
handleSettingsRecording,
|
||||||
handleEditRobot,
|
handleEditRobot,
|
||||||
handleDuplicateRobot,
|
handleDuplicateRobot,
|
||||||
|
handleRetrainRobot,
|
||||||
handleDelete: async (id: string) => {
|
handleDelete: async (id: string) => {
|
||||||
const hasRuns = await checkRunsForRecording(id);
|
const hasRuns = await checkRunsForRecording(id);
|
||||||
if (hasRuns) {
|
if (hasRuns) {
|
||||||
@@ -395,7 +466,7 @@ export const RecordingsTable = ({
|
|||||||
fetchRecordings();
|
fetchRecordings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}), [handleRunRecording, handleScheduleRecording, handleIntegrateRecording, handleSettingsRecording, handleEditRobot, handleDuplicateRobot, notify, t]);
|
}), [handleRunRecording, handleScheduleRecording, handleIntegrateRecording, handleSettingsRecording, handleEditRobot, handleDuplicateRobot, handleRetrainRobot, notify, t]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
@@ -597,12 +668,13 @@ const SettingsButton = ({ handleSettings }: SettingsButtonProps) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface OptionsButtonProps {
|
interface OptionsButtonProps {
|
||||||
|
handleRetrain: () => void;
|
||||||
handleEdit: () => void;
|
handleEdit: () => void;
|
||||||
handleDelete: () => void;
|
handleDelete: () => void;
|
||||||
handleDuplicate: () => void;
|
handleDuplicate: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const OptionsButton = ({ handleEdit, handleDelete, handleDuplicate }: OptionsButtonProps) => {
|
const OptionsButton = ({ handleRetrain, handleEdit, handleDelete, handleDuplicate }: OptionsButtonProps) => {
|
||||||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
||||||
|
|
||||||
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
|
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
|
||||||
@@ -629,6 +701,13 @@ const OptionsButton = ({ handleEdit, handleDelete, handleDuplicate }: OptionsBut
|
|||||||
open={Boolean(anchorEl)}
|
open={Boolean(anchorEl)}
|
||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
>
|
>
|
||||||
|
<MenuItem onClick={() => { handleRetrain(); handleClose(); }}>
|
||||||
|
<ListItemIcon>
|
||||||
|
<Refresh fontSize="small" />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText>{t('recordingtable.retrain')}</ListItemText>
|
||||||
|
</MenuItem>
|
||||||
|
|
||||||
<MenuItem onClick={() => { handleEdit(); handleClose(); }}>
|
<MenuItem onClick={() => { handleEdit(); handleClose(); }}>
|
||||||
<ListItemIcon>
|
<ListItemIcon>
|
||||||
<Edit fontSize="small" />
|
<Edit fontSize="small" />
|
||||||
|
|||||||
Reference in New Issue
Block a user