Skip to content

Commit

Permalink
Request mappers to read invalidated task comments:
Browse files Browse the repository at this point in the history
- add info svg icon
- add banner request to view task history comments
- conditional render of banner if task was invalidated and has comments
  • Loading branch information
d-rita committed Dec 13, 2020
1 parent ddff15b commit 3e9b02e
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions frontend/src/components/svgIcons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ export { SidebarIcon } from './sidebar';
export { QuestionCircleIcon } from './questionCircle';
export { ChartLineIcon } from './chart';
export { EditIcon } from './edit';
export { InfoIcon } from './info';
15 changes: 15 additions & 0 deletions frontend/src/components/svgIcons/info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';

export class InfoIcon extends React.PureComponent {
render() {
return (
<svg class="w1" data-icon="info" viewBox="0 0 32 32" {...this.props}>
<title>info icon</title>
<path
fill="currentColor"
d="M16 0 A16 16 0 0 1 16 32 A16 16 0 0 1 16 0 M19 15 L13 15 L13 26 L19 26 z M16 6 A3 3 0 0 0 16 12 A3 3 0 0 0 16 6"
/>
</svg>
);
}
}
1 change: 1 addition & 0 deletions frontend/src/components/taskSelection/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export function TaskMapAction({ project, projectIsReady, tasks, activeTasks, act
<CompletionTabForMapping
project={project}
tasksIds={tasksIds}
taskHistory={taskHistory}
taskInstructions={
activeTasks && activeTasks.length === 1
? activeTasks[0].perTaskInstructions
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/components/taskSelection/actionSidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ import {
QuestionCircleIcon,
ChevronRightIcon,
ChevronDownIcon,
InfoIcon,
} from '../svgIcons';
import { getEditors } from '../../utils/editorsList';
import { htmlFromMarkdown } from '../../utils/htmlFromMarkdown';
import { pushToLocalJSONAPI, fetchLocalJSONAPI } from '../../network/genericJSONRequest';
import { CommentInputField } from '../comments/commentInput';
import { useFetchLockedTasks, useClearLockedTasks } from '../../hooks/UseLockedTasks';
import useReadTaskComments from '../../hooks/useReadTaskComments';

export function CompletionTabForMapping({
project,
tasksIds,
taskHistory,
taskInstructions,
disabled,
taskComment,
Expand All @@ -38,6 +41,7 @@ export function CompletionTabForMapping({
const radioInput = 'radio-input input-reset pointer v-mid dib h2 w2 mr2 br-100 ba b--blue-light';
const fetchLockedTasks = useFetchLockedTasks();
const clearLockedTasks = useClearLockedTasks();
const readTaskComments = useReadTaskComments(taskHistory);

const splitTask = () => {
if (!disabled) {
Expand Down Expand Up @@ -104,6 +108,14 @@ export function CompletionTabForMapping({
{(close) => <UnsavedMapChangesModalContent close={close} action={showMapChangesModal} />}
</Popup>
)}
{readTaskComments && (
<div class="flex items-center justify-center pa1 mb1 bg-grey-light blue-grey">
<InfoIcon />
<span class="ml2 fw1 pa1">
<FormattedMessage {...messages.readTaskComments} />
</span>
</div>
)}
<div className="cf">
{taskInstructions && <TaskSpecificInstructions instructions={taskInstructions} />}
<h4 className="ttu blue-grey f5">
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/taskSelection/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ export default defineMessages({
id: 'project.tasks.filter.noTasksFound',
defaultMessage: 'No tasks were found.',
},
readTaskComments: {
id: 'project.tasks.readComments',
defaultMessage: 'Please check history for relevant task comments.',
},
completion: {
id: 'project.tasks.action.completion',
defaultMessage: 'Completion',
Expand Down
29 changes: 29 additions & 0 deletions frontend/src/hooks/tests/useReadTaskComments.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { renderHook } from '@testing-library/react-hooks';
import { invalidatedTaskHistory, history } from '../../network/tests/mockData/taskHistory';
import useReadTaskComments from '../useReadTaskComments';

describe('test useReadTaskComments hook', () => {
it('returns false when there is no task history', () => {
const { result } = renderHook(() => useReadTaskComments({}));
const readTaskComments = result.current;
expect(readTaskComments).toBe(false);
});

it('returns false if task has not been previously invalidated', () => {
const { result } = renderHook(() => useReadTaskComments(history));
const readTaskComments = result.current;
expect(readTaskComments).toBe(false);
});

it('returns false if task history does not have comments', () => {
const { result } = renderHook(() => useReadTaskComments(history));
const readTaskComments = result.current;
expect(readTaskComments).toBe(false);
});

it('returns true if was invalidated and has comments', () => {
const { result } = renderHook(() => useReadTaskComments(invalidatedTaskHistory));
const readTaskComments = result.current;
expect(readTaskComments).toBe(true);
});
});
21 changes: 21 additions & 0 deletions frontend/src/hooks/useReadTaskComments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { useState, useEffect } from 'react';

const useReadTaskComments = (history) => {
const [readTaskComments, setReadTaskComments] = useState(false);

useEffect(() => {
if (history && history.taskHistory && history.taskHistory.length > 1) {
const invalidatedTaskHistory = history.taskHistory.filter(
(task) => task.actionText === 'INVALIDATED',
);
const taskComments = history.taskHistory.filter((task) => task.action === 'COMMENT');

if (invalidatedTaskHistory.length > 0 && taskComments.length > 0) {
setReadTaskComments(true);
}
}
}, [history]);
return readTaskComments;
};

export default useReadTaskComments;
1 change: 1 addition & 0 deletions frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@
"project.tasks.filter.readyToValidate": "Ready for validation",
"project.tasks.filter.readyToMap": "Available for mapping",
"project.tasks.filter.noTasksFound": "No tasks were found.",
"project.tasks.readComments": "Please check history for relevant task comments.",
"project.tasks.action.completion": "Completion",
"project.tasks.action.history": "History",
"project.tasks.action.finish_mapping.title": "Once you have finished mapping",
Expand Down
25 changes: 25 additions & 0 deletions frontend/src/network/tests/mockData/taskHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,28 @@ export const history = {
},
],
};

export const invalidatedTaskHistory = {
taskHistory: [
{
historyId: 12001,
taskId: 1,
action: 'COMMENT',
actionText: 'More buildings need to be mapped',
actionDate: '2020-10-04T14:35:30.174515Z',
actionBy: 'test_user',
pictureUrl: null,
issues: null,
},
{
historyId: 12000,
taskId: 1,
action: 'STATE_CHANGE',
actionText: 'INVALIDATED',
actionDate: '2020-10-04T14:35:20.174515Z',
actionBy: 'test_user',
pictureUrl: null,
issues: null,
},
],
};

0 comments on commit 3e9b02e

Please sign in to comment.