Skip to content

Commit 58b8fec

Browse files
committed
682 client - Additional fixes
1 parent 512ceef commit 58b8fec

File tree

18 files changed

+945
-235
lines changed

18 files changed

+945
-235
lines changed

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

Lines changed: 22 additions & 14 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,
@@ -201,7 +207,9 @@ export const useWorkflowBuilderHeader = ({bottomResizablePanelRef, chatTrigger,
201207
// On mount: try to restore an ongoing run using jobId persisted in localStorage.
202208
// Attach-first approach: immediately call attach with the exact jobId string.
203209
useEffect(() => {
204-
if (!workflow.id || currentEnvironmentId === undefined) return;
210+
if (!workflow.id || currentEnvironmentId === undefined) {
211+
return;
212+
}
205213

206214
const jobId = getPersistedJobId();
207215

@@ -215,23 +223,23 @@ export const useWorkflowBuilderHeader = ({bottomResizablePanelRef, chatTrigger,
215223
setStreamRequest(getTestWorkflowAttachRequest({jobId}));
216224
}, [workflow.id, currentEnvironmentId, getPersistedJobId, setWorkflowIsRunning, setJobId, setStreamRequest]);
217225

226+
// Stop the workflow execution when:
227+
// - The node details panel is opened (this always cancels runs, regardless of chat mode), or
228+
// - We are in chat mode (`chatTrigger` is true) and the chat panel is not open (`!workflowTestChatPanelOpen`)
218229
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
222230
if (workflowNodeDetailsPanelOpen || (chatTrigger && !workflowTestChatPanelOpen)) {
223231
handleStopClick();
224232
}
225233
}, [chatTrigger, handleStopClick, workflowNodeDetailsPanelOpen, workflowTestChatPanelOpen]);
226234

227235
useEffect(() => {
228-
if (error) {
236+
if (workflowTestStreamError) {
229237
setWorkflowIsRunning(false);
230238
setStreamRequest(null);
231239
persistJobId(null);
232240
setJobId(null);
233241
}
234-
}, [error, persistJobId, setWorkflowIsRunning, setStreamRequest]);
242+
}, [workflowTestStreamError, persistJobId, setWorkflowIsRunning, setStreamRequest]);
235243

236244
return {
237245
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/tests/useProjectHeader.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ describe('useProjectHeader', () => {
222222
});
223223

224224
// Simulate start -> persist jobId
225-
act(() => latest.handlers?.start?.(JSON.stringify({jobId})));
225+
act(() => latest.handlers?.start?.({jobId}));
226226
expect(localStorage.getItem(storageKey)).toBe(jobId);
227227

228228
// Simulate result -> stop running, set execution, clear jobId and resize panel if closed
229-
act(() => latest.handlers?.result?.(JSON.stringify({ok: true})));
229+
act(() => latest.handlers?.result?.({ok: true}));
230230
await waitFor(() => expect(hoisted.editorSpies.setWorkflowIsRunning).toHaveBeenCalledWith(false));
231231
expect(hoisted.editorSpies.setWorkflowTestExecution).toHaveBeenCalled();
232232
expect(panelRef.current.resize).toHaveBeenCalledWith(35);
@@ -245,7 +245,7 @@ describe('useProjectHeader', () => {
245245
const {result} = renderHook(() =>
246246
useProjectHeader({bottomResizablePanelRef: panelRef, chatTrigger: false, projectId: 42})
247247
);
248-
act(() => latest.handlers?.start?.(JSON.stringify({jobId})));
248+
act(() => latest.handlers?.start?.({jobId}));
249249
localStorage.setItem(storageKey, jobId);
250250

251251
// Mock fetch and cookie

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

Lines changed: 26 additions & 18 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,27 +214,29 @@ 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 when:
226+
// - The node details panel is opened (this always cancels runs, regardless of chat mode), or
227+
// - We are in chat mode (`chatTrigger` is true) and the chat panel is not open (`!workflowTestChatPanelOpen`)
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(() => {
231-
if (!workflow.id || currentEnvironmentId === undefined) return;
237+
if (!workflow.id || currentEnvironmentId === undefined) {
238+
return;
239+
}
232240

233241
const jobId = getPersistedJobId();
234242

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

245253
useEffect(() => {
246-
if (error) {
254+
if (workflowTestStreamError) {
247255
setWorkflowIsRunning(false);
248256
setStreamRequest(null);
249257
persistJobId(null);
250258
setJobId(null);
251259
}
252-
}, [error, persistJobId, setWorkflowIsRunning, setStreamRequest]);
260+
}, [workflowTestStreamError, persistJobId, setWorkflowIsRunning, setStreamRequest]);
253261

254262
return {
255263
handleProjectWorkflowValueChange,

0 commit comments

Comments
 (0)