select number records returned
This commit is contained in:
@@ -45,10 +45,11 @@ const DocumentDetails = (props) => {
|
||||
|
||||
var documentDetailsArr = documentDetailsObj || [];
|
||||
|
||||
const DocumentView = (documentDetailsArr) => {
|
||||
//console.log(documentDetailsArr);
|
||||
const [selectedOption, setSelectedOption] = useState(10);
|
||||
|
||||
const DocumentView = (documentDetailsArr) => {
|
||||
documentDetailsArr = documentDetailsArr.value;
|
||||
|
||||
return (
|
||||
<>
|
||||
<p>
|
||||
@@ -60,13 +61,36 @@ const DocumentDetails = (props) => {
|
||||
? t("case:documents-count-label-2")
|
||||
: t("case:documents-count-label-2a")}
|
||||
</p>
|
||||
<div id="recordCountSelect" className="govuk-grid-row">
|
||||
<div className="govuk-form-group">
|
||||
<label className="govuk-label-s " htmlFor="sort">
|
||||
Show
|
||||
<select
|
||||
onChange={(e) => {
|
||||
setSelectedOption(e.target.value);
|
||||
}}
|
||||
value={selectedOption}
|
||||
className="govuk-select"
|
||||
id="showNumberOfRecords"
|
||||
name="showNumberOfRecords"
|
||||
>
|
||||
<option value="5">5</option>
|
||||
<option value="10">10</option>
|
||||
<option value="20">20</option>
|
||||
<option value="30">30</option>
|
||||
<option value="50">50</option>
|
||||
</select>{" "}
|
||||
records
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<dl className="documentList govuk-summary-list govuk-!-margin-bottom-9 results">
|
||||
<div className="govuk-summary-list__row results-headings">
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16 ">
|
||||
{t("case:documents-name-label")}
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||
{t("case:documents-doc-type-label")}
|
||||
{/* {t("case:documents-doc-type-label")} */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
@@ -85,7 +109,7 @@ const DocumentDetails = (props) => {
|
||||
</button>
|
||||
</dd>
|
||||
<dd className="govuk-summary-list__key govuk-!-font-size-16">
|
||||
{t("case:documents-date-published-label")}
|
||||
{/* {t("case:documents-date-published-label")} */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => sortDataBy("createdon")}
|
||||
@@ -225,6 +249,7 @@ const DocumentDetails = (props) => {
|
||||
)}
|
||||
</dl>
|
||||
<PaginationControl
|
||||
showNoOfRecords={selectedOption}
|
||||
currentPage={currentPage}
|
||||
searchResultsObj={documentDetailsObj}
|
||||
spinnerState={spinnerState}
|
||||
@@ -237,6 +262,11 @@ const DocumentDetails = (props) => {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedOption) {
|
||||
setShowSpinnerState(true);
|
||||
getDocumentResults(1, orderByState, fieldSortState);
|
||||
}
|
||||
|
||||
const docDetailsObj = async () => {
|
||||
let docObj = await getSearchDocumentDetails(incidentid)
|
||||
.then((data) => {
|
||||
@@ -279,14 +309,15 @@ const DocumentDetails = (props) => {
|
||||
return Promise.all(historyArr);
|
||||
};
|
||||
const searchDocumentResultsObj = docDetailsObj();
|
||||
}, [incidentid, setDocumentHistory, setDocumentDetails]);
|
||||
}, [incidentid, setDocumentHistory, setDocumentDetails, selectedOption]);
|
||||
|
||||
const getDocumentResults = (incidentid, pageNumber, orderBy, fieldSort) => {
|
||||
const getDocumentResults = (pageNumber, orderBy, fieldSort) => {
|
||||
getSearchDocumentDetailsPaged(
|
||||
incidentid,
|
||||
props.incidentid,
|
||||
pageNumber,
|
||||
orderBy,
|
||||
fieldSort
|
||||
fieldSort,
|
||||
selectedOption
|
||||
)
|
||||
.then((data) => data)
|
||||
.then((data) => {
|
||||
@@ -395,18 +426,18 @@ const DocumentDetails = (props) => {
|
||||
: setDocumentSearchState(true);
|
||||
};
|
||||
|
||||
// const sortDataBy = (whichField) => {
|
||||
// setOrderbyState(whichField);
|
||||
// setfieldSortState("asc");
|
||||
const sortDataBy = (whichField) => {
|
||||
setOrderbyState(whichField);
|
||||
setfieldSortState("asc");
|
||||
|
||||
// getSearchPageResults(1, whichField, fieldSortState);
|
||||
// whichField == orderByState
|
||||
// ? fieldSortState == "desc"
|
||||
// ? setfieldSortState("asc")
|
||||
// : setfieldSortState("desc")
|
||||
// : setfieldSortState("asc");
|
||||
// setShowSpinnerState(true);
|
||||
// };
|
||||
getDocumentResults(1, whichField, fieldSortState);
|
||||
whichField == orderByState
|
||||
? fieldSortState == "desc"
|
||||
? setfieldSortState("asc")
|
||||
: setfieldSortState("desc")
|
||||
: setfieldSortState("asc");
|
||||
setShowSpinnerState(true);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -4,6 +4,7 @@ import useTranslation from "next-translate/useTranslation";
|
||||
|
||||
const PaginationControl = (props) => {
|
||||
const {
|
||||
showNoOfRecords,
|
||||
orderBy,
|
||||
fieldSort,
|
||||
searchString,
|
||||
@@ -17,7 +18,9 @@ const PaginationControl = (props) => {
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
|
||||
const pagesCount = Math.ceil(searchResultsObj["@odata.count"] / 10);
|
||||
const pagesCount = Math.ceil(
|
||||
searchResultsObj["@odata.count"] / showNoOfRecords
|
||||
);
|
||||
|
||||
const getRange = (start, end) => {
|
||||
//console.log(start, end);
|
||||
@@ -29,9 +32,9 @@ const PaginationControl = (props) => {
|
||||
const paginationNumbers = (currentPage, pageCount) => {
|
||||
//console.log(currentPage);
|
||||
let delta;
|
||||
if (pageCount <= 10) {
|
||||
if (pageCount <= showNoOfRecords) {
|
||||
// delta === 7: [1 2 3 4 5 6 7]
|
||||
delta = 10;
|
||||
delta = showNoOfRecords;
|
||||
} else {
|
||||
// delta === 2: [1 ... 4 5 6 ... 10]
|
||||
// delta === 4: [1 2 3 4 5 ... 10]
|
||||
|
||||
@@ -154,7 +154,7 @@ export default function Footer(props) {
|
||||
"common:footer-contact-us-link"
|
||||
)}
|
||||
className="govuk-footer__link"
|
||||
id="aAccess"
|
||||
id="aContactUs"
|
||||
>
|
||||
{t(
|
||||
"common:footer-contact-us-link-label"
|
||||
@@ -176,7 +176,7 @@ export default function Footer(props) {
|
||||
>
|
||||
<a
|
||||
className="govuk-footer__link"
|
||||
id="aAccess"
|
||||
id="aAccessibility"
|
||||
>
|
||||
{t(
|
||||
"common:footer-accessibility-link-label"
|
||||
|
||||
@@ -7,7 +7,7 @@ import jsonpath from "jsonpath";
|
||||
import _ from "lodash";
|
||||
import transLookup from "../../data/lookuptranslations.json";
|
||||
import PaginationControl from "./pagination";
|
||||
import { useState } from "react";
|
||||
import { useState, useEffect } from "react";
|
||||
import LoadingOverlay from "react-loading-overlay";
|
||||
import {
|
||||
getBasicDNSSearchPaged,
|
||||
@@ -48,6 +48,7 @@ const DNSSearchResults = (props) => {
|
||||
|
||||
const [orderByState, setOrderbyState] = useState("createdon");
|
||||
const [fieldSortState, setfieldSortState] = useState("asc");
|
||||
const [selectedOption, setSelectedOption] = useState(10);
|
||||
|
||||
const ResultsView = (resultsArr) => {
|
||||
return (
|
||||
@@ -273,6 +274,7 @@ const DNSSearchResults = (props) => {
|
||||
)}
|
||||
</dl>
|
||||
<PaginationControl
|
||||
showNoOfRecords={selectedOption}
|
||||
currentPage={currentPage}
|
||||
searchResultsObj={searchResultsObj}
|
||||
orderBy={orderByState}
|
||||
@@ -335,6 +337,12 @@ const DNSSearchResults = (props) => {
|
||||
setShowSpinnerState(true);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedOption) {
|
||||
setShowSpinnerState(true);
|
||||
getSearchPageResults(1, orderByState, fieldSortState);
|
||||
}
|
||||
}, [selectedOption]);
|
||||
return (
|
||||
<>
|
||||
<div className="govuk-grid-row">
|
||||
@@ -354,6 +362,29 @@ const DNSSearchResults = (props) => {
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div id="recordCountSelect" className="govuk-grid-row">
|
||||
<div className="govuk-form-group">
|
||||
<label className="govuk-label-s " htmlFor="sort">
|
||||
{t("search:searchresults-show-records-label-a")}
|
||||
<select
|
||||
onChange={(e) => {
|
||||
setSelectedOption(e.target.value);
|
||||
}}
|
||||
value={selectedOption}
|
||||
className="govuk-select"
|
||||
id="showNumberOfRecords"
|
||||
name="showNumberOfRecords"
|
||||
>
|
||||
<option value="5">5</option>
|
||||
<option value="10">10</option>
|
||||
<option value="20">20</option>
|
||||
<option value="30">30</option>
|
||||
<option value="50">50</option>
|
||||
</select>{" "}
|
||||
{t("search:searchresults-show-records-label-b")}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{resultsArr.length > 0 ? (
|
||||
ResultsView(resultsArr)
|
||||
) : (
|
||||
|
||||
@@ -4,6 +4,7 @@ import useTranslation from "next-translate/useTranslation";
|
||||
|
||||
const PaginationControl = (props) => {
|
||||
const {
|
||||
showNoOfRecords,
|
||||
orderBy,
|
||||
fieldSort,
|
||||
searchString,
|
||||
@@ -17,7 +18,9 @@ const PaginationControl = (props) => {
|
||||
const router = useRouter();
|
||||
const { locale } = router;
|
||||
|
||||
const pagesCount = Math.ceil(searchResultsObj["@odata.count"] / 10);
|
||||
const pagesCount = Math.ceil(
|
||||
searchResultsObj["@odata.count"] / showNoOfRecords
|
||||
);
|
||||
|
||||
const getRange = (start, end) => {
|
||||
//console.log(start, end);
|
||||
@@ -29,9 +32,9 @@ const PaginationControl = (props) => {
|
||||
const paginationNumbers = (currentPage, pageCount) => {
|
||||
//console.log(currentPage);
|
||||
let delta;
|
||||
if (pageCount <= 10) {
|
||||
if (pageCount <= showNoOfRecords) {
|
||||
// delta === 7: [1 2 3 4 5 6 7]
|
||||
delta = 10;
|
||||
delta = showNoOfRecords;
|
||||
} else {
|
||||
// delta === 2: [1 ... 4 5 6 ... 10]
|
||||
// delta === 4: [1 2 3 4 5 ... 10]
|
||||
|
||||
@@ -67,6 +67,7 @@ const SearchResults = (props) => {
|
||||
var resultsArr = searchResultsObj.value || [];
|
||||
|
||||
const [showSpinnerState, setShowSpinnerState] = useState(false);
|
||||
const [selectedOption, setSelectedOption] = useState(10);
|
||||
|
||||
let spinnerState = () => {
|
||||
showSpinnerState == true
|
||||
@@ -494,6 +495,7 @@ const SearchResults = (props) => {
|
||||
</dl>
|
||||
|
||||
<PaginationControl
|
||||
showNoOfRecords={selectedOption}
|
||||
currentPage={currentPage}
|
||||
searchResultsObj={searchResultsObj}
|
||||
orderBy={orderByState}
|
||||
@@ -534,7 +536,13 @@ const SearchResults = (props) => {
|
||||
...searchString.map(([key, val]) => ({ [key]: val }))
|
||||
);
|
||||
|
||||
getAdvancedSearchPaged(searchoObj, pageNumber, orderBy, fieldSort)
|
||||
getAdvancedSearchPaged(
|
||||
searchoObj,
|
||||
pageNumber,
|
||||
orderBy,
|
||||
fieldSort,
|
||||
selectedOption
|
||||
)
|
||||
.then((data) => data)
|
||||
.then((data) => {
|
||||
//console.log("getting details", data);
|
||||
@@ -545,7 +553,13 @@ const SearchResults = (props) => {
|
||||
});
|
||||
});
|
||||
} else {
|
||||
getBasicSearchPaged(searchString, pageNumber, orderBy, fieldSort)
|
||||
getBasicSearchPaged(
|
||||
searchString,
|
||||
pageNumber,
|
||||
orderBy,
|
||||
fieldSort,
|
||||
selectedOption
|
||||
)
|
||||
.then((data) => data)
|
||||
.then((data) => {
|
||||
//console.log("getting details", data);
|
||||
@@ -571,6 +585,12 @@ const SearchResults = (props) => {
|
||||
setShowSpinnerState(true);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (selectedOption) {
|
||||
setShowSpinnerState(true);
|
||||
getSearchPageResults(1, orderByState, fieldSortState);
|
||||
}
|
||||
}, [selectedOption]);
|
||||
// console.log(
|
||||
// "page is here ",
|
||||
// currentPage,
|
||||
@@ -610,6 +630,29 @@ const SearchResults = (props) => {
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
<div id="recordCountSelect" className="govuk-grid-row">
|
||||
<div className="govuk-form-group">
|
||||
<label className="govuk-label-s " htmlFor="sort">
|
||||
{t("search:searchresults-show-records-label-a")}
|
||||
<select
|
||||
onChange={(e) => {
|
||||
setSelectedOption(e.target.value);
|
||||
}}
|
||||
value={selectedOption}
|
||||
className="govuk-select"
|
||||
id="showNumberOfRecords"
|
||||
name="showNumberOfRecords"
|
||||
>
|
||||
<option value="5">5</option>
|
||||
<option value="10">10</option>
|
||||
<option value="20">20</option>
|
||||
<option value="30">30</option>
|
||||
<option value="50">50</option>
|
||||
</select>{" "}
|
||||
{t("search:searchresults-show-records-label-b")}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
{resultsArr.length > 0 ? (
|
||||
ResultsView(resultsArr)
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user