Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 3fa1196

Browse files
authored
Merge pull request #201 from anehx/analysis-edit-states
Fix states in bulk edit mask
2 parents b1f6ee5 + 46e9504 commit 3fa1196

File tree

10 files changed

+77
-16
lines changed

10 files changed

+77
-16
lines changed

app/analysis/edit/controller.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { cleanParams } from 'timed/utils/url'
77
import computed from 'ember-computed-decorators'
88
import { toQueryString } from 'timed/utils/url'
99
import IntersectionValidations from 'timed/validations/intersection'
10+
import { later } from '@ember/runloop'
1011
import {
1112
underscoreQueryParams,
1213
serializeParachuteQueryParams,
@@ -154,7 +155,12 @@ export default Controller.extend(AnalysisEditQueryParams.Mixin, {
154155
},
155156

156157
reset(changeset) {
157-
changeset.rollback()
158+
// We have to defer the rollback for some milliseconds since the combobox
159+
// reset action triggers mutation of customer, task, and project which
160+
// would be run after this rollback and therefore trigger changes
161+
later(() => {
162+
changeset.rollback()
163+
})
158164
}
159165
}
160166
})

app/analysis/edit/template.hbs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,24 @@
3434
<div class="form-group" data-test-customer>
3535
<label>
3636
Customer
37-
{{#unless f.model.customer}}{{not-identical-warning}}{{/unless}}
37+
{{#unless model.customer}}{{not-identical-warning}}{{/unless}}
38+
{{#unless (eq f.model.change.customer.id model.customer.id)}}{{changed-warning}}{{/unless}}
3839
</label>
3940
{{t.customer}}
4041
</div>
4142
<div class="form-group" data-test-project>
4243
<label>
4344
Project
44-
{{#unless f.model.project}}{{not-identical-warning}}{{/unless}}
45+
{{#unless model.project}}{{not-identical-warning}}{{/unless}}
46+
{{#unless (eq f.model.change.project.id model.project.id)}}{{changed-warning}}{{/unless}}
4547
</label>
4648
{{t.project}}
4749
</div>
4850
<div class="form-group" data-test-task>
4951
<label>
5052
Task
51-
{{#unless f.model.task}}{{not-identical-warning}}{{/unless}}
53+
{{#unless model.task}}{{not-identical-warning}}{{/unless}}
54+
{{#unless (eq f.model.change.task.id model.task.id)}}{{changed-warning}}{{/unless}}
5255
</label>
5356
{{t.task}}
5457
</div>
@@ -57,30 +60,34 @@
5760
{{#f.input data-test-comment name='comment' as |fi|}}
5861
<label>
5962
Comment
60-
{{#if (eq f.model.comment null)}}{{not-identical-warning}}{{/if}}
63+
{{#if (eq model.comment null)}}{{not-identical-warning}}{{/if}}
64+
{{#unless (eq f.model.comment model.comment)}}{{changed-warning}}{{/unless}}
6165
</label>
6266
<input type="text" placeholder="Enter comment..." class="form-control" onchange={{action fi.update value='target.value'}} value={{fi.value}}>
6367
{{/f.input}}
6468

6569
{{#f.input data-test-not-billable name='notBillable' as |fi|}}
6670
{{#sy-checkbox checked=fi.value on-change=fi.update}}
6771
Not billable
68-
{{#if (eq f.model.notBillable null)}}{{not-identical-warning}}{{/if}}
72+
{{#if (eq model.notBillable null)}}{{not-identical-warning}}{{/if}}
73+
{{#unless (eq f.model.notBillable model.notBillable)}}{{changed-warning}}{{/unless}}
6974
{{/sy-checkbox}}
7075
{{/f.input}}
7176

7277
{{#f.input data-test-review name='review' as |fi|}}
7378
{{#sy-checkbox checked=fi.value on-change=fi.update}}
7479
Needs Review
75-
{{#if (eq f.model.review null)}}{{not-identical-warning}}{{/if}}
80+
{{#if (eq model.review null)}}{{not-identical-warning}}{{/if}}
81+
{{#unless (eq f.model.review model.review)}}{{changed-warning}}{{/unless}}
7682
{{/sy-checkbox}}
7783
{{/f.input}}
7884

7985
{{#if (or (eq reviewer session.data.user.id) session.data.user.isSuperuser)}}
8086
{{#f.input data-test-verified name='verified' as |fi|}}
8187
{{#sy-checkbox checked=fi.value on-change=fi.update}}
8288
Verfied
83-
{{#if (eq f.model.verified null)}}{{not-identical-warning}}{{/if}}
89+
{{#if (eq model.verified null)}}{{not-identical-warning}}{{/if}}
90+
{{#unless (eq f.model.verified model.verified)}}{{changed-warning}}{{/unless}}
8491
{{/sy-checkbox}}
8592
{{/f.input}}
8693
{{/if}}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Component from '@ember/component'
2+
3+
export default Component.extend({
4+
tagName: 'span',
5+
classNames: ['color-warning'],
6+
attributeBindings: ['title'],
7+
title: 'This field has unsaved changes'
8+
})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
&nbsp;{{fa-icon 'warning'}}

app/components/task-selection/component.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export default Component.extend({
226226
this.set('_project', value)
227227

228228
if (value && value.get('customer')) {
229-
this.set('_customer', value.get('customer'))
229+
this.set('customer', value.get('customer'))
230230
}
231231

232232
/* istanbul ignore else */
@@ -262,10 +262,7 @@ export default Component.extend({
262262
this.set('_task', value)
263263

264264
if (value && value.get('project')) {
265-
this.setProperties({
266-
_project: value.get('project'),
267-
_customer: value.get('project.customer')
268-
})
265+
this.set('project', value.get('project'))
269266
}
270267

271268
later(this, () => {

app/validations/intersection.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import validateIntersectionTask from 'timed/validators/intersection-task'
2+
import validateNullOrNotBlank from 'timed/validators/null-or-not-blank'
23

34
export default {
4-
task: validateIntersectionTask()
5+
task: validateIntersectionTask(),
6+
comment: validateNullOrNotBlank()
57
}

app/validators/null-or-not-blank.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { capitalize } from '@ember/string'
2+
3+
export default function validateNullOrNotBlank() {
4+
return (key, newValue) => {
5+
return (
6+
!!(newValue === null || (newValue && newValue.length > 0)) ||
7+
`${capitalize(key)} must be null or not blank`
8+
)
9+
}
10+
}

tests/acceptance/analysis-edit-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ describe('Acceptance | analysis edit', function() {
5151
let { data: { type, attributes, relationships } } = res
5252

5353
expect(type).to.equal('report-bulks')
54+
5455
// only changed attributes were sent
5556
expect(Object.keys(attributes)).to.deep.equal([
5657
'comment',
5758
'not-billable',
5859
'review'
5960
])
60-
// since no relationships were edited - nothing was sent
6161
expect(Object.keys(relationships)).to.deep.equal([
62-
'task' // task will be changed since the relation updates..
62+
'customer',
63+
'project',
64+
'task'
6365
])
6466

6567
expect(currentURL()).to.equal('/analysis')
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect } from 'chai'
2+
import { describe, it } from 'mocha'
3+
import { setupComponentTest } from 'ember-mocha'
4+
import hbs from 'htmlbars-inline-precompile'
5+
import { find } from 'ember-native-dom-helpers'
6+
7+
describe('Integration | Component | changed warning', function() {
8+
setupComponentTest('changed-warning', {
9+
integration: true
10+
})
11+
12+
it('renders', function() {
13+
this.render(hbs`{{changed-warning}}`)
14+
15+
expect(find('i.fa.fa-warning')).to.be.ok
16+
})
17+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect } from 'chai'
2+
import { describe, it } from 'mocha'
3+
import validateNullOrNotBlank from 'timed/validators/null-or-not-blank'
4+
5+
describe('Unit | Validator | null or not blank', function() {
6+
it('works', function() {
7+
expect(validateNullOrNotBlank()('key', 'test')).to.be.true
8+
expect(validateNullOrNotBlank()('key', null)).to.be.true
9+
expect(validateNullOrNotBlank()('key', '')).to.be.a('string')
10+
})
11+
})

0 commit comments

Comments
 (0)