Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8662-qa-items-in-countries-modal-not-displayed-correctly-for-de-pl-an… #1979

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions src/app/core/record-countries/record-countries.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpClient, HttpHeaders } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { forkJoin, merge, Observable, of, ReplaySubject } from 'rxjs'
import { retry, catchError, tap, map } from 'rxjs/operators'
import { retry, catchError, tap, map, take } from 'rxjs/operators'
import { CountriesEndpoint } from 'src/app/types/record-country.endpoint'
import {
SideBarPublicUserRecord,
Expand Down Expand Up @@ -301,15 +301,17 @@ export class RecordCountriesService {
): Observable<CountriesEndpoint> {
if (options.publicRecordId) {
return forkJoin([
this._recordPublicSidebar.getPublicRecordSideBar(options),
this.getCountryCodes(),
this._recordPublicSidebar.getPublicRecordSideBar(options).pipe(take(1)),
this.getCountryCodes().pipe(take(1)),
]).pipe(
map((value) => {
const countries = value[0].countries
const countryCodes = value[1]
countries.addresses.forEach((country) => {
//Override backend country name translations
country.countryName = countryCodes[country.iso2Country.value] || ''
country.countryName =
countryCodes.find((x) => x.value === country.iso2Country.value)
.key || ''
})
return countries
})
Expand All @@ -325,22 +327,37 @@ export class RecordCountriesService {
this.$addresses.next(<CountriesEndpoint>undefined)
}

this._http
.get<CountriesEndpoint>(
environment.API_WEB + `account/countryForm.json`,
{
headers: this.headers,
}
)
forkJoin([
this._http
.get<CountriesEndpoint>(
environment.API_WEB + `account/countryForm.json`,
{
headers: this.headers,
}
)
.pipe(take(1)),
this.getCountryCodes().pipe(take(1)),
])
.pipe(
retry(3),
catchError((error) => this._errorHandler.handleError(error)),
catchError(() => of({ addresses: [] } as CountriesEndpoint)),
tap((value) => {
this.reverseSort(value)
this.reverseSort(value[0])
}),
tap((value) => {
this.$addresses.next(value)
this.$addresses.next(value[0])
}),
map((value) => {
const countries = value[0] as CountriesEndpoint
const countryCodes = value[1] as { key: string; value: string }[]
countries.addresses.forEach((country) => {
//Override backend country name translations
country.countryName =
countryCodes.find((x) => x.value === country.iso2Country.value)
.key || ''
})
return countries
})
)
.subscribe()
Expand Down