Skip to content

Commit

Permalink
Merge 075865d into d57bb40
Browse files Browse the repository at this point in the history
  • Loading branch information
sheriefvt committed Nov 3, 2017
2 parents d57bb40 + 075865d commit 37eae7e
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 129 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- Headless Firefox for tests
- Add integration test for moderation-list-row component
### Changed
- Remove global eslint rule and inline in router
- Update travis to use Firefox
Expand All @@ -15,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Update yarn.lock
- Use COS ember-base image and multi-stage build
- Notify DevOps prior to merging into master to update Jenkins
- Show moderator name (instead of creator) in the accepted/rejected records in the moderation list
### Removed
### Fixed
- Fix Loading indicator on Reviews dashboard which was not displaying when user clicks on see more link button.
Expand Down
39 changes: 26 additions & 13 deletions app/components/moderation-list-row/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { computed } from '@ember/object';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import moment from 'moment';
import latestAction from 'reviews/utils/latest-action';

const PENDING = 'pending';
const ACCEPTED = 'accepted';
Expand All @@ -13,22 +14,37 @@ const ACTION_LABELS = Object.freeze({
ltDay: 'components.moderation-list-row.submission.submitted',
},
[ACCEPTED]: {
gtDay: 'components.moderation-list-row.submission.was_accepted_on',
ltDay: 'components.moderation-list-row.submission.was_accepted',
gtDay: 'components.moderation-list-row.submission.accepted_on',
ltDay: 'components.moderation-list-row.submission.accepted',
gtDay_automatic: 'components.moderation-list-row.submission.accepted_automatically_on',
ltDay_automatic: 'components.moderation-list-row.submission.accepted_automatically',
},
[REJECTED]: {
gtDay: 'components.moderation-list-row.submission.was_rejected_on',
ltDay: 'components.moderation-list-row.submission.was_rejected',
gtDay: 'components.moderation-list-row.submission.rejected_on',
ltDay: 'components.moderation-list-row.submission.rejected',
},
});


export default Component.extend({
theme: service(),
i18n: service(),

classNames: ['moderation-list-row'],

dataLoading: computed.not('firstContributors.length'),
latestActionCreator: computed.alias('latestAction.creator.fullName'),

moderatorLoading: computed('noActions', 'latestActionCreator', function () {
return !(this.get('noActions') || this.get('latestActionCreator'));
}),

latestAction: computed('submission.actions.[]', function() {
return latestAction(this.get('submission.actions'));
}),

noActions: computed('submission.actions.{length,isPending}', function () {
return !this.get('submission.actions.length') || this.get('submission.actions.isPending');
}),

firstContributors: computed('submission.node.contributors', function() {
return this.get('submission.node.contributors').slice(0, 3);
Expand All @@ -49,15 +65,12 @@ export default Component.extend({
}),

// translations
dateLabel: computed('submission.reviewsState', 'gtDay', function() {
statusTimeDate: computed('submission.reviewsState', 'gtDay', 'noActions', function() {
const i18n = this.get('i18n');
const dayValue = this.get('gtDay') ? 'gtDay' : 'ltDay';
return ACTION_LABELS[this.get('submission.reviewsState')][dayValue];
}),

submittedByLabel: computed('submission.reviewsState', function() {
return this.get('submission.reviewsState') === PENDING ?
'components.moderation-list-row.submission.by' :
'components.moderation-list-row.submission.submission_by';
const timeWording = this.get('noActions') ? `${dayValue}_automatic` : dayValue;
const labels = ACTION_LABELS[this.get('submission.reviewsState')][timeWording];
return i18n.t(labels, { timeDate: this.get('relevantDate'), moderatorName: this.get('latestActionCreator') });
}),

init() {
Expand Down
24 changes: 11 additions & 13 deletions app/components/moderation-list-row/template.hbs
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
{{#link-to 'preprints.provider.preprint-detail' theme.id submission.id disabled=dataLoading}}
{{#link-to 'preprints.provider.preprint-detail' theme.id submission.id
disabled=(or moderatorLoading submission.node.isPending submission.node.contributors.isPending)}}
<div data-status={{submission.reviewsState}} class="flex-container">
<i class="fa fa-lg {{get iconClass submission.reviewsState}} status-icon"></i>
<div title={{submission.title}} class="submission-info">
<div class="submission-title">{{submission.title}}</div>
{{#if dataLoading}}
{{#if (or moderatorLoading submission.node.isPending submission.node.contributors.isPending)}}
{{loading-indicator classes='ball-dark'}}
{{else}}
<div class="submission-body">
{{#if (eq submission.reviewsState 'pending')}}
{{t dateLabel}} {{relevantDate}} {{t submittedByLabel}}
{{statusTimeDate}}
{{#each firstContributors as |contributor| ~}}
<li>{{contributor.users.fullName}}</li>
{{/each}}
{{#if (gt additionalContributors 0)}}
+ {{additionalContributors}}
{{/if}}
{{else}}
{{t submittedByLabel}}
{{/if}}
{{#each firstContributors as |contributor| ~}}
<li>{{contributor.users.fullName}}</li>
{{/each}}
{{#if (gt additionalContributors 0)}}
+ {{additionalContributors}}
{{/if}}
{{#if (not-eq submission.reviewsState 'pending')}}
{{t dateLabel}} {{relevantDate}}
{{statusTimeDate}}
{{/if}}
</div>
{{/if}}
Expand Down
1 change: 0 additions & 1 deletion app/components/preprint-status-banner/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { inject as service } from '@ember/service';
import Component from '@ember/component';
import latestAction from 'reviews/utils/latest-action';


const PENDING = 'pending';
const ACCEPTED = 'accepted';
const REJECTED = 'rejected';
Expand Down
16 changes: 8 additions & 8 deletions app/locales/en/translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ export default {
},
'moderation-list-row': {
submission: {
submitted_on: 'submitted on',
was_accepted_on: 'was accepted on',
was_rejected_on: 'was rejected on',
submitted: 'submitted',
was_accepted: 'was accepted',
was_rejected: 'was rejected',
by: 'by',
submission_by: 'submission by',
submitted_on: 'submitted on {{timeDate}} by',
submitted: 'submitted {{timeDate}} by',
accepted_on: 'accepted on {{timeDate}} by {{moderatorName}}',
accepted: 'accepted {{timeDate}} by {{moderatorName}}',
accepted_automatically_on: 'accepted automatically on {{timeDate}}',
accepted_automatically: 'accepted automatically {{timeDate}}',
rejected_on: 'rejected on {{timeDate}} by {{moderatorName}}',
rejected: 'rejected {{timeDate}} by {{moderatorName}}',
},
},
'preprint-status-banner': {
Expand Down
8 changes: 4 additions & 4 deletions app/utils/latest-action.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import moment from 'moment';


export default function latestAction(actions) {
if (!actions.length) {
export default function latestAction(submissionActions) {
if (!submissionActions.get('length')) {
return null;
}
// on create, Ember puts the new object at the end of the array
// https://stackoverflow.com/questions/15210249/ember-data-insert-new-item-at-beginning-of-array-instead-of-at-the-end
const first = actions.get('firstObject');
const last = actions.get('lastObject');
const first = submissionActions.get('firstObject');
const last = submissionActions.get('lastObject');
return moment(first.get('dateModified')) > moment(last.get('dateModified')) ? first : last;
}
90 changes: 90 additions & 0 deletions tests/integration/components/moderation-list-row/component-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import EmberObject from '@ember/object';
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('moderation-list-row', 'Integration | Component | moderation-list-row', {
integration: true,
});


test('it renders moderation-list-row accepted with actions', function(assert) {
this.set('submission', {
dateLastTransitioned: '2017-10-27T19:14:27.816946Z',
actions: [
EmberObject.create({
fromState: 'pending', toState: 'accepted', dateModified: '2017-10-28T14:57:35.949534Z', creator: { fullName: 'Kung-fu Panda' },
}),
EmberObject.create({
fromState: 'initial', toState: 'pending', dateModified: '2017-10-27T14:57:35.949534Z', creator: { fullName: 'Viper' },
}),
],
reviewsState: 'accepted',
node: { contributors: ['Viper', 'Oogway'] },
});
this.render(hbs`{{moderation-list-row submission=submission}}`);
assert.ok(this.$('[data-status=accepted]').length);
assert.notOk(this.$('[data-status=pending]').length);
assert.notOk(this.$('[data-status=rejected]').length);

assert.equal(this.$('[data-status=accepted]').text().trim(), 'accepted on October 27, 2017 by Kung-fu Panda');
});

test('it renders moderation-list-row accepted without actions', function(assert) {
this.set('submission', {
dateLastTransitioned: '2017-10-27T19:14:27.816946Z',
actions: [],
reviewsState: 'accepted',
node: { contributors: ['Tigerss', 'Crane'] },
});
this.render(hbs`{{moderation-list-row submission=submission}}`);
assert.equal(this.$('[data-status=accepted]').text().trim(), 'accepted automatically on October 27, 2017');
});

test('it renders moderation-list-row rejected with actions', function(assert) {
this.set('submission', {
dateLastTransitioned: '2017-10-27T19:14:27.816946Z',
actions: [
EmberObject.create({
fromState: 'pending', toState: 'rejected', dateModified: '2017-10-28T14:57:35.949534Z', creator: { fullName: 'Master Shifu' },
}),
EmberObject.create({
fromState: 'initial', toState: 'pending', dateModified: '2017-10-27T14:57:35.949534Z', creator: { fullName: 'Mantis' },
}),
],
reviewsState: 'rejected',
node: { contributors: ['Mr. Ping', 'Mantis'] },
});
this.render(hbs`{{moderation-list-row submission=submission}}`);
assert.equal(this.$('[data-status=rejected]').text().trim(), 'rejected on October 27, 2017 by Master Shifu');
});

test('it renders moderation-list-row pending with actions', function(assert) {
this.set('submission', {
dateLastTransitioned: '2017-10-27T19:14:27.816946Z',
actions: [
EmberObject.create({
fromState: 'initial', toState: 'pending', dateModified: '2017-10-27T14:57:35.949534Z', creator: { fullName: 'Mantis' },
}),
],
reviewsState: 'pending',
node: { contributors: [{ users: { fullName: 'Mr. Ping' } }, { users: { fullName: 'Mantis' } }] },
});
this.render(hbs`{{moderation-list-row submission=submission}}`);
assert.equal(this.$('[data-status=pending]').text().replace(/\n/g, ' ').trim(), 'submitted on October 27, 2017 by Mr. Ping Mantis');
});

test('it renders moderation-list-row pending with actions and more than three contributors', function(assert) {
this.set('submission', {
dateLastTransitioned: '2017-10-27T19:14:27.816946Z',
actions: [
EmberObject.create({
fromState: 'initial', toState: 'pending', dateModified: '2017-10-27T14:57:35.949534Z', creator: { fullName: 'Mantis' },
}),
],
reviewsState: 'pending',
node: { contributors: [{ users: { fullName: 'Mr. Ping' } }, { users: { fullName: 'Mantis' } }, { users: { fullName: 'Crane' } }, { users: { fullName: 'Tai Lung' } }] },
});
this.set('submission.node.contributors.content', { meta: { pagination: { total: this.get('submission.node.contributors.length') } } });
this.render(hbs`{{moderation-list-row submission=submission}}`);
assert.equal(this.$('[data-status=pending]').text().replace(/\s+/g, ' ').trim(), 'submitted on October 27, 2017 by Mr. Ping Mantis Crane + 1');
});
Loading

0 comments on commit 37eae7e

Please sign in to comment.