Skip to content

Commit

Permalink
fix: prevent out of bounds navigation on new list views (#9875)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtonG authored Aug 29, 2024
1 parent a605f00 commit ad5fe5a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
8 changes: 7 additions & 1 deletion webui/react/src/components/Searches/Searches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,13 @@ const Searches: React.FC<Props> = ({ project }) => {
kind: 'group',
};

const offset = page * settings.pageLimit;
const response = await searchExperiments(
{
...experimentFilters,
filter: JSON.stringify(filters),
limit: settings.pageLimit,
offset: page * settings.pageLimit,
offset,
sort: sortString || undefined,
},
{ signal: canceler.signal },
Expand All @@ -355,6 +356,10 @@ const Searches: React.FC<Props> = ({ project }) => {
setTotal(
response.pagination.total !== undefined ? Loaded(response.pagination.total) : NotLoaded,
);
// oob check
if ((response.pagination.total || 0) < offset) {
resetPagination();
}
} catch (e) {
handleError(e, { publicSubject: 'Unable to fetch experiments.' });
} finally {
Expand All @@ -367,6 +372,7 @@ const Searches: React.FC<Props> = ({ project }) => {
isLoadingSettings,
loadableFormset,
page,
resetPagination,
sortString,
settings.pageLimit,
]);
Expand Down
16 changes: 11 additions & 5 deletions webui/react/src/pages/F_ExpList/F_ExperimentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,13 @@ const F_ExperimentList: React.FC<Props> = ({ project }) => {
const fetchExperiments = useCallback(async (): Promise<void> => {
if (isLoadingSettings || Loadable.isNotLoaded(loadableFormset)) return;
try {
const offset = page * settings.pageLimit;
const response = await searchExperiments(
{
...experimentFilters,
filter: filtersString,
limit: settings.pageLimit,
offset: page * settings.pageLimit,
offset,
sort: sortString || undefined,
},
{ signal: canceler.signal },
Expand All @@ -361,20 +362,25 @@ const F_ExperimentList: React.FC<Props> = ({ project }) => {
setTotal(
response.pagination.total !== undefined ? Loaded(response.pagination.total) : NotLoaded,
);
// oob check
if ((response.pagination.total || 0) < offset) {
resetPagination();
}
} catch (e) {
handleError(e, { publicSubject: 'Unable to fetch experiments.' });
} finally {
setIsLoading(false);
}
}, [
canceler.signal,
experimentFilters,
filtersString,
isLoadingSettings,
loadableFormset,
page,
sortString,
settings.pageLimit,
experimentFilters,
filtersString,
resetPagination,
sortString,
canceler.signal,
]);

const { stopPolling } = usePolling(fetchExperiments, { rerunOnNewFn: true });
Expand Down
20 changes: 13 additions & 7 deletions webui/react/src/pages/FlatRuns/FlatRuns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ const FlatRuns: React.FC<Props> = ({ projectId, workspaceId, searchId }) => {
[page, updateSettings, setPage],
);

const resetPagination = useCallback(() => {
setIsLoading(true);
setPage(0);
setRuns(INITIAL_LOADING_RUNS);
}, [setPage]);

const fetchRuns = useCallback(async (): Promise<void> => {
if (isLoadingSettings || Loadable.isNotLoaded(loadableFormset)) return;
try {
Expand All @@ -546,11 +552,12 @@ const FlatRuns: React.FC<Props> = ({ projectId, workspaceId, searchId }) => {
kind: 'group',
};
}
const offset = page * settings.pageLimit;
const response = await searchRuns(
{
filter: JSON.stringify(filters),
limit: settings.pageLimit,
offset: page * settings.pageLimit,
offset,
projectId: projectId,
sort: sortString || undefined,
},
Expand All @@ -562,6 +569,10 @@ const FlatRuns: React.FC<Props> = ({ projectId, workspaceId, searchId }) => {
setTotal(
response.pagination.total !== undefined ? Loaded(response.pagination.total) : NotLoaded,
);
// if we're out of bounds, load page one
if ((response.pagination.total || 0) < offset) {
resetPagination();
}
} catch (e) {
handleError(e, { publicSubject: 'Unable to fetch runs.' });
} finally {
Expand All @@ -574,6 +585,7 @@ const FlatRuns: React.FC<Props> = ({ projectId, workspaceId, searchId }) => {
loadableFormset,
page,
projectId,
resetPagination,
settings.pageLimit,
sortString,
searchId,
Expand All @@ -585,12 +597,6 @@ const FlatRuns: React.FC<Props> = ({ projectId, workspaceId, searchId }) => {
return rootFilterChildren.length;
}, [rootFilterChildren.length]);

const resetPagination = useCallback(() => {
setIsLoading(true);
setPage(0);
setRuns(INITIAL_LOADING_RUNS);
}, [setPage]);

useLayoutEffect(() => {
let cleanup: () => void;
// eslint-disable-next-line prefer-const
Expand Down

0 comments on commit ad5fe5a

Please sign in to comment.