Skip to content

Commit

Permalink
feat: update pagination query params on pressing next/prev page
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadshaheer committed Dec 23, 2024
1 parent 56f260d commit 88598ed
Showing 1 changed file with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
transformDataWithDate,
} from 'container/TracesExplorer/ListView/utils';
import { Pagination } from 'hooks/queryPagination';
import { useSafeNavigate } from 'hooks/useSafeNavigate';
import { GetQueryResultsProps } from 'lib/dashboard/getQueryResults';
import history from 'lib/history';
import { RowData } from 'lib/query/createTableColumnsFromQuery';
Expand Down Expand Up @@ -39,6 +40,7 @@ function TracesTableComponent({
offset: 0,
limit: 10,
});
const { safeNavigate } = useSafeNavigate();

useEffect(() => {
setRequestData((prev) => ({
Expand Down Expand Up @@ -87,6 +89,25 @@ function TracesTableComponent({
[],
);

const handlePaginationChange = useCallback(
(newPagination: Pagination) => {
const urlQuery = new URLSearchParams(window.location.search);

// Update URL with new pagination values
urlQuery.set('offset', newPagination.offset.toString());
urlQuery.set('limit', newPagination.limit.toString());

// Update URL without page reload
safeNavigate({
search: urlQuery.toString(),
});

// Update component state
setPagination(newPagination);
},
[safeNavigate],
);

if (queryResponse.isError) {
return <div>{SOMETHING_WENT_WRONG}</div>;
}
Expand Down Expand Up @@ -116,19 +137,19 @@ function TracesTableComponent({
offset={pagination.offset}
countPerPage={pagination.limit}
handleNavigatePrevious={(): void => {
setPagination({
handlePaginationChange({
...pagination,
offset: pagination.offset - pagination.limit,
});
}}
handleNavigateNext={(): void => {
setPagination({
handlePaginationChange({
...pagination,
offset: pagination.offset + pagination.limit,
});
}}
handleCountItemsPerPageChange={(value): void => {
setPagination({
handlePaginationChange({
...pagination,
limit: value,
offset: 0,
Expand Down

0 comments on commit 88598ed

Please sign in to comment.