Skip to content

Commit 2a8f7e7

Browse files
authored
Merge pull request #1017 from getmaxun/success-fix
fix: success status being displayed
2 parents bd818a5 + 3077b1e commit 2a8f7e7

4 files changed

Lines changed: 39 additions & 10 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"start": "npm run build:server && concurrently -k \"npm run server\" \"npm run client\"",
8989
"server": "cross-env NODE_OPTIONS='--max-old-space-size=4096' node server/dist/server/src/server.js",
9090
"start:dev": "concurrently -k \"npm run server:dev\" \"npm run client\"",
91-
"server:dev": "cross-env NODE_OPTIONS='--max-old-space-size=2048' nodemon server/src/server.ts",
91+
"server:dev": "cross-env NODE_OPTIONS='--max-old-space-size=4096' nodemon server/src/server.ts",
9292
"client": "vite",
9393
"build": "vite build",
9494
"build:server": "tsc -p server/tsconfig.json",

src/components/robot/pages/RobotCreate.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const RobotCreate: React.FC = () => {
9999

100100
const { state } = React.useContext(AuthContext);
101101
const { user } = state;
102-
const { addOptimisticRobot, removeOptimisticRobot, invalidateRecordings, invalidateRuns, addOptimisticRun } = useCacheInvalidation();
102+
const { addOptimisticRobot, removeOptimisticRobot, invalidateRecordings, invalidateRuns, updateOptimisticRun } = useCacheInvalidation();
103103

104104
const handleTabChange = (event: React.SyntheticEvent, newValue: number) => {
105105
setTabValue(newValue);
@@ -621,7 +621,7 @@ const RobotCreate: React.FC = () => {
621621
isOptimistic: true
622622
};
623623

624-
addOptimisticRun(optimisticRun);
624+
updateOptimisticRun(optimisticRun);
625625

626626
const runResponse = await createAndRunRecording(robotMetaId, {
627627
maxConcurrency: 1,

src/context/globalInfo.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,18 @@ export const useCacheInvalidation = () => {
176176
queryClient.invalidateQueries({ queryKey: dataCacheKeys.recordings });
177177
};
178178

179-
const addOptimisticRun = (newRun: any) => {
179+
const updateOptimisticRun = (newRun: any, oldRunId?: string) => {
180180
queryClient.setQueryData(dataCacheKeys.runs, (oldData: any) => {
181181
if (!oldData) return [{ id: 0, ...newRun }];
182+
const runToMatch = oldRunId || newRun.runId;
183+
const existingIndex = oldData.findIndex((r: any) => r.runId === runToMatch);
184+
185+
if (existingIndex !== -1) {
186+
const newData = [...oldData];
187+
newData[existingIndex] = { ...newData[existingIndex], ...newRun };
188+
return newData;
189+
}
190+
182191
return [{ id: oldData.length, ...newRun }, ...oldData];
183192
});
184193
};
@@ -205,7 +214,7 @@ export const useCacheInvalidation = () => {
205214
return {
206215
invalidateRuns,
207216
invalidateRecordings,
208-
addOptimisticRun,
217+
updateOptimisticRun,
209218
addOptimisticRobot,
210219
removeOptimisticRobot,
211220
invalidateAllCache

src/pages/MainPage.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ interface MainPageProps {
2323
}
2424

2525
export interface CreateRunResponse {
26-
browserId: string;
26+
browserId: string | null;
2727
runId: string;
2828
robotMetaId: string;
29+
httpExecution?: boolean;
2930
}
3031

3132
export interface ScheduleRunResponse {
@@ -50,7 +51,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
5051
let aborted = false;
5152

5253
const { notify, setRerenderRuns, setRecordingId } = useGlobalInfoStore();
53-
const { invalidateRuns, addOptimisticRun } = useCacheInvalidation();
54+
const { invalidateRuns, updateOptimisticRun } = useCacheInvalidation();
5455
const navigate = useNavigate();
5556

5657
React.useEffect(() => {
@@ -157,19 +158,36 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
157158
isOptimistic: true
158159
};
159160

160-
addOptimisticRun(optimisticRun);
161+
updateOptimisticRun(optimisticRun);
162+
setIds({ browserId: '', runId: optimisticRun.runId, robotMetaId: runningRecordingId });
163+
navigate(`/runs/${runningRecordingId}/run/${optimisticRun.runId}`);
161164

162165
createAndRunRecording(runningRecordingId, settings).then((response: CreateRunResponseWithQueue) => {
163166
invalidateRuns();
164167
const { browserId, runId, robotMetaId, queued } = response;
165168

169+
if (!runId && !queued) {
170+
notify('error', t('main_page.notifications.run_start_failed', { name: runningRecordingName }));
171+
setContent('robots');
172+
return;
173+
}
174+
175+
const realRun = {
176+
...optimisticRun,
177+
runId,
178+
status: browserId === null ? 'success' : (queued ? 'queued' : 'running'),
179+
isOptimistic: true
180+
};
181+
182+
updateOptimisticRun(realRun, optimisticRun.runId);
183+
166184
setIds({ browserId, runId, robotMetaId });
167185
navigate(`/runs/${robotMetaId}/run/${runId}`);
168186

169187
if (queued) {
170188
setQueuedRuns(prev => new Set([...prev, runId]));
171189
notify('info', `Run queued: ${runningRecordingName}`);
172-
} else {
190+
} else if (browserId) {
173191
const socket = io(`${apiUrl}/${browserId}`, {
174192
transports: ["websocket", "polling"],
175193
rejectUnauthorized: false
@@ -205,6 +223,8 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
205223
} else {
206224
notify('error', t('main_page.notifications.run_start_failed', { name: runningRecordingName }));
207225
}
226+
} else if (runId) {
227+
notify('info', t('main_page.notifications.run_started', { name: runningRecordingName }));
208228
}
209229

210230
setContent('runs');
@@ -218,7 +238,7 @@ export const MainPage = ({ handleEditRecording, initialContent }: MainPageProps)
218238
socket.off('connect_error');
219239
socket.off('disconnect');
220240
}
221-
}, [runningRecordingName, sockets, ids, debugMessageHandler, user?.id, t, notify, setRerenderRuns, setQueuedRuns, navigate, setContent, setIds, invalidateRuns, addOptimisticRun, runningRecordingId]);
241+
}, [runningRecordingName, sockets, ids, debugMessageHandler, user?.id, t, notify, setRerenderRuns, setQueuedRuns, navigate, setContent, setIds, invalidateRuns, updateOptimisticRun, runningRecordingId]);
222242

223243
useEffect(() => {
224244
return () => {

0 commit comments

Comments
 (0)