Skip to content

Commit a0c3ca5

Browse files
97065: Make the error clickable and resend request if it failed
1 parent 4ba5eba commit a0c3ca5

3 files changed

Lines changed: 36 additions & 19 deletions

File tree

src/app/shared/dso-selector/dso-selector/authorized-collection-selector/authorized-collection-selector.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ export class AuthorizedCollectionSelectorComponent extends DSOSelectorComponent
5353
* Perform a search for authorized collections with the current query and page
5454
* @param query Query to search objects for
5555
* @param page Page to retrieve
56+
* @param useCache Whether or not to use the cache
5657
*/
57-
search(query: string, page: number): Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>> {
58+
search(query: string, page: number, useCache: boolean = true): Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>> {
5859
let searchListService$: Observable<RemoteData<PaginatedList<Collection>>> = null;
5960
const findOptions: FindListOptions = {
6061
currentPage: page,
@@ -69,7 +70,7 @@ export class AuthorizedCollectionSelectorComponent extends DSOSelectorComponent
6970
findOptions);
7071
} else {
7172
searchListService$ = this.collectionDataService
72-
.getAuthorizedCollection(query, findOptions, true, false, followLink('parentCommunity'));
73+
.getAuthorizedCollection(query, findOptions, useCache, false, followLink('parentCommunity'));
7374
}
7475
return searchListService$.pipe(
7576
getFirstCompletedRemoteData(),

src/app/shared/dso-selector/dso-selector/dso-selector.component.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,25 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
186186
);
187187
})
188188
).subscribe((rd: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>) => {
189-
this.loading = false;
190-
const currentEntries = this.listEntries$.getValue();
191-
if (rd.hasSucceeded) {
192-
if (hasNoValue(currentEntries)) {
193-
this.listEntries$.next(rd.payload.page);
194-
} else {
195-
this.listEntries$.next([...currentEntries, ...rd.payload.page]);
196-
}
197-
// Check if there are more pages available after the current one
198-
this.hasNextPage = rd.payload.totalElements > this.listEntries$.getValue().length;
189+
this.updateList(rd);
190+
}));
191+
}
192+
193+
updateList(rd: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>) {
194+
this.loading = false;
195+
const currentEntries = this.listEntries$.getValue();
196+
if (rd.hasSucceeded) {
197+
if (hasNoValue(currentEntries)) {
198+
this.listEntries$.next(rd.payload.page);
199199
} else {
200-
this.listEntries$.next([...(hasNoValue(currentEntries) ? [] : this.listEntries$.getValue()), new ListableNotificationObject(NotificationType.Error, 'dso-selector.results-could-not-be-retrieved', LISTABLE_NOTIFICATION_OBJECT.value)]);
201-
this.hasNextPage = false;
200+
this.listEntries$.next([...currentEntries, ...rd.payload.page]);
202201
}
203-
}));
202+
// Check if there are more pages available after the current one
203+
this.hasNextPage = rd.payload.totalElements > this.listEntries$.getValue().length;
204+
} else {
205+
this.listEntries$.next([...(hasNoValue(currentEntries) ? [] : this.listEntries$.getValue()), new ListableNotificationObject(NotificationType.Error, 'dso-selector.results-could-not-be-retrieved', LISTABLE_NOTIFICATION_OBJECT.value)]);
206+
this.hasNextPage = false;
207+
}
204208
}
205209

206210
/**
@@ -214,16 +218,19 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
214218
* Perform a search for the current query and page
215219
* @param query Query to search objects for
216220
* @param page Page to retrieve
221+
* @param useCache Whether or not to use the cache
217222
*/
218-
search(query: string, page: number): Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>> {
223+
search(query: string, page: number, useCache: boolean = true): Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>> {
219224
return this.searchService.search(
220225
new PaginatedSearchOptions({
221226
query: query,
222227
dsoTypes: this.types,
223228
pagination: Object.assign({}, this.defaultPagination, {
224229
currentPage: page
225230
})
226-
})
231+
}),
232+
null,
233+
useCache,
227234
).pipe(
228235
getFirstCompletedRemoteData()
229236
);
@@ -266,12 +273,21 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
266273
}
267274

268275
/**
269-
* Emits only when the {@link listableObject} is a {@link DSpaceObject}.
276+
* Handles the user clicks on the {@link ListableObject}s. When the {@link listableObject} is a
277+
* {@link ListableObject} it will retry the error when the user clicks it. Otherwise it will emit the {@link onSelect}.
270278
*
271279
* @param listableObject The {@link ListableObject} to evaluate
272280
*/
273281
onClick(listableObject: ListableObject): void {
274282
if (listableObject.getRenderTypes().includes(LISTABLE_NOTIFICATION_OBJECT.value)) {
283+
this.listEntries$.value.pop();
284+
this.hasNextPage = true;
285+
this.search(this.input.value ? this.input.value : '', this.currentPage$.value, false).pipe(
286+
getFirstCompletedRemoteData(),
287+
).subscribe((rd: RemoteData<PaginatedList<SearchResult<DSpaceObject>>>) => {
288+
this.updateList(rd);
289+
});
290+
} else {
275291
this.onSelect.emit((listableObject as SearchResult<DSpaceObject>).indexableObject);
276292
}
277293
}

src/assets/i18n/en.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@
13971397

13981398
"dso-selector.claim.item.create-from-scratch": "Create a new one",
13991399

1400-
"dso-selector.results-could-not-be-retrieved": "Something went wrong, please refresh the page to try again",
1400+
"dso-selector.results-could-not-be-retrieved": "Something went wrong, please refresh again",
14011401

14021402
"confirmation-modal.export-metadata.header": "Export metadata for {{ dsoName }}",
14031403

0 commit comments

Comments
 (0)