diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/MicroplanCard.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/MicroplanCard.js index 28aa95f0700..d960ee66df7 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/MicroplanCard.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/components/MicroplanCard.js @@ -18,7 +18,7 @@ const MicroplanCard = () => { }; }; - let links = [generateLink("SETUP_MICROLAN","setup-microplan")]; + let links = [generateLink("SETUP_MICROCLAN","setup-microplan"),generateLink("SEARCH_MICROPLANS","microplan-search")]; links = links.filter((link) => (link?.roles && link?.roles?.length > 0 ? Digit.Utils.didEmployeeHasAtleastOneRole(link?.roles) : true)); diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/MicroplanSearchConfig.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/MicroplanSearchConfig.js new file mode 100644 index 00000000000..1bbbdd330e0 --- /dev/null +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/MicroplanSearchConfig.js @@ -0,0 +1,126 @@ + + +// default values of search input component +const defaultSearchValues = { + microplanName: "", + + }; + + + //config for tab search sceeen + export const TabSearchconfig = { + // moduleName: "commonCampaignUiConfig", + showTab: true, // setting true will enable tab screen + TabSearchconfig: [ // all tab config should be added in json array + { + label: "ALL", + type: "search", + apiDetails: { + serviceName: "/plan-service/config/_search", //! Note + requestParam: {}, + requestBody: {}, + masterName: "commonUiConfig", + moduleName: "MicroplanSearchConfig", + minParametersForSearchForm: 0, + tableFormJsonPath: "requestBody.PlanConfigurationSearchCriteria.pagination", + // filterFormJsonPath: "requestBody.MdmsCriteria.customs", + searchFormJsonPath: "requestBody.PlanConfigurationSearchCriteria", + }, + + sections: { + search: { + uiConfig: { + formClassName: "custom-both-clear-search", + primaryLabel: "ES_COMMON_SEARCH", + secondaryLabel: "ES_COMMON_CLEAR_SEARCH", + minReqFields: 0, + defaultValues: defaultSearchValues, // Set default values for search fields + fields: [ + { + label: "Name of the microplan", + isMandatory: false, + key: "microplanName", + type: "text", + populators: { + name: "microplanName", + error: "Required", + validation: { pattern: /^[A-Za-z]+$/i }, + }, + }, + // { + // label: "Phone number", + // isMandatory: false, + // key: "Phone number", + // type: "number", + // disable: false, + // populators: { name: "mobileNumber", error: "sample error message", validation: { min: 0, max: 999999999 } }, + // }, + // { + // label: "Individual Id ", + // isMandatory: false, + // type: "text", + // disable: false, + // populators: { + // name: "individualId", + // }, + // }, + ], + }, + + show: true, + }, + searchResult: { + uiConfig: { + columns: [ + { + label: "Name of the Microplan", + jsonPath: "name", + additionalCustomization:true + }, + + { + label: "Microplan Status", + jsonPath: "status", + }, + { + label: "Campaign Disease", + jsonPath: "CampaignDetails.campaignName", + }, + { + label:"Camapaign Type", + jsonPath:"CampaignDetails.startDate" + }, + { + label:"Distribution Strategy", + jsonPath:" proposalDate" + }, + { + label:"Actions", + jsonPath:"", + additionalCustomization:true + } + ], + resultsJsonPath: "PlanConfiguration", + + enableColumnSort: true, + // resultsJsonPath: "mdms", + }, + show: true, + }, + // customHookName: "microplanv1.useSavedMicroplans", //! Note + + }, + customHookName:"microplanv1.useSavedMicroplans" + }, + + + {label: "DRAFTED_SETUP"}, + {label: "EXECUTION_TO_BE_DONE",}, + {label:"EXECUTION_IN_PROGRESS"}, + {label:"MICROPLAN_EXECUTED"} + + ], + }; + + + \ No newline at end of file diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js index 427e1c5bb18..a8ce71c57ab 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/configs/UICustomizations.js @@ -1,5 +1,7 @@ import { Link, useHistory } from "react-router-dom"; import _ from "lodash"; +import React from "react"; +import { Dropdown } from "@egovernments/digit-ui-components"; //create functions here based on module name set in mdms(eg->SearchProjectConfig) //how to call these -> Digit?.Customizations?.[masterName]?.[moduleName] @@ -10,108 +12,90 @@ const businessServiceMap = {}; const inboxModuleNameMap = {}; +function cleanObject(obj) { + for (const key in obj) { + if (Object.hasOwn(obj, key)) { + if (Array.isArray(obj[key])) { + if (obj[key].length === 0) { + delete obj[key]; + } + } else if ( + obj[key] === undefined || + obj[key] === null || + obj[key] === false || + obj[key] === "" || // Check for empty string + (typeof obj[key] === "object" && Object.keys(obj[key]).length === 0) + ) { + delete obj[key]; + } + } + } + return obj; +} + export const UICustomizations = { - SearchPucarConfig: { - customValidationCheck: (data) => { - //checking both to and from date are present - const { createdFrom, createdTo } = data; - if ((createdFrom === "" && createdTo !== "") || (createdFrom !== "" && createdTo === "")) - return { warning: true, label: "ES_COMMON_ENTER_DATE_RANGE" }; - - return false; - }, - preProcess: (data) => { - // data.params = { ...data.params, tenantId: Digit.ULBService.getCurrentTenantId() }; - - // let requestBody = { ...data.body.Individual }; - // const pathConfig = { - // name: "name.givenName", - // }; - // const dateConfig = { - // createdFrom: "daystart", - // createdTo: "dayend", - // }; - // const selectConfig = { - // wardCode: "wardCode[0].code", - // socialCategory: "socialCategory.code", - // }; - // const textConfig = ["name", "individualId"]; - // let Individual = Object.keys(requestBody) - // .map((key) => { - // if (selectConfig[key]) { - // requestBody[key] = _.get(requestBody, selectConfig[key], null); - // } else if (typeof requestBody[key] == "object") { - // requestBody[key] = requestBody[key]?.code; - // } else if (textConfig?.includes(key)) { - // requestBody[key] = requestBody[key]?.trim(); - // } - // return key; - // }) - // .filter((key) => requestBody[key]) - // .reduce((acc, curr) => { - // if (pathConfig[curr]) { - // _.set(acc, pathConfig[curr], requestBody[curr]); - // } else if (dateConfig[curr] && dateConfig[curr]?.includes("day")) { - // _.set(acc, curr, Digit.Utils.date.convertDateToEpoch(requestBody[curr], dateConfig[curr])); - // } else { - // _.set(acc, curr, requestBody[curr]); - // } - // return acc; - // }, {}); - - // data.body.Individual = { ...Individual }; - console.log(data,"data"); - return data; - }, - additionalCustomizations: (row, key, column, value, t, searchResult) => { - //here we can add multiple conditions - //like if a cell is link then we return link - //first we can identify which column it belongs to then we can return relevant result - switch (key) { - case "MASTERS_WAGESEEKER_ID": - return ( - - - {String(value ? (column.translate ? t(column.prefix ? `${column.prefix}${value}` : value) : value) : t("ES_COMMON_NA"))} - - - ); - - case "MASTERS_SOCIAL_CATEGORY": - return value ? {String(t(`MASTERS_${value}`))} : t("ES_COMMON_NA"); - - case "CORE_COMMON_PROFILE_CITY": - return value ? {String(t(Digit.Utils.locale.getCityLocale(value)))} : t("ES_COMMON_NA"); - - case "MASTERS_WARD": - return value ? ( - {String(t(Digit.Utils.locale.getMohallaLocale(value, row?.tenantId)))} - ) : ( - t("ES_COMMON_NA") - ); + + MicroplanSearchConfig: { + preProcess: (data, additionalDetails) => { + const { name, status } = data?.state?.searchForm || {}; + + data.body.PlanConfigurationSearchCriteria = {}; + data.body.PlanConfigurationSearchCriteria.limit = data?.state?.tableForm?.limit; + // data.body.PlanConfigurationSearchCriteria.limit = 10 + data.body.PlanConfigurationSearchCriteria.offset = data?.state?.tableForm?.offset; + data.body.PlanConfigurationSearchCriteria.name = name; + data.body.PlanConfigurationSearchCriteria.tenantId = Digit.ULBService.getCurrentTenantId(); + data.body.PlanConfigurationSearchCriteria.userUuid = Digit.UserService.getUser().info.uuid; + // delete data.body.PlanConfigurationSearchCriteria.pagination + data.body.PlanConfigurationSearchCriteria.status = status?.status; + cleanObject(data.body.PlanConfigurationSearchCriteria); - case "MASTERS_LOCALITY": - return value ? ( - {String(t(Digit.Utils.locale.getMohallaLocale(value, row?.tenantId)))} - ) : ( - t("ES_COMMON_NA") - ); - default: - return t("ES_COMMON_NA"); - } - }, - MobileDetailsOnClick: (row, tenantId) => { - let link; - Object.keys(row).map((key) => { - if (key === "MASTERS_WAGESEEKER_ID") - link = `/${window.contextPath}/employee/masters/view-wageseeker?tenantId=${tenantId}&wageseekerId=${row[key]}`; - }); - return link; - }, - additionalValidations: (type, data, keys) => { - if (type === "date") { - return data[keys.start] && data[keys.end] ? () => new Date(data[keys.start]).getTime() <= new Date(data[keys.end]).getTime() : true; - } - }, - }, + return data; + }, + additionalCustomizations: (row, key, column, value, t, searchResult) => { + if (key === "Actions") { + return ( + { console.log(e, "event") }} + optionKey={"name"} + selected={{ code: "1", name: "Actions" }} + > + //

$${value}

+ + ); + } + + if (key === "Name of the Microplan") { + if (value && value !== "NA") { + + return ( +
+

{value}

+
+ ) + } else { + return ( +
+

NA

+
+ ) + } + + } + + }, + }, + }; \ No newline at end of file diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/MicroplanSearch.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/MicroplanSearch.js new file mode 100644 index 00000000000..4a58c7ea454 --- /dev/null +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/MicroplanSearch.js @@ -0,0 +1,50 @@ +import { Header, InboxSearchComposer } from "@egovernments/digit-ui-react-components"; +import React, { useState, useEffect } from "react"; +import { useTranslation } from "react-i18next"; +import { TabSearchconfig } from '../../configs/MicroplanSearchConfig' + + + +const defaultSearchValues = { + +}; + +const MicroplanSearch = () => { + const { t } = useTranslation(); + const [defaultValues, setDefaultValues] = useState(defaultSearchValues); // State to hold default values for search fields + const [config, setConfig] = useState(TabSearchconfig?.TabSearchconfig?.[0]); // initially setting first index config as default from jsonarray + const [tabData, setTabData] = useState( + TabSearchconfig?.TabSearchconfig?.map((configItem, index) => ({ key: index, label: configItem.label, active: index === 0 ? true : false })) + ); // setting number of tab component and making first index enable as default + useEffect(() => { + // Set default values when component mounts + setDefaultValues(defaultSearchValues); + }, []); + + const onTabChange = (n) => { + + setTabData((prev) => prev.map((i, c) => ({ ...i, active: c === n ? true : false }))); //setting tab enable which is being clicked + // setConfig(TabSearchconfig?.TabSearchconfig?.[n]);// as per tab number filtering the config + const url = new URL(window.location.href); + url.searchParams.set("tabId", `${n}`); + window.history.replaceState({}, "", url); + + }; + return ( + + +
{t(config?.label)}
+
+ {/* Pass defaultValues as props to InboxSearchComposer */} + +
+
+ ); +}; +export default MicroplanSearch; \ No newline at end of file diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/SetupMicroplan.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/SetupMicroplan.js index 15e34e2d87b..30ed0970100 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/SetupMicroplan.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/SetupMicroplan.js @@ -81,7 +81,7 @@ const SetupMicroplan = () => { }, [params]); const onSubmit = (formData) => { - debugger + //run validations // setIsSubmittting to true -> to run inline validations within the components setIsSubmitting(true); diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/index.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/index.js index f29f2a01ba1..40397038d3a 100644 --- a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/index.js +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/pages/employee/index.js @@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next"; import { Switch } from "react-router-dom"; import SetupMicroplan from "./SetupMicroplan"; import { useMyContext } from "../../utils/context"; +import MicroplanSearch from "./MicroplanSearch"; const bredCrumbStyle={ maxWidth: "min-content" }; const ProjectBreadCrumb = ({ location }) => { @@ -59,6 +60,7 @@ const App = ({ path, stateCode, userType, tenants }) => { } /> + } /> ); diff --git a/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/services/searchSavedPlans.js b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/services/searchSavedPlans.js new file mode 100644 index 00000000000..532c83625c2 --- /dev/null +++ b/health/micro-ui/web/micro-ui-internals/packages/modules/microplan/src/services/searchSavedPlans.js @@ -0,0 +1,71 @@ +function mergeArrays(array1, key1, array2, key2) { + const mergedArray = []; + + // Create a map of values from array2 using key2 + const map = new Map(); + array2.forEach((item) => { + map.set(item[key2], item); + }); + + // Iterate over array1 and merge with matching items from array2 + array1.forEach((item) => { + const matchingItem = map.get(item[key1]); + if (matchingItem) { + // Merge properties from both items and append to 'CampaignDetails' + const mergedItem = { ...item, CampaignDetails: { ...matchingItem } }; + mergedArray.push(mergedItem); + } else { + // No matching item found in array2, add array1 item with empty 'CampaignDetails' + const mergedItem = { ...item, CampaignDetails: {} }; + mergedArray.push(mergedItem); + } + }); + return mergedArray; + } + + const SearchSavedPlans = async (body) => { + try { + //here get response from both apis and process data and return + const responsePlan = await Digit.CustomService.getResponse({ + url: "/plan-service/config/_search", + useCache: false, + method: "POST", + userService: false, + body, + }); + + const { PlanConfiguration } = responsePlan; + if (!PlanConfiguration || PlanConfiguration.length === 0) return []; + + const executionPlanIds = PlanConfiguration?.map((row) => row?.executionPlanId)?.filter((item) => item); + const CampaignDetails = { + tenantId: Digit.ULBService.getCurrentTenantId(), + ids: executionPlanIds, + }; + + + + const responseCampaign = await Digit.CustomService.getResponse({ + url: "/project-factory/v1/project-type/search", + useCache: false, + method: "POST", + userService: false, + body: { + CampaignDetails, + }, + }); + + const finalResult = { + PlanConfiguration: mergeArrays(responsePlan?.PlanConfiguration, "executionPlanId", responseCampaign?.CampaignDetails, "id"), + }; + + return finalResult; + } catch (error) { + if (error?.response?.data?.Errors) { + throw new Error(error.response.data.Errors[0].message); + } + throw new Error("An unknown error occurred"); + } + }; + + export default SearchSavedPlans; \ No newline at end of file