Merged PR 1507: 14769 search by project type

14769 search by project type

Related work items: #14769
This commit is contained in:
Robert Bond
2025-03-21 17:40:49 +00:00
14 changed files with 379 additions and 8 deletions
+16
View File
@@ -646,6 +646,22 @@ export const getAppealsTypes = () => {
});
};
export const getProjectTypes = () => {
return axios
.get(BASE_URL + "/api/endpoint/getprojecttypes_api")
.then((res) => res.data)
.catch((error) => {
consoleLogger(error);
let ErrResponse = {
value: [],
errorCode: error.response.status,
errorMsg: error.response.statusText,
};
return ErrResponse;
});
};
export const getAppealsTypesForNewAppeal = () => {
return axios
.get(BASE_URL + "/api/endpoint/getappealtypesfornewappeal_api")
+1 -1
View File
@@ -14,7 +14,7 @@ export default function Search(props) {
id="main-content"
role="main"
>
<AdvancedSearch myportal={props.myportal || false} />
<AdvancedSearch props={props} myportal={props.myportal || false} />
</main>
);
}
+144 -1
View File
@@ -174,6 +174,16 @@ let AdvancedSearch = (props) => {
? [{}]
: props.appealType.appealTypeOptions.value;
const projecttypeOptionsObj = _.isEmpty(props)
? [{}]
: _.isEmpty(props.appealType)
? [{}]
: _.isEmpty(props.appealType.projectTypeOptions)
? [{}]
: _.isEmpty(props.appealType.projectTypeOptions.value)
? [{}]
: props.appealType.projectTypeOptions.value;
let lpaOptionsObj = _.isEmpty(props)
? [{}]
: _.isEmpty(props.LPAData)
@@ -362,9 +372,117 @@ let AdvancedSearch = (props) => {
</>
);
};
const RenderProjectTypeList = ({
name,
id,
input,
optionsObj,
meta: { touched, error },
label,
errormsg,
}) => {
return (
<>
<div
className={
touched && error
? "govuk-form-group govuk-form-group--error"
: "govuk-form-group "
}
>
<label className="govuk-label" htmlFor={id}>
{label}
{name}
</label>
{touched && error && (
<span
id={name + "-error"}
className="govuk-error-message"
>
<span className="govuk-visually-hidden">
Error:
</span>{" "}
{errormsg}
</span>
)}
<div>
<select
{...input}
className="govuk-select"
id={id}
name={name}
//onChange={(e) => props.onChangeSelectAppealType(e)}
>
<option value="" disabled defaultValue>
{t("common:drop-down-select")}
</option>
{_.isEmpty(optionsObj)
? ""
: Object.keys(optionsObj).map((key, index) => {
return (
<option
key={key}
value={
_.isEmpty(optionsObj[key])
? ""
: _.isEmpty(
optionsObj[key]
)
? ""
: _.isEmpty(
optionsObj[key]
.pinswg_sipsprojecttypeid
)
? ""
: optionsObj[key]
.pinswg_sipsprojecttypeid +
"," +
optionsObj[
key
].pinswg_name
.replace(
/(\band|[\s\-\+\(\)\,\&])/g,
""
)
.toLowerCase()
}
>
{_.isEmpty(optionsObj[key])
? ""
: _.isEmpty(optionsObj[key])
? ""
: _.isEmpty(
optionsObj[key]
.pinswg_name
)
? ""
: router.locale == "cy"
? jsonpath(
'$..[?(@.value=="' +
optionsObj[key]
.pinswg_name +
'")].value_cy',
transLookup
)
: optionsObj[key]
.pinswg_name ||
t(
"case:summary-no-date-entered-label"
)}
</option>
);
})}
</select>
</div>
</div>
</>
);
};
//const [showSpinnerState, setShowSpinnerState] = useState(false);
const selectAppealTypesValue = props.formValues?.appealTypes || "";
// let spinnerState = () => {
// showSpinnerState == true
// ? setShowSpinnerState(false)
@@ -390,7 +508,12 @@ let AdvancedSearch = (props) => {
searchString +=
values.statusCode != null
? "statuscode=" + values.statusCode + "&"
? "statuscode=" + values.projecttype + "&"
: "";
searchString +=
values.projecttype != null
? "projecttype=" + values.projecttype.split(",")[0] + "&"
: "";
searchString = "?" + searchString.slice(0, -1);
@@ -457,6 +580,26 @@ let AdvancedSearch = (props) => {
label={t("search:appealtype-label")}
errormsg="Appeal type is required"
/>
{props.props?.props.form[
props.form
]?.values?.appealTypes.split(",")[0] ===
"846040002" && (
<Field
name="projecttype"
id="projecttype"
component={
RenderProjectTypeList
}
optionsObj={
projecttypeOptionsObj
}
// validate={[required]}
label={t(
"search:project-type-label"
)}
errormsg="Project type is required"
/>
)}
<Field
name="lpaTypes"
id="lpaTypes"
+12
View File
@@ -317,6 +317,18 @@ const SearchResults = (props) => {
</span>
{item.title}
</Link>
{detailsObj.hasOwnProperty(
"_pinswg_projecttype_value@OData.Community.Display.V1.FormattedValue"
) && (
<div className="govuk-!-font-size-14">
{
detailsObj[
"_pinswg_projecttype_value@OData.Community.Display.V1.FormattedValue"
]
}
</div>
)}
<RepsOnResults
detailsObj={detailsObj}
/>
+1
View File
@@ -43,6 +43,7 @@
"norecords-awaiting-submissions": "Nid oes gennych unrhyw gyflwyniadau sy'n aros",
"on-behalf-of-label": "Ar ran",
"appeal-type-label": "Math o apêl",
"project-type-label": "Math o brosiect",
"lpa-reference-label": "Cyfeirnod yr ACLl",
"raised-by-label": "Codwyd gan",
"representation-id": "Cyfeirnod y sylw",
+1
View File
@@ -10,6 +10,7 @@
"lpa-label": "Awdurdod Cynllunio Lleol",
"lpa-reference-label": "Cyfeirnod yr Awdurdod Cynllunio Lleol",
"appealtype-label": "Dewiswch fath o achos",
"project-type-label": "Math o brosiect",
"case-status-label": "Statws yr Achos",
"case-type-label": "Math o Achos",
"case-type-option-1": "--Dewiswch--",
+1
View File
@@ -43,6 +43,7 @@
"norecords-awaiting-submissions": "You have no awaiting submissions",
"on-behalf-of-label": "On behalf of",
"appeal-type-label": "Appeal type",
"project-type-label": "Project type",
"lpa-reference-label": "LPA reference",
"raised-by-label": "Raised by",
"representation-id": "Representation ID",
+1
View File
@@ -10,6 +10,7 @@
"lpa-label": "Local Planning Authority",
"lpa-reference-label": "LPA reference",
"appealtype-label": "Select a case type",
"project-type-label": "Project type",
"case-status-label": "Case Status",
"case-type-label": "Case type",
"case-type-option-1": "-- Select --",
+7 -4
View File
@@ -3,14 +3,14 @@ import useTranslation from "next-translate/useTranslation";
import Head from "next/head";
import { useRouter } from "next/router";
import { connect } from "react-redux";
import { getAppealsTypes, getLPA } from "../actions";
import { getAppealsTypes, getProjectTypes, getLPA } from "../actions";
import Breadcrumbs from "../components/breadcrumbs";
import CookieBanner from "../components/cookieBanner";
import CRMError from "../components/crmError";
import Footer from "../components/footer";
import Header from "../components/header";
import Search from "../components/search";
import { setAppealType } from "../store/appealType/action";
import { setAppealType, setProjectType } from "../store/appealType/action";
import { setLPA } from "../store/lpa/action";
import { wrapper } from "../store/store";
import ServiceBanner from "../components/servicebanner";
@@ -110,6 +110,7 @@ const Home = (props) => {
<Search
lpadata={props.LPAData}
appealType={props.appealType}
props={props}
/>
)}
</div>
@@ -122,8 +123,9 @@ const Home = (props) => {
export const getServerSideProps = wrapper.getServerSideProps(
(store) =>
async ({ query, req, res }) => {
let [appealTypeData, lpaData] = await Promise.all([
let [appealTypeData, projectTypeData, lpaData] = await Promise.all([
await getAppealsTypes(),
await getProjectTypes(),
await getLPA(),
]);
@@ -131,6 +133,7 @@ export const getServerSideProps = wrapper.getServerSideProps(
//const appealTypeData = require("../data/appealtypes.json");
store.dispatch(setAppealType(appealTypeData));
store.dispatch(setProjectType(projectTypeData));
store.dispatch(setLPA(lpaData));
}
);
@@ -142,7 +145,7 @@ const mapStateToProps = (state) => {
formData: state.formData,
appealType: state.appealType,
LPAData: state.LPAData,
//form: state.form,
form: state.form,
accountDetails: state.accountDetails,
};
};
+64 -1
View File
@@ -95,11 +95,74 @@ export default async function ApiProxy(req, res) {
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPaged(token.access_token)
)
.then(({ data }) => {
.then(async ({ data }) => {
var dataStr;
_.has(data, "@odata.nextLink") == true &&
((dataStr = JSON.stringify(data["@odata.nextLink"])),
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
if (_.has(searchString, "projecttype")) {
await updateValueArray(data, token);
async function updateValueArray(data, token) {
for (let i = 0; i < data.value.length; i++) {
const item = data.value[i];
try {
// Axios call using the `incidentid` to fetch additional data
const response = await axios.get(
WEBAPI_URL +
"pinswg_sipses?$filter=_pinswg_sipscase_value eq " +
item.incidentid +
" and _pinswg_projecttype_value eq " +
searchString.projecttype +
"&$select=_pinswg_projecttype_value" +
hashAPIPath(
"pinswg_sipses?$filter=_pinswg_sipscase_value eq " +
item.incidentid +
" and _pinswg_projecttype_value eq " +
searchString.projecttype +
"&$select=_pinswg_projecttype_value"
),
azureHeadersPaged(token.access_token)
);
// Assuming the response contains the additional data you want to add
// console.log(response.data.value[0]);
console.log(response.data.value);
if (
response.data.value.length > 0 &&
response.data.value[0]
._pinswg_projecttype_value != null
) {
Object.assign(
item,
response.data.value[0]
); // Update item with new data
} else {
console.log(
`No project type found for incident ID ${item.incidentid}`
);
}
} catch (error) {
console.error(
`Error fetching data for incident ID ${item.incidentid}:`,
error
);
}
}
}
data.value = data.value.filter(
(item) => item._pinswg_projecttype_value != null
);
data["@odata.count"] = data.value.length;
// console.log(newDataObj);
}
res.status(200).json(data);
})
.catch((error) => {
@@ -52,6 +52,7 @@ import CryptoJS from "crypto-js";
import _ from "lodash";
import {
azureHeadersPagedCustom,
azureHeadersPaged,
consoleLogger,
getToken,
} from "../../../actions";
@@ -138,11 +139,72 @@ export default async function ApiProxy(req, res) {
showNumberOfRecords
)
)
.then(({ data }) => {
.then(async ({ data }) => {
var dataStr;
_.has(data, "@odata.nextLink") == true &&
((dataStr = JSON.stringify(data["@odata.nextLink"])),
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
if (_.has(searchString, "projecttype")) {
await updateValueArray(data, token);
async function updateValueArray(data, token) {
for (let i = 0; i < data.value.length; i++) {
const item = data.value[i];
try {
// Axios call using the `incidentid` to fetch additional data
const response = await axios.get(
WEBAPI_URL +
"pinswg_sipses?$filter=_pinswg_sipscase_value eq " +
item.incidentid +
" and _pinswg_projecttype_value eq " +
searchString.projecttype +
"&$select=_pinswg_projecttype_value" +
hashAPIPath(
"pinswg_sipses?$filter=_pinswg_sipscase_value eq " +
item.incidentid +
" and _pinswg_projecttype_value eq " +
searchString.projecttype +
"&$select=_pinswg_projecttype_value"
),
azureHeadersPaged(token.access_token)
);
// Assuming the response contains the additional data you want to add
// console.log(response.data.value[0]);
console.log(response.data.value);
if (
response.data.value.length > 0 &&
response.data.value[0]
._pinswg_projecttype_value != null
) {
Object.assign(
item,
response.data.value[0]
); // Update item with new data
} else {
console.log(
`No project type found for incident ID ${item.incidentid}`
);
}
} catch (error) {
console.error(
`Error fetching data for incident ID ${item.incidentid}:`,
error
);
}
}
}
data.value = data.value.filter(
(item) => item._pinswg_projecttype_value != null
);
data["@odata.count"] = data.value.length;
}
res.status(200).json(data);
})
.catch((error) => {
+54
View File
@@ -0,0 +1,54 @@
/**
* @swagger
* /api/endpoint/getappealtypes_api:
* get:
* tags: [Misc]
* description: Get Appeal Types
* responses:
* 200:
* description: Success
*/
import axios from "axios";
import CryptoJS from "crypto-js";
import { azureHeaders, consoleLogger, getToken } 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 token = await getToken();
var queryUrl =
"pinswg_sipsprojecttypes?$select=pinswg_name,pinswg_sector,pinswg_sipsprojecttypeid&$orderby=pinswg_name asc&$count=true";
//console.log(queryUrl);
return axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token)
)
.then(({ data }) => {
res.status(200).json(data);
})
.catch((error) => {
consoleLogger(error);
res.status(400).json(error);
});
}
+8
View File
@@ -12,6 +12,7 @@ export const appealTypeDataActionTypes = {
SETFILELIST: "SETFILELIST",
SETNEWAPPEALPROGRESS: "SETNEWAPPEALPROGRESS",
SETFILECOUNT: "SETFILECOUNT",
SETPROJECTTYPEDATA: "SETPROJECTTYPEDATA",
};
export const getAppealTypeObj = () => (dispatch) => {
@@ -27,6 +28,13 @@ export const setAppealType = (appealTypeData) => (dispatch) => {
});
};
export const setProjectType = (projectTypeData) => (dispatch) => {
return dispatch({
type: appealTypeDataActionTypes.SETPROJECTTYPEDATA,
projectTypeOptions: projectTypeData,
});
};
export const setAppealTypeTitle = (appealTypeData) => (dispatch) => {
return dispatch({
type: appealTypeDataActionTypes.SETAPPEALTYPETITLEDATA,
+6
View File
@@ -2,6 +2,7 @@ import { appealTypeDataActionTypes } from "./action";
const appealTypeDataInitialState = {
appealTypeOptions: {},
projectTypeOptions: {},
appealTypeTitle: {},
appealTypeID: {},
currentSection: 1,
@@ -21,6 +22,11 @@ export default function reducer(state = appealTypeDataInitialState, action) {
...state,
appealTypeOptions: action.appealTypeOptions,
};
case appealTypeDataActionTypes.SETPROJECTTYPEDATA:
return {
...state,
projectTypeOptions: action.projectTypeOptions,
};
case appealTypeDataActionTypes.SETAPPEALTYPETITLEDATA:
return {
...state,