Skip to content

Commit

Permalink
fix: Update sort by source functionality to sort also alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielPalafox committed Oct 19, 2023
1 parent 4f46a95 commit 986e89c
Showing 1 changed file with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { Injectable } from '@angular/core'
import { MonthDayYearDate } from 'src/app/types'
import {
AffiliationUIGroup,
AffiliationGroup,
AffiliationType,
} from 'src/app/types/record-affiliation.endpoint'
import { AffiliationGroup, AffiliationType, AffiliationUIGroup } from 'src/app/types/record-affiliation.endpoint'
import { UserRecordOptions } from 'src/app/types/record.local'

@Injectable({
Expand Down Expand Up @@ -88,15 +84,9 @@ export class AffiliationsSortService {
}

if (by === 'source') {
affiliationGroup.sort((a, b) => {
return (
Number(AffiliationsSortService.isSelfAsserted(a, orcid)) -
Number(AffiliationsSortService.isSelfAsserted(b, orcid))
)
})
if (ascending) {
affiliationGroup.reverse()
}
const selfAsserted = this.getSelfAssertedOrValidatedAffiliations(affiliationGroup, ascending, orcid, 'self-asserted')
const validated = this.getSelfAssertedOrValidatedAffiliations(affiliationGroup, ascending, orcid, 'validated')
x.affiliationGroup = ascending ? [...selfAsserted, ...validated] : [...validated, ...selfAsserted]
}
}
})
Expand Down Expand Up @@ -206,7 +196,21 @@ export class AffiliationsSortService {
})
}

private static isSelfAsserted(
private getSelfAssertedOrValidatedAffiliations(affiliationGroup: AffiliationGroup[], ascending: boolean, orcid: string, type: 'self-asserted' | 'validated'): AffiliationGroup[] {
return affiliationGroup
.filter(
(affiliationGroup) => {
const selfAsserted = this.isSelfAsserted(affiliationGroup, orcid)
return type === 'self-asserted' ? selfAsserted : !selfAsserted
},
).sort((a, b) => {
return (
'' + a.defaultAffiliation.affiliationName.value
).localeCompare('' + b.defaultAffiliation.affiliationName.value)
})
}

private isSelfAsserted(
affiliationGroup: AffiliationGroup,
orcid: string
): boolean {
Expand Down

0 comments on commit 986e89c

Please sign in to comment.