Skip to content

Commit 6cac3ab

Browse files
authored
PD-5781 & PD-0000 avoid oauth breaks when affiliations endpoint comes with issues. (#2871)
* PD-0000 avoid apps breaks when the affiliations groups comes with issues * PD-000 format
1 parent 81da3c1 commit 6cac3ab

4 files changed

Lines changed: 34 additions & 5 deletions

File tree

src/app/cdk/side-bar/modals/modal-email/modal-email.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,9 @@ export class ModalEmailComponent implements OnInit, OnDestroy {
655655
private getMostPermissiveVisibility(
656656
visibilities: VisibilityStrings[]
657657
): VisibilityStrings {
658+
if (!visibilities.length) {
659+
return null
660+
}
658661
return visibilities.reduce((most, current) =>
659662
VisibilityWeightMap[current] > VisibilityWeightMap[most] ? current : most
660663
)
@@ -663,6 +666,9 @@ export class ModalEmailComponent implements OnInit, OnDestroy {
663666
private getLeastPermissiveVisibility(
664667
visibilities: VisibilityStrings[]
665668
): VisibilityStrings {
669+
if (!visibilities.length) {
670+
return null
671+
}
666672
return visibilities.reduce((least, current) =>
667673
VisibilityWeightMap[current] < VisibilityWeightMap[least]
668674
? current

src/app/core/record-affiliations-affiliations-grouping/record-affiliations-grouping.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ export class RecordAffiliationsGroupingService {
8686
.map((key) => value.affiliationGroups[key])
8787
})
8888
// Reduce all elements with different AffiliationGroupsTypeName on the same expectedUiOrderGroup
89-
.reduce((accumulator, currentValue) =>
90-
accumulator.concat(currentValue)
89+
.reduce(
90+
(accumulator, currentValue) => accumulator.concat(currentValue),
91+
[]
9192
)
9293
// Concatenates affiliations lists
93-
.reduce((accumulator, currentValue) =>
94-
accumulator.concat(currentValue)
94+
.reduce(
95+
(accumulator, currentValue) => accumulator.concat(currentValue),
96+
[]
9597
),
9698
}
9799
}

src/assets/print-view/fetch-orcid.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ const STRINGS = {
5959
relFundedBy: $localize`:@@printView.relFundedBy:Funded by`,
6060
}
6161

62+
function peerReviewHeadingText(reviewsCount, publicationsCount) {
63+
return $localize`:@@printView.peerReviewSummary:Peer review (${reviewsCount}:reviewCount: reviews for ${publicationsCount}:publicationCount: publications/grants)`
64+
}
65+
6266
// Localized country names keyed by ISO 3166-1 alpha-2 code.
6367
// Mirrors `getCountryCodes` in
6468
// src/app/core/record-countries/record-countries.service.ts so the print view
@@ -1113,7 +1117,10 @@ function renderPeerReviews(activities, section) {
11131117
const block = document.createElement('div')
11141118
block.className = 'activity-group'
11151119
const heading = document.createElement('h3')
1116-
heading.textContent = `Peer review (${reviews} reviews for ${sortedPublications.size} publications/grants)`
1120+
heading.textContent = peerReviewHeadingText(
1121+
reviews,
1122+
sortedPublications.size
1123+
)
11171124
block.appendChild(heading)
11181125
const list = document.createElement('ul')
11191126
for (publication of sortedPublications || []) {

src/assets/print-view/fetch-orcid.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ declare function jsonText(value: any): string
1515
declare function jsonList(list: any): any[]
1616
declare function jsonDate(parts: any): string
1717
declare function jsonOrcidUri(orcidIdentifier: any): string
18+
declare function peerReviewHeadingText(
19+
reviewsCount: number,
20+
publicationsCount: number
21+
): string
1822
declare function renderOrcidPrompt(message?: string): void
1923
declare function makeSection(title: string): HTMLElement
2024
declare function textLineNode(
@@ -219,6 +223,16 @@ describe('fetch-orcid.js', () => {
219223
})
220224
})
221225

226+
// ── peerReviewHeadingText ───────────────────────────────────────────────────
227+
228+
describe('peerReviewHeadingText', () => {
229+
it('builds heading text including review and publication counts', () => {
230+
expect(peerReviewHeadingText(7, 3)).toBe(
231+
'Peer review (7 reviews for 3 publications/grants)'
232+
)
233+
})
234+
})
235+
222236
// ── makeSection ───────────────────────────────────────────────────────────────
223237

224238
describe('makeSection', () => {

0 commit comments

Comments
 (0)