Skip to content

Commit 908b23e

Browse files
Added contributor project edits functionality. Resolves #1143. (#1145)
* Added contributor project edits functionality. Resolves #1143. * Minor linting.
1 parent 27d6b93 commit 908b23e

File tree

2 files changed

+79
-6
lines changed

2 files changed

+79
-6
lines changed

spa/src/app/files/project-edits/project-edits.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
},
2020
{
2121
"entryId": "c4077b3c-5c98-4d26-a614-246d12c2e5d7",
22+
"contributors": [
23+
{
24+
"contactName": "Sarah,A,Teichmann",
25+
"projectRole": "Co-investigator"
26+
}
27+
],
2228
"publications": [
2329
{
2430
"publicationTitle": "scRNA-seq assessment of the human lung, spleen, and esophagus tissue stability after cold preservation",
@@ -43,5 +49,18 @@
4349
"publicationUrl": "https://www.nature.com/articles/s41467-019-12464-3"
4450
}
4551
]
52+
},
53+
{
54+
"entryId": "4d6f6c96-2a83-43d8-8fe1-0f53bffd4674",
55+
"contributors": [
56+
{
57+
"contactName": "Jeff,C,Liu",
58+
"projectRole": "Computational Scientist"
59+
},
60+
{
61+
"contactName": "Brendan,T,Innes",
62+
"projectRole": "Computational Scientist"
63+
}
64+
]
4665
}
4766
]

spa/src/app/files/project/project-mapper.ts

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { EntityRow } from "../table/entity-row.model";
1111
import { ProjectRowMapper } from "../hca-table-projects/project-row-mapper";
1212
import { Project } from "../shared/project.model";
1313
import { getUnspecifiedIfNullValue } from "../table/table-methods";
14+
import { Contributor } from "../shared/contributor.model";
15+
import { Publication } from "../shared/publication.model";
1416

1517
export class ProjectMapper extends ProjectRowMapper {
1618

@@ -28,15 +30,19 @@ export class ProjectMapper extends ProjectRowMapper {
2830
*/
2931
public mapRow(): EntityRow {
3032

31-
// If there publications listed in the updated project (from projects edits JSON), use the updated project's
32-
// publications. Otherwise, use the publication data returned from the server.
33-
const publications = this.updatedProject.publications && this.updatedProject.publications.length > 0 ?
34-
this.updatedProject.publications :
35-
this.rollupArray(this.row.projects, "publications");
33+
// If there publications listed in the updated project (loaded from the projects edits JSON), use the updated
34+
// project's publications. That is, replace the entire publications array returned from the server with the
35+
// publications array specified in the project edits JSON.
36+
// Otherwise, use the publication data returned from the server.
37+
const publications = this.mapPublications(this.row.projects, this.updatedProject);
38+
39+
// If there are contributors listed in the updated project (loaded from the project edits JSON), use it to
40+
// update the project's contributors. Otherwise, use the publication data return from server.
41+
const contributors = this.mapContributors(this.row.projects, this.updatedProject);
3642

3743
return Object.assign({}, super.mapRow(), {
3844
arrayExpressAccessions: getUnspecifiedIfNullValue(this.projects.arrayExpressAccessions),
39-
contributors: this.rollupArray(this.row.projects, "contributors"),
45+
contributors: contributors,
4046
fileType: (this.row.fileTypeSummaries || []).map(fileType => fileType.fileType),
4147
geoSeriesAccessions: getUnspecifiedIfNullValue(this.projects.geoSeriesAccessions),
4248
insdcProjectAccessions: getUnspecifiedIfNullValue(this.projects.insdcProjectAccessions),
@@ -47,6 +53,54 @@ export class ProjectMapper extends ProjectRowMapper {
4753
});
4854
}
4955

56+
/**
57+
* Determine the set of contributors for the project being mapped. If there are project edits for this project, we
58+
* must overwrite contributor data as specified in the project edits. For contributor edits, we only overwrite the
59+
* values of the contributors that are specified in the project edits JSON (and not the entire contributor list).
60+
*
61+
* @param {any[]} projects
62+
* @param {Project} updatedProject
63+
* @returns {Contributor[]}
64+
*/
65+
private mapContributors(projects: any[], updatedProject: Project): Contributor[] {
66+
67+
const projectContributors = this.rollupArray(this.row.projects, "contributors");
68+
if ( !updatedProject.contributors || updatedProject.contributors.length === 0 ) {
69+
return projectContributors;
70+
}
71+
72+
// Updates have been specified for this project's contributors list; update according to the project edits.
73+
const updatedContributorsByName = updatedProject.contributors.reduce((accum, contributor) => {
74+
75+
accum.set(contributor.contactName, contributor);
76+
return accum;
77+
}, new Map<string, Contributor>());
78+
79+
return projectContributors.reduce((accum, contributor) => {
80+
const updatedContributor = updatedContributorsByName.get(contributor.contactName) || {};
81+
accum.push(Object.assign({}, contributor, updatedContributor));
82+
return accum;
83+
}, []);
84+
}
85+
86+
/**
87+
* Determine the set of publications for the project being mapped. If there are project edits for this project, we
88+
* must overwrite publication data as specified in the project edits. For publication edits, we overwrite the entire
89+
* set of publications, using only the publications set in the JSON.
90+
*
91+
* @param {any[]} projects
92+
* @param {Project} updatedProject
93+
* @returns {Contributor[]}
94+
*/
95+
private mapPublications(projects: any[], updatedProject: Project): Publication[] {
96+
97+
if ( updatedProject.publications && updatedProject.publications.length > 0 ) {
98+
return updatedProject.publications;
99+
}
100+
101+
return this.rollupArray(this.row.projects, "publications");
102+
}
103+
50104
/**
51105
* Custom roll up functionality for project meta - combine all values of the specified key into a single array, but
52106
* do not map to single string value. For example, we want to be able to pull out specific contributor or

0 commit comments

Comments
 (0)