Skip to content

Commit

Permalink
Add logic to change perPage in component ListWithOwnState states when…
Browse files Browse the repository at this point in the history
… new perPage prop arrives (#17278)

* Add logic to change perPage in state of ListWithOwnState component when new perPage prop would arrive

* Some refactoring

* Add changelog

* fix changelog

* fix changelog

* fix changelog
  • Loading branch information
maxiadlovskii authored Nov 14, 2023
1 parent 3657b94 commit df0e7e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 4 additions & 0 deletions changelog/unreleased/issue-17261.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type = "f"
message = "Fixing problem with persisting selected page size for some paginated lists."
issues = ["17261"]
pulls = ["17278"]
23 changes: 15 additions & 8 deletions graylog2-web-interface/src/components/common/PaginatedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import * as React from 'react';
import { useEffect, useMemo, useCallback } from 'react';
import { useEffect, useMemo, useCallback, useState } from 'react';

import IfInteractive from 'views/components/dashboard/IfInteractive';
import usePaginationQueryParameter, { DEFAULT_PAGE_SIZES } from 'hooks/usePaginationQueryParameter';
Expand Down Expand Up @@ -110,16 +110,23 @@ const ListWithOwnState = ({
pageSize: propPageSize,
...props
}: Required<Props> & { activePage: number, pageSize: number }) => {
const [{ page: currentPage, pageSize: currentPageSize }, setPagination] = React.useState({
page: Math.max(activePage, INITIAL_PAGE),
pageSize: propPageSize,
});
const [currentPage, setCurrentPage] = useState<number>(Math.max(activePage, INITIAL_PAGE));
const [currentPageSize, setCurrentPageSize] = useState<number>(propPageSize);

useEffect(() => {
if (activePage > 0 && activePage !== currentPage) {
setPagination((cur) => ({ ...cur, page: activePage }));
if (activePage > 0) {
setCurrentPage(activePage);
}
}, [activePage, currentPage]);
}, [activePage]);

useEffect(() => {
setCurrentPageSize(propPageSize);
}, [propPageSize]);

const setPagination = useCallback(({ page, pageSize }) => {
setCurrentPageSize(pageSize);
setCurrentPage(page);
}, []);

return (
<ListBase {...props}
Expand Down

0 comments on commit df0e7e3

Please sign in to comment.