refactor of code

This commit is contained in:
2025-01-03 08:04:42 +00:00
parent b79e21c419
commit 223c35e426
+46 -19
View File
@@ -261,24 +261,11 @@ const ViewAllResults = (props) => {
</Link>
)}
</dd>
<dd className="govuk-summary-list__value govuk-!-font-size-16">
{/* <dd className="govuk-summary-list__value govuk-!-font-size-16">
<span className="results-visually-hidden">
{t("search:searchresults-site-address-label")}:
</span>
{/* {getFormCollectionByID(appealTypeID).PrimaryIdAttribute ==
"pinswg_dnsid"
? detailsObj.pinswg_projectlocation != null
? detailsObj.pinswg_projectlocation.indexOf(";") < 0
? detailsObj.pinswg_projectlocation
: router.locale == "cy"
? detailsObj.pinswg_projectlocation.split(
";"
)[1]
: detailsObj.pinswg_projectlocation.split(
";"
)[0]
: ""
: ""} */}
{currentView.viewKey == "awaitingSubmissionDetails" &&
_.has(searchDetailsObj[key], "pinswg_siteaddressline1")
? searchDetailsObj[key].pinswg_siteaddressline1
@@ -329,14 +316,12 @@ const ViewAllResults = (props) => {
) &&
searchDetailsObj[key].pinswg_siteaddressline2 !=
null && <br />}
{currentView.viewKey == "myRepresentations" &&
_.has(
searchDetailsObj[key].pinswg_siteaddressline2
) &&
searchDetailsObj[key].pinswg_siteaddressline1 !=
null && <br />}
{_.has(detailsObj, "pinswg_siteaddressline2") &&
detailsObj.pinswg_siteaddressline2 != null && (
<br />
@@ -359,7 +344,6 @@ const ViewAllResults = (props) => {
) &&
searchDetailsObj[key].pinswg_siteaddresstown !=
null && <br />}
{currentView.viewKey == "myRepresentations" &&
_.has(
searchDetailsObj[key],
@@ -367,7 +351,6 @@ const ViewAllResults = (props) => {
) &&
searchDetailsObj[key].pinswg_siteaddresstown !=
null && <br />}
{_.has(detailsObj, "pinswg_siteaddresstown") &&
detailsObj.pinswg_siteaddresstown != null && <br />}
{currentView.viewKey == "awaitingSubmissionDetails" &&
@@ -402,7 +385,51 @@ const ViewAllResults = (props) => {
{_.has(detailsObj, "pinswg_siteaddresspostcode")
? detailsObj.pinswg_siteaddresspostcode
: ""}
</dd> */}
<dd className="govuk-summary-list__value govuk-!-font-size-16">
<span className="results-visually-hidden">
{t("search:searchresults-site-address-label")}:
</span>
{/* Helper function to extract address lines based on current view and data */}
{[
"pinswg_siteaddressline1",
"pinswg_siteaddressline2",
"pinswg_siteaddresstown",
"pinswg_siteaddresscounty",
"pinswg_siteaddresspostcode",
].map((field, idx) => {
const isAwaitingSubmission =
currentView.viewKey ===
"awaitingSubmissionDetails";
const isMyRepresentations =
currentView.viewKey === "myRepresentations";
const searchValue = _.get(
searchDetailsObj,
`${key}.${field}`
);
const detailsValue = _.get(detailsObj, field);
// Determine the display value based on current view
const valueToDisplay =
(isAwaitingSubmission && searchValue) ||
(isMyRepresentations && searchValue) ||
detailsValue ||
"";
// Only render a line break if there is a valid value and it's not the last address part
const renderLineBreak = valueToDisplay && idx < 4; // Only insert <br> if it's not the last element
return (
<>
{valueToDisplay}
{renderLineBreak && <br />}
</>
);
})}
</dd>
<dd className="govuk-summary-list__value govuk-!-font-size-16">
<span className="results-visually-hidden">
{currentView.viewKey == "awaitingSubmissionDetails"