diff --git a/packages/console/src/components/AuditLogTable/index.tsx b/packages/console/src/components/AuditLogTable/index.tsx index a92ad4d49..a8a23a212 100644 --- a/packages/console/src/components/AuditLogTable/index.tsx +++ b/packages/console/src/components/AuditLogTable/index.tsx @@ -145,7 +145,7 @@ const AuditLogTable = ({ userId }: Props) => { { diff --git a/packages/console/src/components/Pagination/index.tsx b/packages/console/src/components/Pagination/index.tsx index 07894c8fc..41f042190 100644 --- a/packages/console/src/components/Pagination/index.tsx +++ b/packages/console/src/components/Pagination/index.tsx @@ -2,6 +2,8 @@ import classNames from 'classnames'; import { useTranslation } from 'react-i18next'; import ReactPaginate from 'react-paginate'; +import useCacheValue from '@/hooks/use-cache-value'; + import Button from '../Button'; import DangerousRaw from '../DangerousRaw'; import Next from './Next'; @@ -10,7 +12,7 @@ import * as styles from './index.module.scss'; type Props = { pageIndex: number; - totalCount: number; + totalCount?: number; pageSize: number; className?: string; onChange?: (pageIndex: number) => void; @@ -18,19 +20,27 @@ type Props = { const Pagination = ({ pageIndex, totalCount, pageSize, className, onChange }: Props) => { const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); - const pageCount = Math.ceil(totalCount / pageSize); + + /** + * Note: + * The `totalCount` will become `undefined` temporarily when fetching data on page changes, and this causes the pagination to disappear. + * Cache `totalCount` to solve this problem. + */ + const cachedTotalCount = useCacheValue(totalCount) ?? 0; + + const pageCount = Math.ceil(cachedTotalCount / pageSize); if (pageCount <= 1) { return null; } const min = (pageIndex - 1) * pageSize + 1; - const max = Math.min(pageIndex * pageSize, totalCount); + const max = Math.min(pageIndex * pageSize, cachedTotalCount); return (
- {t('general.page_info', { min, max, total: totalCount })} + {t('general.page_info', { min, max, total: cachedTotalCount })}
(value: T) => { + const [cachedValue, setCachedValue] = useState(); + + useEffect(() => { + if (value !== undefined) { + setCachedValue(value); + } + }, [value]); + + return cachedValue; +}; + +export default useCacheValue; diff --git a/packages/console/src/pages/ApiResources/index.tsx b/packages/console/src/pages/ApiResources/index.tsx index c78bb1753..4a8ae3e34 100644 --- a/packages/console/src/pages/ApiResources/index.tsx +++ b/packages/console/src/pages/ApiResources/index.tsx @@ -145,7 +145,7 @@ const ApiResources = () => {
{ diff --git a/packages/console/src/pages/Applications/index.tsx b/packages/console/src/pages/Applications/index.tsx index 52f65dc06..fee727072 100644 --- a/packages/console/src/pages/Applications/index.tsx +++ b/packages/console/src/pages/Applications/index.tsx @@ -137,7 +137,7 @@ const Applications = () => { { diff --git a/packages/console/src/pages/Users/index.tsx b/packages/console/src/pages/Users/index.tsx index 9ae4cc5ed..406d9c177 100644 --- a/packages/console/src/pages/Users/index.tsx +++ b/packages/console/src/pages/Users/index.tsx @@ -164,7 +164,7 @@ const Users = () => { {