diff --git a/CHANGELOG.md b/CHANGELOG.md index 69dafeb606..1a6fd90927 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## v2.43.3 - 2023-10-20 + +[Full Changelog](https://github.com/ORCID/orcid-angular/compare/v2.43.2...v2.43.3) + +### Fix + +- Update sort by source functionality to sort also alphabetically (#2079) + +## v2.43.2 - 2023-10-18 + +[Full Changelog](https://github.com/ORCID/orcid-angular/compare/v2.43.1...v2.43.2) + +- [#2078](https://github.com/ORCID/orcid-angular/pull/2078): Revert "Angular update 15 16" + ## v2.43.1 - 2023-10-17 [Full Changelog](https://github.com/ORCID/orcid-angular/compare/v2.43.0...v2.43.1) diff --git a/src/app/core/record-affiliations-sort/record-affiliations-sort.service.ts b/src/app/core/record-affiliations-sort/record-affiliations-sort.service.ts index d0efe278ed..16b5cb13fb 100644 --- a/src/app/core/record-affiliations-sort/record-affiliations-sort.service.ts +++ b/src/app/core/record-affiliations-sort/record-affiliations-sort.service.ts @@ -1,9 +1,9 @@ import { Injectable } from '@angular/core' import { MonthDayYearDate } from 'src/app/types' import { - AffiliationUIGroup, AffiliationGroup, AffiliationType, + AffiliationUIGroup, } from 'src/app/types/record-affiliation.endpoint' import { UserRecordOptions } from 'src/app/types/record.local' @@ -88,15 +88,21 @@ 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] } } }) @@ -206,7 +212,25 @@ 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 {