Skip to content

Commit

Permalink
fix(frontend): tweak frontend to use TaskAction enum for now
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Oct 25, 2024
1 parent 6175134 commit 94edd62
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 32 deletions.
11 changes: 6 additions & 5 deletions src/frontend/src/components/DialogTaskActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function Dialog({ taskId, feature }: dialogPropType) {
const geojsonStyles = MapStyles();

const [list_of_task_status, set_list_of_task_status] = useState<taskListstatusType[]>([]);
const [task_status, set_task_status] = useState('READY');
const [task_status, set_task_status] = useState('RELEASED_FOR_MAPPING');
const [currentTaskInfo, setCurrentTaskInfo] = useState<taskSubmissionInfoType>();
const [toggleMappedConfirmationModal, setToggleMappedConfirmationModal] = useState(false);

Expand All @@ -46,7 +46,7 @@ export default function Dialog({ taskId, feature }: dialogPropType) {
const projectIndex = projectData.findIndex((project) => project.id == parseInt(currentProjectId));
const currentStatus = {
...taskBoundaryData?.[projectIndex]?.taskBoundries?.filter((task) => {
return task?.index == taskId;
return task?.id == taskId;
})?.[0],
};
const checkIfTaskAssignedOrNot =
Expand All @@ -64,15 +64,16 @@ export default function Dialog({ taskId, feature }: dialogPropType) {

useEffect(() => {
if (taskInfo?.length === 0) return;
const currentTaskInfo = taskInfo?.filter((task) => taskId.toString() === task?.index);
const currentTaskInfo = taskInfo?.filter((task) => taskId.toString() === task?.task_id);
if (currentTaskInfo?.[0]) {
setCurrentTaskInfo(currentTaskInfo?.[0]);
}
}, [taskId, taskInfo]);

useEffect(() => {
if (projectIndex != -1) {
const currentStatus = projectTaskActivityList.length > 0 ? projectTaskActivityList[0].status : 'READY';
const currentStatus =
projectTaskActivityList.length > 0 ? projectTaskActivityList[0].status : 'RELEASED_FOR_MAPPING';
const findCorrectTaskStatusIndex = environment.tasksStatus.findIndex((data) => data.label == currentStatus);
const tasksStatus =
feature.id_ != undefined ? environment.tasksStatus[findCorrectTaskStatusIndex]?.['label'] : '';
Expand Down Expand Up @@ -210,7 +211,7 @@ export default function Dialog({ taskId, feature }: dialogPropType) {
})}
</div>
)}
{task_status !== 'READY' && task_status !== 'LOCKED_FOR_MAPPING' && (
{task_status !== 'RELEASED_FOR_MAPPING' && task_status !== 'LOCKED_FOR_MAPPING' && (
<div className="fmtm-p-2 sm:fmtm-p-5 fmtm-border-t">
<Button
btnText="GO TO TASK SUBMISSION"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const ActivitiesPanel = ({ defaultTheme, state, params, map }: activitiesPanelTy
let geojson: Record<string, any> = {};
const index = state.findIndex((project) => project.id == params.id);
if (index != -1) {
const taskIndex = state[index]?.taskBoundries.findIndex((task) => task?.index == taskId);
const taskIndex = state[index]?.taskBoundries.findIndex((task) => task?.id == taskId);
if (index != -1) {
geojson = state[index]?.taskBoundries[taskIndex]?.outline;
}
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/components/ProjectDetailsV2/Comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ const Comments = () => {
const taskBoundaryData = useAppSelector((state) => state.project.projectTaskBoundries);
const currentStatus = {
...taskBoundaryData?.[projectIndex]?.taskBoundries?.filter((task) => {
return task?.index == selectedTask;
return task?.id == selectedTask;
})?.[0],
};
const filteredProjectCommentsList = projectCommentsList?.filter(
(comment) => !comment?.action_text?.includes('-SUBMISSION_INST-'),
);

useEffect(() => {
console.log(currentStatus);
dispatch(
GetProjectComments(
`${import.meta.env.VITE_API_URL}/tasks/${currentStatus?.id}/history/?project_id=${projectId}&comment=true`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,25 @@ const TaskFeatureSelectionPopup = ({ featureProperties, taskId, taskFeature }: T

const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails);
const currentProjectId = params.id || '';
const [task_status, set_task_status] = useState('READY');
const [task_status, set_task_status] = useState('RELEASED_FOR_MAPPING');
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;
return task?.id == taskId;
})?.[0],
};
const geoStyle = geojsonStyles['LOCKED_FOR_MAPPING'];
const entity = entityOsmMap.find((x) => x.osm_id === featureProperties?.osm_id);

useEffect(() => {
console.log(currentTaskInfo);
if (projectIndex != -1) {
const currentStatus = projectTaskActivityList.length > 0 ? projectTaskActivityList[0].status : 'READY';
const currentStatus =
projectTaskActivityList.length > 0 ? projectTaskActivityList[0].status : 'RELEASED_FOR_MAPPING';
const findCorrectTaskStatusIndex = environment.tasksStatus.findIndex((data) => data?.label == currentStatus);
const tasksStatus =
taskFeature?.id_ != undefined ? environment?.tasksStatus[findCorrectTaskStatusIndex]?.['label'] : '';
Expand Down Expand Up @@ -106,7 +108,7 @@ const TaskFeatureSelectionPopup = ({ featureProperties, taskId, taskFeature }: T
</p>
</div>
</div>
{(task_status === 'READY' || task_status === 'LOCKED_FOR_MAPPING') && (
{(task_status === 'RELEASED_FOR_MAPPING' || task_status === 'LOCKED_FOR_MAPPING') && (
<div className="fmtm-p-2 sm:fmtm-p-5 fmtm-border-t">
<Button
btnText="MAP FEATURE IN ODK"
Expand All @@ -132,7 +134,7 @@ const TaskFeatureSelectionPopup = ({ featureProperties, taskId, taskFeature }: T
}),
);

if (task_status === 'READY') {
if (task_status === 'RELEASED_FOR_MAPPING') {
dispatch(
UpdateTaskStatus(
`${import.meta.env.VITE_API_URL}/tasks/${currentTaskInfo?.id}/new-status/1`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const ProjectInfo: React.FC = () => {
const projectTotalFeatures: number = projectEntities.length;

const projectMappedFeatures: number = projectEntities.filter(
// FIXME this needs updating as entity status is numerical
(entity: EntityOsmMap) => entity.status === task_status.MAPPED,
).length;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const TaskSelectionPopup = ({ taskId, body, feature }: TaskSelectionPopupPropTyp
const dispatch = CoreModules.useAppDispatch();

const currentProjectId: string = params.id;
const [task_status, set_task_status] = useState('READY');
const [task_status, set_task_status] = useState('RELEASED_FOR_MAPPING');

const taskModalStatus = useAppSelector((state) => state.project.taskModalStatus);
const projectData = useAppSelector((state) => state.project.projectTaskBoundries);
Expand All @@ -37,12 +37,12 @@ const TaskSelectionPopup = ({ taskId, body, feature }: TaskSelectionPopupPropTyp
if (projectIndex != -1) {
const currentStatus = {
...projectData[projectIndex].taskBoundries.filter((task) => {
return task?.index == taskId;
return task?.id == taskId;
})[0],
};
const findCorrectTaskStatusIndex = environment.tasksStatus.findIndex(
(data) => data.label == currentStatus.task_status,
);
const findCorrectTaskStatusIndex = environment.tasksStatus.findIndex((data) => {
return data.label == currentStatus.task_status;
});
const tasksStatus =
feature.id_ != undefined ? environment.tasksStatus[findCorrectTaskStatusIndex]?.['label'] : '';
set_task_status(tasksStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const SubmissionsTable = ({ toggleView }) => {
const taskBoundaryData = useAppSelector((state) => state.project.projectTaskBoundries);
const currentStatus = {
...taskBoundaryData?.[projectIndex]?.taskBoundries?.filter((task) => {
return filter.task_id && task?.index === +filter.task_id;
return filter.task_id && task?.id === +filter.task_id;
})?.[0],
};
const taskList = projectData[projectIndex]?.taskBoundries;
Expand Down Expand Up @@ -403,7 +403,7 @@ const SubmissionsTable = ({ toggleView }) => {
</div>
<div className="fmtm-w-full fmtm-flex fmtm-justify-end xl:fmtm-w-fit fmtm-gap-3">
{filter?.task_id &&
taskBoundaryData?.[projectIndex]?.taskBoundries?.find((task) => task?.index === +filter?.task_id)
taskBoundaryData?.[projectIndex]?.taskBoundries?.find((task) => task?.id === +filter?.task_id)
?.task_status === 'LOCKED_FOR_VALIDATION' && (
<Button
isLoading={updateTaskStatusLoading}
Expand Down Expand Up @@ -463,7 +463,7 @@ const SubmissionsTable = ({ toggleView }) => {
headerClassName="updatedHeader !fmtm-sticky fmtm-right-0 fmtm-shadow-[-10px_0px_20px_0px_rgba(0,0,0,0.1)] fmtm-text-center"
rowClassName="updatedRow !fmtm-sticky fmtm-right-0 fmtm-bg-white fmtm-shadow-[-10px_0px_20px_0px_rgba(0,0,0,0.1)]"
dataFormat={(row) => {
const taskUId = taskList?.find((task) => task?.index == row?.task_id)?.id;
const taskUId = taskList?.find((task) => task?.id == row?.task_id)?.id;
return (
<div className="fmtm-w-[5rem] fmtm-overflow-hidden fmtm-truncate fmtm-text-center">
<AssetModules.VisibilityOutlinedIcon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const TaskSubmissions = () => {
setTaskInfoList(taskInfo);
} else {
const updatedTask: taskSubmissionInfoType[] = Array.from({ length: projectTaskLength })?.map((_, i) => {
// TODO check this logic should be id or index for task?
const task = taskInfo?.find((task) => parseInt(task?.index) === i + 1);
if (task) {
return task;
Expand Down
14 changes: 7 additions & 7 deletions src/frontend/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ export default {
matomoTrackingId: '28',
tasksStatus: [
{
label: 'READY',
label: 'RELEASED_FOR_MAPPING',
action: [{ key: 'Start Mapping', value: 'LOCKED_FOR_MAPPING', btnBG: 'red' }],
btnBG: 'red',
},
{
label: 'LOCKED_FOR_MAPPING',
action: [
{ key: 'Mark as fully mapped', value: 'MAPPED', btnBG: 'gray' },
{ key: 'Stop Mapping', value: 'READY', btnBG: 'transparent' },
{ key: 'Mark as fully mapped', value: 'MARKED_MAPPED', btnBG: 'gray' },
{ key: 'Stop Mapping', value: 'RELEASED_FOR_MAPPING', btnBG: 'transparent' },
],
},
{
label: 'MAPPED',
label: 'MARKED_MAPPED',
action: [
{ key: 'Start Validation', value: 'LOCKED_FOR_VALIDATION', btnBG: 'gray' },
// { key: 'Return to Mapping', value: 'LOCKED_FOR_MAPPING' },
Expand All @@ -33,13 +33,13 @@ export default {
label: 'LOCKED_FOR_VALIDATION',
action: [
{ key: 'Mark as validated', value: 'VALIDATED', btnBG: 'gray' },
{ key: 'Mapping Needed', value: 'INVALIDATED', btnBG: 'transparent' },
{ key: 'Mapping Needed', value: 'MARKED_INVALID', btnBG: 'transparent' },
],
},
{ label: 'VALIDATED', action: [] },
// { label: 'VALIDATED', action: [{ key: 'Merge data with OSM', value: 'MERGE_WITH_OSM', btnBG: 'gray' }] },
{ label: 'INVALIDATED', action: [{ key: 'Map Again', value: 'LOCKED_FOR_MAPPING', btnBG: 'gray' }] },
{ label: 'BAD', action: [] },
{ label: 'MARKED_INVALID', action: [{ key: 'Map Again', value: 'LOCKED_FOR_MAPPING', btnBG: 'gray' }] },
{ label: 'MARKED_BAD', action: [] },
// "SPLIT",
// "ARCHIVED",
],
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/models/project/projectModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type projectTaskBoundriesType = {

export type taskBoundriesTypes = {
id: number;
index: number;
project_task_index: number;
actioned_by_uid: null | string;
actioned_by_username: null | string;
Expand All @@ -111,7 +112,6 @@ export type taskBoundriesTypes = {
};
task_history: taskHistoryTypes[];
task_status: string;
index: number;
};

export type taskBoundriesGeojson = {
Expand Down
1 change: 0 additions & 1 deletion src/frontend/src/store/slices/TaskSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { createSlice } from '@reduxjs/toolkit';
import { TaskStateTypes } from '@/store/types/ITask';
import { taskSubmissionInfoType } from '@/models/task/taskModel';
import { EntityOsmMap } from '@/store/types/IProject';
import { task_status } from '@/types/enums';

const initialState: TaskStateTypes = {
taskLoading: false,
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/views/ProjectDetailsV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import DebugConsole from '@/utilities/DebugConsole';
import { CustomCheckbox } from '@/components/common/Checkbox';
import useDocumentTitle from '@/utilfunctions/useDocumentTitle';
import QrcodeComponent from '@/components/QrcodeComponent';
import { createDropdownMenuScope } from '@radix-ui/react-dropdown-menu';

const ProjectDetailsV2 = () => {
useDocumentTitle('Project Details');
Expand Down Expand Up @@ -135,7 +136,7 @@ const ProjectDetailsV2 = () => {
// FIXME should the feature id be an int, not a string?
const features = state.projectTaskBoundries[0]?.taskBoundries?.map((taskObj) => ({
type: 'Feature',
id: `project_${projectId}_task_${taskObj.id}`,
id: taskObj.id,
geometry: { ...taskObj.outline },
properties: {
...taskObj.outline.properties,
Expand All @@ -149,7 +150,6 @@ const ProjectDetailsV2 = () => {
...geojsonObjectModel,
features: features,
};
console.log(taskBoundariesFeatcol);
setTaskBoundariesLayer(taskBoundariesFeatcol);
}, [state.projectTaskBoundries[0]?.taskBoundries?.length]);

Expand Down Expand Up @@ -186,7 +186,7 @@ const ProjectDetailsV2 = () => {
behavior: 'smooth',
});

dispatch(CoreModules.TaskActions.SetSelectedTask(properties?.fid));
dispatch(CoreModules.TaskActions.SetSelectedTask(feature.getId()));
dispatch(ProjectActions.ToggleTaskModalStatus(true));

// Fit the map view to the clicked feature's extent based on the window size
Expand Down

0 comments on commit 94edd62

Please sign in to comment.