Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-6471] Add status labels to version dropdowns #2444

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/models/preprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export enum PreprintPreregLinkInfoEnum {
PREREG_BOTH = 'prereg_both',
}

export const VersionStatusSimpleLabelKey = {
[ReviewsState.PENDING]: 'preprints.detail.version_status.pending',
[ReviewsState.REJECTED]: 'preprints.detail.version_status.rejected',
[ReviewsState.WITHDRAWN]: 'preprints.detail.version_status.withdrawn',
};

export interface PreprintLicenseRecordModel {
copyright_holders: string[];
year: string;
Expand Down
41 changes: 40 additions & 1 deletion app/preprints/-components/preprint-doi/component-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ModelInstance } from 'ember-cli-mirage';

import PreprintProviderModel from 'ember-osf-web/models/preprint-provider';
import PreprintModel from 'ember-osf-web/models/preprint';
import { ReviewsState } from 'ember-osf-web/models/provider';

module('Integration | Component | preprint-doi', function(hooks) {
setupRenderingTest(hooks);
Expand Down Expand Up @@ -56,7 +57,7 @@ module('Integration | Component | preprint-doi', function(hooks) {
// check dropdown exists
assert.dom('[data-test-version-select-dropdown]').exists('Version select dropdown exists');
assert.dom('[data-test-version-select-dropdown]')
.hasText('Version 3', 'Dropdown has latest version selected by default');
.hasText('Version 3 (Rejected)', 'Dropdown has latest version selected by default');

// check version3 has no DOI
assert.dom('[data-test-no-doi-text]').exists('No DOI text exists');
Expand All @@ -79,4 +80,42 @@ module('Integration | Component | preprint-doi', function(hooks) {
assert.dom('[data-test-unlinked-doi-description]').doesNotExist('Unlinked description does not exist');
assert.dom('[data-test-linked-doi-url]').exists('Preprint DOI URL exists');
});

test('it renders statuses', async function(assert) {
this.store = this.owner.lookup('service:store');
server.loadFixtures('preprint-providers');
const mirageProvider = server.schema.preprintProviders.find('osf') as ModelInstance<PreprintProviderModel>;
const miragePreprint = server.create('preprint', {
id: 'doied',
provider: mirageProvider,
}, 'withVersions');
const version1 = server.schema.preprints.find('doied_v1') as ModelInstance<PreprintModel>;
version1.update({ reviewsState: ReviewsState.ACCEPTED });
const version2 = server.schema.preprints.find('doied_v2') as ModelInstance<PreprintModel>;
version2.update({ reviewsState: ReviewsState.PENDING });
const version3 = server.schema.preprints.find('doied_v3') as ModelInstance<PreprintModel>;
version3.update({ reviewsState: ReviewsState.WITHDRAWN });

const preprint = await this.store.findRecord('preprint', miragePreprint.id);
const versions = await preprint.queryHasMany('versions');

const provider = await this.store.findRecord('preprint-provider', mirageProvider.id);
this.set('versions', versions);
this.set('provider', provider);

await render(hbs`
<Preprints::-Components::PreprintDoi
@versions={{this.versions}}
@provider={{this.provider}}
/>
`);

await click('[data-test-version-select-dropdown]');
assert.dom('[data-test-preprint-version="1"]').exists('Version 1 exists');
assert.dom('[data-test-preprint-version="1"]').hasText('Version 1', 'Version 1 is accepted');
assert.dom('[data-test-preprint-version="2"]').exists('Version 2 exists');
assert.dom('[data-test-preprint-version="2"]').hasText('Version 2 (Pending)', 'Version 2 is pending');
assert.dom('[data-test-preprint-version="3"]').exists('Version 3 exists');
assert.dom('[data-test-preprint-version="3"]').hasText('Version 3 (Withdrawn)', 'Version 3 is withdrawn');
});
});
9 changes: 8 additions & 1 deletion app/preprints/-components/preprint-doi/component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import PreprintModel from 'ember-osf-web/models/preprint';
import Intl from 'ember-intl/services/intl';

import PreprintModel, { VersionStatusSimpleLabelKey } from 'ember-osf-web/models/preprint';
import PreprintProviderModel from 'ember-osf-web/models/preprint-provider';

interface InputArgs {
Expand All @@ -10,11 +13,15 @@ interface InputArgs {
}

export default class PreprintAbstract extends Component<InputArgs> {
@service intl!: Intl;

provider = this.args.provider;
documentType = this.provider.documentType.singularCapitalized;

@tracked selectedVersion = this.args.versions[0];

reviewStateLabelKeyMap = VersionStatusSimpleLabelKey;

@action
selectVersion(version: PreprintModel) {
this.selectedVersion = version;
Expand Down
2 changes: 1 addition & 1 deletion app/preprints/-components/preprint-doi/styles.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.version-dropdown {
margin-bottom: 12px;
width: 120px;
width: 200px;
}
7 changes: 6 additions & 1 deletion app/preprints/-components/preprint-doi/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
<span
data-test-preprint-version={{version.version}}
>
{{t 'preprints.detail.version_doi_title' number=version.version}}
{{#let (get this.reviewStateLabelKeyMap version.reviewsState) as |reviewStateLabelKey|}}
{{t 'preprints.detail.version_doi_title' number=version.version}}
{{#if reviewStateLabelKey}}
{{t (get this.reviewStateLabelKeyMap version.reviewsState)}}
{{/if}}
{{/let}}
</span>
</PowerSelect>
{{else}}
Expand Down
21 changes: 12 additions & 9 deletions app/preprints/detail/controller.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import config from 'ember-osf-web/config/environment';
import Theme from 'ember-osf-web/services/theme';
import CurrentUserService from 'ember-osf-web/services/current-user';
import { waitFor } from '@ember/test-waiters';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency';
import Features from 'ember-feature-flags';
import ContributorModel from 'ember-osf-web/models/contributor';
import Intl from 'ember-intl/services/intl';
import { Permission } from 'ember-osf-web/models/osf-model';
import { ReviewsState, PreprintProviderReviewsWorkFlow } from 'ember-osf-web/models/provider';
import { tracked } from '@glimmer/tracking';
import Media from 'ember-responsive';
import Toast from 'ember-toastr/services/toast';
import { task } from 'ember-concurrency';
import { waitFor } from '@ember/test-waiters';

import config from 'ember-osf-web/config/environment';
import ContributorModel from 'ember-osf-web/models/contributor';
import { Permission } from 'ember-osf-web/models/osf-model';
import { VersionStatusSimpleLabelKey } from 'ember-osf-web/models/preprint';
import { PreprintProviderReviewsWorkFlow, ReviewsState } from 'ember-osf-web/models/provider';
import CurrentUserService from 'ember-osf-web/services/current-user';
import Theme from 'ember-osf-web/services/theme';


/**
Expand Down Expand Up @@ -53,6 +55,7 @@ export default class PrePrintsDetailController extends Controller {
@tracked plauditIsReady = false;

metricsStartDate = config.OSF.metricsStartDate;
reviewStateLabelKeyMap = VersionStatusSimpleLabelKey;

get hyperlink(): string {
return window.location.href;
Expand Down
1 change: 1 addition & 0 deletions app/preprints/detail/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
}

.version-picker-list {
width: max-content;
list-style: none;
margin: 0;
padding-inline-start: 0;
Expand Down
7 changes: 6 additions & 1 deletion app/preprints/detail/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@
@route='preprints.detail'
@models={{array this.model.provider.id version.id}}
>
{{t 'preprints.detail.preprint_version_number' number=version.version}}
{{#let (get this.reviewStateLabelKeyMap version.reviewsState) as |reviewStateLabelKey|}}
{{t 'preprints.detail.preprint_version_number' number=version.version}}
{{#if reviewStateLabelKey}}
{{t (get this.reviewStateLabelKeyMap version.reviewsState)}}
{{/if}}
{{/let}}
</OsfLink>
</li>
{{else}}
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/preprints/detail-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ module('Acceptance | preprints | detail', hooks => {
dateWithdrawn: new Date(),
currentUserPermissions: Object.values(Permission),
title: 'Test Preprint',
reviewsState: ReviewsState.WITHDRAWN,
description: 'This is a test preprint',
}, 'withVersions');
this.preprint.update({
Expand Down
4 changes: 4 additions & 0 deletions translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1445,6 +1445,10 @@ preprints:
orphan_preprint: 'The user has removed this file.'
preprint_doi: '{documentType} DOI'
version_doi_title: 'Version {number}'
version_status:
pending: '(Pending)'
rejected: '(Rejected)'
withdrawn: '(Withdrawn)'
preprint_pending_doi: 'DOI created after {documentType} is made public'
preprint_pending_doi_moderation: 'DOI created after moderator approval'
no_doi: 'No DOI'
Expand Down
Loading