Skip to content

Commit 4c2b299

Browse files
committed
Use debouncer on testhistory, remove toString
1 parent 866c372 commit 4c2b299

File tree

8 files changed

+31
-53
lines changed

8 files changed

+31
-53
lines changed

frontend/src/components/classify-failures.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ const ClassifyFailuresTable = () => {
110110
);
111111
const data = await HttpClient.handleResponse(response);
112112
setFilteredResults(data.results);
113-
setPage(data.pagination.page.toString());
114-
setPageSize(data.pagination.pageSize.toString());
113+
setPage(data.pagination.page);
114+
setPageSize(data.pagination.pageSize);
115115
setTotalItems(data.pagination.totalItems);
116116
setFetching(false);
117117
} catch (error) {

frontend/src/components/test-history.js

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const TestHistoryTable = ({ comparisonResults, testResult }) => {
9696
operator: 'gt',
9797
value: new Date(
9898
new Date(testResult?.start_time).getTime() -
99-
WEEKS['1 Week'] * millisecondsInMonth,
99+
WEEKS[selectedTimeRange] * millisecondsInMonth,
100100
).toISOString(),
101101
}
102102
: {};
@@ -131,7 +131,7 @@ const TestHistoryTable = ({ comparisonResults, testResult }) => {
131131
),
132132
]);
133133
}
134-
}, [onlyFailures, setActiveFilters, testResult]);
134+
}, [onlyFailures, setActiveFilters, testResult, selectedTimeRange]);
135135

136136
// fetch result data with active filters
137137
useEffect(() => {
@@ -158,8 +158,8 @@ const TestHistoryTable = ({ comparisonResults, testResult }) => {
158158
.flat(),
159159
);
160160

161-
setPage(data.pagination.page.toString());
162-
setPageSize(data.pagination.pageSize.toString());
161+
setPage(data.pagination.page);
162+
setPageSize(data.pagination.pageSize);
163163
setTotalItems(data.pagination.totalItems);
164164
} catch (error) {
165165
console.error('Error fetching result data:', error);
@@ -168,11 +168,17 @@ const TestHistoryTable = ({ comparisonResults, testResult }) => {
168168
}
169169
setFetching(false);
170170
};
171+
171172
if (comparisonResults !== undefined) {
172173
setRows([...comparisonResults]);
173174
setFetching(false);
174175
} else {
175-
getResults();
176+
const debouncer = setTimeout(() => {
177+
getResults();
178+
}, 200);
179+
return () => {
180+
clearTimeout(debouncer);
181+
};
176182
}
177183
}, [
178184
activeFilters,
@@ -232,8 +238,12 @@ const TestHistoryTable = ({ comparisonResults, testResult }) => {
232238
console.error(error);
233239
}
234240
};
235-
236-
resultAggFetch();
241+
const debouncer = setTimeout(() => {
242+
resultAggFetch();
243+
}, 200);
244+
return () => {
245+
clearTimeout(debouncer);
246+
};
237247
}
238248
}, [activeFilters]);
239249

@@ -245,30 +255,12 @@ const TestHistoryTable = ({ comparisonResults, testResult }) => {
245255
// Handle time range select
246256
const onTimeRangeSelect = useCallback(
247257
(_, selection) => {
248-
if (testResult?.start_time) {
249-
const startTime = new Date(testResult?.start_time);
250-
const selectionCoefficient = WEEKS[selection];
251-
const timeRange = new Date(
252-
startTime.getTime() - selectionCoefficient * millisecondsInMonth,
253-
);
254-
setActiveFilters((prevFilters) => {
255-
return prevFilters.map((filter) => {
256-
if (filter.field === 'start_time') {
257-
return {
258-
...filter,
259-
operator: 'gt',
260-
value: timeRange.toISOString(),
261-
};
262-
} else {
263-
return filter;
264-
}
265-
});
266-
});
258+
if (Object.hasOwn(testResult, 'start_time')) {
267259
setTimeRangeOpen(false);
268260
setSelectedTimeRange(selection);
269261
}
270262
},
271-
[setActiveFilters, testResult?.start_time],
263+
[testResult],
272264
);
273265

274266
// Handle time range toggle

frontend/src/pages/admin/project-list.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ const ProjectList = () => {
119119
setFilteredProjects(
120120
data.projects.map((project) => projectToRow(project)),
121121
);
122-
setPage(data.pagination.page.toString());
123-
setPageSize(data.pagination.pageSize.toString());
122+
setPage(data.pagination.page);
123+
setPageSize(data.pagination.pageSize);
124124
setTotalItems(data.pagination.totalItems);
125125
}
126126
})

frontend/src/report-builder.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ const ReportBuilder = () => {
141141
setRows(row_data);
142142
setTotalItems(data.pagination.totalItems);
143143
setIsError(false);
144-
pagination_page.current = data.pagination.page.toString();
145-
pagination_pageSize.current = data.pagination.pageSize.toString();
144+
pagination_page.current = data.pagination.page;
145+
pagination_pageSize.current = data.pagination.pageSize;
146146
})
147147
.catch((error) => {
148148
console.error('Error fetching result data:', error);

frontend/src/run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ const Run = ({ defaultTab = 'summary' }) => {
117117
.then((response) => HttpClient.handleResponse(response))
118118
.then((data) => {
119119
setRows(data.results.map((result) => resultToRow(result)));
120-
setPage(data.pagination.page.toString());
121-
setPageSize(data.pagination.pageSize.toString());
120+
setPage(data.pagination.page);
121+
setPageSize(data.pagination.pageSize);
122122
setTotalItems(data.pagination.totalItems);
123123
setFetching(false);
124124
})

frontend/src/utilities.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -869,19 +869,6 @@ export const cleanPath = (path) => {
869869
return pathParts.join('/');
870870
};
871871

872-
export const debounce = (func, timeout = 500) => {
873-
let timerId;
874-
return (...args) => {
875-
if (!timerId) {
876-
func.apply(this, args);
877-
}
878-
clearTimeout(timerId);
879-
timerId = setTimeout(() => {
880-
timerId = undefined;
881-
}, timeout);
882-
};
883-
};
884-
885872
export const getDarkTheme = () => {
886873
// check local storage and browser theme for a preference
887874
const local_theme = localStorage.getItem(THEME_KEY);

frontend/src/views/accessibilitydashboard.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ const AccessibilityDashboardView = ({ view }) => {
242242
setRows(
243243
data.runs.map((run) => runToRow(run, setFilters, analysisViewId)),
244244
);
245-
setPage(data.pagination.page.toString());
246-
setPageSize(data.pagination.pageSize.toString());
245+
setPage(data.pagination.page);
246+
setPageSize(data.pagination.pageSize);
247247
setTotalItems(data.pagination.totalItems);
248248
})
249249
.catch((error) => {

frontend/src/views/compareruns.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ const CompareRunsView = () => {
143143
})
144144
.then((response) => HttpClient.handleResponse(response))
145145
.then((data) => {
146-
console.dir(data.results);
147146
setResults(data.results);
148-
setPage(data.pagination.page.toString());
149-
setPageSize(data.pagination.pageSize.toString());
147+
setPage(data.pagination.page);
148+
setPageSize(data.pagination.pageSize);
150149
setTotalItems(data.pagination.totalItems);
151150
})
152151
.catch((error) => {

0 commit comments

Comments
 (0)