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

refactor: remove remaining Ember 5 deprecation warnings #1275

13 changes: 6 additions & 7 deletions app/components/found-manuscripts/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { A } from '@ember/array';
import { task } from 'ember-concurrency-decorators';
import { action, get, set } from '@ember/object';

Expand All @@ -11,8 +10,8 @@ export default class FoundManuscriptsComponent extends Component {
@service store;
@service appStaticConfig;

@tracked foundManuscripts = A([]);
@tracked manuscriptsWithErrors = A([]);
@tracked foundManuscripts = [];
@tracked manuscriptsWithErrors = [];
@tracked selectedManuscript = null;
@tracked contactUrl;

Expand All @@ -24,10 +23,10 @@ export default class FoundManuscriptsComponent extends Component {
}

get foundManuscriptsToDisplay() {
let prevFiles = this.args.previouslyUploadedFiles || A([]);
let newFiles = this.args.newFiles || A([]);
let prevFiles = this.args.previouslyUploadedFiles || [];
let newFiles = this.args.newFiles || [];

const allFileNames = [...newFiles.toArray(), ...prevFiles.toArray()].map((file) => file.name);
const allFileNames = [...newFiles.slice(), ...prevFiles.slice()].map((file) => file.name);

return this.foundManuscripts
.filter((manuscript) => !allFileNames.includes(manuscript.name))
Expand All @@ -47,7 +46,7 @@ export default class FoundManuscriptsComponent extends Component {
const foundOAMss = yield this.oaManuscriptService.lookup(doi);

if (foundOAMss) {
this.foundManuscripts.pushObjects(foundOAMss);
this.foundManuscripts.push(foundOAMss);
}
};
}
18 changes: 11 additions & 7 deletions app/components/policy-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,22 @@ export default class PolicyCard extends Component {
}
}

_addEffectivePolicy(policy) {
async _addEffectivePolicy(policy) {
const effectivePolicies = await this.args.submission.effectivePolicies;
// Only add the policy if it is not already in the list of effective policies
if (!this._hasEffectivePolicy(policy.id)) {
this.args.submission.effectivePolicies.pushObject(policy);
const hasEffectivePolicy = await this._hasEffectivePolicy(policy.id);
if (!hasEffectivePolicy) {
this.args.submission.effectivePolicies = [...effectivePolicies, policy];
}
}

_removeEffectivePolicy(policy) {
this.args.submission.effectivePolicies.removeObject(policy);
async _removeEffectivePolicy(policy) {
let effectivePolicies = await this.args.submission.effectivePolicies;
this.args.submission.effectivePolicies = effectivePolicies.filter((p) => p.id !== policy.id);
}

_hasEffectivePolicy(policyId) {
return this.args.submission.effectivePolicies && this.args.submission.effectivePolicies.isAny('id', policyId);
async _hasEffectivePolicy(policyId) {
const effectivePolicies = await this.args.submission.effectivePolicies;
return !!effectivePolicies && effectivePolicies.some((policy) => policy.id === policyId);
}
}
11 changes: 5 additions & 6 deletions app/components/submissions-repoid-cell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action, get, set } from '@ember/object';
import { inject as service } from '@ember/service';
import { A } from '@ember/array';

export default class SubmissionsRepoidCell extends Component {
@service store;
Expand All @@ -13,18 +12,18 @@ export default class SubmissionsRepoidCell extends Component {
jscholarshipCheckString = '/handle/';

@action
setUpRepoidCell() {
const publicationId = get(this, 'args.record.publication.id');
if (!publicationId) {
async setUpRepoidCell() {
const publication = await this.args.record.publication;
if (!publication?.id) {
if (!(get(this, 'isDestroyed') || get(this, 'isDestroying'))) {
set(this, 'repoCopies', A());
this.repoCopies = [];
return;
}
}

const query = {
filter: {
repositoryCopy: `publication.id==${publicationId}`,
repositoryCopy: `publication.id==${publication.id}`,
},
};

Expand Down
9 changes: 4 additions & 5 deletions app/components/workflow-basics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { tracked } from '@glimmer/tracking';
import { action, get, set } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import { A } from '@ember/array';
import { task, timeout } from 'ember-concurrency';
import { scheduleOnce } from '@ember/runloop';
import { dropTask } from 'ember-concurrency-decorators';
Expand Down Expand Up @@ -207,7 +206,7 @@ export default class WorkflowBasics extends Component {
});

if (result.value) {
set(this, 'submission.grants', A());
set(this, 'submission.grants', []);
this.updateSubmitterModel(isProxySubmission, submitter);

this.flashMessages.info('Submitter and related grants removed from submission.');
Expand All @@ -224,10 +223,10 @@ export default class WorkflowBasics extends Component {
this.submission.submitterName = '';
if (isProxySubmission) {
this.submission.submitter = submitter;
this.submission.preparers = A([get(this, 'currentUser.user')]);
this.submission.preparers = [this.currentUser.user];
} else {
this.submission.submitter = get(this, 'currentUser.user');
this.submission.preparers = A();
this.submission.submitter = this.currentUser.user;
this.submission.preparers = [];
}
}

Expand Down
52 changes: 26 additions & 26 deletions app/components/workflow-files/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable ember/no-computed-properties-in-native-classes, ember/no-get, ember/require-computed-property-dependencies */
import Component from '@glimmer/component';
import { action, get, set, computed } from '@ember/object';
import { action, get } from '@ember/object';
import { inject as service } from '@ember/service';
import { A } from '@ember/array';
import { task } from 'ember-concurrency-decorators';
import ENV from 'pass-ui/config/environment';
import { tracked } from '@glimmer/tracking';

export default class WorkflowFiles extends Component {
@service store;
Expand All @@ -13,42 +13,37 @@ export default class WorkflowFiles extends Component {
@service currentUser;
@service flashMessages;

@computed('manuscript')
get hasManuscript() {
return !!get(this, 'manuscript');
return !!this.manuscript;
}

@computed('args.newFiles.[]', 'previouslyUploadedFiles.[]')
get manuscript() {
const newFiles = get(this, 'args.newFiles') || A([]);
const prevFiles = get(this, 'args.previouslyUploadedFiles') || A([]);
const newFiles = this.args.newFiles || [];
const prevFiles = this.args.previouslyUploadedFiles || [];

return [...prevFiles.toArray(), ...newFiles.toArray()].find((file) => file.fileRole === 'manuscript');
return [...prevFiles.slice(), ...newFiles.slice()].find((file) => file.fileRole === 'manuscript');
}

/**
* Any non-manuscript files
*/
@computed('args.newFiles.[]', 'previouslyUploadedFiles.[]')
get supplementalFiles() {
const newFiles = get(this, 'args.newFiles') || A([]);
const prevFiles = get(this, 'args.previouslyUploadedFiles') || A([]);
const newFiles = this.args.newFiles || [];
const prevFiles = this.args.previouslyUploadedFiles || [];

return [...prevFiles.toArray(), ...newFiles.toArray()].filter((file) => file.fileRole !== 'manuscript');
return [...prevFiles.slice(), ...newFiles.slice()].filter((file) => file.fileRole !== 'manuscript');
}

@task
handleExternalMs = function* (file) {
const newFiles = get(this, 'args.newFiles');

file.set('submission', get(this, 'args.submission'));
if (!get(this, 'hasManuscript')) {
file.set('fileRole', 'manuscript');
file.submission = this.args.submission;
if (!this.hasManuscript) {
file.fileRole = 'manuscript';
} else {
file.set('fileRole', 'supplemental');
file.fileRole = 'supplemental';
}

newFiles.pushObject(file);
this.args.updateNewFiles(file);
yield file.save();
};

Expand All @@ -68,15 +63,15 @@ export default class WorkflowFiles extends Component {
const deleted = await this.deleteFile(file);

if (deleted) {
const mFiles = get(this, 'args.previouslyUploadedFiles');
const mFiles = this.args.previouslyUploadedFiles;
// Remove the file from the model
if (mFiles) {
mFiles.removeObject(file);
this.args.updatePreviouslyUploadedFiles(mFiles.filter((f) => f.id !== file.id));
}

const newFiles = get(this, 'args.newFiles');
const newFiles = this.args.newFiles;
if (newFiles) {
newFiles.removeObject(file);
this.args.updateNewFiles(newFiles.filter((f) => f.id !== file.id));
}
document.querySelector('#file-multiple-input').value = null;
}
Expand Down Expand Up @@ -117,8 +112,10 @@ export default class WorkflowFiles extends Component {
if (!this.hasManuscript) {
newFile.fileRole = 'manuscript';
}
await newFile.save();
this.args.newFiles.pushObject(newFile);
const savedFile = await newFile.save();

this.args.updateNewFiles([savedFile, ...this.args.newFiles]);
this.args.updateAllFiles([savedFile, ...this.args.newFiles, ...this.args.previouslyUploadedFiles]);
} catch (error) {
FileUpload.file.state = 'aborted';
console.error(error);
Expand All @@ -140,7 +137,10 @@ export default class WorkflowFiles extends Component {
return await file
.destroyRecord()
.then(() => {
files.removeObject(file);
const filteredFiles = files.filter((f) => f.id !== file.id);

this.args.updateAllFiles(filteredFiles);

return true;
})
.catch((error) => {
Expand Down
35 changes: 19 additions & 16 deletions app/components/workflow-grants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action, get, set } from '@ember/object';
import { A } from '@ember/array';
import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency';

Expand All @@ -28,7 +27,7 @@ export default class WorkflowGrants extends Component {
@tracked submitterGrants = null;
@tracked totalGrants = 0;
/** Grants already attached to the submission on component init */
@tracked _selectedGrants = A();
@tracked _selectedGrants = [];
@tracked preLoadedGrant = this.args.preLoadedGrant;
@tracked grantColumns = [
{
Expand Down Expand Up @@ -92,24 +91,26 @@ export default class WorkflowGrants extends Component {
setup = function* () {
this.contactUrl = this.appStaticConfig?.config?.branding?.pages?.contactUrl;

if (get(this, 'args.submission.submitter.id')) {
const submitter = yield this.args.submission.submitter;
if (submitter?.id) {
yield this.updateGrants.perform();
}

// Init selected grants to grants already attached to submission

this._selectedGrants.clear();
this._selectedGrants = [];
let grants = yield this.args.submission.grants;
if (this.preLoadedGrant) {
this.args.submission.grants.pushObject(this.preLoadedGrant);
grants = [this.preLoadedGrant, ...grants];
this.workflow.addGrant(this.preLoadedGrant);
}
this._selectedGrants.addObjects(get(this, 'args.submission.grants'));
this._selectedGrants = [...grants];
};

updateGrants = task(async () => {
let info = {};

const userId = get(this, 'args.submission.submitter.id');
const userId = await this.args.submission.submitter.id;
// TODO: Ignore date filter for now ( >= 2011-01-01 )
const grantQuery = {
filter: {
Expand All @@ -125,8 +126,8 @@ export default class WorkflowGrants extends Component {

this.submitterGrants = results;
// TODO: How do we get pagination to work with store.query like this?
set(this, 'totalGrants', info.total);
set(this, 'pageCount', Math.ceil(info.total / this.pageSize));
this.totalGrants = info.total;
this.pageCount = Math.ceil(info.total / this.pageSize);
});

/**
Expand Down Expand Up @@ -175,18 +176,19 @@ export default class WorkflowGrants extends Component {
* @param {Grant} grant
*/
@action
addGrant(grant) {
async addGrant(grant) {
const workflow = this.workflow;
const submission = this.args.submission;
let grants = await submission.grants;

if (!get(submission, 'grants').includes(grant)) {
get(submission, 'grants').pushObject(grant);
if (!grants.includes(grant)) {
this.args.submission.grants = [grant, ...grants];
}
if (!workflow.getAddedGrants().includes(grant)) {
workflow.addGrant(grant);
}
if (!this._selectedGrants.includes(grant)) {
this._selectedGrants.pushObject(grant);
this._selectedGrants = [grant, ...this._selectedGrants];
}

this.setWorkflowStepHere();
Expand All @@ -201,17 +203,18 @@ export default class WorkflowGrants extends Component {
* @param {Grant} grant
*/
@action
removeGrant(grant) {
async removeGrant(grant) {
const workflow = this.workflow;

// if grant is grant passed in from grant detail page remove query parms
if (grant === this.preLoadedGrant) {
this.preLoadedGrant = null;
}
const submission = this.args.submission;
get(submission, 'grants').removeObject(grant);
const grants = await submission.grants;
this.args.submission.grants = grants.filter((g) => g !== grant);
workflow.removeGrant(grant);
this._selectedGrants.removeObject(grant);
this._selectedGrants = this._selectedGrants.filter((g) => g !== grant);

this.setWorkflowStepHere();
}
Expand Down
5 changes: 3 additions & 2 deletions app/components/workflow-metadata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,12 @@ export default class WorkflowMetadata extends Component {
// 10.4137/CMC.S38446
// 10.1039/c7an01256j
if (!this.schemas) {
const repos = this.args.submission.repositories.map((repo) => repo.id);
const repositories = yield this.args.submission.repositories;
const repoIds = repositories.map((repo) => repo.id);

// Load schemas by calling the Schema service
try {
const schemas = yield this.metadataSchema.getMetadataSchemas(repos);
const schemas = yield this.metadataSchema.getMetadataSchemas(repoIds);

const requiresJournal =
schemas.findIndex((schema) => 'required' in schema && schema.required.includes('journal-title')) != -1;
Expand Down
Loading
Loading