Skip to content

Commit

Permalink
show pagination for role page
Browse files Browse the repository at this point in the history
Signed-off-by: ryjiang <[email protected]>
  • Loading branch information
shanghaikid committed Jan 22, 2025
1 parent 7173d19 commit 58aa340
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions client/src/pages/user/Roles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Theme, Chip } from '@mui/material';
import { useTranslation } from 'react-i18next';
import { UserService } from '@/http';
import { rootContext, dataContext } from '@/context';
import { useNavigationHook } from '@/hooks';
import { useNavigationHook, usePaginationHook } from '@/hooks';
import AttuGrid from '@/components/grid/Grid';
import DeleteTemplate from '@/components/customDialog/DeleteDialogTemplate';
import UpdateRoleDialog from './dialogs/UpdateRoleDialog';
Expand All @@ -14,6 +14,7 @@ import type {
ToolBarConfig,
} from '@/components/grid/Types';
import type { DeleteRoleParams, RoleData } from './Types';
import { getLabelDisplayedRows } from '@/pages/search/Utils';

const useStyles = makeStyles((theme: Theme) => ({
wrapper: {
Expand All @@ -28,6 +29,7 @@ const Roles = () => {
useNavigationHook(ALL_ROUTER_TYPES.USER);
const classes = useStyles();
const { database } = useContext(dataContext);
const [loading, setLoading] = useState(false);

const [roles, setRoles] = useState<RoleData[]>([]);
const [selectedRole, setSelectedRole] = useState<RoleData[]>([]);
Expand Down Expand Up @@ -201,25 +203,42 @@ const Roles = () => {
fetchRoles();
}, [database]);

const {
pageSize,
handlePageSize,
currentPage,
handleCurrentPage,
total,
data: result,
order,
orderBy,
handleGridSort,
} = usePaginationHook(roles || []);

const handlePageChange = (e: any, page: number) => {
handleCurrentPage(page);
};

return (
<div className={classes.wrapper}>
<AttuGrid
toolbarConfigs={toolbarConfigs}
colDefinitions={colDefinitions}
rows={roles}
rowCount={roles.length}
rows={result}
rowCount={total}
primaryKey="name"
showPagination={false}
showPagination={true}
selected={selectedRole}
setSelected={handleSelectChange}
// page={currentPage}
// onPageChange={handlePageChange}
// rowsPerPage={pageSize}
// setRowsPerPage={handlePageSize}
// isLoading={loading}
// order={order}
// orderBy={orderBy}
// handleSort={handleGridSort}
page={currentPage}
onPageChange={handlePageChange}
rowsPerPage={pageSize}
setRowsPerPage={handlePageSize}
isLoading={loading}
order={order}
orderBy={orderBy}
handleSort={handleGridSort}
labelDisplayedRows={getLabelDisplayedRows(userTrans('roles'))}
/>
</div>
);
Expand Down

0 comments on commit 58aa340

Please sign in to comment.