Skip to content

Commit bbce8f9

Browse files
Merge pull request #120 from VineetBala-AOT/main
Make management plan name mandatory
2 parents f53d22c + 54f81fd commit bbce8f9

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515

1616
"""Service for condition attribute management."""
17+
from marshmallow import ValidationError
18+
1719
from condition_api.models.db import db
1820
from condition_api.models.condition import Condition
1921
from condition_api.models.management_plan import ManagementPlan
@@ -31,7 +33,10 @@ def update_management_plan_name(plan_id, payload):
3133

3234
# Update name if present
3335
if "name" in payload:
34-
plan.name = payload["name"]
36+
name = payload["name"]
37+
if not isinstance(name, str) or not name.strip():
38+
raise ValidationError("Management plan name cannot be blank.")
39+
plan.name = name.strip()
3540

3641
# Update is_approved if present
3742
if "is_approved" in payload:

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const ManagementPlanAccordion: React.FC<Props> = ({
6767
const [attributeHasData, setAttributeHasData] = useState(false);
6868
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
6969
const isManagementRequired = true;
70+
const [planNameError, setPlanNameError] = useState(false);
7071

7172
const {
7273
mutateAsync: updatePlanName,
@@ -170,8 +171,15 @@ const ManagementPlanAccordion: React.FC<Props> = ({
170171
const handleSavePlanName = (e: React.MouseEvent) => {
171172
e.stopPropagation();
172173
e.preventDefault();
174+
const trimmedName = planName.trim();
175+
if (!trimmedName) {
176+
setPlanNameError(true);
177+
return;
178+
}
179+
180+
setPlanNameError(false);
173181
setConditionAttributeError(false);
174-
handleUpdatePlan({ name: planName }, () => setEditMode(false));
182+
handleUpdatePlan({ name: trimmedName }, () => setEditMode(false));
175183
};
176184

177185
useEffect(() => {
@@ -303,7 +311,8 @@ const ManagementPlanAccordion: React.FC<Props> = ({
303311
<Typography>Management Plan</Typography>
304312

305313
{editMode && expanded ? (
306-
<Box display="flex" flexDirection="row" alignItems="stretch" gap={1}>
314+
<Box>
315+
<Box display="flex" flexDirection="row" alignItems="stretch" gap={1}>
307316
<TextField
308317
variant="outlined"
309318
fullWidth
@@ -345,6 +354,20 @@ const ManagementPlanAccordion: React.FC<Props> = ({
345354
<Box sx={{ color: "#255A90", fontWeight: "bold" }}>Save</Box>
346355
</Button>
347356
)}
357+
</Box>
358+
{planNameError && (
359+
<Box
360+
sx={{
361+
display: "flex",
362+
flexDirection: "row",
363+
marginTop: "-15px",
364+
color: "#CE3E39",
365+
fontSize: "14px",
366+
}}
367+
>
368+
Please enter a Management Plan Name.
369+
</Box>
370+
)}
348371
</Box>
349372
) : (
350373
<Box display="flex" alignItems="center" gap={1}>

0 commit comments

Comments
 (0)