Skip to content

Commit 1df334b

Browse files
authored
[CORE-737] Do not refresh submissions history when viewing all submissions (#5444)
1 parent d0d9fca commit 1df334b

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

src/pages/workspaces/workspace/SubmissionHistory.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ export const SubmissionHistory = _.flow(
173173

174174
// Helpers
175175
const refresh = Utils.withBusyState(setLoading, async () => {
176+
if (scheduledRefresh.current) {
177+
clearTimeout(scheduledRefresh.current);
178+
}
176179
try {
177180
let startDate;
178181
if (dateRange === '30') {
@@ -184,7 +187,6 @@ export const SubmissionHistory = _.flow(
184187

185188
const params = {};
186189
if (startDate) params.startDate = startDate.toISOString().split('T')[0];
187-
188190
const submissions = _.flow(
189191
_.orderBy('submissionDate', 'desc'),
190192
_.map((sub) => {
@@ -215,8 +217,7 @@ export const SubmissionHistory = _.flow(
215217
})
216218
)(await Workspaces(signal).workspace(namespace, name).listSubmissions(params));
217219
setSubmissions(submissions);
218-
219-
if (_.some(({ status }) => !isTerminal(status), submissions)) {
220+
if (dateRange !== 'all' && _.some(({ status }) => !isTerminal(status), submissions)) {
220221
scheduledRefresh.current = setTimeout(refresh, 1000 * 60);
221222
}
222223
} catch (error) {
@@ -239,8 +240,6 @@ export const SubmissionHistory = _.flow(
239240

240241
// Lifecycle
241242
useOnMount(() => {
242-
refresh();
243-
244243
return () => {
245244
if (scheduledRefresh.current) {
246245
clearTimeout(scheduledRefresh.current);

src/pages/workspaces/workspace/SubmissionHistory.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,28 @@ describe('SubmissionHistory date range filter', () => {
274274
// Verify the URL parameter is set to default instead of invalid value
275275
expect(window.location.hash).toContain('?dateRange=30');
276276
});
277+
278+
test('does not schedule refresh when "All Submissions" is selected', async () => {
279+
// Set the URL to "all" to ensure that the refresh logic is tested correctly
280+
window.location.hash = '#workspaces/test-ns/test-ws/submission_history?dateRange=all';
281+
282+
jest.useFakeTimers();
283+
const setTimeoutSpy = jest.spyOn(global, 'setTimeout');
284+
const runningSubmission = { ...newerSubmission, status: 'Running' };
285+
mockListSubmissions([runningSubmission]);
286+
await act(async () => {
287+
renderSubmissionHistory();
288+
});
289+
290+
// Wait for UI update
291+
await waitFor(() => {
292+
expect(screen.getByText('Recent Submission')).toBeInTheDocument();
293+
});
294+
295+
// Assert setTimeout was not called to schedule a refresh
296+
expect(setTimeoutSpy).not.toHaveBeenCalledWith(expect.any(Function), 1000 * 60);
297+
298+
setTimeoutSpy.mockRestore();
299+
jest.useRealTimers();
300+
});
277301
});

0 commit comments

Comments
 (0)