Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/event driven tasks continuation #1839

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c4f0cb9
build: add migrations to update task_history --> task_events
spwoodcock Oct 26, 2024
bd0c727
refactor(backend): wip update to use TaskEvent / State enums
spwoodcock Oct 26, 2024
ccb0b2e
refactor(frontend): wip update to use TaskEvent / State enums
spwoodcock Oct 26, 2024
3c07231
build: add trigger to set task_event.state automatically from event
spwoodcock Oct 26, 2024
9577f6f
refactor: continued wip to use task events
spwoodcock Oct 26, 2024
182706d
refactor: fixes to task state/event distinction
spwoodcock Oct 26, 2024
59a782f
fix: additional fixes to backend usage action --> event
spwoodcock Oct 26, 2024
2cc37b6
build: fix migration conflict if task_history does not exist
spwoodcock Oct 26, 2024
7e19cdc
build: add conflate to enums in case for future
spwoodcock Oct 26, 2024
7f30af2
refactor: further wip updates for task events
spwoodcock Oct 26, 2024
ec06864
fix(taskSelectionPopup): project task index display on task popup
NSUWAL123 Oct 28, 2024
88c1b83
fix(submissionsInfographics): handle undefined task_history
NSUWAL123 Oct 28, 2024
3b477bd
fix(merge): merge conflict solve
NSUWAL123 Oct 29, 2024
d703213
fix(dialogTaskActions): remove taskBoundary from args, pass geojsonSt…
NSUWAL123 Oct 29, 2024
534e891
fix(taskEvent): use response state to track and update current task s…
NSUWAL123 Oct 29, 2024
2acb75c
fix(featureSelectionPopup): page crash on taskStateEnum undefined fix
NSUWAL123 Oct 29, 2024
a1d7fab
fix(getTaskStatusStyle): update feature style key based on entiy_stat…
NSUWAL123 Oct 29, 2024
31023bd
fix(projectInfo): change card title accessor key
NSUWAL123 Oct 29, 2024
54b7b78
fix(taskSubmissionsMap): fix taskGeojson schema
NSUWAL123 Oct 29, 2024
ffbc959
Merge branch 'feat/event-driven-tasks' of github.com:hotosm/fmtm into…
NSUWAL123 Oct 29, 2024
07a87a3
fix(submissionDetails): update get comments api
NSUWAL123 Oct 29, 2024
5175780
fix(updateReviewStatusModal): update reviewList id, update post submi…
NSUWAL123 Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies Nishit, I think I messed up the usage if task id vs index again πŸ˜…

})?.[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