mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(console): hide pagination if the page count is less than two (#2474)
This commit is contained in:
parent
ea0200b795
commit
f2aa2d2d8c
5 changed files with 44 additions and 51 deletions
|
@ -139,18 +139,15 @@ const AuditLogTable = ({ userId }: Props) => {
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className={styles.pagination}>
|
||||
{!!totalCount && (
|
||||
<Pagination
|
||||
pageIndex={pageIndex}
|
||||
totalCount={totalCount}
|
||||
totalCount={totalCount ?? 0}
|
||||
pageSize={pageSize}
|
||||
className={styles.pagination}
|
||||
onChange={(page) => {
|
||||
updateQuery('page', String(page));
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -12,18 +12,23 @@ type Props = {
|
|||
pageIndex: number;
|
||||
totalCount: number;
|
||||
pageSize: number;
|
||||
className?: string;
|
||||
onChange?: (pageIndex: number) => void;
|
||||
};
|
||||
|
||||
const Pagination = ({ pageIndex, totalCount, pageSize, onChange }: Props) => {
|
||||
const Pagination = ({ pageIndex, totalCount, pageSize, className, onChange }: Props) => {
|
||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||
const pageCount = Math.ceil(totalCount / pageSize);
|
||||
|
||||
if (pageCount <= 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const min = (pageIndex - 1) * pageSize + 1;
|
||||
const max = pageIndex * pageSize;
|
||||
const max = Math.min(pageIndex * pageSize, totalCount);
|
||||
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<div className={classNames(styles.container, className)}>
|
||||
<div className={styles.positionInfo}>
|
||||
{t('general.page_info', { min, max, total: totalCount })}
|
||||
</div>
|
||||
|
|
|
@ -137,18 +137,15 @@ const ApiResources = () => {
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className={styles.pagination}>
|
||||
{!!totalCount && (
|
||||
<Pagination
|
||||
pageIndex={pageIndex}
|
||||
totalCount={totalCount}
|
||||
totalCount={totalCount ?? 0}
|
||||
pageSize={pageSize}
|
||||
className={styles.pagination}
|
||||
onChange={(page) => {
|
||||
setQuery({ page: String(page) });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -128,18 +128,15 @@ const Applications = () => {
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className={styles.pagination}>
|
||||
{!!totalCount && (
|
||||
<Pagination
|
||||
pageIndex={pageIndex}
|
||||
totalCount={totalCount}
|
||||
totalCount={totalCount ?? 0}
|
||||
pageSize={pageSize}
|
||||
className={styles.pagination}
|
||||
onChange={(page) => {
|
||||
setQuery({ page: String(page) });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -153,18 +153,15 @@ const Users = () => {
|
|||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className={styles.pagination}>
|
||||
{!!totalCount && (
|
||||
<Pagination
|
||||
pageIndex={pageIndex}
|
||||
totalCount={totalCount}
|
||||
totalCount={totalCount ?? 0}
|
||||
pageSize={pageSize}
|
||||
className={styles.pagination}
|
||||
onChange={(page) => {
|
||||
setQuery({ page: String(page), ...conditional(keyword && { search: keyword }) });
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue