Skip to content

Commit cdedee1

Browse files
committed
682 client - Fixes
1 parent 3f22b9d commit cdedee1

File tree

12 files changed

+240
-195
lines changed

12 files changed

+240
-195
lines changed

client/src/ee/pages/embedded/automation-workflows/workflow-builder/components/workflow-builder-header/hooks/useWorkflowBuilderHeader.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -101,18 +101,24 @@ export const useWorkflowBuilderHeader = ({bottomResizablePanelRef, chatTrigger,
101101
);
102102
};
103103

104-
const {close, error, getPersistedJobId, persistJobId, setStreamRequest} = useWorkflowTestStream(
105-
workflow.id!,
106-
() => {
104+
const {
105+
close: closeWorkflowTestStream,
106+
error: workflowTestStreamError,
107+
getPersistedJobId,
108+
persistJobId,
109+
setStreamRequest,
110+
} = useWorkflowTestStream({
111+
onError: () => setJobId(null),
112+
onResult: () => {
107113
if (bottomResizablePanelRef.current && bottomResizablePanelRef.current.getSize() === 0) {
108114
bottomResizablePanelRef.current.resize(35);
109115
}
110116

111117
setJobId(null);
112118
},
113-
() => setJobId(null),
114-
(jobId) => setJobId(jobId)
115-
);
119+
onStart: (jobId) => setJobId(jobId),
120+
workflowId: workflow.id!,
121+
});
116122

117123
const handleRunClick = useCallback(() => {
118124
setShowBottomPanelOpen(true);
@@ -170,7 +176,7 @@ export const useWorkflowBuilderHeader = ({bottomResizablePanelRef, chatTrigger,
170176

171177
const handleStopClick = useCallback(() => {
172178
setWorkflowIsRunning(false);
173-
close();
179+
closeWorkflowTestStream();
174180
setStreamRequest(null);
175181

176182
if (jobId) {
@@ -190,7 +196,7 @@ export const useWorkflowBuilderHeader = ({bottomResizablePanelRef, chatTrigger,
190196
}, [
191197
bottomResizablePanelRef,
192198
chatTrigger,
193-
close,
199+
closeWorkflowTestStream,
194200
jobId,
195201
persistJobId,
196202
setStreamRequest,
@@ -215,23 +221,23 @@ export const useWorkflowBuilderHeader = ({bottomResizablePanelRef, chatTrigger,
215221
setStreamRequest(getTestWorkflowAttachRequest({jobId}));
216222
}, [workflow.id, currentEnvironmentId, getPersistedJobId, setWorkflowIsRunning, setJobId, setStreamRequest]);
217223

224+
// Stop the workflow execution only when:
225+
// - The node details panel is opened (always cancels runs), or
226+
// - We are in chat mode and the chat panel is not open
218227
useEffect(() => {
219-
// Stop only when:
220-
// - The node details panel is opened (always cancels runs), or
221-
// - We are in chat mode and the chat panel is not open
222228
if (workflowNodeDetailsPanelOpen || (chatTrigger && !workflowTestChatPanelOpen)) {
223229
handleStopClick();
224230
}
225231
}, [chatTrigger, handleStopClick, workflowNodeDetailsPanelOpen, workflowTestChatPanelOpen]);
226232

227233
useEffect(() => {
228-
if (error) {
234+
if (workflowTestStreamError) {
229235
setWorkflowIsRunning(false);
230236
setStreamRequest(null);
231237
persistJobId(null);
232238
setJobId(null);
233239
}
234-
}, [error, persistJobId, setWorkflowIsRunning, setStreamRequest]);
240+
}, [workflowTestStreamError, persistJobId, setWorkflowIsRunning, setStreamRequest]);
235241

236242
return {
237243
handleProjectWorkflowValueChange,

client/src/ee/pages/embedded/integration/components/integration-header/IntegrationHeader.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,24 @@ const IntegrationHeader = ({
9797
!showDeleteIntegrationAlertDialog
9898
);
9999

100-
const {close, error, getPersistedJobId, persistJobId, setStreamRequest} = useWorkflowTestStream(
101-
workflow.id!,
102-
() => {
100+
const {
101+
close: closeWorkflowTestStream,
102+
error: workflowTestStreamError,
103+
getPersistedJobId,
104+
persistJobId,
105+
setStreamRequest,
106+
} = useWorkflowTestStream({
107+
onError: () => setJobId(null),
108+
onResult: () => {
103109
if (bottomResizablePanelRef.current && bottomResizablePanelRef.current.getSize() === 0) {
104110
bottomResizablePanelRef.current.resize(35);
105111
}
106112

107113
setJobId(null);
108114
},
109-
() => setJobId(null),
110-
(jobId) => setJobId(jobId)
111-
);
115+
onStart: (jobId) => setJobId(jobId),
116+
workflowId: workflow.id!,
117+
});
112118

113119
const createIntegrationWorkflowMutation = useCreateIntegrationWorkflowMutation({
114120
onSuccess: (integrationWorkflowId) => {
@@ -208,11 +214,11 @@ const IntegrationHeader = ({
208214
setJobId(null);
209215
persistJobId(null);
210216

211-
const req = getTestWorkflowStreamPostRequest({
217+
const request = getTestWorkflowStreamPostRequest({
212218
environmentId: currentEnvironmentId,
213219
id: workflow.id,
214220
});
215-
setStreamRequest(req);
221+
setStreamRequest(request);
216222
}
217223
}, [
218224
captureIntegrationWorkflowTested,
@@ -228,7 +234,7 @@ const IntegrationHeader = ({
228234

229235
const handleStopClick = useCallback(() => {
230236
setWorkflowIsRunning(false);
231-
close();
237+
closeWorkflowTestStream();
232238
setStreamRequest(null);
233239

234240
if (jobId) {
@@ -237,7 +243,7 @@ const IntegrationHeader = ({
237243
setJobId(null);
238244
});
239245
}
240-
}, [close, jobId, persistJobId, setStreamRequest, setWorkflowIsRunning]);
246+
}, [closeWorkflowTestStream, jobId, persistJobId, setStreamRequest, setWorkflowIsRunning]);
241247

242248
useEffect(() => {
243249
if (!workflow.id || currentEnvironmentId === undefined) return;
@@ -254,15 +260,15 @@ const IntegrationHeader = ({
254260
setStreamRequest(getTestWorkflowAttachRequest({jobId}));
255261
}, [workflow.id, currentEnvironmentId, getPersistedJobId, setWorkflowIsRunning, setJobId, setStreamRequest]);
256262

257-
// On transport error (e.g., 4xx/5xx), make sure to reset running state and clear the request to prevent retries
263+
// On transport error (e.g., 4xx/5xx), make sure to reset the running state and clear the request to prevent retries
258264
useEffect(() => {
259-
if (error) {
265+
if (workflowTestStreamError) {
260266
setWorkflowIsRunning(false);
261267
setStreamRequest(null);
262268
persistJobId(null);
263269
setJobId(null);
264270
}
265-
}, [error, persistJobId, setWorkflowIsRunning, setStreamRequest]);
271+
}, [workflowTestStreamError, persistJobId, setWorkflowIsRunning, setStreamRequest]);
266272

267273
return (
268274
<header className="flex items-center px-3 py-2.5">

client/src/pages/automation/project/components/project-header/hooks/useProjectHeader.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,24 @@ export const useProjectHeader = ({bottomResizablePanelRef, chatTrigger, projectI
7373

7474
const queryClient = useQueryClient();
7575

76-
const {close, error, getPersistedJobId, persistJobId, setStreamRequest} = useWorkflowTestStream(
77-
workflow.id!,
78-
() => {
76+
const {
77+
close: closeWorkflowTestStream,
78+
error: workflowTestStreamError,
79+
getPersistedJobId,
80+
persistJobId,
81+
setStreamRequest,
82+
} = useWorkflowTestStream({
83+
onError: () => setJobId(null),
84+
onResult: () => {
7985
if (bottomResizablePanelRef.current && bottomResizablePanelRef.current.getSize() === 0) {
8086
bottomResizablePanelRef.current.resize(35);
8187
}
8288

8389
setJobId(null);
8490
},
85-
() => setJobId(null),
86-
(jobId) => setJobId(jobId)
87-
);
91+
onStart: (jobId) => setJobId(jobId),
92+
workflowId: workflow.id!,
93+
});
8894

8995
const publishProjectMutation = usePublishProjectMutation({
9096
onSuccess: () => {
@@ -154,11 +160,11 @@ export const useProjectHeader = ({bottomResizablePanelRef, chatTrigger, projectI
154160
setJobId(null);
155161
persistJobId(null);
156162

157-
const req = getTestWorkflowStreamPostRequest({
163+
const request = getTestWorkflowStreamPostRequest({
158164
environmentId: currentEnvironmentId,
159165
id: workflow.id,
160166
});
161-
setStreamRequest(req);
167+
setStreamRequest(request);
162168
}
163169
}
164170
}, [
@@ -188,7 +194,7 @@ export const useProjectHeader = ({bottomResizablePanelRef, chatTrigger, projectI
188194

189195
const handleStopClick = useCallback(() => {
190196
setWorkflowIsRunning(false);
191-
close();
197+
closeWorkflowTestStream();
192198
setStreamRequest(null);
193199

194200
if (jobId) {
@@ -208,25 +214,25 @@ export const useProjectHeader = ({bottomResizablePanelRef, chatTrigger, projectI
208214
}, [
209215
bottomResizablePanelRef,
210216
chatTrigger,
211-
close,
217+
closeWorkflowTestStream,
212218
jobId,
213219
persistJobId,
214220
setStreamRequest,
215221
setWorkflowIsRunning,
216222
setWorkflowTestChatPanelOpen,
217223
]);
218224

225+
// Stop the workflow execution only when:
226+
// - The node details panel is opened (always cancels runs), or
227+
// - We are in chat mode and the chat panel is not open
219228
useEffect(() => {
220-
// Stop only when:
221-
// - The node details panel is opened (always cancels runs), or
222-
// - We are in chat mode and the chat panel is not open
223229
if (workflowNodeDetailsPanelOpen || (chatTrigger && !workflowTestChatPanelOpen)) {
224230
handleStopClick();
225231
}
226232
}, [chatTrigger, handleStopClick, workflowNodeDetailsPanelOpen, workflowTestChatPanelOpen]);
227233

228-
// On mount: try to restore an ongoing run using jobId persisted in localStorage.
229-
// Attach-first approach: immediately call attach with the exact jobId string.
234+
// On mount: try to restore an ongoing workflow execution using jobId persisted in localStorage by calling
235+
// attach endpoint.
230236
useEffect(() => {
231237
if (!workflow.id || currentEnvironmentId === undefined) return;
232238

@@ -243,13 +249,13 @@ export const useProjectHeader = ({bottomResizablePanelRef, chatTrigger, projectI
243249
}, [workflow.id, currentEnvironmentId, getPersistedJobId, setWorkflowIsRunning, setJobId, setStreamRequest]);
244250

245251
useEffect(() => {
246-
if (error) {
252+
if (workflowTestStreamError) {
247253
setWorkflowIsRunning(false);
248254
setStreamRequest(null);
249255
persistJobId(null);
250256
setJobId(null);
251257
}
252-
}, [error, persistJobId, setWorkflowIsRunning, setStreamRequest]);
258+
}, [workflowTestStreamError, persistJobId, setWorkflowIsRunning, setStreamRequest]);
253259

254260
return {
255261
handleProjectWorkflowValueChange,

client/src/pages/platform/workflow-editor/components/WorkflowCodeEditorSheet.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ const WorkflowCodeEditorSheet = ({
5656
const currentEnvironmentId = useEnvironmentStore((state) => state.currentEnvironmentId);
5757

5858
const {persistJobId} = usePersistJobId(workflow.id, currentEnvironmentId);
59-
const {close, setStreamRequest} = useWorkflowTestStream(
60-
workflow.id!,
61-
(execution) => {
62-
setWorkflowTestExecution(execution);
59+
const {close: closeWorkflowTestStream, setStreamRequest} = useWorkflowTestStream({
60+
onError: () => {
61+
setWorkflowTestExecution(undefined);
6362
setWorkflowIsRunning(false);
6463
},
65-
() => {
66-
setWorkflowTestExecution(undefined);
64+
onResult: (execution) => {
65+
setWorkflowTestExecution(execution);
6766
setWorkflowIsRunning(false);
68-
}
69-
);
67+
},
68+
workflowId: workflow.id!,
69+
});
7070
const {updateWorkflowMutation} = useWorkflowEditor();
7171

7272
const handleRunClick = () => {
@@ -190,7 +190,7 @@ const WorkflowCodeEditorSheet = ({
190190
setWorkflowIsRunning(false);
191191
setStreamRequest(null);
192192
persistJobId(null);
193-
close();
193+
closeWorkflowTestStream();
194194
}}
195195
size="icon"
196196
variant="destructive"

client/src/pages/platform/workflow-editor/components/workflow-test-chat/runtime-providers/WorkflowTestChatRuntimeProvider.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ export function WorkflowTestChatRuntimeProvider({
4242
}))
4343
);
4444

45-
const {setStreamRequest} = useWorkflowTestStream(
46-
workflow.id!,
47-
() => {
48-
setIsRunning(false);
49-
},
50-
() => setIsRunning(false)
51-
);
45+
const {setStreamRequest} = useWorkflowTestStream({
46+
onError: () => setIsRunning(false),
47+
onResult: () => setIsRunning(false),
48+
workflowId: workflow.id!,
49+
});
5250

5351
const onNew = async (message: AppendMessage) => {
5452
if (message.content[0]?.type !== 'text') {

client/src/shared/components/WorkflowTestRunLeaveDialog.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ const WorkflowTestRunLeaveDialog = ({onCancel, onConfirm, open}: WorkflowTestRun
2222
<AlertDialogTitle>Workflow is running</AlertDialogTitle>
2323

2424
<AlertDialogDescription>
25-
A test run is currently in progress. Do you really want to leave this page? The run will be stopped.
25+
A test run is currently in progress. Do you really want to leave this page? The workflow execution
26+
will be stopped.
2627
</AlertDialogDescription>
2728
</AlertDialogHeader>
2829

2930
<AlertDialogFooter>
3031
<AlertDialogCancel onClick={onCancel}>Cancel</AlertDialogCancel>
3132

32-
<AlertDialogAction onClick={onConfirm}>Continue</AlertDialogAction>
33+
<AlertDialogAction onClick={onConfirm}>Confirm</AlertDialogAction>
3334
</AlertDialogFooter>
3435
</AlertDialogContent>
3536
</AlertDialog>

client/src/shared/hooks/tests/useWorkflowTestStream.test.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ describe('useWorkflowTestStream', () => {
5252
});
5353

5454
it('should initialize with null streamRequest', () => {
55-
renderHook(() => useWorkflowTestStream('workflow-123'));
55+
renderHook(() => useWorkflowTestStream({workflowId: 'workflow-123'}));
5656

5757
expect(useSSE).toHaveBeenCalledWith(null, expect.any(Object));
5858
});
5959

6060
it('should call setStreamRequest and trigger useSSE', () => {
61-
const {result} = renderHook(() => useWorkflowTestStream('workflow-123'));
61+
const {result} = renderHook(() => useWorkflowTestStream({workflowId: 'workflow-123'}));
6262

6363
const mockRequest = {init: {method: 'POST'}, url: '/test'};
6464

@@ -71,7 +71,12 @@ describe('useWorkflowTestStream', () => {
7171

7272
it('should handle start event', () => {
7373
const onStart = vi.fn();
74-
renderHook(() => useWorkflowTestStream('workflow-123', undefined, undefined, onStart));
74+
renderHook(() =>
75+
useWorkflowTestStream({
76+
onStart,
77+
workflowId: 'workflow-123',
78+
})
79+
);
7580

7681
/* eslint-disable @typescript-eslint/no-explicit-any */
7782
const eventHandlers = (useSSE as any).mock.calls[0][1].eventHandlers;
@@ -86,7 +91,12 @@ describe('useWorkflowTestStream', () => {
8691

8792
it('should handle result event', () => {
8893
const onResult = vi.fn();
89-
renderHook(() => useWorkflowTestStream('workflow-123', onResult));
94+
renderHook(() =>
95+
useWorkflowTestStream({
96+
onResult,
97+
workflowId: 'workflow-123',
98+
})
99+
);
90100

91101
/* eslint-disable @typescript-eslint/no-explicit-any */
92102
const eventHandlers = (useSSE as any).mock.calls[0][1].eventHandlers;
@@ -103,7 +113,12 @@ describe('useWorkflowTestStream', () => {
103113
it('should handle error event', () => {
104114
const onError = vi.fn();
105115
/* eslint-disable @typescript-eslint/no-explicit-any */
106-
renderHook(() => useWorkflowTestStream('workflow-123', undefined, onError));
116+
renderHook(() =>
117+
useWorkflowTestStream({
118+
onError,
119+
workflowId: 'workflow-123',
120+
})
121+
);
107122

108123
const eventHandlers = (useSSE as any).mock.calls[0][1].eventHandlers;
109124

0 commit comments

Comments
 (0)