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-6813] FE Reference PR for Preprints DOI Versioning #2447

Draft
wants to merge 12 commits into
base: develop
Choose a base branch
from
Draft
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
19 changes: 19 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 Expand Up @@ -70,6 +76,8 @@ export default class PreprintModel extends AbstractNodeModel {
@attr('string') whyNoData!: string | null;
@attr('string') whyNoPrereg!: string | null;
@attr('string') preregLinkInfo!: PreprintPreregLinkInfoEnum;
@attr('number') version!: number;
@attr('boolean') isLatestVersion!: boolean;

@belongsTo('node', { inverse: 'preprints' })
node!: AsyncBelongsTo<NodeModel> & NodeModel;
Expand Down Expand Up @@ -107,6 +115,9 @@ export default class PreprintModel extends AbstractNodeModel {
@hasMany('identifiers')
identifiers!: AsyncHasMany<IdentifierModel>;

@hasMany('preprint', { inverse: null })
versions!: AsyncHasMany<PreprintModel>;

@alias('links.doi') articleDoiUrl!: string | null;
@alias('links.preprint_doi') preprintDoiUrl!: string;

Expand All @@ -123,6 +134,14 @@ export default class PreprintModel extends AbstractNodeModel {
.replace(/({{year}})/g, year)
.replace(/({{copyrightHolders}})/g, copyright_holders.join(', '));
}

get currentUserIsAdmin(): boolean {
return this.currentUserPermissions.includes(Permission.Admin);
}

get canCreateNewVersion(): boolean {
return this.currentUserIsAdmin && this.datePublished && this.isLatestVersion;
}
}

declare module 'ember-data/types/registries/model' {
Expand Down
135 changes: 135 additions & 0 deletions app/preprints/-components/preprint-doi/component-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
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';
import { ReviewsState } from 'ember-osf-web/models/provider';
import { OsfLinkRouterStub } from 'ember-osf-web/tests/integration/helpers/osf-link-router-stub';

module('Integration | Component | preprint-doi', function(hooks) {
setupRenderingTest(hooks);
setupMirage(hooks);

test('it renders', async function(assert) {
this.owner.unregister('service:router');
this.owner.register('service:router', OsfLinkRouterStub);
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');
// Version 1 has a DOI and has a preprintDoiCreated date
const version1 = server.schema.preprints.find('doied_v1') as ModelInstance<PreprintModel>;
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<PreprintModel>;
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<PreprintModel>;
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('currentVersion', versions[1]);
this.set('provider', provider);

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

// 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 2 (Rejected)', 'Dropdown has passed in currentVersiom selected by default');
assert.dom('[data-test-preprint-version="2"]').exists('Version 2 is shown');

assert.dom('[data-test-view-version-link]').exists('View in OSF button exists');
assert.dom('[data-test-view-version-link]').hasText('View version 2', 'View version link has correct text');

// check version2 has DOI text
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 version3 has DOI, but no preprintDoiCreated date
await click('[data-test-version-select-dropdown]');
await click('[data-test-preprint-version="3"]');
assert.dom('[data-test-unlinked-doi-url]').doesNotExist('Unlinked preprint DOI URL does not exist');
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 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');
});

test('it renders statuses', async function(assert) {
this.owner.unregister('service:router');
this.owner.register('service:router', OsfLinkRouterStub);
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('currentVersion', versions[0]);
this.set('versions', versions);
this.set('provider', provider);

await render(hbs`
<Preprints::-Components::PreprintDoi
@currentVersion={{this.currentVersion}}
@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');
});
});
22 changes: 19 additions & 3 deletions app/preprints/-components/preprint-doi/component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import Component from '@glimmer/component';
import PreprintModel from 'ember-osf-web/models/preprint';
import { tracked } from '@glimmer/tracking';
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 {
preprint: PreprintModel;
versions: PreprintModel[];
provider: PreprintProviderModel;
currentVersion: PreprintModel;
}

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

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

@tracked selectedVersion = this.args.currentVersion;

reviewStateLabelKeyMap = VersionStatusSimpleLabelKey;

documentType = this.provider.documentType.singular;
@action
selectVersion(version: PreprintModel) {
this.selectedVersion = version;
}
}
8 changes: 8 additions & 0 deletions app/preprints/-components/preprint-doi/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.version-dropdown {
margin-bottom: 12px;
width: 200px;
}

.current-version {
font-weight: bold;
}
76 changes: 58 additions & 18 deletions app/preprints/-components/preprint-doi/template.hbs
Original file line number Diff line number Diff line change
@@ -1,23 +1,63 @@
<div>
<h4>{{t 'preprints.detail.preprint_doi' documentType=this.documentType}}</h4>
{{#if @preprint.preprintDoiUrl}}
{{#if @preprint.preprintDoiCreated}}
<OsfLink
data-test-article-doi
data-analytics-name='preprint doi'
@href={{@preprint.preprintDoiUrl}}
<h4 data-test-preprint-doi-heading>
{{t 'preprints.detail.preprint_doi' documentType=this.documentType}}
</h4>
{{#if @versions}}
<PowerSelect
data-test-version-select-dropdown
local-class='version-dropdown'
@options={{@versions}}
@selected={{this.selectedVersion}}
@onChange={{this.selectVersion}}
as |version|
>
<span
local-class={{if (eq version.version @currentVersion.version) 'current-version'}}
data-test-preprint-version={{version.version}}
>
{{@preprint.preprintDoiUrl}}
</OsfLink>
{{else}}
<p> {{@preprint.preprintDoiUrl}} </p>
<p> {{t 'preprints.detail.preprint_pending_doi_minted'}} </p>
{{/if}}
{{#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}}
{{#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'}}
<p>{{t 'preprints.detail.no_versions'}}</p>
{{/if}}
{{#if this.selectedVersion}}
<OsfLink
data-test-view-version-link
data-analytics-name='View version link'
@route='preprints.detail'
@models={{array @provider.id this.selectedVersion.id}}
>
{{t 'preprints.detail.view_version' number=this.selectedVersion.version}}
</OsfLink>
{{#if this.selectedVersion.preprintDoiUrl}}
{{#if this.selectedVersion.preprintDoiCreated}}
<OsfLink
data-test-linked-doi-url
data-analytics-name='preprint doi'
@href={{this.selectedVersion.preprintDoiUrl}}
>
{{this.selectedVersion.preprintDoiUrl}}
</OsfLink>
{{else}}
<p data-test-unlinked-doi-url> {{this.selectedVersion.preprintDoiUrl}} </p>
<p data-test-unlinked-doi-description> {{t 'preprints.detail.preprint_pending_doi_minted'}} </p>
{{/if}}
{{else}}
<p data-test-no-doi-text>
{{#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}}
</p>
{{/if}}
{{/if}}
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<div local-class='create-button-container'>
<Button
data-test-create-preprints
data-analytics-name='Create Preprint'
local-class='create-button {{if this.isDisabled 'disabled'}}'
disabled={{this.isDisabled}}
@type='create'
Expand Down
6 changes: 5 additions & 1 deletion app/preprints/-components/preprint-tombstone/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
</div>
{{/if}}
<Preprints::-Components::PreprintAbstract @preprint={{@preprint}} />
<Preprints::-Components::PreprintDoi @preprint={{@preprint}} @provider={{@provider}} />
<Preprints::-Components::PreprintDoi
@currentVersion={{@preprint}}
@versions={{@versions}}
@provider={{@provider}}
/>
<Preprints::-Components::PreprintLicense @preprint={{@preprint}} />
<Preprints::-Components::PreprintDiscipline @subjects={{@subjects}} />
<Preprints::-Components::PreprintTag @preprint={{@preprint}} />
Expand Down
2 changes: 1 addition & 1 deletion app/preprints/-components/submit/file/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class PreprintFile extends Component<FileArgs>{
}

@action
public async addNewfile(): Promise<void> {
public addNewfile(): void {
this.file = null;
this.isFileAttached = false;
this.isFileUploadDisplayed = false;
Expand Down
Loading
Loading