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>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.pagination}>
|
|
||||||
{!!totalCount && (
|
|
||||||
<Pagination
|
<Pagination
|
||||||
pageIndex={pageIndex}
|
pageIndex={pageIndex}
|
||||||
totalCount={totalCount}
|
totalCount={totalCount ?? 0}
|
||||||
pageSize={pageSize}
|
pageSize={pageSize}
|
||||||
|
className={styles.pagination}
|
||||||
onChange={(page) => {
|
onChange={(page) => {
|
||||||
updateQuery('page', String(page));
|
updateQuery('page', String(page));
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -12,18 +12,23 @@ type Props = {
|
||||||
pageIndex: number;
|
pageIndex: number;
|
||||||
totalCount: number;
|
totalCount: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
|
className?: string;
|
||||||
onChange?: (pageIndex: number) => void;
|
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 { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||||
const pageCount = Math.ceil(totalCount / pageSize);
|
const pageCount = Math.ceil(totalCount / pageSize);
|
||||||
|
|
||||||
|
if (pageCount <= 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const min = (pageIndex - 1) * pageSize + 1;
|
const min = (pageIndex - 1) * pageSize + 1;
|
||||||
const max = pageIndex * pageSize;
|
const max = Math.min(pageIndex * pageSize, totalCount);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.container}>
|
<div className={classNames(styles.container, className)}>
|
||||||
<div className={styles.positionInfo}>
|
<div className={styles.positionInfo}>
|
||||||
{t('general.page_info', { min, max, total: totalCount })}
|
{t('general.page_info', { min, max, total: totalCount })}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -137,18 +137,15 @@ const ApiResources = () => {
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.pagination}>
|
|
||||||
{!!totalCount && (
|
|
||||||
<Pagination
|
<Pagination
|
||||||
pageIndex={pageIndex}
|
pageIndex={pageIndex}
|
||||||
totalCount={totalCount}
|
totalCount={totalCount ?? 0}
|
||||||
pageSize={pageSize}
|
pageSize={pageSize}
|
||||||
|
className={styles.pagination}
|
||||||
onChange={(page) => {
|
onChange={(page) => {
|
||||||
setQuery({ page: String(page) });
|
setQuery({ page: String(page) });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -128,18 +128,15 @@ const Applications = () => {
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.pagination}>
|
|
||||||
{!!totalCount && (
|
|
||||||
<Pagination
|
<Pagination
|
||||||
pageIndex={pageIndex}
|
pageIndex={pageIndex}
|
||||||
totalCount={totalCount}
|
totalCount={totalCount ?? 0}
|
||||||
pageSize={pageSize}
|
pageSize={pageSize}
|
||||||
|
className={styles.pagination}
|
||||||
onChange={(page) => {
|
onChange={(page) => {
|
||||||
setQuery({ page: String(page) });
|
setQuery({ page: String(page) });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -153,18 +153,15 @@ const Users = () => {
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.pagination}>
|
|
||||||
{!!totalCount && (
|
|
||||||
<Pagination
|
<Pagination
|
||||||
pageIndex={pageIndex}
|
pageIndex={pageIndex}
|
||||||
totalCount={totalCount}
|
totalCount={totalCount ?? 0}
|
||||||
pageSize={pageSize}
|
pageSize={pageSize}
|
||||||
|
className={styles.pagination}
|
||||||
onChange={(page) => {
|
onChange={(page) => {
|
||||||
setQuery({ page: String(page), ...conditional(keyword && { search: keyword }) });
|
setQuery({ page: String(page), ...conditional(keyword && { search: keyword }) });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue