Skip to content

Commit

Permalink
Revert "Allowed to update the name of microplan (#1795)" (#1812)
Browse files Browse the repository at this point in the history
This reverts commit e32aad6.

Co-authored-by: Nipun Arora <aroranipun1@gmail.com>
  • Loading branch information
rachana-egov and nipunarora-eGov authored Nov 12, 2024
1 parent cd57493 commit 5bc4a38
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "@egovernments/digit-ui-react-components";
import { useTranslation } from "react-i18next";
import { useMyContext } from "../utils/context";
import { InfoCard, Modal, Toast, FieldV1, LabelFieldPair } from "@egovernments/digit-ui-components";
import { InfoCard, Modal, Toast, FieldV1,LabelFieldPair} from "@egovernments/digit-ui-components";
import { Card as CardNew, ViewCard } from "@egovernments/digit-ui-components";

const MicroplanDetails = ({ onSelect, props: customProps, ...props }) => {
Expand All @@ -25,7 +25,7 @@ const MicroplanDetails = ({ onSelect, props: customProps, ...props }) => {
);
const [executionCount, setExecutionCount] = useState(0);
const { campaignId, microplanId, key, ...queryParams } = Digit.Hooks.useQueryParams();
//const [isFreezed, setIsFreezed] = useState(campaignId && microplanId ? true : false);
const [isFreezed, setIsFreezed] = useState(campaignId && microplanId ? true : false);
const campaignData = customProps?.sessionData?.CAMPAIGN_DETAILS?.campaignDetails;
const campaignCard = [
{
Expand Down Expand Up @@ -119,7 +119,7 @@ const MicroplanDetails = ({ onSelect, props: customProps, ...props }) => {
placeholder={t("MICROPLAN_NAME_INPUT_PLACEHOLDER")}
value={microplan}
onChange={onChangeMicroplanName}
// disabled={isFreezed}
disabled={isFreezed}
/>
</div>
</LabelFieldPair>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from "lodash";
const requestBodyGenerator = () => { };
const requestBodyGenerator = () => {};
//checking for duplicates
const isValidResourceName = async (name) => {
try {
Expand Down Expand Up @@ -59,7 +59,6 @@ const CreateResource = async (req) => {
tenantId: Digit.ULBService.getCurrentTenantId(),
action: "draft",
parentId: null,
startDate: Math.floor(new Date(new Date().setDate(new Date().getDate() + 30)).getTime()), //hardcoding this rn to update campaign. Check with admin console team
campaignName: totalFormData?.MICROPLAN_DETAILS?.microplanDetails?.microplanName,
resources: [],
projectType: totalFormData?.CAMPAIGN_DETAILS?.campaignDetails?.campaignType?.code,
Expand Down Expand Up @@ -114,54 +113,6 @@ const CreateResource = async (req) => {
}
};

/// we will update the name of microplan and and campaign
const UpdateResource = async (req, currentPlanObject, currentCampaignObject) => {
//creating a microplan and campaign instance here
const { totalFormData, state, setShowToast, setCurrentKey, setCurrentStep, config, campaignObject, planObject } = req;
try {

// Update the campaign object by keeping existing properties and only changing the name
const updatedCampaignObject = {
...currentCampaignObject,
campaignName: totalFormData?.MICROPLAN_DETAILS?.microplanDetails?.microplanName,
};

const campaignRes = await Digit.CustomService.getResponse({
url: "/project-factory/v1/project-type/update",
body: {
CampaignDetails: updatedCampaignObject,
},
});

// Update the plan object by keeping existing properties and only changing the name
const updatedPlanObject = {
...currentPlanObject,
name: totalFormData?.MICROPLAN_DETAILS?.microplanDetails?.microplanName,
};

const planRes = await Digit.CustomService.getResponse({
url: "/plan-service/config/_update",
useCache: false,
method: "POST",
userService: true,
body: {
PlanConfiguration: updatedPlanObject
},
});

if (campaignRes?.CampaignDetails?.id && planRes?.PlanConfiguration?.[0]?.id) {
return true;
}
return false;
} catch (error) {
if (!error?.response?.data?.Errors[0].description) {
throw new Error(error?.response?.data?.Errors[0].code);
} else {
throw new Error(error?.response?.data?.Errors[0].description);
}
}
};

const searchPlanConfig = async (body) => {
//assuming it will be success
const response = await Digit.CustomService.getResponse({
Expand Down Expand Up @@ -236,7 +187,6 @@ const createUpdatePlanProject = async (req) => {

const triggeredFrom = config.name;
switch (triggeredFrom) {
// the screens will be freezed so don't need to do anything
case "CAMPAIGN_DETAILS":
setCurrentKey((prev) => prev + 1);
setCurrentStep((prev) => prev + 1);
Expand All @@ -245,39 +195,12 @@ const createUpdatePlanProject = async (req) => {
};

case "MICROPLAN_DETAILS":

/// updating these changes becuase now we will update the campaign and microplan name


//here just check if microplanId and campaignId is already available(we will update the name only)
//both the screens will be freezed so don't need to do anything
//here just check if microplanId and campaignId is already there then don't do anything (details will be freezed so only create will be required no update)
if (microplanId && campaignId) {

// if current name is same as previous name do not need to do anything
if (planObject?.name === totalFormData?.MICROPLAN_DETAILS?.microplanDetails?.microplanName) {
setCurrentKey((prev) => prev + 1);
setCurrentStep((prev) => prev + 1);
return;
}

// check if the name is valid
const isResourceNameValid = await isValidResourceName(totalFormData?.MICROPLAN_DETAILS?.microplanDetails?.microplanName);
if (!isResourceNameValid) {
setShowToast({ key: "error", label: "ERROR_MICROPLAN_NAME_ALREADY_EXISTS" });
return;
}
// we will udpate the current planobject and campaign object
const isResourceCreated = await UpdateResource(req, planObject, campaignObject);
if (!isResourceCreated) {
setShowToast({ key: "error", label: "ERROR_CREATING_MICROPLAN" });
return;
}
setCurrentKey((prev) => prev + 1);
setCurrentStep((prev) => prev + 1);

return {
triggeredFrom,
};

return;
}
//if we reach here then we need to create a plan and project instance
// validate campaign and microplan name feasible or not -> search campaign + search plan
Expand Down Expand Up @@ -324,6 +247,8 @@ const createUpdatePlanProject = async (req) => {
const updatedCampaignObject = {
...campaignObjectForBoundary,
boundaries: totalFormData?.BOUNDARY?.boundarySelection?.selectedData,
startDate: Math.floor(new Date(new Date().setDate(new Date().getDate() + 100)).getTime()),
//hardcoding this rn to update campaign. Check with admin console team
};
const campaignResBoundary = await updateProject(updatedCampaignObject);
await new Promise((resolve) => setTimeout(resolve, 5000));
Expand All @@ -342,14 +267,14 @@ const createUpdatePlanProject = async (req) => {
files:
fetchedPlanForBoundaryInvalidate?.files?.length > 0
? fetchedPlanForBoundaryInvalidate?.files?.map((file) => {
return {
...file,
active: false,
};
})
return {
...file,
active: false,
};
})
: [],
};

// update plan object
const planUpdateForBoundaryInvalidation = await updatePlan(updatedPlanObjectForBoundaryInvalidate);
if (planUpdateForBoundaryInvalidation) {
Expand All @@ -358,7 +283,7 @@ const createUpdatePlanProject = async (req) => {
// setCurrentStep((prev) => prev + 1);
return {
triggeredFrom,
invalidateSession: true
invalidateSession:true
};
} else {
setShowToast({ key: "error", label: "ERR_BOUNDARY_UPDATE" });
Expand All @@ -367,8 +292,8 @@ const createUpdatePlanProject = async (req) => {
case "ASSUMPTIONS_FORM":
// here we have to invalidate the existing assumptions in update call if there is a change in assumptionsForm
// check whether the currentAssumptionsForm is equal to prev assumptionsForm (if so then skip this update call)

if (_.isEqual(planObject?.additionalDetails?.assumptionsForm, totalFormData?.ASSUMPTIONS_FORM?.assumptionsForm) && Object.keys(planObject?.additionalDetails?.assumptionsForm).length > 0) {
if (_.isEqual(planObject?.additionalDetails?.assumptionsForm, totalFormData?.ASSUMPTIONS_FORM?.assumptionsForm) && Object.keys(planObject?.additionalDetails?.assumptionsForm).length>0) {
setCurrentKey((prev) => prev + 1);
setCurrentStep((prev) => prev + 1);
return {
Expand All @@ -380,20 +305,20 @@ const createUpdatePlanProject = async (req) => {
const invalidatedAssumptions =
planObject.assumptions.length > 0
? planObject.assumptions.map((row) => {
return {
...row,
active: false,
};
})
return {
...row,
active: false,
};
})
: [];
const invalidatedOperations =
planObject.operations.length > 0
? planObject.operations.map((row) => {
return {
...row,
active: false,
};
})
return {
...row,
active: false,
};
})
: [];
const updatedPlanObjAssumptionsForm = {
...planObject,
Expand Down Expand Up @@ -426,7 +351,7 @@ const createUpdatePlanProject = async (req) => {
// setCurrentStep((prev) => prev + 1);
return {
triggeredFrom,
invalidateSession: true
invalidateSession:true
};
} else {
setShowToast({ key: "error", label: "ERR_ASSUMPTIONS_FORM_UPDATE" });
Expand Down Expand Up @@ -481,12 +406,12 @@ const createUpdatePlanProject = async (req) => {
const prevAssumptionsForSubHypothesis =
fetchedPlanForSubHypothesis?.assumptions.length > 0
? fetchedPlanForSubHypothesis?.assumptions?.map((row) => {
const updatedRow = {
...row,
active: false,
};
return updatedRow;
})
const updatedRow = {
...row,
active: false,
};
return updatedRow;
})
: [];

//get the list of assumptions from UI
Expand Down Expand Up @@ -556,7 +481,7 @@ const createUpdatePlanProject = async (req) => {
setShowToast({ key: "error", label: "ERR_ASSUMPTIONS_FORM_UPDATE" });
}

case "SUB_FORMULA":
case "SUB_FORMULA":
//first fetch current plan object
const fetchedPlanForSubFormula = await searchPlanConfig({
PlanConfigurationSearchCriteria: {
Expand All @@ -568,25 +493,25 @@ const createUpdatePlanProject = async (req) => {
const prevFormulaValues =
fetchedPlanForSubFormula?.operations.length > 0
? fetchedPlanForSubFormula?.operations?.map((row) => {
const updatedRow = {
...row,
active: false,
};
return updatedRow;
})
const updatedRow = {
...row,
active: false,
};
return updatedRow;
})
: [];

//get the list of assumptions from UI
const formulasToUpdateFromUIForSubFormula = req?.formulasToUpdate?.filter((row) => {
return row.category && row.output && row.input && row.operatorName && row.assumptionValue;
})
?.map((row) => {
const updatedRow = { ...row };
const operatorName = row?.operatorName;
delete updatedRow?.operatorName;
updatedRow.operator = state?.RuleConfigureOperators?.find((operation) => operation.operatorName === operatorName)?.operatorCode;
return updatedRow;
});
?.map((row) => {
const updatedRow = { ...row };
const operatorName = row?.operatorName;
delete updatedRow?.operatorName;
updatedRow.operator = state?.RuleConfigureOperators?.find((operation) => operation.operatorName === operatorName)?.operatorCode;
return updatedRow;
});
//mix the current + api res
const upatedPlanObjSubFormula = {
...fetchedPlanForSubFormula,
Expand All @@ -596,7 +521,7 @@ const createUpdatePlanProject = async (req) => {
await updatePlan(upatedPlanObjSubFormula);
return;


case "UPLOADBOUNDARYDATA":
const fetchedPlanForBoundary = await searchPlanConfig({
PlanConfigurationSearchCriteria: {
Expand Down

0 comments on commit 5bc4a38

Please sign in to comment.