Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added changes in the master for draft boundary #1002

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@egovernments/digit-ui-components": "0.0.2-beta.1",
"@egovernments/digit-ui-module-core": "1.8.2-beta.2",
"@egovernments/digit-ui-module-utilities": "1.0.1-beta.30",
"@egovernments/digit-ui-react-components": "1.8.2-beta.6",
"@egovernments/digit-ui-react-components": "1.8.2-beta.10",
"@egovernments/digit-ui-module-hcmworkbench":"0.0.38",
"@egovernments/digit-ui-module-campaign-manager": "0.0.1",
"@egovernments/digit-ui-module-hcmmicroplanning": "0.0.1",
Expand Down
2 changes: 1 addition & 1 deletion health/micro-ui/web/micro-ui-internals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"ajv": "8.12.0",
"lodash": "4.17.21",
"microbundle-crl": "0.13.11",
"@egovernments/digit-ui-react-components": "1.8.2-beta.6",
"@egovernments/digit-ui-react-components": "1.8.2-beta.10",
"@egovernments/digit-ui-components": "0.0.2-beta.1",
"react": "17.0.2",
"react-dom": "17.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"react-router-dom": "5.3.0"
},
"dependencies": {
"@egovernments/digit-ui-react-components": "1.8.2-beta.6",
"@egovernments/digit-ui-react-components": "1.8.2-beta.10",
"@egovernments/digit-ui-components": "0.0.2-beta.1",
"@rjsf/core": "5.10.0",
"@rjsf/utils": "5.10.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import AddProductField from "./components/AddProductField";
import CycleDataPreview from "./components/CycleDataPreview";
import { ErrorBoundary } from "@egovernments/digit-ui-components";
import CampaignResourceDocuments from "./components/CampaignResourceDocuments";
import { DSSCard } from "./components/DSSCard";

/**
* The CampaignModule function fetches store data based on state code, module code, and language, and
Expand Down Expand Up @@ -82,6 +83,7 @@ const componentsToRegister = {
AddProductField,
CycleDataPreview,
CampaignResourceDocuments,
DSSCard
};

const overrideHooks = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import { EmployeeModuleCard, ModuleCardFullWidth, DSSIcon } from "@egovernments/digit-ui-react-components";
import React from "react";
import { useTranslation } from "react-i18next";

const nationalScreenURLs = {
overview: { key: "national-overview", stateKey: "overview", label: "NURT_OVERVIEW", active: true, nActive: true },
propertytax: { key: "national-propertytax", stateKey: "propertytax", label: "NURT_PROPERTY_TAX", active: true, nActive: true },
tradelicense: { key: "national-tradelicense", stateKey: "tradelicense", label: "NURT_TRADE_LICENCE", active: true, nActive: true },
pgr: { key: "national-pgr", stateKey: "pgr", label: "NURT_COMPLAINS", active: true, nActive: true },
fsm: { key: "fsm", stateKey: "fsm", label: "CS_HOME_FSM_SERVICES", active: true, nActive: false },
mCollect: { key: "national-mcollect", stateKey: "mCollect", label: "NURT_MCOLLECT", active: true, nActive: true },
ws: { key: "national-ws", stateKey: "ws", label: "NURT_WATER_SEWERAGE", active: true, nActive: true },
obps: { key: "nss-obps", stateKey: "obps", label: "DSS_BUILDING_PERMISSION", active: true, nActive: true },
noc: { key: "national-firenoc", stateKey: "noc", label: "NURT_FIRENOC", active: true, nActive: true },
bnd: { key: "nss-birth-death", stateKey: "birth-death", label: "BIRTH_AND_DEATH", active: true, nActive: true },
faqs: { key: "national-faqs", stateKey: "national-faqs", label: "DSS_FAQS", active: false, nActive: true, others: true },
finance: { key: "national-finance", stateKey: "finance", label: "DSS_FINANCE", active: true, nActive: false },
about: { key: "national-about", stateKey: "national-about", label: "DSS_ABOUT_DASHBOARD", active: false, nActive: true, others: true },
};

const healthDSSURLs = {
about: { key: "about", stateKey: "about", label: "DSS_ABOUT", active: true },
faqs: { key: "faqs", stateKey: "faqs", label: "DSS_FAQS", active: true },
calculations: { key: "calculations", stateKey: "calculations", label: "DSS_CALCULATIONS", active: true }
};

export const checkCurrentScreen = () => {
const moduleName = Digit.Utils.dss.getCurrentModuleName();
const nationalURLS = Object.keys(nationalScreenURLs).map((key) => nationalScreenURLs[key].key);
return nationalURLS.filter(ele=>ele!=="fsm").some((e) => moduleName?.includes(e));
};

const NDSSCard = () => {
const NATADMIN = Digit.UserService.hasAccess("NATADMIN");
const { t } = useTranslation();

if (!NATADMIN) {
return null;
}

let links = Object.values(nationalScreenURLs)
.filter((ele) => ele["nActive"] === true)
.map((obj) => ({
label: t(obj?.label),
link: `/digit-ui/employee/dss/dashboard/${obj?.key}`,
link: obj?.others?`/digit-ui/employee/dss/${obj?.key}`:`/digit-ui/employee/dss/dashboard/${obj?.key}`,
}));

const propsForModuleCard = {
headerStyle: { border: "none", height: "48px" },
moduleName: t("ACTION_TEST_NATDASHBOARD"),
subHeader: t("ACTION_TEST_NATDASHBOARD"),
subHeaderLink: `/digit-ui/employee/dss/landing/NURT_DASHBOARD`,
className: "employeeCard customEmployeeCard card-home full-width-card full-employee-card-height",
links: [...links],
};
return <ModuleCardFullWidth {...propsForModuleCard} />;
};

const DSSCard = () => {
const STADMIN = Digit.UserService.hasAccess("STADMIN");
const { t } = useTranslation();

const { data: tenantData } = Digit.Hooks.dss.useMDMS(Digit.ULBService.getStateId(), "tenant", ["tenants"], {
select: (data) => {
const tenantData = data?.["tenant"]?.["tenants"]?.[0];
return tenantData;
},
enabled: true,
});

const shouldInvokeProjectService = tenantData?.integrateProjectService || false;
if (shouldInvokeProjectService) {
return <DynamicDSSCard />;
}

if (!STADMIN) {
return null;
}

let links = Object.values(nationalScreenURLs)
.filter((ele) => ele["active"] === true)
.map((obj) => ({
label: t(obj?.label),
link: obj.active ? `/digit-ui/employee/dss/dashboard/${obj?.stateKey}` : `/employee/integration/dss/${obj?.stateKey}`,
}));

const propsForModuleCard = {
headerStyle: { border: "none", height: "48px" },
moduleName: t("ES_TITLE_DSS"),
subHeader: t("ACTION_TEST_SURE_DASHBOARD"),
subHeaderLink: `/digit-ui/employee/dss/landing/home`,
className: "employeeCard card-home customEmployeeCard full-width-card full-employee-card-height",
links: [...links],
};
return <ModuleCardFullWidth {...propsForModuleCard} styles={{ width: "100%" }} />;
};

const DynamicDSSCard = () => {
const { t } = useTranslation();

const isNationalSupervisor = Digit.UserService.hasAccess(["NATIONAL_SUPERVISOR"]);
const isProvincialSupervisor = Digit.UserService.hasAccess(["PROVINCIAL_SUPERVISOR"]);
const isDistrictSupervisor = Digit.UserService.hasAccess(["DISTRICT_SUPERVISOR"]);
const isHealthFacilitySupervisor = Digit.UserService.hasAccess(["HEALTH_FACILITY_SUPERVISOR"]);
const isCommunitySupervisor = Digit.UserService.hasAccess(["COMMUNITY_SUPERVISOR"]);

const projectTypes = Digit.SessionStorage.get("projectTypes");
const campaignData = Digit.SessionStorage.get("campaigns-info");

if(!isCommunitySupervisor && !isHealthFacilitySupervisor){
if (!campaignData || !projectTypes) {
return null;
}
}
const generateLinks = (location, code) => {
let links = [];
Object.keys(campaignData)?.map((key) => {
if (key === "LLIN-Default") {
const campaignType = campaignData[key];
campaignType.forEach((data) => {
const locationParam = data.boundaries?.[location]?.[0];
const url = projectTypes?.filter(project => project?.code === "LLIN-Default")[0]?.dashboardUrls?.[code]
links.push({
label: `${t(key)} - ${Digit.Utils.locale.getTitleHeading(locationParam)}`,
link: location === "province" ? `${url}?province=${locationParam}` : `${url}`,
});
})
}
});
return links;
};

let links = [];

// if (isNationalSupervisor) {
// links = Object.keys(campaignData)?.map((key) => {
// return {
// label: `${t(`${key}`)} - Mozambique`,
// link: projectTypes?.filter(project => project?.code === key)[0]?.dashboardUrls?.["NATIONAL_SUPERVISOR"]
// };
// });
// } else if (isProvincialSupervisor) {
// links = generateLinks("province","PROVINCIAL_SUPERVISOR");
// } else if (isDistrictSupervisor) {
// links = generateLinks("district","DISTRICT_SUPERVISOR");
// }
// links.push(...Object.values(healthDSSURLs)
// .filter((ele) => ele["active"] === true)
// .map((obj) => ({
// label: t(obj?.label),
// link: `/digit-ui/employee/dss/${obj?.stateKey}`
// })));

if (isNationalSupervisor) {
links.push({
label: t("NATIONAL_DASHBOARD"),
link: "/digit-ui/employee/utilities/iframe/elastic/national"
});
// TODO: To remove these hardcoded urls and generate all of this from mdms config
links.push({
label: t("NDSS_DASHBOARD"),
link: "/digit-ui/employee/dss/landing/national-health-dashboard"
})
} else if (isProvincialSupervisor) {
links.push({
label: t("PROVINCIAL_DASHBOARD"),
link: "/digit-ui/employee/utilities/iframe/elastic/province?query=true"
})
links = [...links, ...generateLinks("province","PROVINCIAL_SUPERVISOR")]
} else if (isDistrictSupervisor) {
links.push({
label: t("DISTRICT_DASHBOARD"),
link: "/digit-ui/employee/utilities/iframe/elastic/district?query=true"
})
links = [...links, ...generateLinks("district","DISTRICT_SUPERVISOR")]
console.log(links)
}
else if(isHealthFacilitySupervisor){
links.push({
label: t("REFERRAL_DASHBOARD"),
link: "/digit-ui/employee/utilities/iframe/elastic/hf?query=true"
})
}

// if(isNationalSupervisor || isProvincialSupervisor || isDistrictSupervisor){
// links.push({
// label: t('CUSTOM_REPORTS_LINK'),
// link: Digit.SessionStorage.get("initData")?.stateInfo?.customReportsDriveLink,
// external: true
// })

// links.push({
// label: t('FEEDBACK_LINK'),
// link: Digit.SessionStorage.get("initData")?.stateInfo?.feedbackLink,
// external: true
// })
// }

const propsForModuleCard = {
Icon: <DSSIcon />,
moduleName: t("DSS_CARD_HEADER_DASHBOARD"),
links: [...links],
};

return <EmployeeModuleCard {...propsForModuleCard} />;
};

export { DSSCard, NDSSCard };
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,60 @@ function SelectingBoundaries({ onSelect, formData, ...props }) {
const lowestChild = hierarchyTypeDataresult?.boundaryHierarchy.filter((item) => item.parentBoundaryType === lowestHierarchy)?.[0]?.boundaryType;
const searchParams = new URLSearchParams(location.search);
const isDraft = searchParams.get("draft");
const draftBoundary = searchParams.get("draftBoundary");

function updateUrlParams(params) {
const url = new URL(window.location.href);
Object.entries(params).forEach(([key, value]) => {
url.searchParams.set(key, value);
});
window.history.replaceState({}, "", url);
}

const fetchOptions = async ()=>{
setLoaderEnabled(true);
const draftSelected = props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.selectedData;
for (const item of draftSelected) {
const code = item?.code;
const parent = item?.parent;
const boundary = item?.type;

const childBoundary = props?.props?.dataParams?.hierarchy?.boundaryHierarchy.filter((item) => item.parentBoundaryType === boundary)?.[0]?.boundaryType;
const reqCriteriaBoundaryTypeSearch = await Digit.CustomService.getResponse({
url: "/boundary-service/boundary-relationships/_search",
params: {
tenantId: tenantId,
hierarchyType: props?.props?.dataParams?.hierarchyType,
boundaryType: childBoundary,
parent: code,
},
body: {},
});
const boundaryTypeData = reqCriteriaBoundaryTypeSearch;

setBoundaryData((prevBoundaryData) => {
const existingData = prevBoundaryData[childBoundary] || [];

// Check if the entry already exists
const updatedData = {
...prevBoundaryData,
[childBoundary]: [...existingData.filter((entry) => entry.parentCode !== code), { parentCode: code, boundaryTypeData }],
};
return updatedData;
});
}
updateUrlParams({ draftBoundary: false });
setLoaderEnabled(false);
}
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved

useEffect(()=>{
if(isDraft == "true" && props?.props?.dataParams?.hierarchy &&
props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.selectedData?.length > 0 &&
draftBoundary === "true"
){
fetchOptions();
}
},[isDraft,draftBoundary,props?.props?.dataParams?.hierarchy , props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.selectedData])

useEffect(() => {
if (!updateBoundary) {
Expand Down Expand Up @@ -333,7 +387,7 @@ function SelectingBoundaries({ onSelect, formData, ...props }) {
} else {
// transformedRes = selectedData.filter((item) => item?.type === boundary?.boundaryType)
const filteredData = selectedData.filter((item) => item?.type === boundary?.boundaryType);
if (filteredData.length === 0) {
if (filteredData.length === 0 || filteredData.length !== res.length) {
// If no selected data for the particular boundary type, run the transformation logic
transformedRes = res?.map((item) => ({
code: item.code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const MyCampaign = () => {
history.push(`/${window.contextPath}/employee/campaign/setup-campaign?id=${row.id}&preview=${true}&action=${false}`);
break;
case "CAMPAIGN_DRAFTS":
history.push(`/${window.contextPath}/employee/campaign/setup-campaign?id=${row.id}&draft=${true}&fetchBoundary=${true}`);
history.push(`/${window.contextPath}/employee/campaign/setup-campaign?id=${row.id}&draft=${true}&fetchBoundary=${true}&draftBoundary=${true}`);
break;
case "CAMPAIGN_FAILED":
history.push(`/${window.contextPath}/employee/campaign/setup-campaign?id=${row.id}&preview=${true}&action=${false}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,26 +189,28 @@ function groupByTypeRemap(data) {
data.forEach((item) => {
const type = item?.type;
const boundaryType = item?.type;
const parentCode = item?.parent;
const obj = {
parentCode,
boundaryTypeData: {
TenantBoundary: [
{
boundary: [{ ...item, boundaryType }],
},
],
},
};
const parentCode = item?.parent !== undefined ? item.parent : null;

if (result[type]) {
result[type][0].boundaryTypeData.TenantBoundary[0].boundary.push(item);
} else {
result[type] = [obj];
if (!result[type]) {
result[type] = {};
}

if (!result[type][parentCode]) {
result[type][parentCode] = {
parentCode,
boundaryTypeData: {
TenantBoundary: [
{
boundary: [],
},
],
},
};
}
});

return result;
const targetBoundaryArray = result[type][parentCode].boundaryTypeData.TenantBoundary[0].boundary;
targetBoundaryArray.push({ ...item, boundaryType });
});
jagankumar-egov marked this conversation as resolved.
Show resolved Hide resolved
}

// Example usage:
Expand Down
2 changes: 1 addition & 1 deletion health/micro-ui/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@egovernments/digit-ui-module-workbench": "1.0.1-beta.16",
"@egovernments/digit-ui-module-core": "1.8.2-beta.2",
"@egovernments/digit-ui-module-hrms": "1.8.0-beta.2",
"@egovernments/digit-ui-react-components": "1.8.2-beta.6",
"@egovernments/digit-ui-react-components": "1.8.2-beta.10",
"@egovernments/digit-ui-components": "0.0.2-beta.1",
"@egovernments/digit-ui-module-dss": "1.8.0-beta",
"@egovernments/digit-ui-module-common": "1.8.0-beta",
Expand Down
2 changes: 1 addition & 1 deletion health/micro-ui/web/workbench/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@egovernments/digit-ui-components": "0.0.2-beta.1",
"@egovernments/digit-ui-module-core": "1.8.2-beta.2",
"@egovernments/digit-ui-module-utilities": "1.0.1-beta.30",
"@egovernments/digit-ui-react-components": "1.8.2-beta.6",
"@egovernments/digit-ui-react-components": "1.8.2-beta.10",
"@egovernments/digit-ui-module-hcmworkbench":"0.0.38",
"@egovernments/digit-ui-module-campaign-manager": "0.0.1",
"babel-loader": "8.1.0",
Expand Down