From 738dd0182fb10df412b3f1a0ae78258fa7ce5476 Mon Sep 17 00:00:00 2001 From: futa-ikeda Date: Wed, 4 Dec 2024 10:36:25 -0500 Subject: [PATCH 1/2] Update preprint-doi component to handle versions --- .../preprint-doi/component-test.ts | 82 +++++++++++++++++++ .../-components/preprint-doi/component.ts | 12 ++- .../-components/preprint-doi/template.hbs | 61 ++++++++++---- app/preprints/detail/template.hbs | 5 +- mirage/factories/preprint.ts | 4 +- mirage/views/preprint.ts | 3 +- translations/en-us.yml | 2 + 7 files changed, 146 insertions(+), 23 deletions(-) create mode 100644 app/preprints/-components/preprint-doi/component-test.ts diff --git a/app/preprints/-components/preprint-doi/component-test.ts b/app/preprints/-components/preprint-doi/component-test.ts new file mode 100644 index 00000000000..ff763efb3b8 --- /dev/null +++ b/app/preprints/-components/preprint-doi/component-test.ts @@ -0,0 +1,82 @@ +import { click } from '@ember/test-helpers'; +import { module, test } from 'qunit'; +import { setupRenderingTest } from 'ember-qunit'; +import { render } from '@ember/test-helpers'; +import hbs from 'htmlbars-inline-precompile'; +import { setupMirage } from 'ember-cli-mirage/test-support'; +import { ModelInstance } from 'ember-cli-mirage'; + +import PreprintProviderModel from 'ember-osf-web/models/preprint-provider'; +import PreprintModel from 'ember-osf-web/models/preprint'; + +module('Integration | Component | preprint-doi', function(hooks) { + setupRenderingTest(hooks); + setupMirage(hooks); + + test('it renders', 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'); + // Version 1 has a DOI and has a preprintDoiCreated date + const version1 = server.schema.preprints.find('doied_v1') as ModelInstance; + version1.update({ preprintDoiCreated: new Date('2020-02-02') }); + // Version 2 has a DOI but no preprintDoiCreated date + const version2 = server.schema.preprints.find('doied_v2') as ModelInstance; + version2.update({ preprintDoiCreated: null }); + // Version 3 is pending moderator approval and is not published, therefore has no DOI + const version3 = server.schema.preprints.find('doied_v3') as ModelInstance; + version3.update({ + preprintDoiCreated: null, + isPublished: false, + isPreprintDoi: false, // Mirage flag used to determine if a DOI should be created + }); + + 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` + + `); + + // check headings exist + assert.dom('[data-test-preprint-doi-heading]').exists('Preprint DOI heading exists'); + assert.dom('[data-test-preprint-doi-heading]').hasText('Preprint DOI', 'Preprint DOI heading has correct text'); + + // 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'); + + // check version3 has no DOI + assert.dom('[data-test-no-doi-text]').exists('No DOI text exists'); + assert.dom('[data-test-no-doi-text]').hasText('DOI created after moderator approval', 'No DOI text is correct'); + + // check version2 has DOI, but no preprintDoiCreated date + await click('[data-test-version-select-dropdown]'); + await click('[data-test-preprint-version="2"]'); + assert.dom('[data-test-no-doi-text]').doesNotExist('No DOI text does not exist'); + assert.dom('[data-test-unlinked-doi-url]').exists('Preprint DOI URL exists'); + assert.dom('[data-test-unlinked-doi-description]').exists('Preprint DOI description exists'); + assert.dom('[data-test-unlinked-doi-description]') + // eslint-disable-next-line max-len + .hasText('DOIs are minted by a third party, and may take up to 24 hours to be registered.', 'Description is correct'); + + // check version1 has DOI and preprintDoiCreated date + await click('[data-test-version-select-dropdown]'); + await click('[data-test-preprint-version="1"]'); + assert.dom('[data-test-unlinked-doi-url]').doesNotExist('Unlinked preprint DOI URL does not exist'); + 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'); + }); +}); diff --git a/app/preprints/-components/preprint-doi/component.ts b/app/preprints/-components/preprint-doi/component.ts index 6ad155176a8..e67a9dea037 100644 --- a/app/preprints/-components/preprint-doi/component.ts +++ b/app/preprints/-components/preprint-doi/component.ts @@ -1,14 +1,22 @@ +import { action } from '@ember/object'; import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; import PreprintModel from 'ember-osf-web/models/preprint'; import PreprintProviderModel from 'ember-osf-web/models/preprint-provider'; interface InputArgs { - preprint: PreprintModel; + versions: PreprintModel[]; provider: PreprintProviderModel; } export default class PreprintAbstract extends Component { provider = this.args.provider; + documentType = this.provider.documentType.singularCapitalized; - documentType = this.provider.documentType.singular; + @tracked selectedVersion = this.args.versions[0]; + + @action + selectVersion(version: PreprintModel) { + this.selectedVersion = version; + } } diff --git a/app/preprints/-components/preprint-doi/template.hbs b/app/preprints/-components/preprint-doi/template.hbs index 55942ff37e3..22d31dc3e0d 100644 --- a/app/preprints/-components/preprint-doi/template.hbs +++ b/app/preprints/-components/preprint-doi/template.hbs @@ -1,23 +1,48 @@
-

{{t 'preprints.detail.preprint_doi' documentType=this.documentType}}

- {{#if @preprint.preprintDoiUrl}} - {{#if @preprint.preprintDoiCreated}} - + {{t 'preprints.detail.preprint_doi' documentType=this.documentType}} + + {{#if @versions}} + + - {{@preprint.preprintDoiUrl}} - - {{else}} -

{{@preprint.preprintDoiUrl}}

-

{{t 'preprints.detail.preprint_pending_doi_minted'}}

- {{/if}} + {{t 'preprints.detail.version_doi_title' number=version.preprintVersion}} + + {{else}} - {{#if (not @preprint.public)}} - {{t 'preprints.detail.preprint_pending_doi' documentType=this.documentType}} - {{else if (and this.provider.reviewsWorkflow (not this.preprint.isPublished))}} - {{t 'preprints.detail.preprint_pending_doi_moderation'}} +

{{t 'preprints.detail.no_versions'}}

+ {{/if}} + {{#if this.selectedVersion}} + {{#if this.selectedVersion.preprintDoiUrl}} + {{#if this.selectedVersion.preprintDoiCreated}} + + {{this.selectedVersion.preprintDoiUrl}} + + {{else}} +

{{this.selectedVersion.preprintDoiUrl}}

+

{{t 'preprints.detail.preprint_pending_doi_minted'}}

+ {{/if}} + {{else}} +

+ {{#if (not this.selectedVersion.public)}} + {{t 'preprints.detail.preprint_pending_doi' documentType=this.documentType}} + {{else if (and this.provider.reviewsWorkflow (not this.preprint.isPublished))}} + {{t 'preprints.detail.preprint_pending_doi_moderation'}} + {{else}} + {{t 'preprints.detail.no_doi'}} + {{/if}} +

{{/if}} {{/if}} -
\ No newline at end of file + diff --git a/app/preprints/detail/template.hbs b/app/preprints/detail/template.hbs index a6a14847d5f..e2c16f42825 100644 --- a/app/preprints/detail/template.hbs +++ b/app/preprints/detail/template.hbs @@ -181,7 +181,10 @@ {{/if}} - + {{#if this.model.preprint.articleDoiUrl}}

{{t 'preprints.detail.article_doi'}}

diff --git a/mirage/factories/preprint.ts b/mirage/factories/preprint.ts index 34c711446f0..60755c234c6 100644 --- a/mirage/factories/preprint.ts +++ b/mirage/factories/preprint.ts @@ -255,7 +255,9 @@ export default Factory.extend({ isLatestVersion: version === 3, }); }); - preprint.provider.update({ preprints: versionedPreprints }); + if (preprint.provider) { + preprint.provider.update({ preprints: versionedPreprints }); + } }, }), diff --git a/mirage/views/preprint.ts b/mirage/views/preprint.ts index b969bc9866c..e71845b6817 100644 --- a/mirage/views/preprint.ts +++ b/mirage/views/preprint.ts @@ -90,6 +90,7 @@ export function getPreprintVersions(this: HandlerContext, schema: Schema) { const baseId = preprintId.split('_v')[0]; // assumes preprint id is of the form _v const preprints = schema.preprints.all().models .filter((preprint: ModelInstance) => preprint.id !== baseId && preprint.id.includes(baseId)); + const versions = preprints.sortBy('versionNumber').reverse(); return process(schema, this.request, this, - preprints.map((preprint: ModelInstance) => this.serialize(preprint).data)); + versions.map((version: ModelInstance) => this.serialize(version).data)); } diff --git a/translations/en-us.yml b/translations/en-us.yml index 0416c52097d..0383cd7f79e 100644 --- a/translations/en-us.yml +++ b/translations/en-us.yml @@ -1431,8 +1431,10 @@ preprints: original_publication_date: 'Original Publication Date' orphan_preprint: 'The user has removed this file.' preprint_doi: '{documentType} DOI' + version_doi_title: 'Version {number}' preprint_pending_doi: 'DOI created after {documentType} is made public' preprint_pending_doi_moderation: 'DOI created after moderator approval' + no_doi: 'No DOI' preprint_pending_doi_minted: 'DOIs are minted by a third party, and may take up to 24 hours to be registered.' private_preprint_warning: 'This {documentType} is private. Contact {supportEmail} if this is in error.' project_button: From d0dca8b9bff0eaa6b6785bac842b6920dd3977c2 Mon Sep 17 00:00:00 2001 From: futa-ikeda Date: Wed, 4 Dec 2024 10:47:20 -0500 Subject: [PATCH 2/2] Styling --- app/preprints/-components/preprint-doi/styles.scss | 4 ++++ app/preprints/-components/preprint-doi/template.hbs | 1 + 2 files changed, 5 insertions(+) create mode 100644 app/preprints/-components/preprint-doi/styles.scss diff --git a/app/preprints/-components/preprint-doi/styles.scss b/app/preprints/-components/preprint-doi/styles.scss new file mode 100644 index 00000000000..d85b72a0d94 --- /dev/null +++ b/app/preprints/-components/preprint-doi/styles.scss @@ -0,0 +1,4 @@ +.version-dropdown { + margin-bottom: 12px; + width: 120px; +} diff --git a/app/preprints/-components/preprint-doi/template.hbs b/app/preprints/-components/preprint-doi/template.hbs index 22d31dc3e0d..e063aa422e4 100644 --- a/app/preprints/-components/preprint-doi/template.hbs +++ b/app/preprints/-components/preprint-doi/template.hbs @@ -5,6 +5,7 @@ {{#if @versions}}