Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random Pagination ISSUE-143 #147

Open
wants to merge 1 commit into
base: revamp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/app/api/v1/endpoints/cpt/cptJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def jobs(
"endDate": end_date.__str__(),
"results": results_df.to_dict("records"),
"total": jobsCount,
"offset": offset + size,
"offset": offset + size if size else 0,
}

if pretty:
Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/endpoints/ocp/ocpJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def jobs(
"endDate": end_date.__str__(),
"results": jobs,
"total": results["total"],
"offset": offset + size,
"offset": offset + size if size else 0,
}

if pretty:
Expand Down
4 changes: 2 additions & 2 deletions backend/app/api/v1/endpoints/quay/quayJobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ async def jobs(
"startDate": start_date.__str__(),
"endDate": end_date.__str__(),
"results": jobs,
"total": 0,
"offset": 0,
"total": results["total"],
"offset": offset + size if size else 0,
}

if pretty:
Expand Down
13 changes: 10 additions & 3 deletions backend/app/api/v1/endpoints/telco/telcoJobs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
from fastapi import Response
from datetime import datetime, timedelta, date
from fastapi import APIRouter
from fastapi import APIRouter, HTTPException
from ...commons.telco import getData
from ...commons.example_responses import telco_200_response, response_422
from fastapi.param_functions import Query
Expand Down Expand Up @@ -50,6 +50,13 @@ async def jobs(
),
status_code=422,
)
if offset and not size:
raise HTTPException(400, f"offset {offset} specified without size")
elif not offset and not size:
size = 10000
offset = 0
elif not offset:
offset = 0

results = await getData(start_date, end_date, size, offset, "telco.splunk")
jobs = []
Expand All @@ -60,8 +67,8 @@ async def jobs(
"startDate": start_date.__str__(),
"endDate": end_date.__str__(),
"results": jobs,
"total": 0,
"offset": 0,
"total": results["total"],
"offset": offset + size if size else 0,
}

if pretty:
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/actions/commonActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ export const getSelectedFilter =
};

export const getRequestParams = (type) => (dispatch, getState) => {
const { start_date, end_date, size, offset } = getState()[type];
const { start_date, end_date, perPage, offset } = getState()[type];
const params = {
pretty: true,
...(start_date && { start_date }),
...(end_date && { end_date }),
size: size,
size: perPage,
offset: offset,
};

Expand Down
44 changes: 23 additions & 21 deletions frontend/src/actions/paginationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from "./ocpActions";
import {
fetchOCPJobsData,
setCPTOffset,
setCPTPage,
setCPTPageOptions,
sliceCPTTableRows,
Expand Down Expand Up @@ -47,36 +48,37 @@ const calculateOffset = (pageNumber, itemsPerPage) => {
return (pageNumber - 1) * itemsPerPage;
};

const fetchActions = {
ocp: fetchOCPJobs,
quay: fetchQuayJobsData,
telco: fetchTelcoJobsData,
cpt: fetchOCPJobsData,
};
const offsetActions = {
ocp: setOCPOffset,
quay: setQuayOffset,
telco: setTelcoOffset,
cpt: setCPTOffset,
};

export const checkTableData = (newPage, currType) => (dispatch, getState) => {
const { results, totalJobs, perPage, page } = getState()[currType];
const fetchActions = {
ocp: fetchOCPJobs,
quay: fetchQuayJobsData,
telco: fetchTelcoJobsData,
};
const offsetActions = {
ocp: setOCPOffset,
quay: setQuayOffset,
telco: setTelcoOffset,
};

const hasPageData = results.length >= newPage * perPage;
const offset = calculateOffset(newPage, perPage);
if (results.length < totalJobs && !hasPageData) {
if (currType === "cpt") {
const startIdx = (page - 1) * perPage;
const endIdx = startIdx + perPage - 1;

if (currType === "cpt") {
const startIdx = (page - 1) * perPage;
const endIdx = startIdx + perPage - 1;
if (results.length < totalJobs && !hasPageData) {
if (results[startIdx] === undefined || results[endIdx] === undefined) {
dispatch(fetchOCPJobsData());
}
} else {
dispatch(offsetActions[currType](offset));
dispatch(fetchActions[currType]());
}
} else {
if (currType === "cpt") {
const startIdx = (page - 1) * perPage;
const endIdx = startIdx + perPage - 1;
dispatch(sliceCPTTableRows(startIdx, endIdx));
}
} else if (results.length < totalJobs) {
dispatch(offsetActions[currType](offset));
dispatch(fetchActions[currType]());
}
};
4 changes: 4 additions & 0 deletions frontend/src/components/organisms/Pagination/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const RenderPagination = (props) => {
const onPerPageSelect = useCallback(
(_evt, newPerPage, newPage, startIdx, endIdx) => {
dispatch(setPageOptions(newPage, newPerPage, props.type));
dispatch(checkTableData(newPage, props.type));
},
[dispatch, props.type]
);
Expand All @@ -51,8 +52,11 @@ const RenderPagination = (props) => {
perPageOptions={perPageOptions}
onSetPage={onSetPage}
onPerPageSelect={onPerPageSelect}
onPreviousClick={onNextClick}
onNextClick={onNextClick}
onPageInput={onNextClick}
onFirstClick={onNextClick}
onLastClick={onNextClick}
isCompact={props.type === "cpt" ? true : false}
/>
);
Expand Down
1 change: 0 additions & 1 deletion frontend/src/reducers/homeReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const initialState = {
filteredResults: [],
page: START_PAGE,
perPage: DEFAULT_PER_PAGE,
size: DEFAULT_PER_PAGE,
offset: INITAL_OFFSET,
totalJobs: 0,
summary: {},
Expand Down
1 change: 0 additions & 1 deletion frontend/src/reducers/ocpReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const initialState = {
activeSortIndex: null,
page: START_PAGE,
perPage: DEFAULT_PER_PAGE,
size: DEFAULT_PER_PAGE,
offset: INITAL_OFFSET,
totalJobs: 0,
//tableData: [],
Expand Down
1 change: 0 additions & 1 deletion frontend/src/reducers/quayReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const initialState = {
graphData: [],
page: START_PAGE,
perPage: DEFAULT_PER_PAGE,
size: DEFAULT_PER_PAGE,
offset: INITAL_OFFSET,
totalJobs: 0,
summary: {},
Expand Down
1 change: 0 additions & 1 deletion frontend/src/reducers/telcoReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const initialState = {
graphData: [],
page: START_PAGE,
perPage: DEFAULT_PER_PAGE,
size: DEFAULT_PER_PAGE,
offset: INITAL_OFFSET,
totalJobs: 0,
summary: {},
Expand Down