Skip to content

Commit bcb880f

Browse files
authored
Merge pull request #417 from getmaxun/show-run
feat: display currently running robot run
2 parents 6e57c08 + 3efd413 commit bcb880f

File tree

5 files changed

+39
-12
lines changed

5 files changed

+39
-12
lines changed

server/src/routes/storage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ router.put('/runs/:id', requireSignIn, async (req: AuthenticatedRequest, res) =>
501501
return res.send({
502502
browserId: id,
503503
runId: plainRun.runId,
504+
robotMetaId: recording.recording_meta.id,
504505
});
505506
} catch (e) {
506507
const { message } = e as Error;

src/api/storage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export const createRunForStoredRecording = async (id: string, settings: RunSetti
161161
}
162162
} catch (error: any) {
163163
console.log(error);
164-
return { browserId: '', runId: '' };
164+
return { browserId: '', runId: '', robotMetaId: '' };
165165
}
166166
}
167167

src/components/run/ColapsibleRow.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ interface CollapsibleRowProps {
3535
currentLog: string;
3636
abortRunHandler: () => void;
3737
runningRecordingName: string;
38+
urlRunId: string | null;
3839
}
39-
export const CollapsibleRow = ({ row, handleDelete, isOpen, currentLog, abortRunHandler, runningRecordingName }: CollapsibleRowProps) => {
40+
export const CollapsibleRow = ({ row, handleDelete, isOpen, currentLog, abortRunHandler, runningRecordingName, urlRunId }: CollapsibleRowProps) => {
4041
const { t } = useTranslation();
4142
const navigate = useNavigate();
4243
const [open, setOpen] = useState(isOpen);
@@ -62,14 +63,18 @@ export const CollapsibleRow = ({ row, handleDelete, isOpen, currentLog, abortRun
6263
abortRunHandler();
6364
}
6465

66+
useEffect(() => {
67+
setOpen(urlRunId === row.runId || isOpen);
68+
}, [urlRunId, row.runId, isOpen]);
69+
6570
const handleRowExpand = () => {
6671
const newOpen = !open;
6772
setOpen(newOpen);
68-
if (newOpen) {
69-
navigate(`/runs/${row.robotMetaId}/run/${row.runId}`);
70-
} else {
71-
navigate(`/runs/${row.robotMetaId}`);
72-
}
73+
navigate(
74+
newOpen
75+
? `/runs/${row.robotMetaId}/run/${row.runId}`
76+
: `/runs/${row.robotMetaId}`
77+
);
7378
//scrollToLogBottom();
7479
};
7580

src/components/run/RunsTable.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import TableRow from '@mui/material/TableRow';
1212
import { Accordion, AccordionSummary, AccordionDetails, Typography, Box, TextField, CircularProgress, Tooltip } from '@mui/material';
1313
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
1414
import SearchIcon from '@mui/icons-material/Search';
15-
import { useNavigate } from 'react-router-dom';
15+
import { useLocation, useNavigate } from 'react-router-dom';
1616
import { useGlobalInfoStore } from "../../context/globalInfo";
1717
import { getStoredRuns } from "../../api/storage";
1818
import { RunSettings } from "./RunSettings";
@@ -85,6 +85,21 @@ export const RunsTable: React.FC<RunsTableProps> = ({
8585
}) => {
8686
const { t } = useTranslation();
8787
const navigate = useNavigate();
88+
const location = useLocation();
89+
90+
const getUrlParams = () => {
91+
const match = location.pathname.match(/\/runs\/([^\/]+)(?:\/run\/([^\/]+))?/);
92+
return {
93+
robotMetaId: match?.[1] || null,
94+
urlRunId: match?.[2] || null
95+
};
96+
};
97+
98+
const { robotMetaId: urlRobotMetaId, urlRunId } = getUrlParams();
99+
100+
const isAccordionExpanded = useCallback((currentRobotMetaId: string) => {
101+
return currentRobotMetaId === urlRobotMetaId;
102+
}, [urlRobotMetaId]);
88103

89104
const [accordionPage, setAccordionPage] = useState(0);
90105
const [accordionsPerPage, setAccordionsPerPage] = useState(10);
@@ -314,10 +329,11 @@ export const RunsTable: React.FC<RunsTableProps> = ({
314329
key={`row-${row.id}`}
315330
row={row}
316331
handleDelete={handleDelete}
317-
isOpen={runId === row.runId && runningRecordingName === row.name}
332+
isOpen={urlRunId === row.runId || (runId === row.runId && runningRecordingName === row.name)}
318333
currentLog={currentInterpretationLog}
319334
abortRunHandler={abortRunHandler}
320335
runningRecordingName={runningRecordingName}
336+
urlRunId={urlRunId}
321337
/>
322338
));
323339
}, [paginationStates, runId, runningRecordingName, currentInterpretationLog, abortRunHandler, handleDelete, accordionSortConfigs]);

src/pages/MainPage.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ScheduleSettings } from "../components/robot/ScheduleSettings";
1515
import { IntegrationSettings } from "../components/integration/IntegrationSettings";
1616
import { RobotSettings } from "../components/robot/RobotSettings";
1717
import { apiUrl } from "../apiConfig";
18+
import { useNavigate } from 'react-router-dom';
1819

1920
interface MainPageProps {
2021
handleEditRecording: (id: string, fileName: string) => void;
@@ -24,6 +25,7 @@ interface MainPageProps {
2425
export interface CreateRunResponse {
2526
browserId: string;
2627
runId: string;
28+
robotMetaId: string;
2729
}
2830

2931
export interface ScheduleRunResponse {
@@ -40,12 +42,14 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
4042
const [currentInterpretationLog, setCurrentInterpretationLog] = React.useState('');
4143
const [ids, setIds] = React.useState<CreateRunResponse>({
4244
browserId: '',
43-
runId: ''
45+
runId: '',
46+
robotMetaId: ''
4447
});
4548

4649
let aborted = false;
4750

4851
const { notify, setRerenderRuns, setRecordingId } = useGlobalInfoStore();
52+
const navigate = useNavigate();
4953

5054
const abortRunHandler = (runId: string) => {
5155
aborted = true;
@@ -88,8 +92,9 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
8892
}, [currentInterpretationLog])
8993

9094
const handleRunRecording = useCallback((settings: RunSettings) => {
91-
createRunForStoredRecording(runningRecordingId, settings).then(({ browserId, runId }: CreateRunResponse) => {
92-
setIds({ browserId, runId });
95+
createRunForStoredRecording(runningRecordingId, settings).then(({ browserId, runId, robotMetaId }: CreateRunResponse) => {
96+
setIds({ browserId, runId, robotMetaId });
97+
navigate(`/runs/${robotMetaId}/run/${runId}`);
9398
const socket =
9499
io(`${apiUrl}/${browserId}`, {
95100
transports: ["websocket"],

0 commit comments

Comments
 (0)