Skip to content

Commit

Permalink
ensure files are deduped
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredgalanis committed Jul 3, 2024
1 parent 9366f89 commit 0343405
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nodejs 18.15.0
nodejs 21.7.3
5 changes: 3 additions & 2 deletions app/components/workflow-files/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export default class WorkflowFiles extends Component {
}

get manuscript() {
const newFiles = this.args.newFiles || [];
const prevFiles = this.args.previouslyUploadedFiles || [];
const newFiles = this.args.newFiles.filter((file) => file.submission.id === this.args.submission.id) || [];
const prevFiles =
this.args.previouslyUploadedFiles.filter((file) => file.submission.id === this.args.submission.id) || [];

return [...prevFiles.slice(), ...newFiles.slice()].find((file) => file.fileRole === 'manuscript');
}
Expand Down
12 changes: 3 additions & 9 deletions app/components/workflow-review/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { action, get, set } from '@ember/object';
import { inject as service } from '@ember/service';
import { task } from 'ember-concurrency-decorators';
import { later } from '@ember/runloop';
import _ from 'lodash';

/**
* Present the user with a summary of all information known about the current in-progress
Expand All @@ -18,6 +19,7 @@ import { later } from '@ember/runloop';
* interaction
*/
export default class WorkflowReview extends Component {
@service store;
@service workflow;
@service currentUser;
@service flashMessages;
Expand All @@ -28,15 +30,7 @@ export default class WorkflowReview extends Component {
@tracked repositories = this.args.submission.repositories;

get parsedFiles() {
let newArr = [];
if (this.filesTemp) {
newArr = [...this.filesTemp, ...newArr];
}
if (this.args.previouslyUploadedFiles) {
newArr = [...this.args.previouslyUploadedFiles, ...newArr];
}

return newArr;
return this.store.peekAll('file').filter((file) => file.submission.id === this.args.submission.id);
}

get weblinkRepos() {
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/submissions/detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ export default class SubmissionsDetail extends Controller {
// Validate manuscript files
let manuscriptFiles = []
.concat(this.filesTemp, get(this, 'model.files') && get(this, 'model.files').slice())
.filter((file) => file && file.get('fileRole') === 'manuscript');
.filter((file) => file && file.get('fileRole') === 'manuscript')
.filter((file) => file.submission.id === this.model.sub.id);

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

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/submissions/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export default class SubmissionsNew extends Controller {
async submit() {
let manuscriptFiles = []
.concat(this.filesTemp, this.model.files && this.model.files.slice())
.filter((file) => file && file.fileRole === 'manuscript');
.filter((file) => file && file.fileRole === 'manuscript')
.filter((file) => file.submission.id === this.model.newSubmission.id);

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

Expand Down
13 changes: 8 additions & 5 deletions app/controllers/submissions/new/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { tracked } from '@glimmer/tracking';
import { action, computed, get, set } from '@ember/object';
import { alias } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import _ from 'lodash';

export default class SubmissionsNewFiles extends Controller {
@service workflow;
Expand Down Expand Up @@ -53,8 +54,10 @@ export default class SubmissionsNewFiles extends Controller {

@action
updateAllFiles(files) {
this.workflow.filesTemp = [...files, ...this.workflow.filesTemp];
files.forEach((file) => {
const filteredFiles = _.uniq(files, 'id').filter((file) => file.submission.id === this.submission.id);

this.workflow.filesTemp = [...filteredFiles, ...this.workflow.filesTemp];
filteredFiles.forEach((file) => {
file.submission = this.submission;
});
}
Expand All @@ -73,9 +76,9 @@ export default class SubmissionsNewFiles extends Controller {
async validateAndLoadTab(gotoTab) {
let needValidation = this.needValidation;
if (needValidation) {
let manuscriptFiles = [...this.newFiles, ...this.model.files.slice()].filter(
(file) => file && get(file, 'fileRole') === 'manuscript',
);
let manuscriptFiles = [...this.newFiles, ...this.model.files.slice()]
.filter((file) => file && get(file, 'fileRole') === 'manuscript')
.filter((file) => file.submission.id === this.submission.id);

const submitter = await this.parent.userIsSubmitter();

Expand Down

0 comments on commit 0343405

Please sign in to comment.