From b4ac393ec5bbc83fc762af9c325a54b2f152f320 Mon Sep 17 00:00:00 2001 From: sujanadh Date: Wed, 6 Dec 2023 14:58:56 +0545 Subject: [PATCH 1/3] fix: returned task status as string --- src/backend/app/tasks/tasks_schemas.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/backend/app/tasks/tasks_schemas.py b/src/backend/app/tasks/tasks_schemas.py index bde911e32b..69b1e6e533 100644 --- a/src/backend/app/tasks/tasks_schemas.py +++ b/src/backend/app/tasks/tasks_schemas.py @@ -24,7 +24,7 @@ from geojson_pydantic import Feature from loguru import logger as log -from pydantic import BaseModel, ConfigDict, Field, ValidationInfo +from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, validator from pydantic.functional_validators import field_validator from app.db.postgis_utils import geometry_to_geojson, get_centroid @@ -70,6 +70,15 @@ class TaskBase(BaseModel): locked_by_username: Optional[str] = None task_history: Optional[List[TaskHistoryBase]] = None + @validator("task_status", pre=False, always=True) + def get_enum_name(cls, value, values): + if isinstance(value, int): + try: + return TaskStatus(value).name + except ValueError as e: + raise ValueError(f"Invalid integer value for task_status: {value}") from e + return value + @field_validator("outline_geojson", mode="before") @classmethod def get_geojson_from_outline(cls, v: Any, info: ValidationInfo) -> str: From 87fa51a07de24f05ff2f0ee992814db38e998f91 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 6 Dec 2023 10:14:24 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/backend/app/tasks/tasks_schemas.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/backend/app/tasks/tasks_schemas.py b/src/backend/app/tasks/tasks_schemas.py index 69b1e6e533..4cd8fe51e4 100644 --- a/src/backend/app/tasks/tasks_schemas.py +++ b/src/backend/app/tasks/tasks_schemas.py @@ -76,7 +76,9 @@ def get_enum_name(cls, value, values): try: return TaskStatus(value).name except ValueError as e: - raise ValueError(f"Invalid integer value for task_status: {value}") from e + raise ValueError( + f"Invalid integer value for task_status: {value}" + ) from e return value @field_validator("outline_geojson", mode="before") From 80f5ccab57b838c3e8e0b97ec464aabc63e03afb Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Wed, 6 Dec 2023 16:15:15 +0545 Subject: [PATCH 3/3] fix (projectDetails): taskStatus - replace task status enum with task status string --- src/frontend/src/components/DialogTaskActions.jsx | 10 +++++----- src/frontend/src/utilfunctions/getTaskStatusStyle.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/frontend/src/components/DialogTaskActions.jsx b/src/frontend/src/components/DialogTaskActions.jsx index d41bb965e3..5b0a3179c7 100755 --- a/src/frontend/src/components/DialogTaskActions.jsx +++ b/src/frontend/src/components/DialogTaskActions.jsx @@ -12,7 +12,7 @@ export default function Dialog({ taskId, feature, map, view }) { const token = CoreModules.useAppSelector((state) => state.login.loginToken); const loading = CoreModules.useAppSelector((state) => state.common.loading); const [list_of_task_status, set_list_of_task_status] = useState([]); - const [task_status, set_task_status] = useState(task_priority_str['READY']); + const [task_status, set_task_status] = useState('READY'); const geojsonStyles = MapStyles(); const dispatch = CoreModules.useAppDispatch(); @@ -34,11 +34,11 @@ export default function Dialog({ taskId, feature, map, view }) { })[0], }; const findCorrectTaskStatusIndex = environment.tasksStatus.findIndex( - (data) => data.label == task_priority_str[currentStatus.task_status], + (data) => data.label == currentStatus.task_status, ); const tasksStatus = feature.id_ != undefined ? environment.tasksStatus[findCorrectTaskStatusIndex]?.['label'] : ''; - set_task_status(task_priority_str[tasksStatus]); + set_task_status(tasksStatus); const tasksStatusList = feature.id_ != undefined ? environment.tasksStatus[findCorrectTaskStatusIndex]?.['action'] : []; @@ -53,7 +53,7 @@ export default function Dialog({ taskId, feature, map, view }) { const handleOnClick = (event) => { const status = task_priority_str[event.target.id]; const body = token != null ? { ...token } : {}; - const geoStyle = geojsonStyles[status]; + const geoStyle = geojsonStyles[event.target.id]; if (event.target.id != undefined) { if (body.hasOwnProperty('id')) { dispatch( @@ -103,7 +103,7 @@ export default function Dialog({ taskId, feature, map, view }) { {/* {`STATUS : ${task_status?.toString()?.replaceAll('_', ' ')}`} */} - {`STATUS : ${task_priority_str[task_status]}`} + {`STATUS : ${task_status}`} { let id = feature.getId().toString().replace('_', ','); - const status = task_priority_str[id.split(',')[1]]; + const status = id.split(',')[1]; const lockedPolygonStyle = createPolygonStyle(mapTheme.palette.mapFeatureColors.locked_for_mapping_rgb, strokeColor); const lockedValidationStyle = createPolygonStyle( mapTheme.palette.mapFeatureColors.locked_for_validation_rgb,