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 ember data deprecate array like deprecation #1274

Closed
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
4 changes: 2 additions & 2 deletions app/components/found-manuscripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class FoundManuscriptsComponent extends Component {
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 @@ -46,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);
}
};
}
15 changes: 9 additions & 6 deletions app/components/policy-card/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,21 @@ 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);
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);
}
}
51 changes: 26 additions & 25 deletions app/components/workflow-files/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +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 { 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 @@ -12,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') || [];
const prevFiles = get(this, 'args.previouslyUploadedFiles') || [];
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') || [];
const prevFiles = get(this, 'args.previouslyUploadedFiles') || [];
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 @@ -67,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 @@ -111,8 +107,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 @@ -134,7 +132,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
23 changes: 13 additions & 10 deletions app/components/workflow-grants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ export default class WorkflowGrants extends Component {

// 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 () => {
Expand Down Expand Up @@ -174,18 +175,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 @@ -200,17 +202,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
33 changes: 19 additions & 14 deletions app/components/workflow-repositories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export default class WorkflowRepositories extends Component {

// Separate out repositories that PASS has no integration
get requiredWeblinkRepos() {
return this.args.requiredRepositories.filter((repoInfo) => repoInfo.repository._isWebLink);
const webLinkRepos = this.args.requiredRepositories.filter((repoInfo) => repoInfo.repository._isWebLink);

return webLinkRepos;
}

/**
Expand All @@ -54,8 +56,8 @@ export default class WorkflowRepositories extends Component {
*/
@action
setupRepos() {
set(this, 'addedRepos', this.getAddedRepositories());
const currentRepos = get(this, 'submission.repositories');
this.addedRepos = this.getAddedRepositories();
const currentRepos = this.args.submission.repositories.slice();

const opt = this.args.optionalRepositories;
const req = this.args.requiredRepositories;
Expand Down Expand Up @@ -106,7 +108,9 @@ export default class WorkflowRepositories extends Component {
* Use IDs instead of full Repository objects to try to avoid weird JS equality
* nonsense.
*/
currentRepos.filter((repo) => !validRepos.includes(repo.id)).forEach((repo) => currentRepos.removeObject(repo));
currentRepos
.filter((repo) => !validRepos.includes(repo.id))
.forEach((repo) => (this.args.submission.repositories = currentRepos.filter((r) => r.name === repo.name)));
} else {
/**
* If no repositories have been saved to the submission yet, force add all required repositories
Expand All @@ -117,13 +121,13 @@ export default class WorkflowRepositories extends Component {
}
if (opt) {
opt
.filter((repoInfo) => get(repoInfo, 'repository._selected'))
.filter((repoInfo) => repoInfo.repository._selected)
.forEach((repoInfo) => this.addRepository(repoInfo.repository, false));
}
if (choice) {
choice.forEach((group) => {
group
.filter((repoInfo) => get(repoInfo, 'repository._selected'))
.filter((repoInfo) => repoInfo.repository._selected)
.forEach((repoInfo) => this.addRepository(repoInfo.repository, false));
});
}
Expand All @@ -145,16 +149,16 @@ export default class WorkflowRepositories extends Component {
*
* @param {Repository} repo the repository that may be modified
*/
setSelected(repo) {
async setSelected(repo) {
const id = repo.id;
const addedRepos = this.addedRepos;
const currentRepos = get(this, 'args.submission.repositories');
const currentRepos = await this.args.submission.repositories;

if (addedRepos.isAny('id', id)) {
if (addedRepos.some((r) => r.id === id)) {
return;
}

repo.set('_selected', currentRepos.isAny('id', id));
repo._selected = currentRepos.some((r) => r.id === id);
}

/**
Expand Down Expand Up @@ -203,10 +207,10 @@ export default class WorkflowRepositories extends Component {
* @param {boolean} setMaxStep should we modify 'maxStep' in the workflow?
*/
addRepository(repository, setMaxStep) {
const subRepos = get(this, 'args.submission.repositories');
const repos = this.args.submission.repositories.slice();

if (!subRepos.includes(repository)) {
subRepos.pushObject(repository);
if (!repos.includes(repository)) {
this.args.submission.repositories = [repository, ...repos];
}
if (setMaxStep) {
this.workflow.setMaxStep(4);
Expand All @@ -220,7 +224,8 @@ export default class WorkflowRepositories extends Component {
* @param {boolean} setMaxStep should we modify 'maxStep' in the workflow?
*/
removeRepository(repository, setMaxStep) {
get(this, 'args.submission.repositories').removeObject(repository);
const repositories = this.args.submission.repositories.slice();
this.args.submission.repositories = repositories.filter((r) => r.name !== repository.name);
if (setMaxStep) {
this.workflow.setMaxStep(4);
}
Expand Down
7 changes: 2 additions & 5 deletions app/components/workflow-review/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,20 @@
<td>
<ul class="list-unstyled" data-test-workflow-review-grant-list>
{{#each @submission.grants as |grant|}}
<li>
<li class="grant-item">
<b>
{{grant.awardNumber}}
</b>
:
{{grant.projectName}}
</li>
<li>
<li class="grant-item">
<b>
Funder
</b>
:
{{grant.primaryFunder.name}}
</li>
{{#if (not-eq grant @submission.grants.lastObject)}}
<hr />
{{/if}}
{{/each}}
</ul>
</td>
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/grants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export default class GrantsIndexController extends Controller {
submission.grants.forEach((grant) => {
let match = results.grantMap.find((res) => res.grant.id === grant.id);
if (match) {
match.submissions.pushObject(submission);
match.submissions.push(submission);
}
});
});
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/submissions/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { action, get, computed } from '@ember/object';
import ENV from 'pass-ui/config/environment';
import { inject as service } from '@ember/service';
import { later, scheduleOnce } from '@ember/runloop';
import _ from 'lodash';

export default class SubmissionsDetail extends Controller {
@service currentUser;
Expand Down Expand Up @@ -285,9 +286,11 @@ export default class SubmissionsDetail extends Controller {

// Validate manuscript files
let manuscriptFiles = []
.concat(this.filesTemp, get(this, 'model.files') && get(this, 'model.files').toArray())
.concat(this.filesTemp, get(this, 'model.files') && get(this, 'model.files').slice())
.filter((file) => file && file.get('fileRole') === 'manuscript');

manuscriptFiles = _.uniqBy(manuscriptFiles, 'id');

if (manuscriptFiles.length == 0) {
swal(
'Manuscript is missing',
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/submissions/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { action, get, set } from '@ember/object';
import { inject as service } from '@ember/service';
import _ from 'lodash';

export default class SubmissionsNew extends Controller {
queryParams = ['grant', 'submission', 'covid'];
Expand Down Expand Up @@ -79,8 +80,10 @@ export default class SubmissionsNew extends Controller {
@action
async submit() {
let manuscriptFiles = []
.concat(this.filesTemp, get(this, 'model.files') && get(this, 'model.files').toArray())
.filter((file) => file && get(file, 'fileRole') === 'manuscript');
.concat(this.filesTemp, this.model.files && this.model.files.slice())
.filter((file) => file && file.fileRole === 'manuscript');

manuscriptFiles = _.uniqBy(manuscriptFiles, 'id');

if (manuscriptFiles.length == 0 && this.userIsSubmitter) {
swal('Manuscript Is Missing', 'At least one manuscript file is required. Please go back and add one', 'warning');
Expand Down
Loading
Loading