From 6ec8f172e958a1db33fa300b5bc382529834ff80 Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Fri, 10 May 2024 13:57:29 +0545 Subject: [PATCH 1/9] feat(project): updateEntityStatus add to update entity status --- src/frontend/src/api/Project.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/frontend/src/api/Project.js b/src/frontend/src/api/Project.js index ea25faac08..3f0c68cbdd 100755 --- a/src/frontend/src/api/Project.js +++ b/src/frontend/src/api/Project.js @@ -298,3 +298,19 @@ export const GetProjectTaskActivity = (url) => { await getProjectActivity(url); }; }; + +export const UpdateEntityStatus = (url, payload) => { + return async (dispatch) => { + const updateEntityStatus = async (url, payload) => { + try { + dispatch(ProjectActions.UpdateEntityStatusLoading(true)); + const response = await CoreModules.axios.post(url, payload); + dispatch(ProjectActions.UpdateEntityStatus(response.data)); + dispatch(ProjectActions.UpdateEntityStatusLoading(false)); + } catch (error) { + dispatch(ProjectActions.UpdateEntityStatusLoading(false)); + } + }; + await updateEntityStatus(url, payload); + }; +}; From 4d58ac8eaa610e04826de2307888ad17cec987fe Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Fri, 10 May 2024 13:59:03 +0545 Subject: [PATCH 2/9] feat(project): reducer function to update entityStatus and track entityUpdateLoading state --- src/frontend/src/store/slices/ProjectSlice.ts | 13 +++++++++++++ src/frontend/src/store/types/IProject.ts | 1 + 2 files changed, 14 insertions(+) diff --git a/src/frontend/src/store/slices/ProjectSlice.ts b/src/frontend/src/store/slices/ProjectSlice.ts index 82a4cdec0f..d72e322b94 100755 --- a/src/frontend/src/store/slices/ProjectSlice.ts +++ b/src/frontend/src/store/slices/ProjectSlice.ts @@ -32,6 +32,7 @@ const initialState: ProjectStateTypes = { }, entityOsmMap: [], entityOsmMapLoading: false, + updateEntityStatusLoading: false, projectDashboardLoading: false, geolocationStatus: false, projectCommentsList: [], @@ -141,6 +142,18 @@ const ProjectSlice = createSlice({ UpdateProjectTaskActivity(state, action) { state.projectTaskActivity = [action.payload, ...state.projectTaskActivity]; }, + UpdateEntityStatusLoading(state, action) { + state.updateEntityStatusLoading = action.payload; + }, + UpdateEntityStatus(state, action) { + const updatedEntityOsmMap = state.entityOsmMap?.map((entity) => { + if (entity.id === action.payload.id) { + return action.payload; + } + return entity; + }); + state.entityOsmMap = updatedEntityOsmMap; + }, }, }); diff --git a/src/frontend/src/store/types/IProject.ts b/src/frontend/src/store/types/IProject.ts index ab7c4f38fd..200cd33bc5 100644 --- a/src/frontend/src/store/types/IProject.ts +++ b/src/frontend/src/store/types/IProject.ts @@ -26,6 +26,7 @@ export type ProjectStateTypes = { projectDashboardDetail: projectDashboardDetailTypes; entityOsmMap: EntityOsmMap[]; entityOsmMapLoading: boolean; + updateEntityStatusLoading: boolean; projectDashboardLoading: boolean; geolocationStatus: boolean; projectCommentsList: projectCommentsListTypes[]; From 6516fef34d58839f7d2b6fdadb366ea3df7fe2dc Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Fri, 10 May 2024 14:21:58 +0545 Subject: [PATCH 3/9] fix(taskSlice): initial state for selectedFeatureProps --- src/frontend/src/store/slices/TaskSlice.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/store/slices/TaskSlice.ts b/src/frontend/src/store/slices/TaskSlice.ts index d8299d7cea..dda28ab5f2 100644 --- a/src/frontend/src/store/slices/TaskSlice.ts +++ b/src/frontend/src/store/slices/TaskSlice.ts @@ -8,7 +8,13 @@ const initialState: TaskStateTypes = { taskLoading: false, taskInfo: [], selectedTask: null, - selectedFeatureProps: null, + selectedFeatureProps: { + osm_id: 0, + tags: '', + timestamp: '', + version: 0, + changeset: 0, + }, projectBoundaryLoading: false, projectBoundary: [], convertToOsmLoading: false, From 81bce897ece8db56e57afca2aa7acedf616e0eaf Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Fri, 10 May 2024 14:23:02 +0545 Subject: [PATCH 4/9] feat(ITask): taskFeatureSelectionProperties type add --- src/frontend/src/store/types/ITask.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/frontend/src/store/types/ITask.ts b/src/frontend/src/store/types/ITask.ts index df7e7ae0ce..0e1870384d 100644 --- a/src/frontend/src/store/types/ITask.ts +++ b/src/frontend/src/store/types/ITask.ts @@ -4,7 +4,7 @@ export type TaskStateTypes = { taskLoading: boolean; taskInfo: taskSubmissionInfoType[]; selectedTask: number | null; - selectedFeatureProps: number | null; + selectedFeatureProps: TaskFeatureSelectionProperties; projectBoundaryLoading: boolean; projectBoundary: []; convertToOsmLoading: boolean; @@ -18,3 +18,11 @@ type downloadSubmissionLoadingTypes = { type: '' | 'json' | 'csv'; loading: boolean; }; + +export type TaskFeatureSelectionProperties = { + osm_id: number; + tags: string; + timestamp: string; + version: number; + changeset: number; +}; From 3e096f63e5eee490e262adf124db164b4ca933ef Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Fri, 10 May 2024 14:27:45 +0545 Subject: [PATCH 5/9] feat(projectDetailsV2): taskId, taskFeature props pass to featureSlectionPopup component --- src/frontend/src/views/ProjectDetailsV2.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/views/ProjectDetailsV2.tsx b/src/frontend/src/views/ProjectDetailsV2.tsx index b76242c7cf..82a515ac7e 100644 --- a/src/frontend/src/views/ProjectDetailsV2.tsx +++ b/src/frontend/src/views/ProjectDetailsV2.tsx @@ -206,7 +206,7 @@ const Home = () => { */ const projectClickOnTaskFeature = (properties, feature) => { // Close task area popup, open task feature popup - setSelectedTaskArea(undefined); + // setSelectedTaskArea(undefined); setSelectedTaskFeature(feature); dispatch(CoreModules.TaskActions.SetSelectedFeatureProps(properties)); @@ -573,7 +573,7 @@ const Home = () => { )} - {selectedTaskArea != undefined && ( + {selectedTaskArea != undefined && selectedTaskFeature === undefined && ( { } /> )} - {selectedTaskFeature != undefined && } + {selectedTaskFeature != undefined && selectedTask && selectedTaskArea && ( + + )} ); }; From add3af402b45e51c37ff8860d341763d3be8194b Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Fri, 10 May 2024 14:29:02 +0545 Subject: [PATCH 6/9] feat(featureSlectionPopup): post update entity status on Map In ODK button click --- .../FeatureSelectionPopup.tsx | 60 +++++++++++++++---- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/src/frontend/src/components/ProjectDetailsV2/FeatureSelectionPopup.tsx b/src/frontend/src/components/ProjectDetailsV2/FeatureSelectionPopup.tsx index cf8310f727..c518744807 100644 --- a/src/frontend/src/components/ProjectDetailsV2/FeatureSelectionPopup.tsx +++ b/src/frontend/src/components/ProjectDetailsV2/FeatureSelectionPopup.tsx @@ -1,28 +1,53 @@ // Popup used to display task feature info & link to ODK Collect -import React from 'react'; +import React, { useEffect, useState } from 'react'; import CoreModules from '@/shared/CoreModules'; import AssetModules from '@/shared/AssetModules'; import Button from '@/components/common/Button'; import { ProjectActions } from '@/store/slices/ProjectSlice'; - -type TaskFeatureSelectionProperties = { - osm_id: number; - tags: string; - timestamp: string; - version: number; - changeset: number; -}; +import environment from '@/environment'; +import { useParams } from 'react-router-dom'; +import { UpdateEntityStatus } from '@/api/Project'; +import { TaskFeatureSelectionProperties } from '@/store/types/ITask'; type TaskFeatureSelectionPopupPropType = { featureProperties: TaskFeatureSelectionProperties | null; + taskId: number; + taskFeature: Record; }; -const TaskFeatureSelectionPopup = ({ featureProperties }: TaskFeatureSelectionPopupPropType) => { +const TaskFeatureSelectionPopup = ({ featureProperties, taskId, taskFeature }: TaskFeatureSelectionPopupPropType) => { const dispatch = CoreModules.useAppDispatch(); + const params = useParams(); const taskModalStatus = CoreModules.useAppSelector((state) => state.project.taskModalStatus); const projectInfo = CoreModules.useAppSelector((state) => state.project.projectInfo); const entityOsmMap = CoreModules.useAppSelector((state) => state.project.entityOsmMap); + + const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails); + const currentProjectId = params.id; + const [task_status, set_task_status] = useState('READY'); + const projectData = CoreModules.useAppSelector((state) => state.project.projectTaskBoundries); + const projectIndex = projectData.findIndex((project) => project.id == currentProjectId); + const projectTaskActivityList = CoreModules.useAppSelector((state) => state?.project?.projectTaskActivity); + const taskBoundaryData = CoreModules.useAppSelector((state) => state.project.projectTaskBoundries); + const updateEntityStatusLoading = CoreModules.useAppSelector((state) => state.project.updateEntityStatusLoading); + const currentTaskInfo = { + ...taskBoundaryData?.[projectIndex]?.taskBoundries?.filter((task) => { + return task?.index == taskId; + })?.[0], + }; + const entity = entityOsmMap.find((x) => x.osm_id === featureProperties?.osm_id); + + useEffect(() => { + if (projectIndex != -1) { + const currentStatus = projectTaskActivityList.length > 0 ? projectTaskActivityList[0].status : 'READY'; + const findCorrectTaskStatusIndex = environment.tasksStatus.findIndex((data) => data?.label == currentStatus); + const tasksStatus = + taskFeature?.id_ != undefined ? environment?.tasksStatus[findCorrectTaskStatusIndex]?.['label'] : ''; + set_task_status(tasksStatus); + } + }, [projectTaskActivityList, taskId, taskFeature, entityOsmMap]); + return (
-
-
-
+ if (!formName || !entityUuid) { + return; + } + dispatch( + UpdateEntityStatus(`${import.meta.env.VITE_API_URL}/projects/${currentProjectId}/entity/status`, { + entity_id: entityUuid, + status: 1, + label: '', + }), + ); + if (task_status === 'READY') { + dispatch( + ProjectTaskStatus( + `${import.meta.env.VITE_API_URL}/tasks/${currentTaskInfo?.id}/new-status/1`, + geoStyle, + taskBoundaryData, + currentProjectId, + taskFeature, + map, + view, + taskId, + authDetails, + { project_id: currentProjectId }, + ), + ); + } + + document.location.href = `odkcollect://form/${formName}?existing=${entityUuid}`; + }} + /> + + )} );