Skip to content

Commit

Permalink
FWF-3945: [Bugfix] Resolved pagination issue in dashobaord
Browse files Browse the repository at this point in the history
  • Loading branch information
Bonymol-aot committed Nov 18, 2024
1 parent dd75110 commit b6254b2
Showing 1 changed file with 17 additions and 46 deletions.
63 changes: 17 additions & 46 deletions forms-flow-admin/src/components/dashboard/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React from "react";
import { Button } from "react-bootstrap";
import BootstrapTable from "react-bootstrap-table-next";
import DropdownButton from "react-bootstrap/DropdownButton";
import Dropdown from "react-bootstrap/Dropdown";
import OverlayTrigger from "react-bootstrap/OverlayTrigger";
import Popover from "react-bootstrap/Popover";
import "react-bootstrap-table2-paginator/dist/react-bootstrap-table2-paginator.min.css";
import paginationFactory from "react-bootstrap-table2-paginator";
import { toast } from "react-toastify";
import Loading from "../loading";
import { useParams } from "react-router-dom";
Expand All @@ -18,29 +14,9 @@ import {
fetchAuthorizations,
} from "../../services/dashboard";
import { Translation, useTranslation } from "react-i18next";
import { TableFooter } from "@formsflow/components";

const customDropUp = ({ options, currSizePerPage, onSizePerPageChange }) => {
return (
<DropdownButton
drop="up"
variant="secondary"
title={currSizePerPage}
style={{ display: "inline" }}
>
{options.map((option) => (
<Dropdown.Item
key={option.text}
type="button"
onClick={() => onSizePerPageChange(option.page)}
>
{option.text}
</Dropdown.Item>
))}
</DropdownButton>
);
};

export const InsightDashboard = React.memo((props: any) => {
const InsightDashboard = React.memo((props: any) => {
const { dashboards, groups, authorizations, setCount, authReceived } = props;

const isGroupUpdated = groups.length > 0;
Expand All @@ -55,6 +31,7 @@ export const InsightDashboard = React.memo((props: any) => {
const [show, setShow] = React.useState(false);
const [activePage, setActivePage] = React.useState(1);
const [err, setErr] = React.useState({});
const [limit, setLimit] = React.useState(5);
const [isLoading, setIsLoading] = React.useState(true);

React.useEffect(() => {
Expand Down Expand Up @@ -285,36 +262,17 @@ export const InsightDashboard = React.memo((props: any) => {
return list;
};

const customTotal = (from, to, size) => (
<span className="ms-2" role="main">
<Translation>{(t) => t("Showing")}</Translation> {from}{" "}
<Translation>{(t) => t("to")}</Translation> {to}{" "}
<Translation>{(t) => t("of")}</Translation> {size}{" "}
<Translation>{(t) => t("results")}</Translation>
</span>
);

const pagination = paginationFactory({
showTotal: true,
align: "center",
sizePerPageList: getpageList(),
page: activePage,
paginationTotalRenderer: customTotal,
onPageChange: (page) => setActivePage(page),
sizePerPageRenderer: customDropUp,
});

return (
<>
<div className="" role="definition">
<br />
<div>
{!isLoading ? (
<div>
<BootstrapTable
keyField="resourceId"
data={authDashBoardList}
columns={columns}
pagination={authDashBoardList.length > 0 ? pagination : false}
bordered={false}
wrapperClasses="table-container-admin mb-3 px-4"
rowStyle={{
Expand All @@ -324,6 +282,19 @@ export const InsightDashboard = React.memo((props: any) => {
noDataIndication={noData}
data-testid="admin-dashboard-table"
/>
<table className="table">
<tfoot>
<TableFooter
limit={limit}
activePage={activePage}
totalCount={authDashBoardList.length}
handlePageChange={(page) => setActivePage(page)}
onLimitChange={setLimit}
pageOptions={getpageList()}
/>
</tfoot>
</table>
</div>
) : (
<Loading />
)}
Expand Down

0 comments on commit b6254b2

Please sign in to comment.