From 9d609a5ca8db010666586a5862e382b34af45c3e Mon Sep 17 00:00:00 2001 From: Neil Rotstan Date: Mon, 26 Feb 2018 09:40:03 -0800 Subject: [PATCH] Always allow commenting on tasks. Closes #113. A comment field is now offered to users regardless of the task status, whereas before it was only offered if the task was able to progress to a new status. --- .../HOCs/WithCurrentTask/WithCurrentTask.js | 9 +- .../ActiveTaskControls/ActiveTaskControls.js | 22 +- .../ActiveTaskControls.scss | 4 +- .../ActiveTaskControls.test.js | 20 +- .../TaskCommentInput/TaskCommentInput.scss | 1 - .../TaskNextControl/TaskNextControl.scss | 4 +- .../TaskTrackControls/TaskTrackControls.js | 1 + .../TaskTrackControls.test.js.snap | 12 + .../ActiveTaskControls.test.js.snap | 502 +++++++++++++++++- src/services/Task/Task.js | 11 +- 10 files changed, 552 insertions(+), 34 deletions(-) diff --git a/src/components/HOCs/WithCurrentTask/WithCurrentTask.js b/src/components/HOCs/WithCurrentTask/WithCurrentTask.js index 8b7ad5aed..6d2ddddba 100644 --- a/src/components/HOCs/WithCurrentTask/WithCurrentTask.js +++ b/src/components/HOCs/WithCurrentTask/WithCurrentTask.js @@ -128,7 +128,11 @@ export const mapDispatchToProps = (dispatch, ownProps) => { * Move to the next task without setting any completion status, * useful for when a user visits a task that is already complete. */ - nextTask: (challengeId, taskId, taskLoadBy) => + nextTask: (challengeId, taskId, taskLoadBy, comment) => { + if (_isString(comment) && comment.length > 0) { + dispatch(addTaskComment(taskId, comment)) + } + dispatch( loadRandomTaskFromChallenge( challengeId, @@ -136,7 +140,8 @@ export const mapDispatchToProps = (dispatch, ownProps) => { ) ).then(newTask => visitNewTask(challengeId, taskId, newTask, ownProps.history) - ), + ) + }, } } diff --git a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.js b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.js index 154d7ab12..8ad5d78db 100644 --- a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.js +++ b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.js @@ -53,6 +53,10 @@ export class ActiveTaskControls extends Component { taskStatus, this.state.comment, this.props.taskLoadBy) } + next = (challengeId, taskId) => { + this.props.nextTask(challengeId, taskId, this.props.taskLoadBy, this.state.comment) + } + render() { // If the user is not logged in, show a sign-in button instead of controls. if (!_get(this.props, 'user.isLoggedIn')) { @@ -84,8 +88,6 @@ export class ActiveTaskControls extends Component { const allowedProgressions = allowedStatusProgressions(this.props.task.status) - const canProgress = allowedProgressions.size > 0 - const hasExistingStatus = _isNumber(this.props.task.status) && this.props.task.status !== TaskStatus.created @@ -95,22 +97,22 @@ export class ActiveTaskControls extends Component { - {canProgress && - - } + {!isEditingTask && + nextTask={this.next} + {..._omit(this.props, 'nextTask')} /> } {!isEditingTask && hasExistingStatus && - + } {isEditingTask && diff --git a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.scss b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.scss index 2cc026d58..54fd8fdfa 100644 --- a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.scss +++ b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.scss @@ -5,6 +5,9 @@ display: flex; justify-content: space-between; flex-wrap: wrap; + margin-top: 10px; + margin-bottom: 10px; + button.button.large-and-wide { margin-bottom: 10px; @@ -32,7 +35,6 @@ &__task-comment { width: 100%; - margin-bottom: 20px; input { width: 100%; diff --git a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.test.js b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.test.js index 4786fde5f..a16fcc2c2 100644 --- a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.test.js +++ b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/ActiveTaskControls.test.js @@ -86,7 +86,7 @@ test("shows track/untrack controls", () => { expect(wrapper).toMatchSnapshot() }) -test("shows a completion comment field if status is appropriate", () => { +test("shows a completion comment field", () => { const wrapper = shallow( ) @@ -94,27 +94,27 @@ test("shows a completion comment field if status is appropriate", () => { expect(wrapper.find('TaskCommentInput').exists()).toBe(true) }) -test("the comment field contains the current comment", () => { +test("shows a comment field even for tasks that cannot progress further", () => { + basicProps.task.status = TaskStatus.fixed + const wrapper = shallow( ) - wrapper.instance().setComment("Foo") - wrapper.update() + expect(wrapper.find('TaskCommentInput').exists()).toBe(true) - expect(wrapper.find('TaskCommentInput[value="Foo"]').exists()).toBe(true) + expect(wrapper).toMatchSnapshot() }) -test("does not show comment field if task cannot progress to new status", () => { - basicProps.task.status = TaskStatus.fixed - +test("the comment field contains the current comment", () => { const wrapper = shallow( ) - expect(wrapper.find('TaskCommentInput').exists()).toBe(false) + wrapper.instance().setComment("Foo") + wrapper.update() - expect(wrapper).toMatchSnapshot() + expect(wrapper.find('TaskCommentInput[value="Foo"]').exists()).toBe(true) }) test("shows completion controls if the user has begun editing the task", () => { diff --git a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskCommentInput/TaskCommentInput.scss b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskCommentInput/TaskCommentInput.scss index 08afa0b55..8ebea61af 100644 --- a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskCommentInput/TaskCommentInput.scss +++ b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskCommentInput/TaskCommentInput.scss @@ -2,7 +2,6 @@ .task-completion-comment { width: 100%; - margin-bottom: 10px; input { width: 100%; diff --git a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskNextControl/TaskNextControl.scss b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskNextControl/TaskNextControl.scss index 12dd130bd..a6ff86590 100644 --- a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskNextControl/TaskNextControl.scss +++ b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskNextControl/TaskNextControl.scss @@ -1,8 +1,8 @@ @import '../../../../../variables.scss'; .active-task-details .next-control { - margin-top: 15px; - margin-bottom: 0px; + margin-top: 5px; + margin-bottom: 10px; svg { height: 18px; diff --git a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskTrackControls/TaskTrackControls.js b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskTrackControls/TaskTrackControls.js index 000cc3b3c..a13376f60 100644 --- a/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskTrackControls/TaskTrackControls.js +++ b/src/components/TaskPane/ActiveTaskDetails/ActiveTaskControls/TaskTrackControls/TaskTrackControls.js @@ -64,6 +64,7 @@ export default class TaskTrackControls extends Component { control = (
{}} checked={this.taskIsTracked()} />