Skip to content

Commit 9735c43

Browse files
committed
Fixed infinite loading after fillin in author information
1 parent 3e92849 commit 9735c43

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/app/core/submission/vocabularies/vocabulary.service.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,19 @@ export class VocabularyService {
148148
pagination: paginationOptions
149149
});
150150

151-
// Use ORCID external source (try both orcid and orcidV2)
152-
return this.externalSourceDataService.getExternalSourceEntries('orcid', searchOptions).pipe(
153-
switchMap((orcidResponse: RemoteData<PaginatedList<ExternalSourceEntry>>) => {
154-
if (orcidResponse.hasSucceeded && orcidResponse.payload && orcidResponse.payload.page.length > 0) {
151+
// Use ORCID external source with proper completion handling
152+
return this.externalSourceDataService.getExternalSourceEntries('orcid', searchOptions, false, false).pipe(
153+
// Use the existing DSpace operator to ensure completion
154+
getFirstSucceededRemoteDataPayload(),
155+
switchMap((paginatedList: PaginatedList<ExternalSourceEntry>) => {
156+
if (paginatedList && paginatedList.page.length > 0) {
155157
// Convert ExternalSourceEntry to VocabularyEntry
156-
const vocabularyEntries: VocabularyEntry[] = orcidResponse.payload.page.map(entry => {
158+
const vocabularyEntries: VocabularyEntry[] = paginatedList.page.map(entry => {
157159
const vocabEntry = new VocabularyEntry();
158160
// Display shows author name + ORCID for selection
159161
vocabEntry.display = `${entry.display} (ORCID: ${entry.id})`;
160-
// Value should be just the author name (what goes in the main field)
161-
vocabEntry.value = entry.display;
162+
// Value should be just the author name (what goes in the main field)
163+
vocabEntry.value = entry.display;
162164
// Authority is the ORCID ID (what goes in the authority field)
163165
vocabEntry.authority = entry.id;
164166
vocabEntry.otherInformation = { orcid: entry.id };
@@ -173,8 +175,9 @@ export class VocabularyService {
173175
return createSuccessfulRemoteDataObject$(emptyList);
174176
}
175177
}),
176-
catchError(() => {
177-
// On error, return empty list
178+
catchError((error) => {
179+
console.warn('ORCID lookup failed:', error);
180+
// Return empty list on error rather than falling back
178181
const emptyList = buildPaginatedList(new PageInfo(), []);
179182
return createSuccessfulRemoteDataObject$(emptyList);
180183
})

src/app/shared/form/builder/ds-dynamic-form-ui/models/lookup/dynamic-lookup.component.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ChangeDetectorRef, Component, EventEmitter, Input, OnDestroy, OnInit, O
22
import { UntypedFormGroup } from '@angular/forms';
33

44
import { of as observableOf, Subscription } from 'rxjs';
5-
import { catchError, distinctUntilChanged } from 'rxjs/operators';
5+
import { catchError, distinctUntilChanged, finalize } from 'rxjs/operators';
66
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap';
77
import { DynamicFormLayoutService, DynamicFormValidationService } from '@ng-dynamic-forms/core';
88

@@ -230,17 +230,20 @@ export class DsDynamicLookupComponent extends DsDynamicVocabularyComponent imple
230230
[]
231231
))
232232
),
233-
distinctUntilChanged())
234-
.subscribe((list: PaginatedList<VocabularyEntry>) => {
233+
distinctUntilChanged(),
234+
finalize(() => {
235+
// Always reset loading state regardless of success or error
236+
this.loading = false;
237+
this.cdr.detectChanges();
238+
})
239+
).subscribe((list: PaginatedList<VocabularyEntry>) => {
235240
this.optionsList = list.page;
236241
this.updatePageInfo(
237242
list.pageInfo.elementsPerPage,
238243
list.pageInfo.currentPage,
239244
list.pageInfo.totalElements,
240245
list.pageInfo.totalPages
241246
);
242-
this.loading = false;
243-
this.cdr.detectChanges();
244247
}));
245248
}
246249

0 commit comments

Comments
 (0)