Skip to content

Commit

Permalink
Fix/event driven tasks continuation (#1839)
Browse files Browse the repository at this point in the history
* build: add migrations to update task_history --> task_events

* refactor(backend): wip update to use TaskEvent / State enums

* refactor(frontend): wip update to use TaskEvent / State enums

* build: add trigger to set task_event.state automatically from event

* refactor: continued wip to use task events

* refactor: fixes to task state/event distinction

* fix: additional fixes to backend usage action --> event

* build: fix migration conflict if task_history does not exist

* build: add conflate to enums in case for future

* refactor: further wip updates for task events

* fix(taskSelectionPopup): project task index display on task popup

* fix(submissionsInfographics): handle undefined task_history

* fix(dialogTaskActions): remove taskBoundary from args, pass geojsonStyles to as args

* fix(taskEvent): use response state to track and update current task state color

* fix(featureSelectionPopup): page crash on taskStateEnum undefined fix

* fix(getTaskStatusStyle): update feature style key based on entiy_state enums

* fix(projectInfo): change card title accessor key

* fix(taskSubmissionsMap): fix taskGeojson schema

* fix(submissionDetails): update get comments api

* fix(updateReviewStatusModal): update reviewList id, update post submission comments api

---------

Co-authored-by: spwoodcock <[email protected]>
  • Loading branch information
NSUWAL123 and spwoodcock authored Oct 29, 2024
1 parent 090b6b1 commit bc87fd6
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 41 deletions.
1 change: 0 additions & 1 deletion src/backend/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ async def task_event(db, project, tasks, admin_user):
comment="We added a comment!",
)
db_task_event = await DbTaskEvent.create(db, new_event)

return db_task_event


Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/api/TaskEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export const CreateTaskEvent = (
};
const response = await CoreModules.axios.post(url, body, { params });
dispatch(ProjectActions.UpdateProjectTaskActivity(response.data));

if (feature && style) {
await feature.setStyle(style);
// update task color based on current state
await feature.setStyle(style[response?.data?.state]);

// assign userId to actioned_by_uid if state is locked_for_mapping or locked_for_validation
const prevProperties = feature.getProperties();
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/components/DialogTaskActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default function Dialog({ taskId, feature }: dialogPropType) {
}
}, [taskId, taskInfo]);

// TODO need to set the TaskEvent here, not MappingStatus?
useEffect(() => {
if (projectIndex != -1) {
// Get current state of task
Expand All @@ -91,7 +92,7 @@ export default function Dialog({ taskId, feature }: dialogPropType) {
if (!btnId) return;
const selectedAction = taskEventEnum[btnId];
const authDetailsCopy = authDetails != null ? { ...authDetails } : {};
const geoStyle = geojsonStyles[btnId];

if (btnId != undefined) {
if (authDetailsCopy.hasOwnProperty('id')) {
// if (btnId === 'MERGE_WITH_OSM') {
Expand All @@ -106,8 +107,7 @@ export default function Dialog({ taskId, feature }: dialogPropType) {
taskId.toString(),
authDetailsCopy,
{ project_id: currentProjectId },
geoStyle,
taskBoundaryData,
geojsonStyles,
feature,
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { UpdateEntityState } from '@/api/Project';
import { TaskFeatureSelectionProperties } from '@/store/types/ITask';
import { CreateTaskEvent } from '@/api/TaskEvent';
import MapStyles from '@/hooks/MapStyles';
import { task_event } from '@/types/enums';
import { task_event, task_state as taskStateEnum } from '@/types/enums';

type TaskFeatureSelectionPopupPropType = {
taskId: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const TaskSelectionPopup = ({ taskId, body, feature }: TaskSelectionPopupPropTyp
const authDetails = CoreModules.useAppSelector((state) => state.login.authDetails);
const selectedTask = {
...projectData?.[projectIndex]?.taskBoundries?.filter((indTask, i) => {
return indTask?.index == taskId;
return indTask?.id == taskId;
})?.[0],
};
const checkIfTaskAssignedOrNot =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const ProjectInfo = ({ entities }) => {
<div className="fmtm-bg-white fmtm-rounded-lg fmtm-min-w-[12.5rem] fmtm-p-2 fmtm-px-4 md:fmtm-p-4 md:fmtm-shadow-[0px_10px_20px_0px_rgba(96,96,96,0.1)] fmtm-flex fmtm-items-center fmtm-gap-4">
<div className="fmtm-bg-primaryRed fmtm-rounded-full fmtm-p-2">{data.icon}</div>
<div className="fmtm-flex fmtm-flex-col fmtm-items-start">
<h2 className="fmtm-text-lg sm:fmtm-text-xl md:fmtm-text-xl fmtm-text-[#706E6E] fmtm-font-bold">{data.name}</h2>
<h2 className="fmtm-text-lg sm:fmtm-text-xl md:fmtm-text-xl fmtm-text-[#706E6E] fmtm-font-bold">
{data.title}
</h2>
<h2 className="fmtm-text-xl sm:fmtm-text-2xl md:fmtm-text-2xl fmtm-font-bold fmtm-text-primaryRed">
{data.count}
</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const SubmissionsInfographics = ({ toggleView, entities }) => {
const projectIndex = projectTaskList.findIndex((project) => project.id == +projectId);
// task activities history list
const taskActivities = projectTaskList?.[projectIndex]?.taskBoundries?.reduce((acc: taskHistoryTypes[], task) => {
return [...acc, ...task?.task_history];
return [...acc, ...(task?.task_history ?? [])];
}, []);

// filter activities for last 30 days
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,12 @@ const TaskSubmissionsMap = () => {
...basicGeojsonTemplate,
features: [
...projectTaskBoundries?.[0]?.taskBoundries?.map((task) => ({
...task.outline,
id: task?.outline?.properties?.fid,
type: 'Feature',
geometry: { ...task.outline, id: task?.outline?.properties?.fid },
properties: {
fid: task?.index,
uid: task?.id,
},
})),
],
};
Expand All @@ -121,6 +125,7 @@ const TaskSubmissionsMap = () => {

useEffect(() => {
if (!taskBoundaries) return;
if (!selectedTask) return;
const filteredSelectedTaskGeojson = {
...basicGeojsonTemplate,
features: taskBoundaries?.features?.filter((task) => task?.properties?.fid === selectedTask),
Expand All @@ -142,6 +147,7 @@ const TaskSubmissionsMap = () => {
constrainResolution: true,
duration: 2000,
});
dispatch(CoreModules.TaskActions.SetSelectedTask(null));
}, [selectedTask]);

const taskOnSelect = (properties, feature) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import { PostProjectComments } from '@/api/Project';

const reviewList: reviewListType[] = [
{
id: 'approved',
id: 'APPROVED',
title: 'Approved',
className: 'fmtm-bg-[#E7F3E8] fmtm-text-[#40B449] fmtm-border-[#40B449]',
hoverClass: 'hover:fmtm-text-[#40B449] hover:fmtm-border-[#40B449]',
},
{
id: 'hasIssues',
id: 'HASISSUES',
title: 'Has Issue',
className: 'fmtm-bg-[#E9DFCF] fmtm-text-[#D99F00] fmtm-border-[#D99F00]',
hoverClass: 'hover:fmtm-text-[#D99F00] hover:fmtm-border-[#D99F00]',
},
{
id: 'rejected',
id: 'REJECTED',
title: 'Rejected',
className: 'fmtm-bg-[#E8D5D5] fmtm-text-[#D73F37] fmtm-border-[#D73F37]',
hoverClass: 'hover:fmtm-text-[#D73F37] hover:fmtm-border-[#D73F37]',
Expand Down Expand Up @@ -60,10 +60,11 @@ const UpdateReviewStatusModal = () => {
if (noteComments.trim().length > 0) {
dispatch(
PostProjectComments(
`${import.meta.env.VITE_API_URL}/tasks/${updateReviewStatusModal?.taskUId}/comment/?project_id=${updateReviewStatusModal?.projectId}`,
`${import.meta.env.VITE_API_URL}/tasks/${updateReviewStatusModal?.taskUId}/event/?project_id=${updateReviewStatusModal?.projectId}`,
{
task_id: updateReviewStatusModal?.taskUId,
comment: `${updateReviewStatusModal?.instanceId}-SUBMISSION_INST-${noteComments}`,
event: 'COMMENT',
},
),
);
Expand Down
49 changes: 25 additions & 24 deletions src/frontend/src/utilfunctions/getTaskStatusStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Fill, Icon, Stroke, Style } from 'ol/style';
import { getCenter } from 'ol/extent';
import { Point } from 'ol/geom';
import AssetModules from '@/shared/AssetModules';
import { task_state } from '@/types/enums';
import { entity_state } from '@/types/enums';
import { EntityOsmMap } from '@/store/types/IProject';

function createPolygonStyle(fillColor: string, strokeColor: string) {
Expand Down Expand Up @@ -108,7 +108,8 @@ const getTaskStatusStyle = (feature: Record<string, any>, mapTheme: Record<strin

export const getFeatureStatusStyle = (osmId: string, mapTheme: Record<string, any>, entityOsmMap: EntityOsmMap[]) => {
const entity = entityOsmMap?.find((entity) => entity?.osm_id === osmId) as EntityOsmMap;
let status = task_state[entity?.status];

let status = entity_state[entity?.status];

const borderStrokeColor = '#FF0000';

Expand All @@ -124,7 +125,7 @@ export const getFeatureStatusStyle = (osmId: string, mapTheme: Record<string, an
const redIconStyle = createIconStyle(AssetModules.RedLockPng);

const geojsonStyles = {
UNLOCKED_TO_MAP: new Style({
READY: new Style({
stroke: new Stroke({
color: borderStrokeColor,
width: 1,
Expand All @@ -133,18 +134,18 @@ export const getFeatureStatusStyle = (osmId: string, mapTheme: Record<string, an
color: mapTheme.palette.mapFeatureColors.ready_rgb,
}),
}),
LOCKED_FOR_MAPPING: [lockedPolygonStyle, iconStyle],
UNLOCKED_TO_VALIDATE: new Style({
stroke: new Stroke({
color: borderStrokeColor,
width: 1,
}),
fill: new Fill({
color: mapTheme.palette.mapFeatureColors.mapped_rgb,
}),
}),
LOCKED_FOR_VALIDATION: [lockedValidationStyle, redIconStyle],
UNLOCKED_DONE: new Style({
OPENED_IN_ODK: [lockedPolygonStyle, iconStyle],
// UNLOCKED_TO_VALIDATE: new Style({
// stroke: new Stroke({
// color: borderStrokeColor,
// width: 1,
// }),
// fill: new Fill({
// color: mapTheme.palette.mapFeatureColors.mapped_rgb,
// }),
// }),
// LOCKED_FOR_VALIDATION: [lockedValidationStyle, redIconStyle],
SURVEY_SUBMITTED: new Style({
stroke: new Stroke({
color: borderStrokeColor,
width: 1,
Expand All @@ -162,15 +163,15 @@ export const getFeatureStatusStyle = (osmId: string, mapTheme: Record<string, an
// color: mapTheme.palette.mapFeatureColors.invalidated_rgb,
// }),
// }),
// BAD: new Style({
// stroke: new Stroke({
// color: borderStrokeColor,
// width: 1,
// }),
// fill: new Fill({
// color: mapTheme.palette.mapFeatureColors.bad_rgb,
// }),
// }),
MARKED_BAD: new Style({
stroke: new Stroke({
color: borderStrokeColor,
width: 1,
}),
fill: new Fill({
color: mapTheme.palette.mapFeatureColors.bad_rgb,
}),
}),
};
return geojsonStyles[status];
};
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/views/SubmissionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const SubmissionDetails = () => {
if (!taskUId) return;
dispatch(
GetProjectComments(
`${import.meta.env.VITE_API_URL}/tasks/${parseInt(taskUId)}/history/?project_id=${projectId}&comment=true`,
`${import.meta.env.VITE_API_URL}/tasks/${parseInt(taskUId)}/history/?project_id=${projectId}&comments=true`,
),
);
}, [taskUId]);
Expand Down

0 comments on commit bc87fd6

Please sign in to comment.