Skip to content

Commit

Permalink
fix: translations, improve method, alter mapLogo
Browse files Browse the repository at this point in the history
remove untranslated organisation name fields, improving addOrganisationToRecordFromSource without forkJoin, alter mapLogo to not use the record logo for a contact
  • Loading branch information
f-necas committed Jul 3, 2023
1 parent 243f484 commit 2ed6a2a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 47 deletions.
3 changes: 1 addition & 2 deletions libs/feature/catalog/src/lib/feature-catalog.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ const organizationsServiceFactory = (
: new OrganisationsFromMetadataService(
esService,
searchApiService,
groupsApiService,
translateService
groupsApiService
)

@NgModule({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class OrganisationsFromGroupsService
const groupId = parseInt(selectField(source, 'groupOwner'))
const resourceContacts = getAsArray(
selectField(source, 'contactForResource')
).map((contact) => mapContact(contact, source))
).map((contact) => mapContact(contact))
return this.groups$.pipe(
map((groups) => {
const group = groups.find((g) => g.id === groupId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
GROUPS_FIXTURE,
} from '@geonetwork-ui/util/shared/fixtures'
import { MetadataRecord, Organisation } from '@geonetwork-ui/util/shared'
import { TranslateService } from '@ngx-translate/core'

const sampleOrgA: Organisation = {
description: 'A description for ARE',
Expand Down Expand Up @@ -82,11 +81,6 @@ class GoupsApiServiceMock {
getGroups = jest.fn(() => of(GROUPS_FIXTURE))
}

class TranslateServiceMock {
currentLang = 'fr'
get = jest.fn((key) => of(key))
}

describe('OrganisationsFromMetadataService', () => {
let service: OrganisationsFromMetadataService
let searchService: SearchApiService
Expand All @@ -103,10 +97,6 @@ describe('OrganisationsFromMetadataService', () => {
provide: SearchApiService,
useClass: SearchApiServiceMock,
},
{
provide: TranslateService,
useClass: TranslateServiceMock,
},
],
})
service = TestBed.inject(OrganisationsFromMetadataService)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ import {
selectField,
SourceWithUnknownProps,
} from '@geonetwork-ui/util/shared'
import { combineLatest, forkJoin, Observable, of } from 'rxjs'
import { filter, map, shareReplay, startWith } from 'rxjs/operators'
import { combineLatest, Observable, of } from 'rxjs'
import { filter, map, shareReplay, startWith, takeLast } from 'rxjs/operators'
import { OrganisationsServiceInterface } from './organisations.service.interface'
import { TranslateService } from '@ngx-translate/core'
import { LANG_2_TO_3_MAPPER } from '@geonetwork-ui/util/i18n'

const IMAGE_URL = '/geonetwork/images/harvesting/'

Expand Down Expand Up @@ -78,8 +76,7 @@ export class OrganisationsFromMetadataService
constructor(
private esService: ElasticsearchService,
private searchApiService: SearchApiService,
private groupsApiService: GroupsApiService,
private translateService: TranslateService
private groupsApiService: GroupsApiService
) {}

equalsNormalizedStrings(
Expand Down Expand Up @@ -167,13 +164,12 @@ export class OrganisationsFromMetadataService
}

private mapContactFromOrganisation(
organisation: Organisation,
lang3: string
organisation: Organisation
): MetadataContact {
const logoUrl = getAsUrl(`${organisation.logoUrl}`)
return {
name: organisation.name[lang3],
organisation: organisation.name[lang3],
name: organisation.name,
organisation: organisation.name,
email: organisation.email,
...(organisation.logoUrl && logoUrl && { logoUrl }),
} as MetadataContact
Expand Down Expand Up @@ -202,30 +198,35 @@ export class OrganisationsFromMetadataService
source: SourceWithUnknownProps,
record: MetadataRecord
): Observable<MetadataRecord> {
return forkJoin([
of({
...record,
resourceContacts: [
...getAsArray(selectField(source, 'contactForResource')).map(
(contact) => mapContact(contact, source)
),
],
contact: {
...mapContact(getFirstValue(selectField(source, 'contact')), source),
},
}),
this.organisations$,
]).pipe(
map(([record, organisations]) => {
const metadataRecord = {
...record,
resourceContacts: [
...getAsArray(selectField(source, 'contactForResource')).map(
(contact) => mapContact(contact)
),
],
contact: {
...mapContact(getFirstValue(selectField(source, 'contact'))),
},
}

return this.organisations$.pipe(
takeLast(1),
map((organisations) => {
const org = organisations.filter(
(o) => o.name === record.contact.organisation
(o) => o.name === metadataRecord.resourceContacts[0]?.organisation
)[0]

if (org) {
const lang3 = LANG_2_TO_3_MAPPER[this.translateService.currentLang]
record.contact = this.mapContactFromOrganisation(org, lang3)
record.resourceContacts = [record.contact, ...record.resourceContacts]
const contactFromOrg = this.mapContactFromOrganisation(org)
metadataRecord.contact = contactFromOrg
metadataRecord.resourceContacts = [
contactFromOrg,
...metadataRecord.resourceContacts,
]
}
return record

return metadataRecord
})
)
}
Expand Down
7 changes: 3 additions & 4 deletions libs/util/shared/src/lib/utils/atomic-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ export const getAsUrl = (field) => {
}

export const mapLogo = (source: SourceWithUnknownProps) => {
const logo = selectField(source, 'logo')
const logo = selectField(source, 'logoUrl')
return logo ? getAsUrl(`/geonetwork${logo}`) : null
}

export const mapContact = (
sourceContact: SourceWithUnknownProps,
sourceRecord: SourceWithUnknownProps
sourceContact: SourceWithUnknownProps
): MetadataContact => {
const website = getAsUrl(selectField<string>(sourceContact, 'website'))
const logoUrl = mapLogo(sourceRecord)
const logoUrl = mapLogo(sourceContact)
const address = selectField<string>(sourceContact, 'address')
const phone = selectField<string>(sourceContact, 'phone')
return {
Expand Down

0 comments on commit 2ed6a2a

Please sign in to comment.