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 1 commit
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 @@ -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