Skip to content

Commit

Permalink
per Page select error
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed Apr 17, 2023
1 parent e97925a commit 352ba55
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions dashboard/src/assets/constants/browsingPageConstants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const DEFAULT_PER_PAGE = 20;
export const LIMIT = 60;
export const START_PAGE_NUMBER = 1;
export const LIMIT_MULTIPLIER = 3;
40 changes: 27 additions & 13 deletions dashboard/src/modules/components/PaginationComponent/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,47 @@ import {
} from "actions/datasetListActions";
import { useDispatch, useSelector } from "react-redux";

import { LIMIT_MULTIPLIER } from "assets/constants/browsingPageConstants";
import React from "react";

const TablePagination = ({ page, setPage }) => {
const dispatch = useDispatch();

const { totalDatasets, publicData, perPage, limit } = useSelector(
const { totalDatasets, publicData, perPage } = useSelector(
(state) => state.datasetlist
);
const onSetPage = (_event, pageNumber) => {
setPage(pageNumber);

fetchData(_event, pageNumber);
fetchData(_event, pageNumber, perPage);
};
const onPerPageSelect = (_event, perPage, newPage) => {
if (perPage > limit) {
dispatch(setPageLimit(perPage));
}
dispatch(setPerPage(perPage));
const onPerPageSelect = (_event, newPerPage, newPage) => {
dispatch(setPageLimit(newPerPage * LIMIT_MULTIPLIER));

dispatch(setPerPage(newPerPage));
setPage(newPage);

fetchData(_event, newPage);
fetchData(_event, newPage, newPerPage);
};
const fetchData = (_event, newPage) => {
const startIdx = (newPage - 1) * perPage;

if (!publicData[startIdx]) {
const offset = (newPage - 1) * perPage;
const fetchData = (_event, newPage, newPerPage = perPage) => {
const startIdx = (newPage - 1) * newPerPage;
const endIdx = newPage * newPerPage;
let left = startIdx;
let right = endIdx;
while (left < right) {
if (publicData[startIdx]) {
left++;
} else {
break;
}
if (publicData[endIdx]) {
right--;
} else {
break;
}
}
if (left !== right) {
const offset = (newPage - 1) * newPerPage;

dispatch({
type: TYPES.SET_PAGE_OFFSET,
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/modules/components/TableComponent/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ const TableWithFavorite = () => {
</Tr>
))
) : (
<Tr>
<Tr key={"empty-row"}>
<Td colSpan={8}>
<EmptyTable />
</Td>
Expand Down

0 comments on commit 352ba55

Please sign in to comment.