Skip to content

Commit

Permalink
Merge pull request #134 from nrotstan/issue-113-allow-more-commenting…
Browse files Browse the repository at this point in the history
…-options

Always allow commenting on tasks. Closes #113.
  • Loading branch information
nrotstan authored Feb 26, 2018
2 parents cecadce + 9d609a5 commit 4e00920
Show file tree
Hide file tree
Showing 10 changed files with 552 additions and 34 deletions.
9 changes: 7 additions & 2 deletions src/components/HOCs/WithCurrentTask/WithCurrentTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,20 @@ 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,
taskLoadBy === TaskLoadMethod.proximity ? taskId : undefined
)
).then(newTask =>
visitNewTask(challengeId, taskId, newTask, ownProps.history)
),
)
},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down Expand Up @@ -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

Expand All @@ -95,22 +97,22 @@ export class ActiveTaskControls extends Component {
<TaskTrackControls className="active-task-controls__track-task"
{..._omit(this.props, 'className')} />

{canProgress &&
<TaskCommentInput className="active-task-controls__task-comment"
value={this.state.comment}
commentChanged={this.setComment}
{..._omit(this.props, 'className')} />
}
<TaskCommentInput className="active-task-controls__task-comment"
value={this.state.comment}
commentChanged={this.setComment}
{..._omit(this.props, 'className')} />

{!isEditingTask &&
<TaskCompletionStep1 allowedProgressions={allowedProgressions}
pickEditor={this.pickEditor}
complete={this.complete}
{...this.props} />
nextTask={this.next}
{..._omit(this.props, 'nextTask')} />
}

{!isEditingTask && hasExistingStatus &&
<TaskNextControl {...this.props} />
<TaskNextControl nextTask={this.next}
{..._omit(this.props, 'nextTask')} />
}

{isEditingTask &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,7 +35,6 @@

&__task-comment {
width: 100%;
margin-bottom: 20px;

input {
width: 100%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,35 +86,35 @@ 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(
<ActiveTaskControls {...basicProps} />
)

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(
<ActiveTaskControls {...basicProps} />
)

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(
<ActiveTaskControls {...basicProps} />
)

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", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

.task-completion-comment {
width: 100%;
margin-bottom: 10px;

input {
width: 100%;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export default class TaskTrackControls extends Component {
control = (
<div className="field" onClick={this.toggleSaved}>
<input type="checkbox" className="switch is-thin"
onChange={() => {}}
checked={this.taskIsTracked()} />
<label>
<FormattedMessage {...messages.trackLabel } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ShallowWrapper {
<input
checked={true}
className="switch is-thin"
onChange={[Function]}
type="checkbox"
/>
<label>
Expand All @@ -74,6 +75,7 @@ ShallowWrapper {
<input
checked={true}
className="switch is-thin"
onChange={[Function]}
type="checkbox"
/>,
<label>
Expand All @@ -96,6 +98,7 @@ ShallowWrapper {
"props": Object {
"checked": true,
"className": "switch is-thin",
"onChange": [Function],
"type": "checkbox",
},
"ref": null,
Expand Down Expand Up @@ -147,6 +150,7 @@ ShallowWrapper {
<input
checked={true}
className="switch is-thin"
onChange={[Function]}
type="checkbox"
/>
<label>
Expand All @@ -169,6 +173,7 @@ ShallowWrapper {
<input
checked={true}
className="switch is-thin"
onChange={[Function]}
type="checkbox"
/>,
<label>
Expand All @@ -191,6 +196,7 @@ ShallowWrapper {
"props": Object {
"checked": true,
"className": "switch is-thin",
"onChange": [Function],
"type": "checkbox",
},
"ref": null,
Expand Down Expand Up @@ -288,6 +294,7 @@ ShallowWrapper {
<input
checked={false}
className="switch is-thin"
onChange={[Function]}
type="checkbox"
/>
<label>
Expand All @@ -310,6 +317,7 @@ ShallowWrapper {
<input
checked={false}
className="switch is-thin"
onChange={[Function]}
type="checkbox"
/>,
<label>
Expand All @@ -332,6 +340,7 @@ ShallowWrapper {
"props": Object {
"checked": false,
"className": "switch is-thin",
"onChange": [Function],
"type": "checkbox",
},
"ref": null,
Expand Down Expand Up @@ -383,6 +392,7 @@ ShallowWrapper {
<input
checked={false}
className="switch is-thin"
onChange={[Function]}
type="checkbox"
/>
<label>
Expand All @@ -405,6 +415,7 @@ ShallowWrapper {
<input
checked={false}
className="switch is-thin"
onChange={[Function]}
type="checkbox"
/>,
<label>
Expand All @@ -427,6 +438,7 @@ ShallowWrapper {
"props": Object {
"checked": false,
"className": "switch is-thin",
"onChange": [Function],
"type": "checkbox",
},
"ref": null,
Expand Down
Loading

0 comments on commit 4e00920

Please sign in to comment.