updated the documents query and display
This commit is contained in:
+101
-19
@@ -2,10 +2,28 @@ import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import useTranslation from "next-translate/useTranslation";
|
||||
import jsonpath from "jsonpath";
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { useDispatch, useSelector, shallowEqual, connect } from "react-redux";
|
||||
|
||||
import {
|
||||
getBasicSearch,
|
||||
getBasicSearchDetails,
|
||||
getSearchDocumentDetails1,
|
||||
getSearchDocumentHistory1,
|
||||
getSASToken,
|
||||
} from "../../actions";
|
||||
|
||||
import {
|
||||
setSearchResults,
|
||||
setSearchDetails,
|
||||
setDocumentDetails,
|
||||
setDocumentHistory,
|
||||
getSearchResultsObj,
|
||||
} from "../../store/searchOutput/action";
|
||||
|
||||
const DocumentDetails = (props) => {
|
||||
let { t } = useTranslation();
|
||||
|
||||
const firstRender = useRef(false);
|
||||
const {
|
||||
incidentid,
|
||||
caseReference,
|
||||
@@ -20,10 +38,11 @@ const DocumentDetails = (props) => {
|
||||
|
||||
var documentDetailsArr = documentDetailsObj || [];
|
||||
|
||||
console.log(documentDetailsObj);
|
||||
console.log(documentDetailsArr);
|
||||
|
||||
const DocumentView = (documentDetailsArr) => {
|
||||
console.log(documentDetailsArr);
|
||||
|
||||
documentDetailsArr = documentDetailsArr.value;
|
||||
|
||||
return (
|
||||
<dl className="govuk-summary-list govuk-!-margin-bottom-9 results">
|
||||
<div className="govuk-summary-list__row results-headings">
|
||||
@@ -41,15 +60,14 @@ const DocumentDetails = (props) => {
|
||||
</dd>
|
||||
</div>
|
||||
|
||||
{documentDetailsArr.map((item, key) => {
|
||||
console.log(key);
|
||||
{documentDetailsArr.map((item) => {
|
||||
let detailsObj = jsonpath.query(
|
||||
documentDetailsObj[key],
|
||||
"$..value[?(@._pinswg_documentids_value=='" +
|
||||
item,
|
||||
"$..[?(@._pinswg_documentids_value=='" +
|
||||
incidentid +
|
||||
"')]"
|
||||
);
|
||||
detailsObj = detailsObj[0];
|
||||
detailsObj = item;
|
||||
|
||||
if (typeof detailsObj != "undefined") {
|
||||
var documentHistoryArr = documentHistoryObj || [];
|
||||
@@ -60,7 +78,9 @@ const DocumentDetails = (props) => {
|
||||
detailsObj.pinswg_documentid +
|
||||
"')]"
|
||||
);
|
||||
return (
|
||||
|
||||
historyObj = historyObj[0];
|
||||
return !_.isEmpty(historyObj) ? (
|
||||
<div
|
||||
className="govuk-summary-list__row"
|
||||
key={key}
|
||||
@@ -74,10 +94,10 @@ const DocumentDetails = (props) => {
|
||||
)}
|
||||
:
|
||||
</span>
|
||||
{_.has(historyObj[key], [
|
||||
{_.has(historyObj, [
|
||||
"_pinswg_documentid_value@OData.Community.Display.V1.FormattedValue",
|
||||
])
|
||||
? historyObj[key][
|
||||
? historyObj[
|
||||
"_pinswg_documentid_value@OData.Community.Display.V1.FormattedValue"
|
||||
]
|
||||
: ""}
|
||||
@@ -103,10 +123,10 @@ const DocumentDetails = (props) => {
|
||||
:
|
||||
</span>
|
||||
|
||||
{_.has(historyObj[key], [
|
||||
{_.has(historyObj, [
|
||||
"pinswg_publisheddate@OData.Community.Display.V1.FormattedValue",
|
||||
])
|
||||
? historyObj[key][
|
||||
? historyObj[
|
||||
"pinswg_publisheddate@OData.Community.Display.V1.FormattedValue"
|
||||
]
|
||||
: ""}
|
||||
@@ -118,6 +138,8 @@ const DocumentDetails = (props) => {
|
||||
92
|
||||
</dd>
|
||||
</div>
|
||||
) : (
|
||||
""
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -126,20 +148,63 @@ const DocumentDetails = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const docDetailsObj = async () => {
|
||||
let docObj = await getSearchDocumentDetails1(incidentid)
|
||||
.then((data) => {
|
||||
props.setDocumentDetails(data);
|
||||
return data;
|
||||
})
|
||||
.then((data) => {
|
||||
let historyObj = getDocumentHistory(data.value).then(
|
||||
(result) => {
|
||||
props.setDocumentHistory(result);
|
||||
return result;
|
||||
}
|
||||
);
|
||||
|
||||
return data;
|
||||
});
|
||||
|
||||
return docObj;
|
||||
};
|
||||
|
||||
const getDocumentHistory = async (searchDocumentDetailsObj) => {
|
||||
let historyArr = [];
|
||||
searchDocumentDetailsObj = searchDocumentDetailsObj;
|
||||
|
||||
const detailsObj = searchDocumentDetailsObj.map(
|
||||
(historyDetail, index) => {
|
||||
if (historyDetail.pinswg_publishtoweb != true) {
|
||||
console.log(historyDetail.pinswg_documentid);
|
||||
} else {
|
||||
historyArr.push(
|
||||
getSearchDocumentHistory1(
|
||||
historyDetail.pinswg_documentid
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
return Promise.all(historyArr);
|
||||
};
|
||||
|
||||
const searchDocumentResultsObj = docDetailsObj();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-full">
|
||||
<h2>Documents</h2>
|
||||
{console.log(documentDetailsObj)}
|
||||
{documentDetailsArr.length > 0 ? (
|
||||
DocumentView(documentDetailsArr)
|
||||
) : (
|
||||
{_.isEmpty(documentHistoryObj) ? (
|
||||
<div className="govuk-grid-row">
|
||||
<div className="govuk-grid-column-two-thirds">
|
||||
<h3>There are no documents for this appeal</h3>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
DocumentView(documentDetailsArr)
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
@@ -147,4 +212,21 @@ const DocumentDetails = (props) => {
|
||||
);
|
||||
};
|
||||
|
||||
export default DocumentDetails;
|
||||
const mapStateToProps = (state) => {
|
||||
return {
|
||||
...state,
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch) => {
|
||||
return {
|
||||
setDocumentDetails: (detailsObj) => {
|
||||
dispatch(setDocumentDetails(detailsObj));
|
||||
},
|
||||
setDocumentHistory: (historyObj) => {
|
||||
dispatch(setDocumentHistory(historyObj));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapDispatchToProps)(DocumentDetails);
|
||||
|
||||
Reference in New Issue
Block a user