Skip to content

Commit

Permalink
Merge pull request #245 from opendatakit/audit-changes
Browse files Browse the repository at this point in the history
Update AuditList
  • Loading branch information
matthew-white authored Aug 14, 2019
2 parents c7908f1 + 92bbdfc commit 43a7ed4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
23 changes: 16 additions & 7 deletions src/components/audit/filters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,24 @@ export default {
filter() {
this.$emit('filter', { action: this.action, dateRange: this.dateRange });
},
todayToToday() {
const today = DateTime.local().startOf('day');
return [today, today];
},
closeCalendar(dates) {
if (dates.length !== 0) {
this.dateRange = dates.map(date => DateTime.fromJSDate(date));
} else {
const today = DateTime.local().startOf('day');
this.dateRange = [today, today];
this.dateRangeString = this.dateRangeToString(this.dateRange);
const dateRange = dates.length !== 0
? dates.map(date => DateTime.fromJSDate(date))
: this.todayToToday();
if (dateRange[0].valueOf() !== this.dateRange[0].valueOf() ||
dateRange[1].valueOf() !== this.dateRange[1].valueOf()) {
this.dateRange = dateRange;
this.filter();
}
this.filter();
// If the date range is cleared, this.dateRangeString will be empty, and
// we will need to reset it (regardless of whether this.dateRange
// changed).
if (dates.length === 0)
this.dateRangeString = this.dateRangeToString(dateRange);
}
}
};
Expand Down
8 changes: 6 additions & 2 deletions src/components/audit/row.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ except according to the terms contained in the LICENSE file.
{{ targetTitle }}
</router-link>
</td>
<td ref="details" class="details" @click="selectDetails">{{ details }}</td>
<td class="details">
<!-- Adding a <div> to work around a Firefox bug: see
https://bugzilla.mozilla.org/show_bug.cgi?id=386970. -->
<div ref="details" @click="selectDetails">{{ details }}</div>
</td>
</tr>
</template>

Expand Down Expand Up @@ -166,7 +170,7 @@ export default {
white-space: nowrap;
}

.details {
.details div {
font-family: $font-family-monospace;
overflow-x: auto;
white-space: nowrap;
Expand Down
40 changes: 40 additions & 0 deletions test/components/audit/filters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,44 @@ describe('AuditFilters', () => {
.respondWithData(() => testData.extendedAudits.sorted())
.finally(restoreLuxon);
});

it('does not send a request if the same date range is selected', () => {
const restoreLuxon = setLuxon({
defaultZoneName: 'utc',
now: '1970-01-01T12:00:00Z'
});
let called = false;
return mockHttp()
.mount(AuditList)
.respondWithData(() => testData.extendedAudits.sorted())
.complete()
// Select the same date range.
.request(component => {
const date = DateTime.fromISO('1970-01-01').toJSDate();
component.first(AuditFilters).vm.closeCalendar([date, date]);
})
.respondWithData([/* no responses */])
.complete()
// Clear the date range (defaulting to the same date range).
.request(component => {
const auditFilters = component.first(AuditFilters);
const { dateRangeToString } = auditFilters.vm;
auditFilters.setMethods({
dateRangeToString: (dateRange) => {
called = true;
return dateRangeToString(dateRange);
}
});
return auditFilters.vm.$nextTick().then(() => {
auditFilters.vm.closeCalendar([]);
});
})
.respondWithData([/* no responses */])
.then(() => {
// The date range has not changed, but the dateRangeString property
// still should have been reset.
called.should.be.true();
})
.finally(restoreLuxon);
});
});
4 changes: 2 additions & 2 deletions test/components/audit/table.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ describe('AuditTable', () => {
details: { some: 'json' }
})
.sorted())
.afterResponse(app => trigger.click(app, '.audit-row .details'))
.afterResponse(app => trigger.click(app, '.audit-row .details div'))
.then(() => {
const selection = window.getSelection();
const details = document.querySelector('.audit-row .details');
const details = document.querySelector('.audit-row .details div');
selection.anchorNode.should.equal(details);
selection.focusNode.should.equal(details);
}));
Expand Down

0 comments on commit 43a7ed4

Please sign in to comment.