From 1c81a98ad02ef6e5715c0ab6deb6eb17e4e24ddf Mon Sep 17 00:00:00 2001 From: amontenegro Date: Fri, 20 Oct 2023 20:52:43 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20GITHUB=20ACTIONS=20format=5Fpret?= =?UTF-8?q?tier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../record-affiliations-sort.service.ts | 48 +++++++++++++------ 1 file changed, 34 insertions(+), 14 deletions(-) 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 f3ae922fc7..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,6 +1,10 @@ import { Injectable } from '@angular/core' import { MonthDayYearDate } from 'src/app/types' -import { AffiliationGroup, AffiliationType, AffiliationUIGroup } 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({ @@ -84,9 +88,21 @@ export class AffiliationsSortService { } if (by === 'source') { - const selfAsserted = this.getSelfAssertedOrValidatedAffiliations(affiliationGroup, ascending, orcid, 'self-asserted') - const validated = this.getSelfAssertedOrValidatedAffiliations(affiliationGroup, ascending, orcid, 'validated') - x.affiliationGroup = ascending ? [...selfAsserted, ...validated] : [...validated, ...selfAsserted] + const selfAsserted = this.getSelfAssertedOrValidatedAffiliations( + affiliationGroup, + ascending, + orcid, + 'self-asserted' + ) + const validated = this.getSelfAssertedOrValidatedAffiliations( + affiliationGroup, + ascending, + orcid, + 'validated' + ) + x.affiliationGroup = ascending + ? [...selfAsserted, ...validated] + : [...validated, ...selfAsserted] } } }) @@ -196,17 +212,21 @@ export class AffiliationsSortService { }) } - private getSelfAssertedOrValidatedAffiliations(affiliationGroup: AffiliationGroup[], ascending: boolean, orcid: string, type: 'self-asserted' | 'validated'): AffiliationGroup[] { + 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) + .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 + ) }) }