Skip to content

Commit

Permalink
pagination comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed May 2, 2023
1 parent 809145b commit 6cf9c86
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 24 deletions.
12 changes: 4 additions & 8 deletions dashboard/src/actions/datasetListActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export const fetchPublicDatasets = (page) => async (dispatch, getState) => {
params.append("name", searchKey);
}
if (filter.startDate instanceof Date && !isNaN(filter.startDate)) {
params.append("start", new Date(filter.startDate).toUTCString());
params.append("start", filter.startDate.toUTCString());
}
if (filter.endDate instanceof Date && !isNaN(filter.endDate)) {
params.append("end", new Date(filter.endDate).toUTCString());
params.append("end", filter.endDate.toUTCString());
}

const response = await API.get(
Expand All @@ -54,17 +54,13 @@ export const fetchPublicDatasets = (page) => async (dispatch, getState) => {
// in case of last page, next_url is empty
if (response.data.next_url) {
const urlSearchParams = new URLSearchParams(response.data.next_url);
const params = Object.fromEntries(urlSearchParams.entries());
const offset = urlSearchParams.get("offset");

dispatch({
type: TYPES.SET_PAGE_OFFSET,
payload: Number(params?.offset),
payload: Number(offset),
});
}
dispatch({
type: TYPES.SET_TOTAL_DATASETS,
payload: response.data.total,
});
}
} catch (error) {
dispatch(showToast(DANGER, ERROR_MSG));
Expand Down
2 changes: 0 additions & 2 deletions dashboard/src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ export const NAVBAR_CLOSE = "NAVBAR_CLOSE";
/* PUBLIC DATASETS */
export const UPDATE_PUBLIC_DATASETS = "UPDATE_PUBLIC_DATASETS";
export const FAVORITED_DATASETS = "GET_FAVORITE_DATASETS";
export const SET_LOGIN_DETAILS = "SET_LOGIN_DETAILS";
export const SET_PAGE_OFFSET = "SET_PAGE_OFFSET";
export const SET_PAGE_LIMIT = "SET_PAGE_LIMIT";
export const SET_TOTAL_DATASETS = "SET_TOTAL_DATASETS";
export const SET_DATE_RANGE = "SET_DATE_RANGE";
export const SET_SEARCH_KEY = "SET_SEARCH_KEY";
export const SET_PER_PAGE = "SET_PER_PAGE";
Expand Down
10 changes: 4 additions & 6 deletions dashboard/src/modules/components/PaginationComponent/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import React from "react";
const TablePagination = ({ page, setPage }) => {
const dispatch = useDispatch();

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

Expand All @@ -36,12 +34,12 @@ const TablePagination = ({ page, setPage }) => {
let left = startIdx;
let right = endIdx;
while (left < right) {
if (publicData[startIdx]) {
if (publicData[left]) {
left++;
} else {
break;
}
if (publicData[endIdx]) {
if (publicData[right]) {
right--;
} else {
break;
Expand Down Expand Up @@ -69,7 +67,7 @@ const TablePagination = ({ page, setPage }) => {
onLastClick={fetchData}
toggleTemplate={({ firstIndex, lastIndex }) => (
<React.Fragment>
{firstIndex} - {lastIndex} of {totalDatasets}
{firstIndex} - {lastIndex} of {publicData.length}
</React.Fragment>
)}
></Pagination>
Expand Down
9 changes: 1 addition & 8 deletions dashboard/src/reducers/datasetListReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ const initialState = {
publicData: [],
favoriteRepoNames: [],
tableData: [],
offset: 0,
offset: CONSTANTS.START_PAGE_NUMBER - 1,
limit: CONSTANTS.INITIAL_PAGE_LIMIT,
perPage: CONSTANTS.DEFAULT_PER_PAGE,
totalDatasets: 0,
searchKey: "",
filter: {
startDate: "",
Expand All @@ -29,17 +28,11 @@ const DatasetListReducer = (state = initialState, action = {}) => {
...state,
favoriteRepoNames: [...payload],
};

case TYPES.SET_PAGE_OFFSET:
return {
...state,
offset: payload,
};
case TYPES.SET_TOTAL_DATASETS:
return {
...state,
totalDatasets: payload,
};
case TYPES.SET_PAGE_LIMIT:
return {
...state,
Expand Down

0 comments on commit 6cf9c86

Please sign in to comment.