Skip to content

Commit

Permalink
fixed order in boundary details and changed hierarchy master
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavya-egov committed Nov 8, 2024
1 parent fa87589 commit 79af8c4
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ export const CONSOLE_MDMS_MODULENAME="HCM-ADMIN-CONSOLE";
*/
const CampaignModule = ({ stateCode, userType, tenants }) => {
const tenantId = Digit.ULBService.getCurrentTenantId();
const { data: BOUNDARY_HIERARCHY_TYPE , isLoading: hierarchyLoading } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "hierarchyConfig" }], {
const { data: BOUNDARY_HIERARCHY_TYPE , isLoading: hierarchyLoading } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{
name: "HierarchySchema",
"filter": "[?(@.type=='console')]"
}], {
select: (data) => {
return data?.[CONSOLE_MDMS_MODULENAME]?.hierarchyConfig?.find((item) => item.isActive)?.hierarchy;
return data?.[CONSOLE_MDMS_MODULENAME]?.HierarchySchema?.[0]?.hierarchy;
},
},
{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.hierarchyConfig` }
{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` }
);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,15 +501,15 @@ const CampaignSummary = (props) => {
navigationKey: "card5",
sections: [
{
name: "target",
name: "facility",
type: "COMPONENT",
component: "CampaignDocumentsPreview",
props: {
documents: data?.[0]?.resources?.filter((i) => i?.type === "boundaryWithTarget"),
documents: data?.[0]?.resources?.filter((i) => i.type === "facility"),
},
cardHeader: { value: t("TARGET_DETAILS"), inlineStyles: { marginTop: 0, fontSize: "1.5rem" } },
cardHeader: { value: t("FACILITY_DETAILS"), inlineStyles: { marginTop: 0, fontSize: "1.5rem" } },
cardSecondaryAction: noAction !== "false" && (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(12)}>
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(10)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
Expand All @@ -521,15 +521,15 @@ const CampaignSummary = (props) => {
navigationKey: "card5",
sections: [
{
name: "facility",
name: "user",
type: "COMPONENT",
component: "CampaignDocumentsPreview",
props: {
documents: data?.[0]?.resources?.filter((i) => i.type === "facility"),
documents: data?.[0]?.resources?.filter((i) => i.type === "user"),
},
cardHeader: { value: t("FACILITY_DETAILS"), inlineStyles: { marginTop: 0, fontSize: "1.5rem" } },
cardHeader: { value: t("USER_DETAILS"), inlineStyles: { marginTop: 0, fontSize: "1.5rem" } },
cardSecondaryAction: noAction !== "false" && (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(10)}>
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(11)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
Expand All @@ -541,15 +541,15 @@ const CampaignSummary = (props) => {
navigationKey: "card5",
sections: [
{
name: "user",
name: "target",
type: "COMPONENT",
component: "CampaignDocumentsPreview",
props: {
documents: data?.[0]?.resources?.filter((i) => i.type === "user"),
documents: data?.[0]?.resources?.filter((i) => i?.type === "boundaryWithTarget"),
},
cardHeader: { value: t("USER_DETAILS"), inlineStyles: { marginTop: 0, fontSize: "1.5rem" } },
cardHeader: { value: t("TARGET_DETAILS"), inlineStyles: { marginTop: 0, fontSize: "1.5rem" } },
cardSecondaryAction: noAction !== "false" && (
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(11)}>
<div className="campaign-preview-edit-container" onClick={() => handleRedirect(12)}>
<span>{t(`CAMPAIGN_EDIT`)}</span>
<EditIcon />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,68 @@ import { PRIMARY_COLOR, downloadExcelWithCustomName } from "../utils";
import getProjectServiceUrl from "../utils/getProjectServiceUrl";
import NoResultsFound from "./NoResultsFound";

function boundaryDataGrp(boundaryData) {
// Create an empty object to hold grouped data by type
// function boundaryDataGrp(boundaryData) {
// // Create an empty object to hold grouped data by type
// const groupedData = {};

// // Iterate through each boundary item in the data
// boundaryData.forEach((item) => {
// const { type } = item; // Extract the type

// // If the type doesn't exist in the groupedData, create an array for it
// if (!groupedData[type]) {
// groupedData[type] = [];
// }

// // Add the current item to its corresponding type array
// groupedData[type].push(item);
// });

// // Convert the grouped object into an array of objects
// const result = Object.keys(groupedData).map((type) => ({
// type,
// boundaries: groupedData[type],
// }));

// return result;
// }

// Define the function that groups boundary data based on hierarchy
function boundaryDataGrp(boundaryData, hierarchyDefinition) {
if (!hierarchyDefinition) return [];

const groupedData = {};

// Iterate through each boundary item in the data
boundaryData.forEach((item) => {
const { type } = item; // Extract the type
// Function to order the boundary types based on parent-child relationship
function getOrderedBoundaryTypes(hierarchy) {
const result = [];
let currentItem = hierarchy?.BoundaryHierarchy?.[0]?.boundaryHierarchy.find(item => item.parentBoundaryType === null);
while (currentItem) {
result.push(currentItem.boundaryType);
currentItem = hierarchy?.BoundaryHierarchy?.[0]?.boundaryHierarchy.find(item => item.parentBoundaryType === currentItem.boundaryType);
}
return result;
}

// Get the ordered boundary types from hierarchy
const orderedBoundaryTypes = getOrderedBoundaryTypes(hierarchyDefinition);

// If the type doesn't exist in the groupedData, create an array for it
boundaryData.forEach((item) => {
const { type } = item;
if (!groupedData[type]) {
groupedData[type] = [];
}

// Add the current item to its corresponding type array
groupedData[type].push(item);
});

// Convert the grouped object into an array of objects
const result = Object.keys(groupedData).map((type) => ({
const result = orderedBoundaryTypes.map((type) => ({
type,
boundaries: groupedData[type],
}));
boundaries: groupedData[type] || [],
})).filter(entry => entry.boundaries.length > 0);

return result;
}


const fetchResourceFile = async (tenantId, resourceIdArr) => {
const res = await Digit.CustomService.getResponse({
url: `/project-factory/v1/data/_search`,
Expand Down Expand Up @@ -80,23 +116,16 @@ const CampaignUpdateSummary = (props) => {
const noAction = searchParams.get("action");
const [showToast, setShowToast] = useState(null);
const [userCredential, setUserCredential] = useState(null);
const [deliveryErrors, setDeliveryErrors] = useState(null);
const [targetErrors, setTargetErrors] = useState(null);
const [facilityErrors, setFacilityErrors] = useState(null);
const [userErrors, setUserErrors] = useState(null);
const [cycleDatesError, setCycleDatesError] = useState(null);
const [summaryErrors, setSummaryErrors] = useState(null);
const [projectId, setprojectId] = useState(null);
const [startDate, setStartDate] = useState(null);
const [endDate, setEndDate] = useState(null);
const [cycles, setCycles] = useState([]);
const [cards, setCards] = useState([]);
const isPreview = searchParams.get("preview");
const parentId = searchParams.get("parentId");
const [key, setKey] = useState(() => {
const keyParam = searchParams.get("key");
return keyParam ? parseInt(keyParam) : 1;
});
const params = Digit.SessionStorage.get("HCM_CAMPAIGN_MANAGER_UPLOAD_ID");
const handleRedirect = (step, activeCycle) => {
const urlParams = new URLSearchParams(window.location.search);
const id = urlParams.get("id");
Expand Down Expand Up @@ -152,6 +181,30 @@ const CampaignUpdateSummary = (props) => {
// // }
// }, [props?.props?.summaryErrors]);

const reqCriteria = {
url: `/boundary-service/boundary-hierarchy-definition/_search`,
changeQueryName: `${params?.hierarchyType}`,
body: {
BoundaryTypeHierarchySearchCriteria: {
tenantId: tenantId,
limit: 2,
offset: 0,
hierarchyType: params?.hierarchyType,
},
},
};

const { data: hierarchyDefinition } = Digit.Hooks.useCustomAPIHook(reqCriteria);

function getOrderedBoundaryTypes(hierarchy) {
const result = [];
let currentItem = hierarchy?.BoundaryHierarchy?.[0]?.boundaryHierarchy?.find(item => item.parentBoundaryType === null);
while (currentItem) {
result.push(currentItem.boundaryType);
currentItem = hierarchy?.BoundaryHierarchy?.[0]?.boundaryHierarchy?.find(item => item.parentBoundaryType === currentItem.boundaryType);
}
return result;
}

const { isLoading, data, error, refetch } = Digit.Hooks.campaign.useSearchCampaign({
tenantId: tenantId,
Expand All @@ -176,7 +229,7 @@ const CampaignUpdateSummary = (props) => {
};
ss();
const target = data?.[0]?.deliveryRules;
const boundaryData = boundaryDataGrp(data?.[0]?.boundaries);
const boundaryData = boundaryDataGrp(data?.[0]?.boundaries ,hierarchyDefinition );
const hierarchyType = data?.[0]?.hierarchyType;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,21 @@ const DateWithBoundary = ({ onSelect, formData, ...props }) => {
const { state } = useLocation();
const historyState = window.history.state;
const [selectedBoundaries, setSelectedBoundaries] = useState(null);
const { data: BOUNDARY_HIERARCHY_TYPE } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "hierarchyConfig" }], {
const { data: BOUNDARY_HIERARCHY_TYPE } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{
name: "HierarchySchema",
"filter": "[?(@.type=='console')]"
}], {
select: (data) => {
return data?.[CONSOLE_MDMS_MODULENAME]?.hierarchyConfig?.find((item) => item.isActive)?.hierarchy;
return data?.[CONSOLE_MDMS_MODULENAME]?.HierarchySchema?.[0]?.hierarchy;
},
},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.hierarchyConfig` });
const { isLoading, data: hierarchyConfig } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "hierarchyConfig" }],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.hierarchyConfig` });
},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` });
const { isLoading, data: HierarchySchema } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{
name: "HierarchySchema",
"filter": "[?(@.type=='console')]"
}],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` });
const lowestHierarchy = useMemo(() => {
return hierarchyConfig?.[CONSOLE_MDMS_MODULENAME]?.hierarchyConfig?.find((item) => item.isActive)?.lowestHierarchy;
}, [hierarchyConfig]);
return HierarchySchema?.[CONSOLE_MDMS_MODULENAME]?.HierarchySchema?.[0]?.lowestHierarchy;
}, [HierarchySchema]);
const [hierarchyTypeDataresult, setHierarchyTypeDataresult] = useState([]);
const [selectedLevel, setSelectedLevel] = useState(null);
const [filteredBoundaries, setFilteredBoundaries] = useState([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ function SelectingBoundaries({ onSelect, formData, ...props }) {
const [restrictSelection, setRestrictSelection] = useState(null);
const [updateBoundary, setUpdateBoundary] = useState(null);
const [loaderEnabled, setLoaderEnabled] = useState(false);
const { isLoading, data: hierarchyConfig } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "hierarchyConfig" }],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.hierarchyConfig` });
const { isLoading, data: HierarchySchema } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME,[{
name: "HierarchySchema",
"filter": "[?(@.type=='console')]"
}],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` });

const lowestHierarchy = useMemo(() => {
return hierarchyConfig?.[CONSOLE_MDMS_MODULENAME]?.hierarchyConfig?.find(item => item.isActive)?.lowestHierarchy;
}, [hierarchyConfig]);
return HierarchySchema?.[CONSOLE_MDMS_MODULENAME]?.HierarchySchema?.find(item => item.isActive)?.lowestHierarchy;
}, [HierarchySchema]);
const lowestChild = hierarchyTypeDataresult?.boundaryHierarchy.filter((item) => item.parentBoundaryType === lowestHierarchy)?.[0]?.boundaryType;
const searchParams = new URLSearchParams(location.search);
const isDraft = searchParams.get("draft");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ const SelectingBoundariesDuplicate = ({ onSelect, formData, ...props }) => {
const tenantId = Digit.ULBService.getStateId();
const searchParams = new URLSearchParams(location.search);
const hierarchyType = props?.props?.dataParams?.hierarchyType;
const { data: hierarchyConfig } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "hierarchyConfig" }],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.hierarchyConfig` });
const { data: HierarchySchema } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{
name: "HierarchySchema",
"filter": "[?(@.type=='console')]"
}],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` });
const { data: mailConfig } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "mailConfig" }],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.mailConfig` });
const lowestHierarchy = useMemo(() => {
return hierarchyConfig?.[CONSOLE_MDMS_MODULENAME]?.hierarchyConfig?.find((item) => item.isActive)?.lowestHierarchy;
}, [hierarchyConfig]);
return HierarchySchema?.[CONSOLE_MDMS_MODULENAME]?.HierarchySchema?.[0]?.lowestHierarchy;
}, [HierarchySchema]);
const [selectedData, setSelectedData] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.selectedData || []);
const [boundaryOptions, setBoundaryOptions] = useState(
props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.boundaryData || {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ const UpdateBoundaryWrapper = ({ onSelect,...props }) => {
const id = searchParams.get("id");
const isDraft = searchParams.get("draft");
// const hierarchyType = props?.props?.hierarchyType;
const { data: hierarchyConfig } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "hierarchyConfig" }],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.hierarchyConfig` });
const { data: HierarchySchema } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{
name: "HierarchySchema",
"filter": "[?(@.type=='console')]"
}],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` });
const [selectedData, setSelectedData] = useState(props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.selectedData || []);
const [boundaryOptions, setBoundaryOptions] = useState(
props?.props?.sessionData?.HCM_CAMPAIGN_SELECTING_BOUNDARY_DATA?.boundaryType?.boundaryData || {}
);
const [hierarchyType , SetHierarchyType] = useState(props?.props?.hierarchyType);
const lowestHierarchy = useMemo(() => {
return hierarchyConfig?.[CONSOLE_MDMS_MODULENAME]?.hierarchyConfig?.find((item) => item.hierarchy === hierarchyType)?.lowestHierarchy;
}, [hierarchyConfig, hierarchyType]);
return HierarchySchema?.[CONSOLE_MDMS_MODULENAME]?.HierarchySchema?.find((item) => item.hierarchy === hierarchyType)?.lowestHierarchy;
}, [HierarchySchema, hierarchyType]);

const reqCriteriaCampaign = {
url: `/project-factory/v1/project-type/search`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1029,9 +1029,16 @@ const UploadData = ({ formData, onSelect, ...props }) => {
setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT") });
}
},
onError: (result) => {
setDownloadError(true);
setShowToast({ key: "error", label: t("ERROR_WHILE_DOWNLOADING") });
onError: (error, result) => {
const errorCode = error?.response?.data?.Errors?.[0]?.code;
if (errorCode == "NativeIoException") {
setDownloadError(true);
setShowToast({ key: "info", label: t("HCM_PLEASE_WAIT_TRY_IN_SOME_TIME") });
}
else {
setDownloadError(true);
setShowToast({ key: "error", label: t("ERROR_WHILE_DOWNLOADING") });
}
},
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export const CampaignConfig = (totalFormData, dataParams, isSubmitting, summaryE
],
},
{
stepCount: "1",
stepCount: "2",
key: "6",
body: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ export const UpdateBoundaryConfig = ({totalFormData , hierarchyType , projectTyp
customProps: {
module: "HCM",
sessionData: totalFormData,
summaryErrors: summaryErrors
summaryErrors: summaryErrors,
hierarchyType : hierarchyType
},
populators: {
name: "summary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ const SetupCampaign = ({ hierarchyType, hierarchyData }) => {
const [fetchBoundary, setFetchBoundary] = useState(() => Boolean(searchParams.get("fetchBoundary")));
const [fetchUpload, setFetchUpload] = useState(false);
const [active, setActive] = useState(0);
const { data: hierarchyConfig } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{ name: "hierarchyConfig" }],{select:(MdmsRes)=>MdmsRes},{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.hierarchyConfig` });
const { data: HierarchySchema } = Digit.Hooks.useCustomMDMS(tenantId, CONSOLE_MDMS_MODULENAME, [{
name: "HierarchySchema",
"filter": "[?(@.type=='console')]"
}],{select:(MdmsRes)=>MdmsRes},
{ schemaCode: `${CONSOLE_MDMS_MODULENAME}.HierarchySchema` });
const lowestHierarchy = useMemo(() => {
return hierarchyConfig?.[CONSOLE_MDMS_MODULENAME]?.hierarchyConfig?.find((item) => item.isActive)?.lowestHierarchy;
}, [hierarchyConfig]);
return HierarchySchema?.[CONSOLE_MDMS_MODULENAME]?.HierarchySchema?.[0]?.lowestHierarchy;
}, [HierarchySchema]);


const { data: DeliveryConfig } = Digit.Hooks.useCustomMDMS(tenantId, "HCM-PROJECT-TYPES", [{ name: "projectTypes" }], {
Expand Down Expand Up @@ -601,7 +605,7 @@ const SetupCampaign = ({ hierarchyType, hierarchyData }) => {
if (step === 6 && Object.keys(totalFormData).includes("HCM_CAMPAIGN_UPLOAD_USER_DATA")) {
setCurrentKey(14);
setCurrentStep(5);
} else if (step === 1 && totalFormData["HCM_CAMPAIGN_NAME"] && totalFormData["HCM_CAMPAIGN_TYPE"] && totalFormData["HCM_CAMPAIGN_DATE"]) {
} else if (step === 0 && totalFormData["HCM_CAMPAIGN_NAME"] && totalFormData["HCM_CAMPAIGN_TYPE"] && totalFormData["HCM_CAMPAIGN_DATE"]) {
setCurrentKey(4);
setCurrentStep(1);
} else if (!totalFormData["HCM_CAMPAIGN_NAME"] || !totalFormData["HCM_CAMPAIGN_NAME"]) {
Expand Down
Loading

0 comments on commit 79af8c4

Please sign in to comment.