Skip to content

Commit 94ad3b0

Browse files
Merge pull request #117 from VineetBala-AOT/main
Fix issue of condition not getting approved even if all MP are approved
2 parents e3e93e5 + c67b86f commit 94ad3b0

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

condition-api/src/condition_api/services/condition_service.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,22 +680,24 @@ def _build_nested_subconditions(condition_id):
680680
nested_subconditions = []
681681

682682
for row in sub_condition_data:
683-
subcond = {
683+
subcondition_map[row.subcondition_id] = {
684684
"subcondition_id": row.subcondition_id,
685685
"subcondition_identifier": row.subcondition_identifier,
686686
"subcondition_text": row.subcondition_text,
687687
"sort_order": row.sort_order,
688688
"subconditions": []
689689
}
690690

691-
subcondition_map[row.subcondition_id] = subcond
692-
691+
for row in sub_condition_data:
692+
current = subcondition_map[row.subcondition_id]
693693
if row.parent_subcondition_id:
694694
parent = subcondition_map.get(row.parent_subcondition_id)
695695
if parent:
696-
parent["subconditions"].append(subcond)
696+
parent["subconditions"].append(current)
697+
else:
698+
nested_subconditions.append(current)
697699
else:
698-
nested_subconditions.append(subcond)
700+
nested_subconditions.append(current)
699701

700702
return nested_subconditions
701703

condition-web/src/components/ConditionDetails/ConditionAttribute/ManagementPlan/ManagementPlanAccordion.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ const ManagementPlanAccordion: React.FC<Props> = ({
205205
}
206206
}, [conditionAttributeDetails]);
207207

208-
const handleApprovePlan = (e: React.MouseEvent) => {
208+
const handleApprovePlan = async (e: React.MouseEvent) => {
209209
e.stopPropagation();
210210
e.preventDefault();
211211

@@ -233,21 +233,25 @@ const ManagementPlanAccordion: React.FC<Props> = ({
233233
setConditionAttributeError(false);
234234

235235
const currentApproval = attributes.is_approved;
236-
handleUpdatePlan({ is_approved: !currentApproval });
237-
238-
const allPlans = condition.condition_attributes?.management_plans || [];
239-
240-
// Return early if there are no plans
241-
if (allPlans.length === 0) return;
242-
243-
const allApproved = allPlans.every((plan) => plan.is_approved);
244-
245-
// Only update if condition doesn't match the derived value
246-
if (condition.is_condition_attributes_approved !== allApproved) {
247-
updateConditionDetails({
248-
is_condition_attributes_approved: allApproved,
249-
});
250-
}
236+
await handleUpdatePlan(
237+
{ is_approved: !currentApproval },
238+
() => {
239+
const updatedPlans = condition.condition_attributes?.management_plans || [];
240+
241+
if (updatedPlans.length === 0) return;
242+
243+
const allApproved = updatedPlans.every((plan) => plan.id === attributes.id
244+
? !currentApproval // this one just got toggled
245+
: plan.is_approved
246+
);
247+
248+
if (condition.is_condition_attributes_approved !== allApproved) {
249+
updateConditionDetails({
250+
is_condition_attributes_approved: allApproved,
251+
});
252+
}
253+
}
254+
);
251255

252256
};
253257

0 commit comments

Comments
 (0)