diff --git a/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.ts b/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.ts index ab48d058ca..cc1f9822d6 100644 --- a/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.ts +++ b/src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.ts @@ -53,8 +53,9 @@ export class AuthorizedCollectionSelectorComponent extends DSOSelectorComponent * Perform a search for authorized collections with the current query and page * @param query Query to search objects for * @param page Page to retrieve + * @param useCache Whether or not to use the cache */ - search(query: string, page: number): Observable>>> { + search(query: string, page: number, useCache: boolean = true): Observable>>> { let searchListService$: Observable>> = null; const findOptions: FindListOptions = { currentPage: page, @@ -69,7 +70,7 @@ export class AuthorizedCollectionSelectorComponent extends DSOSelectorComponent findOptions); } else { searchListService$ = this.collectionDataService - .getAuthorizedCollection(query, findOptions, true, false, followLink('parentCommunity')); + .getAuthorizedCollection(query, findOptions, useCache, false, followLink('parentCommunity')); } return searchListService$.pipe( getFirstCompletedRemoteData(), diff --git a/src/app/shared/dso-selector/dso-selector/dso-selector.component.ts b/src/app/shared/dso-selector/dso-selector/dso-selector.component.ts index adf8751563..260f3182d5 100644 --- a/src/app/shared/dso-selector/dso-selector/dso-selector.component.ts +++ b/src/app/shared/dso-selector/dso-selector/dso-selector.component.ts @@ -186,23 +186,27 @@ export class DSOSelectorComponent implements OnInit, OnDestroy { ); }) ).subscribe((rd: RemoteData>>) => { - this.loading = false; - const currentEntries = this.listEntries$.getValue(); - if (rd.hasSucceeded) { - if (hasNoValue(currentEntries)) { - this.listEntries$.next(rd.payload.page); - } else { - this.listEntries$.next([...currentEntries, ...rd.payload.page]); - } - // Check if there are more pages available after the current one - this.hasNextPage = rd.payload.totalElements > this.listEntries$.getValue().length; - } else { - this.listEntries$.next([...(hasNoValue(currentEntries) ? [] : this.listEntries$.getValue()), new ListableNotificationObject(NotificationType.Error, 'dso-selector.results-could-not-be-retrieved', LISTABLE_NOTIFICATION_OBJECT.value)]); - this.hasNextPage = false; - } + this.updateList(rd); })); } + updateList(rd: RemoteData>>) { + this.loading = false; + const currentEntries = this.listEntries$.getValue(); + if (rd.hasSucceeded) { + if (hasNoValue(currentEntries)) { + this.listEntries$.next(rd.payload.page); + } else { + this.listEntries$.next([...currentEntries, ...rd.payload.page]); + } + // Check if there are more pages available after the current one + this.hasNextPage = rd.payload.totalElements > this.listEntries$.getValue().length; + } else { + this.listEntries$.next([...(hasNoValue(currentEntries) ? [] : this.listEntries$.getValue()), new ListableNotificationObject(NotificationType.Error, 'dso-selector.results-could-not-be-retrieved', LISTABLE_NOTIFICATION_OBJECT.value)]); + this.hasNextPage = false; + } + } + /** * Get a query to send for retrieving the current DSO */ @@ -214,8 +218,9 @@ export class DSOSelectorComponent implements OnInit, OnDestroy { * Perform a search for the current query and page * @param query Query to search objects for * @param page Page to retrieve + * @param useCache Whether or not to use the cache */ - search(query: string, page: number): Observable>>> { + search(query: string, page: number, useCache: boolean = true): Observable>>> { return this.searchService.search( new PaginatedSearchOptions({ query: query, @@ -223,7 +228,9 @@ export class DSOSelectorComponent implements OnInit, OnDestroy { pagination: Object.assign({}, this.defaultPagination, { currentPage: page }) - }) + }), + null, + useCache, ).pipe( getFirstCompletedRemoteData() ); @@ -266,12 +273,21 @@ export class DSOSelectorComponent implements OnInit, OnDestroy { } /** - * Emits only when the {@link listableObject} is a {@link DSpaceObject}. + * Handles the user clicks on the {@link ListableObject}s. When the {@link listableObject} is a + * {@link ListableObject} it will retry the error when the user clicks it. Otherwise it will emit the {@link onSelect}. * * @param listableObject The {@link ListableObject} to evaluate */ onClick(listableObject: ListableObject): void { if (listableObject.getRenderTypes().includes(LISTABLE_NOTIFICATION_OBJECT.value)) { + this.listEntries$.value.pop(); + this.hasNextPage = true; + this.search(this.input.value ? this.input.value : '', this.currentPage$.value, false).pipe( + getFirstCompletedRemoteData(), + ).subscribe((rd: RemoteData>>) => { + this.updateList(rd); + }); + } else { this.onSelect.emit((listableObject as SearchResult).indexableObject); } } diff --git a/src/assets/i18n/en.json5 b/src/assets/i18n/en.json5 index cc32270c86..491ec8fba0 100644 --- a/src/assets/i18n/en.json5 +++ b/src/assets/i18n/en.json5 @@ -1397,7 +1397,7 @@ "dso-selector.claim.item.create-from-scratch": "Create a new one", - "dso-selector.results-could-not-be-retrieved": "Something went wrong, please refresh the page to try again", + "dso-selector.results-could-not-be-retrieved": "Something went wrong, please refresh again ↻", "confirmation-modal.export-metadata.header": "Export metadata for {{ dsoName }}",