diff --git a/app/models/preprint.ts b/app/models/preprint.ts index 26e05211ff..812359beb0 100644 --- a/app/models/preprint.ts +++ b/app/models/preprint.ts @@ -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; diff --git a/app/preprints/-components/preprint-doi/component-test.ts b/app/preprints/-components/preprint-doi/component-test.ts index ff763efb3b..a13fae9c44 100644 --- a/app/preprints/-components/preprint-doi/component-test.ts +++ b/app/preprints/-components/preprint-doi/component-test.ts @@ -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); @@ -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'); @@ -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; + const miragePreprint = server.create('preprint', { + id: 'doied', + provider: mirageProvider, + }, 'withVersions'); + const version1 = server.schema.preprints.find('doied_v1') as ModelInstance; + version1.update({ reviewsState: ReviewsState.ACCEPTED }); + const version2 = server.schema.preprints.find('doied_v2') as ModelInstance; + version2.update({ reviewsState: ReviewsState.PENDING }); + const version3 = server.schema.preprints.find('doied_v3') as ModelInstance; + 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` + + `); + + 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'); + }); }); diff --git a/app/preprints/-components/preprint-doi/component.ts b/app/preprints/-components/preprint-doi/component.ts index e67a9dea03..5cc8af1829 100644 --- a/app/preprints/-components/preprint-doi/component.ts +++ b/app/preprints/-components/preprint-doi/component.ts @@ -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 { @@ -10,11 +13,15 @@ interface InputArgs { } export default class PreprintAbstract extends Component { + @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; diff --git a/app/preprints/-components/preprint-doi/styles.scss b/app/preprints/-components/preprint-doi/styles.scss index d85b72a0d9..5c7f940f69 100644 --- a/app/preprints/-components/preprint-doi/styles.scss +++ b/app/preprints/-components/preprint-doi/styles.scss @@ -1,4 +1,4 @@ .version-dropdown { margin-bottom: 12px; - width: 120px; + width: 200px; } diff --git a/app/preprints/-components/preprint-doi/template.hbs b/app/preprints/-components/preprint-doi/template.hbs index 1d24a5d5da..76d99f19ba 100644 --- a/app/preprints/-components/preprint-doi/template.hbs +++ b/app/preprints/-components/preprint-doi/template.hbs @@ -14,7 +14,12 @@ - {{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}} {{else}} diff --git a/app/preprints/detail/controller.ts b/app/preprints/detail/controller.ts index c5ff7429f7..6d86ac6b3b 100644 --- a/app/preprints/detail/controller.ts +++ b/app/preprints/detail/controller.ts @@ -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'; /** @@ -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; diff --git a/app/preprints/detail/styles.scss b/app/preprints/detail/styles.scss index 23d5338b80..49872b2728 100644 --- a/app/preprints/detail/styles.scss +++ b/app/preprints/detail/styles.scss @@ -265,6 +265,7 @@ } .version-picker-list { + width: max-content; list-style: none; margin: 0; padding-inline-start: 0; diff --git a/app/preprints/detail/template.hbs b/app/preprints/detail/template.hbs index e3aa6c93bb..fe2aea5a22 100644 --- a/app/preprints/detail/template.hbs +++ b/app/preprints/detail/template.hbs @@ -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}} {{else}} diff --git a/tests/acceptance/preprints/detail-test.ts b/tests/acceptance/preprints/detail-test.ts index d641f59cb4..71e221d544 100644 --- a/tests/acceptance/preprints/detail-test.ts +++ b/tests/acceptance/preprints/detail-test.ts @@ -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({ diff --git a/translations/en-us.yml b/translations/en-us.yml index 12b6639cca..849b9f182b 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -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'