Skip to content

Commit

Permalink
refactor: task status fetched from enums (#1082)
Browse files Browse the repository at this point in the history
* hotfix: location str in create project

* import field_validator

* fix: task_locked_by uid and username

* fix: task_status value obtained from enums

* refactor: remove unused vars from tasks_schemas

---------

Co-authored-by: sujanadh <sujanadh07@gmail.com>
Co-authored-by: spwoodcock <sam.woodcock@protonmail.com>
  • Loading branch information
3 people authored Jan 8, 2024
1 parent 7bde9b5 commit 6d86c66
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/backend/app/projects/project_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from app.models.enums import ProjectPriority, ProjectStatus, TaskSplitType
from app.tasks import tasks_schemas
from app.users.user_schemas import User
from pydantic.functional_validators import field_validator


class ODKCentral(BaseModel):
Expand Down
12 changes: 6 additions & 6 deletions src/backend/app/tasks/tasks_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ def get_centroid_from_outline(cls, value: Any, info: ValidationInfo) -> str:
return None

@field_serializer("locked_by_uid")
def get_lock_uid(self, value: int, info: ValidationInfo) -> str:
def get_locked_by_uid(self, value: str) -> str:
"""Get lock uid from lock_holder details."""
if lock_holder := info.data.get("lock_holder"):
return lock_holder.id
if self.lock_holder:
return self.lock_holder.id
return None

@field_serializer("locked_by_username")
def get_lock_username(self, value: str, info: ValidationInfo) -> str:
def get_locked_by_username(self, value: str) -> str:
"""Get lock username from lock_holder details."""
if lock_holder := info.data.get("lock_holder"):
return lock_holder.username
if self.lock_holder:
return self.lock_holder.username
return None


Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/api/Project.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ProjectActions } from '../store/slices/ProjectSlice';
import CoreModules from '../shared/CoreModules';
import environment from '../environment';
import {task_priority_str} from '../types/enums'

export const ProjectById = (existingProjectList, projectId) => {
return async (dispatch) => {
Expand All @@ -20,7 +21,7 @@ export const ProjectById = (existingProjectList, projectId) => {
return {
id: data.id,
project_task_name: data.project_task_name,
task_status: data.task_status,
task_status: task_priority_str[data.task_status],
outline_geojson: data.outline_geojson,
outline_centroid: data.outline_centroid,
task_history: data.task_history,
Expand Down
4 changes: 3 additions & 1 deletion src/frontend/src/api/ProjectTaskStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { easeIn, easeOut } from 'ol/easing';
import { HomeActions } from '../store/slices/HomeSlice';
import CoreModules from '../shared/CoreModules';
import { CommonActions } from '../store/slices/CommonSlice';
import {task_priority_str} from '../types/enums'

const UpdateTaskStatus = (url, style, existingData, currentProjectId, feature, map, view, taskId, body) => {
return async (dispatch) => {
const index = existingData.findIndex((project) => project.id == currentProjectId);
Expand All @@ -14,7 +16,7 @@ const UpdateTaskStatus = (url, style, existingData, currentProjectId, feature, m
const findIndexForUpdation = existingData[index].taskBoundries.findIndex((obj) => obj.id == response.data.id);

let project_tasks = [...existingData[index].taskBoundries];
project_tasks[findIndexForUpdation] = { ...response.data };
project_tasks[findIndexForUpdation] = { ...response.data, task_status: task_priority_str[response.data.task_status] };

let updatedProject = [...existingData];
const finalProjectOBJ = {
Expand Down

0 comments on commit 6d86c66

Please sign in to comment.