Merged PR 822: Pagination fix and DNS url redirects

Related work items: #7514
This commit is contained in:
Robert Bond
2022-02-25 08:53:22 +00:00
12 changed files with 354 additions and 39 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ RELAYPATH = "prod-pedw-hc"
GOOGLE_TAG_MANAGER = GTM-T78CBC3
SHOWLOGIN = "true"
SHOWREPRESENTATIONS = "false"
SHOWREPRESENTATIONS = false
//BASIC_AUTH_CREDENTIALS = pinswg:password|pinswg2:password2
+16
View File
@@ -145,6 +145,22 @@ export const getBasicSearch = (searchString) => {
});
};
export const getBasicDNSURLSearch = (searchString) => {
return axios
.get(
BASE_URL +
"/api/endpoint/getbasicdnsurlsearch_api?searchString=" +
searchString
)
.then((res) => {
return res.data;
})
.catch((error) => {
console.log(error);
return error.response;
});
};
export const getBasicSearchPaged = (
searchString,
pageNumber,
+31 -12
View File
@@ -64,17 +64,9 @@ const Breadcrumbs = (props) => {
</Link>
</li> */}
<li className="govuk-breadcrumbs__list-item">
<Link
href={
router.pathname.includes("/dns/")
? "/dns"
: "/"
}
>
<Link href={"/"}>
<a className="govuk-breadcrumbs__link">
{router.pathname.includes("/dns/")
? t("dnsCommon:service-name")
: t("common:service-name-breadcrumb")}
{t("common:service-name-breadcrumb")}
</a>
</Link>
</li>
@@ -493,6 +485,33 @@ const Breadcrumbs = (props) => {
) : (
""
)}
{router.pathname == "/dns/[developmentName]" ? (
<>
<li className="govuk-breadcrumbs__list-item">
<Link
href={
router.locale == "en"
? router.locale +
"/../../dnsapplications"
: "/../../dnsapplications"
}
>
<a className="govuk-breadcrumbs__link">
{t("dnsCommon:service-name")}
</a>
</Link>
</li>
<li className="govuk-breadcrumbs__list-item">
{t("common:breadcrumb-case-reference")}:{" "}
{
props.props.currentView.caseReference
.currentReference
}
</li>
</>
) : (
""
)}
{router.pathname == "/dnsapplications" ? (
<>
<li className="govuk-breadcrumbs__list-item">
@@ -628,7 +647,7 @@ const Breadcrumbs = (props) => {
) : (
""
)}
{!_.isEmpty(slug) ? (
{/* {!_.isEmpty(slug) ? (
<>
<li className="govuk-breadcrumbs__list-item">
<Link
@@ -662,7 +681,7 @@ const Breadcrumbs = (props) => {
</>
) : (
""
)}
)} */}
<Breadcrumb />
</ol>
+8 -5
View File
@@ -36,6 +36,7 @@ const PaginationControl = (props) => {
const paginationNumbers = (currentPage, pageCount) => {
//console.log(currentPage);
let delta;
if (pageCount <= 7) {
// delta === 7: [1 2 3 4 5 6 7]
delta = 7;
@@ -43,7 +44,7 @@ const PaginationControl = (props) => {
// delta === 2: [1 ... 4 5 6 ... 10]
// delta === 4: [1 2 3 4 5 ... 10]
//delta = currentPage > 4 && currentPage < pageCount - 3 ? 4 : 4;
delta = currentPage > 4 && currentPage < pageCount - 3 ? 2 : 4;
delta = currentPage > 4 && currentPage < pageCount - 3 ? 4 : 4;
}
const range = {
@@ -79,15 +80,17 @@ const PaginationControl = (props) => {
return pages;
};
const paginationArray = paginationNumbers(currentPage, pagesCount);
const paginationArray = paginationNumbers(
props.currentView.currentPage,
pagesCount
);
return (
<>
{pagesCount > 1 && (
<div className="govuk-!-margin-bottom-7 ">
<div className="govuk-grid-row paginationWrapper">
<div className="govuk-grid-column-one-quarter paginationPrevious">
{currentPage != 1 ? (
{props.currentView.currentPage != 1 ? (
<span
className="govuk-body govuk-link govuk-!-font-weight-bold govuk-link--no-underline activePaginationItem leftTextButton"
onClick={() => {
@@ -114,7 +117,7 @@ const PaginationControl = (props) => {
</div>
<div className="govuk-grid-column-one-half paginationContainer">
{paginationArray.map((e, i) =>
props.currentView.currentPage == i + 1 ? (
props.currentView.currentPage == e ? (
<span
key={i}
className=" govuk-body govuk-!-padding-2 govuk-!-font-weight-bold "
+5 -1
View File
@@ -63,7 +63,11 @@ const CaseSummary = (props) => {
setCurrentReference,
} = props;
const noRepresentationLink = ["/case", "/dnsdetails"];
const noRepresentationLink = [
"/case",
"/dnsdetails",
"/dns/[developmentName]",
];
let setCaseQueryObj = props[currentType];
let setCaseDetailsObj = props[currentType + "Details"];
+6 -3
View File
@@ -34,6 +34,7 @@ const PaginationControl = (props) => {
};
const paginationNumbers = (currentPage, pageCount) => {
//console.log(currentPage);
let delta;
if (pageCount <= 7) {
@@ -43,7 +44,7 @@ const PaginationControl = (props) => {
// delta === 2: [1 ... 4 5 6 ... 10]
// delta === 4: [1 2 3 4 5 ... 10]
//delta = currentPage > 4 && currentPage < pageCount - 3 ? 4 : 4;
delta = currentPage > 4 && currentPage < pageCount - 3 ? 2 : 4;
delta = currentPage > 4 && currentPage < pageCount - 3 ? 4 : 4;
}
const range = {
@@ -79,10 +80,12 @@ const PaginationControl = (props) => {
return pages;
};
const paginationArray = paginationNumbers(currentPage, pagesCount);
const paginationArray = paginationNumbers(
props.currentView.currentPage,
pagesCount
);
return (
<>
{" "}
{pagesCount > 1 && (
<div className="govuk-!-margin-bottom-7 ">
<div className="govuk-grid-row paginationWrapper">
+2 -1
View File
@@ -27,7 +27,8 @@ module.exports = {
"/newappeal": ["newappeal"],
"/newappeal/*": ["newappeal"],
"/newappeal/selectappeal": ["newappeal"],
"/dns/*": ["dnsCommon"],
"/dns/*": ["dnsCommon", "case", "common"],
"/dns/[developmentName]": ["dnsCommon", "case", "common"],
"/dns": ["dnsCommon", "dnsHome"],
"/dns/applications": ["dnsCommon", "dnsApplications"],
"/dns/application-view": ["dnsCommon", "dnsApplicationView"],
@@ -0,0 +1,58 @@
import axios from "axios";
import CryptoJS from "crypto-js";
import _ from "lodash";
import { getToken, azureHeadersPaged } from "../../../actions";
const WORDKEY = process.env.HASHKEY;
const WEBAPI_URL =
process.env.RELAY_ROOT ||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
const hashAPIPath = (queryPath) => {
var hashlink = CryptoJS.HmacSHA256(
queryPath,
CryptoJS.enc.Hex.parse(WORDKEY)
);
hashlink = hashlink.toString(CryptoJS.enc.Hex);
//return "&hash=" + hashlink;
return (queryPath.indexOf("?") > -1 ? "&hash=" : "?hash=") + hashlink;
};
export default async function ApiProxy(req, res) {
var searchString = req.query.searchString;
var token = await getToken();
var queryUrl =
"incidents?$select=description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value&$expand=primarycontactid($select=fullname)&$filter=(contains(title, '" +
searchString +
"') or contains(ticketnumber, '" +
searchString +
"')) and pinswg_appealcasetype eq 846040011 and pinswg_publishtoweb eq true&$orderby=createdon desc&$count=true";
// console.log("basic search ", queryUrl);
var apiResponse = _.isEmpty(req.query)
? res.status(400).json()
: searchString.length > 0
? axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPaged(token.access_token)
)
.then(({ data }) => {
var dataStr;
_.has(data, "@odata.nextLink") == true &&
((dataStr = JSON.stringify(data["@odata.nextLink"])),
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
res.status(200).json(data);
})
.catch(({ err }) => {
res.status(400).json(err);
})
: res.status(400).json();
return apiResponse;
}
+45
View File
@@ -0,0 +1,45 @@
// 404.js
import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import Link from "next/link";
import CookieBanner from "../components/cookieBanner";
import Footer from "../components/footer";
import Header from "../components/header";
const FourOhFour = (props) => {
let { t, lang } = useTranslation();
const { footerLinks, pages } = props;
return (
<div>
<Head>
<title>
{t("common:404-not-found-title")} -{" "}
{t("common:service-name")}
</title>
</Head>
<div id="page_wrapper">
<CookieBanner />
<Header courseName={t("common:service-name")} />
<div className="govuk-width-container govuk-!-padding-bottom-9">
<main className="govuk-main-wrapper govuk-!-padding-top-9 govuk-!-padding-bottom-9">
<div className="govuk-grid-row">
<div className="govuk-grid-column-full ">
<h1>
Development of National Signifcance not
found
</h1>
<Link href="/">
<a>{t("common:404-not-found-link")}</a>
</Link>
</div>
</div>
</main>
</div>
<Footer footerLinks={footerLinks} />
</div>
</div>
);
};
export default FourOhFour;
+174
View File
@@ -0,0 +1,174 @@
import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import { getBasicDNSURLSearch } from "../../actions";
import CookieBanner from "../../components/cookieBanner";
import Footer from "../../components/footer";
import Header from "../../components/header";
import { getSearchDetails } from "../../components/utils";
import { setCurrentReference } from "../../store/currentView/action";
import { setSearch } from "../../store/search/action";
import {
setSearchDetails,
setSearchResults,
} from "../../store/searchOutput/action";
import { wrapper } from "../../store/store";
import Case from "../../components/case";
import Breadcrumbs from "../../components/breadcrumbs";
const CaseHome = (props) => {
const { footerLinks, pages } = props;
let { t, lang } = useTranslation();
const router = useRouter();
const { locale } = router;
const { developmentName } = router.query;
return (
<div>
<Head>
<title>
Reference:{" "}
{props.currentView.caseReference.currentReference}{" "}
Developments of National Significance
</title>
</Head>
<div id="page_wrapper">
<CookieBanner />
<Header serviceName="Developments of National Significance" />
<div className="govuk-width-container">
<Breadcrumbs slug={developmentName} props={props} />
<Case
props={props}
myCases={props.myCases.myCases}
myCasesDetails={props.myCases.myCasesDetails}
searchResultsObj={
props.searchResultsObj.searchResultsObj
}
searchDetailsObj={
props.searchResultsObj.searchDetailsObj
}
documentDetailsObj={
props.searchResultsObj.documentDetailsObj
}
documentHistoryObj={
props.searchResultsObj.documentHistoryObj
}
myRepresentations={
props.myRepresentations.myRepresentations
}
watchedCases={props.watchedCases.watchedCases}
watchedCasesDetails={
props.watchedCases.watchedCasesDetails
}
awaitingSubmission={
props.awaitingSubmission.awaitingSubmission
}
caseReference={
props.currentView.caseReference.currentReference
}
currentType={
props.currentView.caseReference.currentType
}
appealTypeID={
props.currentView.caseReference.appealType
}
incidentid={props.currentView.caseReference.incidentid}
representationsObj={
props.searchResultsObj.representationsObj
}
/>
</div>
<Footer footerLinks={footerLinks} />
</div>
</div>
);
};
export const getServerSideProps = wrapper.getServerSideProps(
(store) => async (ctx) => {
const { query, req, res } = ctx;
const { cookies } = req;
console.log(cookies);
console.log("the query", query.developmentName);
let loggedInUser = cookies.pinsUser;
let developmentQuery = query.developmentName.split("-").join(" ");
const searchResultsObj = await getBasicDNSURLSearch(developmentQuery);
const searchDetailsObj = await getSearchDetails(searchResultsObj);
store.dispatch(setSearchResults(searchResultsObj));
store.dispatch(setSearchDetails(searchDetailsObj));
store.dispatch(setSearch(developmentQuery));
// console.log({
// "currentReference": searchResultsObj.value[0].title,
// "currentType": "searchResultsObj",
// "incidentid": searchResultsObj.value[0].incidentid,
// "appealType": searchResultsObj.value[0].pinswg_appealcasetype,
// });
console.log(
searchResultsObj["@odata.count"] > 1 ||
searchResultsObj["@odata.count"] < 1
);
if (searchResultsObj["@odata.count"] < 1) {
return {
redirect: {
destination: "/404",
permanent: false,
},
};
} else {
if (searchResultsObj["@odata.count"] > 1) {
return {
redirect: {
//destination: "/dns-not-found",
destination: "/404",
permanent: false,
},
};
} else {
store.dispatch(
setCurrentReference({
"currentReference": searchResultsObj.value[0].title,
"currentType": "searchResultsObj",
"incidentid": searchResultsObj.value[0].incidentid,
"appealType":
searchResultsObj.value[0].pinswg_appealcasetype,
})
);
}
}
// console.log(searchResultsObj);
}
);
const mapStateToProps = (state) => {
return {
currentView: state.currentView,
search: state.search,
searchResultsObj: state.searchResultsObj,
formData: state.formData,
appealType: state.appealType,
form: state.form,
myCases: state.myCases,
watchedCases: state.watchedCases,
myRepresentations: state.myRepresentations,
awaitingSubmission: state.awaitingSubmission,
};
};
const mapDispatchToProps = (dispatch) => {
return {
setCurrentReference: (currentReference) => {
dispatch(setCurrentReference(refno));
},
};
};
export default connect(mapStateToProps, mapDispatchToProps)(CaseHome);
+5 -13
View File
@@ -1,18 +1,10 @@
import _ from "lodash";
import Head from "next/head";
import Header from "../../components/header";
import Banner from "../../components/banner";
import CookieBanner from "../../components/cookieBanner";
import Breadcrumbs from "../../components/breadcrumbs";
import Footer from "../../components/footer";
import Errorpage from "../../components/errorpage";
import styles from "../../styles/Home.module.css";
import { useSelector, shallowEqual, connect } from "react-redux";
import { wrapper } from "../../store/store";
import { useRouter } from "next/router";
import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { useRouter } from "next/router";
import CookieBanner from "../../components/cookieBanner";
import Main from "../../components/dns//main";
import Footer from "../../components/footer";
import Header from "../../components/header";
const Home = (props) => {
const { footerLinks, pages } = props;
+3 -3
View File
@@ -108,9 +108,9 @@ const makeStore = ({ isServer }) => {
const persistConfig = {
key: "acp",
whitelist: [
"currentView",
"search",
"searchResultsObj",
// "currentView",
// "search",
// "searchResultsObj",
"formData",
"appealType",
"LPAData",