Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda committed Jan 13, 2025
1 parent dbac450 commit 96b9c59
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 52 deletions.
10 changes: 1 addition & 9 deletions app/preprints/-components/withdrawal-preprint/styles.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
.btn {
width: 145px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-evenly;
}

.withdrawal-button {
color: $brand-danger;
margin-top: 20px;
}

.explanation-container {
Expand Down
31 changes: 9 additions & 22 deletions app/preprints/-components/withdrawal-preprint/template.hbs
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
<OsfDialog as |dialog|>
<dialog.trigger>
{{#if (is-mobile)}}
<Button
data-test-withdrawal-button
data-analytics-name='Withdrawal Button'
local-class='withdrawal-button'
{{on 'click' dialog.open}}
@layout='fake-link'
>
<FaIcon @icon='minus-circle' />
</Button>
{{else}}
<Button
@layout='large'
@type='destroy'
local-class='btn'
data-analytics-name='Withdrawal Button'
data-test-withdrawal-button
{{on 'click' dialog.open}}
>
{{t 'preprints.submit.action-flow.withdraw-button'}}
</Button>
{{/if}}
<Button
@type='destroy'
local-class='withdrawal-button'
data-analytics-name='Withdrawal Button'
data-test-withdrawal-button
{{on 'click' dialog.open}}
>
{{t 'preprints.submit.action-flow.withdraw-button'}}
</Button>
</dialog.trigger>
<dialog.heading
data-test-dialog-heading
Expand Down
6 changes: 5 additions & 1 deletion app/preprints/detail/controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import RouterService from '@ember/routing/router-service';
import { inject as service } from '@ember/service';
import { waitFor } from '@ember/test-waiters';
import Store from '@ember-data/store';
Expand All @@ -18,6 +19,7 @@ import { PreprintProviderReviewsWorkFlow, ReviewsState } from 'ember-osf-web/mod
import CurrentUserService from 'ember-osf-web/services/current-user';
import Theme from 'ember-osf-web/services/theme';
import captureException, { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception';
import { getOwner } from '@ember/application';


/**
Expand Down Expand Up @@ -53,6 +55,7 @@ export default class PrePrintsDetailController extends Controller {
@service intl!: Intl;
@service media!: Media;
@service toast!: Toast;
@service router!: RouterService;

@tracked fullScreenMFR = false;
@tracked plauditIsReady = false;
Expand Down Expand Up @@ -220,7 +223,8 @@ export default class PrePrintsDetailController extends Controller {
}),
);

this.transitionToRoute('preprints.detail', this.model.provider.id, this.model.preprint.id);
const { currentRouteName } = this.router;
getOwner(this).lookup(`route:${currentRouteName}`).refresh();
} catch (e) {
const errorMessage = this.intl.t('preprints.submit.action-flow.error-withdrawal',
{
Expand Down
25 changes: 15 additions & 10 deletions app/preprints/detail/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,24 @@ export default class PreprintsDetail extends Route {
const preprintWithdrawableState = [ReviewsState.ACCEPTED, ReviewsState.PENDING]
.includes(preprint.reviewsState);
let isWithdrawalRejected = false;
const withdrawalRequests = await preprint?.queryHasMany('requests');
if (withdrawalRequests.firstObject) {
const requestActions = await withdrawalRequests.firstObject?.queryHasMany('actions', {
sort: '-modified',
});
const latestRequestAction = requestActions.firstObject;
// @ts-ignore: ActionTrigger is never
if (latestRequestAction && latestRequestAction.actionTrigger === 'reject') {
isWithdrawalRejected = true;
let hasPendingWithdrawal = false;
if (preprintWithdrawableState) {
const withdrawalRequests = await preprint?.queryHasMany('requests');
const latestWithdrawalRequest = withdrawalRequests.firstObject;
if (latestWithdrawalRequest) {
hasPendingWithdrawal = latestWithdrawalRequest.machineState === 'pending';
const requestActions = await withdrawalRequests.firstObject?.queryHasMany('actions', {
sort: '-modified',
});
const latestRequestAction = requestActions.firstObject;
// @ts-ignore: ActionTrigger is never
if (latestRequestAction && latestRequestAction.actionTrigger === 'reject') {
isWithdrawalRejected = true;
}
}
}
const canDisplayWithdrawalButton = preprint.currentUserIsAdmin && preprintWithdrawableState
&& !isWithdrawalRejected;
&& !isWithdrawalRejected && !hasPendingWithdrawal;

return {
preprint,
Expand Down
2 changes: 1 addition & 1 deletion app/preprints/detail/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
{{/if}}
{{#if this.model.canDisplayWithdrawalButton}}
<div local-class='{{if (is-mobile) 'mobile-button-container' 'desktop-button-container'}}'>
<Preprints::-Components::Submit::WithdrawalPreprint
<Preprints::-Components::WithdrawalPreprint
@preprint={{this.model.preprint}}
@provider={{this.model.provider}}
@onWithdrawal={{this.onWithdrawal}}
Expand Down
18 changes: 10 additions & 8 deletions mirage/serializers/preprint-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ export default class PreprintRequestSerializer extends ApplicationSerializer<Pre

buildRelationships(model: ModelInstance<PreprintRequestModel>) {
const relationships: SerializedRelationships<PreprintRequestModel> = {
creator: {
links: {
related: {
href: `${apiUrl}/v2/users/${model.creator.id}`,
meta: {},
},
},
},
target: {
links: {
related: {
Expand All @@ -39,6 +31,16 @@ export default class PreprintRequestSerializer extends ApplicationSerializer<Pre
},
},
};
if (model.creator) {
relationships.creator = {
links: {
related: {
href: `${apiUrl}/v2/users/${model.creator.id}`,
meta: {},
},
},
};
}
return relationships;
}
}
2 changes: 1 addition & 1 deletion translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ preprints:
<a href="mailto:{supportEmail}" target="_blank">{supportEmail}</a> for review and removal. If the request is approved, this {singularPreprintWord} will be replaced by a tombstone page with metadata and the reason for withdrawal. This {singularPreprintWord} will still be searchable by other users after removal.'
post-moderation-notice: '<strong>{pluralCapitalizedPreprintWord} are a permanent part of the scholarly record. Withdrawal requests are subject to this service’s policy on {singularPreprintWord} removal and at the discretion of the moderators.</strong><br>This service uses post-moderation. This request will be submitted to service moderators for review. If the request is approved, this {singularPreprintWord} will be replaced by a tombstone page with metadata and the reason for withdrawal. This {singularPreprintWord} will still be searchable by other users after removal.'
pre-moderation-notice-accepted: '<strong>{pluralCapitalizedPreprintWord} are a permanent part of the scholarly record. Withdrawal requests are subject to this service’s policy on {singularPreprintWord} removal and at the discretion of the moderators.</strong><br>This service uses pre-moderation. This request will be submitted to service moderators for review. If the request is approved, this {singularPreprintWord} will be replaced by a tombstone page with metadata and the reason for withdrawal. This {singularPreprintWord} will still be searchable by other users after removal.'
pre-moderation-notice-pending: 'Your {singularPreprintword} is still pending approval and thus private, but can be withdrawn immediately. If you wish to provide a reason for withdrawal, it will be displayed only to service moderators. Once withdrawn, your preprint will never be made public.'
pre-moderation-notice-pending: 'Your {singularPreprintWord} is still pending approval and thus private, but can be withdrawn immediately. If you wish to provide a reason for withdrawal, it will be displayed only to service moderators. Once withdrawn, your preprint will never be made public.'
save-before-exit: 'Unsaved changes present. Are you sure you want to leave this page?'
success: '{singularPreprintWord} saved.'
success-withdrawal: 'Your {singularCapitalizedPreprintWord} has been successfully withdrawn.'
Expand Down

0 comments on commit 96b9c59

Please sign in to comment.