Merged PR 2350: added in count on case status dropdown
added in count on case status dropdown Related work items: #23447
This commit is contained in:
@@ -274,3 +274,14 @@ export const getPortalModuleDetailsProxy = (appealType, caseReference) => {
|
|||||||
consoleLogger(error);
|
consoleLogger(error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getCaseStatus = async (appealType, caseReference) => {
|
||||||
|
const route = buildFileQuery("/api/endpoint/getStatusCounts_api", {
|
||||||
|
appealType,
|
||||||
|
caseReference: encodeURI(caseReference)
|
||||||
|
});
|
||||||
|
|
||||||
|
return getJson(withBaseUrl(BASE_URL, route)).catch((error) => {
|
||||||
|
consoleLogger(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ import {
|
|||||||
getPartSavedAppeal,
|
getPartSavedAppeal,
|
||||||
getIsPublishedbyID,
|
getIsPublishedbyID,
|
||||||
getPortalModuleDetails,
|
getPortalModuleDetails,
|
||||||
getPortalModuleDetailsProxy
|
getPortalModuleDetailsProxy,
|
||||||
|
getCaseStatus
|
||||||
} from "./caseDirectService";
|
} from "./caseDirectService";
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -37,5 +38,6 @@ export {
|
|||||||
getPartSavedAppeal,
|
getPartSavedAppeal,
|
||||||
getIsPublishedbyID,
|
getIsPublishedbyID,
|
||||||
getPortalModuleDetails,
|
getPortalModuleDetails,
|
||||||
getPortalModuleDetailsProxy
|
getPortalModuleDetailsProxy,
|
||||||
|
getCaseStatus
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,9 +3,10 @@ import useTranslation from "next-translate/useTranslation";
|
|||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { connect } from "react-redux";
|
import { connect } from "react-redux";
|
||||||
import { Field, formValueSelector, reduxForm } from "redux-form";
|
import { Field, formValueSelector, reduxForm } from "redux-form";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
import transLookup from "../../data/lookuptranslations.json";
|
import transLookup from "../../data/lookuptranslations.json";
|
||||||
import { statusValues } from "../utils/caseStagesObj";
|
|
||||||
|
import { getCaseStatus } from "../../actions/services/caseDirectService";
|
||||||
|
|
||||||
const required = (errorMsg) => (value) =>
|
const required = (errorMsg) => (value) =>
|
||||||
value || typeof value === "number" ? undefined : errorMsg;
|
value || typeof value === "number" ? undefined : errorMsg;
|
||||||
@@ -177,16 +178,8 @@ const RenderCaseStatusList = ({
|
|||||||
)
|
)
|
||||||
? ""
|
? ""
|
||||||
: router.locale == "cy"
|
: router.locale == "cy"
|
||||||
? jsonpath({
|
? `${optionsObj[key].value_cy} (${optionsObj[key].caseCount || 0})`
|
||||||
path:
|
: `${optionsObj[key].value} (${optionsObj[key].caseCount || 0})` ||
|
||||||
'$..[?(@ && @.statuscode=="' +
|
|
||||||
optionsObj[key]
|
|
||||||
.statuscode +
|
|
||||||
'")].value_cy',
|
|
||||||
json: optionsObj,
|
|
||||||
eval: true
|
|
||||||
})
|
|
||||||
: optionsObj[key].value ||
|
|
||||||
t(
|
t(
|
||||||
"case:summary-no-date-entered-label"
|
"case:summary-no-date-entered-label"
|
||||||
)}
|
)}
|
||||||
@@ -206,6 +199,27 @@ let AdvancedSearch = (props) => {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { locale } = router;
|
const { locale } = router;
|
||||||
|
|
||||||
|
const [caseStatusValues, setCaseStatusValues] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchCaseStatus = async () => {
|
||||||
|
try {
|
||||||
|
const response = await getCaseStatus();
|
||||||
|
|
||||||
|
setCaseStatusValues(
|
||||||
|
Array.isArray(response?.data)
|
||||||
|
? response.data
|
||||||
|
: response?.data?.value || response || []
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch case statuses", error);
|
||||||
|
setCaseStatusValues([]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
fetchCaseStatus();
|
||||||
|
}, []);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
LPAData,
|
LPAData,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
@@ -691,7 +705,7 @@ let AdvancedSearch = (props) => {
|
|||||||
name="statusCode"
|
name="statusCode"
|
||||||
id="statusCode"
|
id="statusCode"
|
||||||
component={RenderCaseStatusList}
|
component={RenderCaseStatusList}
|
||||||
optionsObj={statusValues}
|
optionsObj={caseStatusValues}
|
||||||
//validate={[required]}
|
//validate={[required]}
|
||||||
label={t(
|
label={t(
|
||||||
"search:case-status-label"
|
"search:case-status-label"
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
// // pages/api/status-counts.js
|
||||||
|
|
||||||
|
// import { azureHeadersPaged, azureHeaders } from "../../../actions/core/headers";
|
||||||
|
// import { respondError } from "../middleware/apiResponse";
|
||||||
|
// import { relayGet } from "../middleware/relayForwarding";
|
||||||
|
// import { RELAY_POLICY_BOUNDED_READ } from "../middleware/relayPolicyPresets";
|
||||||
|
|
||||||
|
// import statusValues from "../../../components/utils/caseStagesObj";
|
||||||
|
|
||||||
|
// export default async function ApiProxy(req, res) {
|
||||||
|
// try {
|
||||||
|
// const relayPolicy = RELAY_POLICY_BOUNDED_READ;
|
||||||
|
|
||||||
|
// const queryUrl =
|
||||||
|
// "incidents?$apply=groupby((statuscode),aggregate($count as caseCount))";
|
||||||
|
|
||||||
|
// const response = await relayGet({
|
||||||
|
// queryUrl,
|
||||||
|
// res,
|
||||||
|
// requestOptionsBuilder: (accessToken) => azureHeaders(accessToken),
|
||||||
|
// relayPolicy,
|
||||||
|
// transformData: (data) => {
|
||||||
|
// if (
|
||||||
|
// Object.prototype.hasOwnProperty.call(
|
||||||
|
// data,
|
||||||
|
// "@odata.nextLink"
|
||||||
|
// )
|
||||||
|
// ) {
|
||||||
|
// const dataStr = JSON.stringify(data["@odata.nextLink"]);
|
||||||
|
// data["@odata.nextLink"] = dataStr.split("/v9.2/")[1];
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return data;
|
||||||
|
// },
|
||||||
|
// errorResponse: {
|
||||||
|
// status: 400,
|
||||||
|
// code: "BASIC_SEARCH_FETCH_FAILED",
|
||||||
|
// message: "Failed to fetch basic search results"
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// const countsByStatusCode = response.data.value.reduce((acc, item) => {
|
||||||
|
// acc[item.statuscode] = item.caseCount;
|
||||||
|
// return acc;
|
||||||
|
// }, {});
|
||||||
|
|
||||||
|
// const result = statusValues.map((status) => ({
|
||||||
|
// ...status,
|
||||||
|
// count: countsByStatusCode[status.statuscode] || 0
|
||||||
|
// }));
|
||||||
|
|
||||||
|
// return res.status(200).json({
|
||||||
|
// count: result.length,
|
||||||
|
// value: result
|
||||||
|
// });
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error(
|
||||||
|
// "Failed to get status counts",
|
||||||
|
// error.response?.data || error.message
|
||||||
|
// );
|
||||||
|
|
||||||
|
// return res.status(500).json({
|
||||||
|
// error: "Failed to get status counts"
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// pages/api/status-counts.js
|
||||||
|
|
||||||
|
import { azureHeaders } from "../../../actions/core/headers";
|
||||||
|
import { relayGet } from "../middleware/relayForwarding";
|
||||||
|
import { RELAY_POLICY_BOUNDED_READ } from "../middleware/relayPolicyPresets";
|
||||||
|
|
||||||
|
import { statusValues } from "../../../components/utils/caseStagesObj";
|
||||||
|
|
||||||
|
export default async function ApiProxy(req, res) {
|
||||||
|
const queryUrl =
|
||||||
|
"incidents?$apply=groupby((statuscode),aggregate($count as caseCount))";
|
||||||
|
|
||||||
|
return relayGet({
|
||||||
|
queryUrl,
|
||||||
|
res,
|
||||||
|
requestOptionsBuilder: (accessToken) => azureHeaders(accessToken),
|
||||||
|
relayPolicy: RELAY_POLICY_BOUNDED_READ,
|
||||||
|
transformData: (data) => {
|
||||||
|
const countsByStatusCode = (data.value || []).reduce(
|
||||||
|
(acc, item) => {
|
||||||
|
acc[item.statuscode] = item.caseCount || 0;
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
|
return statusValues.map((status) => ({
|
||||||
|
...status,
|
||||||
|
caseCount: countsByStatusCode[status.statuscode] || 0
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
errorResponse: {
|
||||||
|
status: 400,
|
||||||
|
code: "STATUS_COUNTS_FETCH_FAILED",
|
||||||
|
message: "Failed to fetch status counts"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user