Skip to content

Commit 15c90ea

Browse files
author
Néstor Diaz
authored
[176073370] Don't send empty submission attributes (#442)
- Don't send empty submission attributes
1 parent 17ee2cf commit 15c90ea

7 files changed

Lines changed: 182 additions & 172 deletions

File tree

src/app/pages/submission/submission-shared/model/pagetab/pagetab-attributes.utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AttrExceptions, PageTab, PtAttribute } from './pagetab.model';
2-
import { isDefinedAndNotEmpty, isStringDefined, isEqualIgnoringCase } from 'app/utils';
2+
import { isDefinedAndNotEmpty, isStringDefined, isEqualIgnoringCase, isAttributeEmpty } from 'app/utils';
33

44
/* merges to attribute lists by overriding only single value attributes*/
55
export function mergeAttributes(attrs1: PtAttribute[], attrs2: PtAttribute[]): PtAttribute[] {
@@ -18,7 +18,8 @@ export function mergeAttributes(attrs1: PtAttribute[], attrs2: PtAttribute[]): P
1818
merged.push(at);
1919
}
2020
});
21-
return merged;
21+
22+
return merged.filter((attr) => !isAttributeEmpty(attr));
2223
}
2324

2425
export function extractKeywordsFromAttributes(attributes: PtAttribute[]): PtAttribute[] {

src/app/pages/submission/submission-shared/model/pagetab/pagetab-authors.utils.spec.ts

Lines changed: 144 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { authorsToContacts, contactsToAuthors } from './pagetab-authors.utils';
22

33
describe('AuthorsAndAffiliations:', () => {
44
it('authorsToContacts: authors and affiliations are merged into contacts', () => {
5-
expect(authorsToContacts(
6-
[
5+
expect(
6+
authorsToContacts([
77
{
88
type: 'Author',
99
attributes: [
@@ -54,157 +54,151 @@ describe('AuthorsAndAffiliations:', () => {
5454
type: 'Other',
5555
attributes: []
5656
}
57-
])).toEqual(
58-
[
59-
{
60-
type: 'Other',
61-
attributes: []
62-
},
63-
{
64-
type: 'Contact',
65-
attributes: [
66-
{
67-
name: 'Name',
68-
value: 'John D'
69-
},
70-
{
71-
name: 'Organisation',
72-
value: ['EMBL-EBI']
73-
}
74-
]
75-
},
76-
{
77-
type: 'Contact',
78-
attributes: [
79-
{
80-
name: 'Name',
81-
value: 'Guy R'
82-
},
83-
{
84-
name: 'Organisation',
85-
value: ['Some organisation']
86-
}
87-
]
88-
},
89-
{
90-
type: 'Contact',
91-
attributes: [
92-
{
93-
name: 'Name',
94-
value: 'Bob D'
95-
}
96-
]
97-
}
98-
]);
57+
])
58+
).toEqual([
59+
{
60+
type: 'Other',
61+
attributes: []
62+
},
63+
{
64+
type: 'Contact',
65+
attributes: [
66+
{
67+
name: 'Name',
68+
value: 'John D'
69+
},
70+
{
71+
name: 'Organisation',
72+
value: ['EMBL-EBI']
73+
}
74+
]
75+
},
76+
{
77+
type: 'Contact',
78+
attributes: [
79+
{
80+
name: 'Name',
81+
value: 'Guy R'
82+
},
83+
{
84+
name: 'Organisation',
85+
value: ['Some organisation']
86+
}
87+
]
88+
},
89+
{
90+
type: 'Contact',
91+
attributes: [
92+
{
93+
name: 'Name',
94+
value: 'Bob D'
95+
}
96+
]
97+
}
98+
]);
9999
});
100100

101101
it('contactsToAuthors: [contact] sections are split into authors and affiliations', () => {
102-
const authors = contactsToAuthors(
103-
[
104-
{
105-
type: 'Contact',
106-
attributes: [
107-
{
108-
name: 'Name',
109-
value: 'John D'
110-
},
111-
{
112-
accno: 'o1',
113-
name: 'Organisation',
114-
value: 'Org1'
115-
}]
116-
},
117-
{
118-
type: 'Contact',
119-
attributes: [
120-
{
121-
name: 'Name',
122-
value: 'Bob D'
123-
},
124-
{
125-
accno: 'o1',
126-
name: 'Organisation',
127-
value: 'Org1'
128-
}
129-
]
130-
},
131-
{
132-
type: 'Contact',
133-
attributes: [
134-
{
135-
name: 'Name',
136-
value: 'Guy R'
137-
},
138-
{
139-
name: 'Organisation',
140-
value: ''
141-
}
142-
]
143-
},
144-
{
145-
type: 'Other',
146-
attributes: []
147-
}]);
148-
149-
expect(authors).toEqual(
150-
[
151-
{
152-
type: 'Other',
153-
attributes: []
154-
},
155-
{
156-
type: 'Author',
157-
attributes: [
158-
{
159-
name: 'Name',
160-
value: 'John D'
161-
},
162-
{
163-
name: 'affiliation',
164-
reference: true,
165-
value: 'o1'
166-
}
167-
]
168-
},
169-
{
170-
type: 'Author',
171-
attributes: [
172-
{
173-
name: 'Name',
174-
value: 'Bob D'
175-
},
176-
{
177-
name: 'affiliation',
178-
reference: true,
179-
value: 'o1'
180-
}
181-
]
182-
},
183-
{
184-
type: 'Author',
185-
attributes: [
186-
{
187-
name: 'Name',
188-
value: 'Guy R'
189-
},
190-
{
191-
name: 'affiliation',
192-
value: ''
193-
}
194-
]
195-
},
196-
{
197-
type: 'Organization',
198-
accno: 'o1',
199-
attributes: [
200-
{
201-
name: 'Name',
202-
value: 'Org1'
203-
}
204-
]
205-
}
206-
]
207-
);
102+
const authors = contactsToAuthors([
103+
{
104+
type: 'Contact',
105+
attributes: [
106+
{
107+
name: 'Name',
108+
value: 'John D'
109+
},
110+
{
111+
accno: 'o1',
112+
name: 'Organisation',
113+
value: 'Org1'
114+
}
115+
]
116+
},
117+
{
118+
type: 'Contact',
119+
attributes: [
120+
{
121+
name: 'Name',
122+
value: 'Bob D'
123+
},
124+
{
125+
accno: 'o1',
126+
name: 'Organisation',
127+
value: 'Org1'
128+
}
129+
]
130+
},
131+
{
132+
type: 'Contact',
133+
attributes: [
134+
{
135+
name: 'Name',
136+
value: 'Guy R'
137+
},
138+
{
139+
name: 'Organisation',
140+
value: ''
141+
}
142+
]
143+
},
144+
{
145+
type: 'Other',
146+
attributes: []
147+
}
148+
]);
208149

150+
expect(authors).toEqual([
151+
{
152+
type: 'Other',
153+
attributes: []
154+
},
155+
{
156+
type: 'Author',
157+
attributes: [
158+
{
159+
name: 'Name',
160+
value: 'John D'
161+
},
162+
{
163+
name: 'affiliation',
164+
reference: true,
165+
value: 'o1'
166+
}
167+
]
168+
},
169+
{
170+
type: 'Author',
171+
attributes: [
172+
{
173+
name: 'Name',
174+
value: 'Bob D'
175+
},
176+
{
177+
name: 'affiliation',
178+
reference: true,
179+
value: 'o1'
180+
}
181+
]
182+
},
183+
{
184+
type: 'Author',
185+
attributes: [
186+
{
187+
name: 'Name',
188+
value: 'Guy R'
189+
}
190+
]
191+
},
192+
{
193+
type: 'Organization',
194+
accno: 'o1',
195+
attributes: [
196+
{
197+
name: 'Name',
198+
value: 'Org1'
199+
}
200+
]
201+
}
202+
]);
209203
});
210204
});

src/app/pages/submission/submission-shared/model/pagetab/pagetab-authors.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { filter } from 'rxjs/operators';
22
import { PtAttribute, PageTabSection } from './pagetab.model';
3-
import { isStringEmpty, isDefinedAndNotEmpty, isStringDefined } from 'app/utils';
3+
import { isStringEmpty, isDefinedAndNotEmpty, isStringDefined, isAttributeEmpty } from 'app/utils';
44

55
export interface Dictionary<T> {
66
[key: string]: T | undefined;
@@ -169,7 +169,7 @@ export function contactsToAuthors(sections: PageTabSection[] = []): PageTabSecti
169169
(contact) =>
170170
({
171171
type: 'Author',
172-
attributes: orgs.orgToReferences(contact)
172+
attributes: orgs.orgToReferences(contact).filter((ref) => !isAttributeEmpty(ref))
173173
} as PageTabSection)
174174
);
175175

src/app/pages/submission/submission-shared/model/pagetab/pagetab-links.utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PtAttribute, PtLink } from './pagetab.model';
2-
import { isDefinedAndNotEmpty } from 'app/utils';
2+
import { isDefinedAndNotEmpty, isAttributeEmpty } from 'app/utils';
33

44
const POINTER_ATTR = 'Link';
55
const TYPE_ATTR = 'Type';
@@ -28,7 +28,7 @@ export class LinksUtils {
2828

2929
const linkObj = {
3030
url: '',
31-
attributes: attributes.filter((at) => ![TYPE_ATTR, POINTER_ATTR].includes(at.name!))
31+
attributes: attributes.filter((at) => ![TYPE_ATTR, POINTER_ATTR].includes(at.name!) && !isAttributeEmpty(at))
3232
} as PtLink;
3333

3434
linkObj.attributes!.push(typeAttr);

0 commit comments

Comments
 (0)