|
1 | 1 | import { Component, Inject, OnInit } from '@angular/core'; |
2 | 2 |
|
3 | 3 | import { TranslateService } from '@ngx-translate/core'; |
4 | | -import { BehaviorSubject, interval, race } from 'rxjs'; |
5 | | -import { map, mapTo, take } from 'rxjs/operators'; |
| 4 | +import { BehaviorSubject } from 'rxjs'; |
| 5 | +import { map, take } from 'rxjs/operators'; |
6 | 6 |
|
7 | 7 | import { FieldRenderingType, MetadataBoxFieldRendering } from '../metadata-box.decorator'; |
8 | 8 | import { VocabularyService } from '../../../../../../../core/submission/vocabularies/vocabulary.service'; |
9 | 9 | import { |
10 | | - getFirstSucceededRemoteDataPayload, |
11 | | - getPaginatedListPayload |
| 10 | + getFirstCompletedRemoteData, |
| 11 | + getPaginatedListPayload, |
| 12 | + getRemoteDataPayload |
12 | 13 | } from '../../../../../../../core/shared/operators'; |
13 | 14 | import { AuthService } from '../../../../../../../core/auth/auth.service'; |
14 | 15 | import { RenderingTypeValueModelComponent } from '../rendering-type-value.model'; |
@@ -49,21 +50,20 @@ export class ValuepairComponent extends RenderingTypeValueModelComponent impleme |
49 | 50 |
|
50 | 51 | const vocabularyName = this.renderingSubType; |
51 | 52 | const authority = this.metadataValue.authority ? this.metadataValue.authority.split(':') : undefined; |
52 | | - const isControlledVocabulary = authority?.length > 1 && authority[0] === vocabularyName; |
53 | | - const metadataValue = isControlledVocabulary ? authority[1] : this.metadataValue.value; |
| 53 | + const isControlledVocabulary = authority?.length > 1 && authority[0] === vocabularyName; |
54 | 54 |
|
55 | | - const entry$ = this.vocabularyService.getPublicVocabularyEntryByValue(vocabularyName, metadataValue).pipe( |
56 | | - getFirstSucceededRemoteDataPayload(), |
57 | | - getPaginatedListPayload(), |
58 | | - map((res) => res[0]?.display ?? this.metadataValue.value), |
59 | | - ); |
60 | | - |
61 | | - // fallback values to be shown if the display value cannot be retrieved |
62 | | - const initValue$ = interval(5000).pipe(mapTo(this.metadataValue.value)); |
| 55 | + let vocabularyEntry$ = isControlledVocabulary ? |
| 56 | + this.vocabularyService.getPublicVocabularyEntryByID(vocabularyName, this.metadataValue.authority) : |
| 57 | + this.vocabularyService.getPublicVocabularyEntryByValue(vocabularyName, this.metadataValue.value); |
63 | 58 |
|
64 | | - race([entry$, initValue$]).pipe(take(1)).subscribe((value: string) => { |
65 | | - this.value$.next(value); |
66 | | - }); |
| 59 | + vocabularyEntry$.pipe( |
| 60 | + getFirstCompletedRemoteData(), |
| 61 | + getRemoteDataPayload(), |
| 62 | + getPaginatedListPayload(), |
| 63 | + map((res) => res?.length > 0 ? res[0] : null), |
| 64 | + map((res) => res?.display ?? this.metadataValue.value), |
| 65 | + take(1) |
| 66 | + ).subscribe(value => this.value$.next(value)); |
67 | 67 |
|
68 | 68 | } |
69 | 69 |
|
|
0 commit comments