Skip to content

Commit 6f51bd8

Browse files
108588: Fixed browse by issue date show loading icon indefinitely when empty
1 parent b240b2c commit 6f51bd8

5 files changed

Lines changed: 42 additions & 16 deletions

File tree

src/app/browse-by/browse-by-date/browse-by-date.component.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { PaginationServiceStub } from '../../shared/testing/pagination-service.s
2323
import { APP_CONFIG } from '../../../config/app-config.interface';
2424
import { environment } from '../../../environments/environment';
2525
import { SortDirection } from '../../core/cache/models/sort-options.model';
26+
import { cold } from 'jasmine-marbles';
2627

2728
describe('BrowseByDateComponent', () => {
2829
let comp: BrowseByDateComponent;
@@ -112,9 +113,13 @@ describe('BrowseByDateComponent', () => {
112113
fixture.detectChanges();
113114
});
114115

115-
it('should initialize the list of items', () => {
116+
it('should initialize the list of items', (done: DoneFn) => {
117+
expect(comp.loading$).toBeObservable(cold('(a|)', {
118+
a: false,
119+
}));
116120
comp.items$.subscribe((result) => {
117121
expect(result.payload.page).toEqual([firstItem]);
122+
done();
118123
});
119124
});
120125

src/app/browse-by/browse-by-date/browse-by-date.component.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { ChangeDetectorRef, Component, Inject, OnInit } from '@angular/core';
2-
import {
3-
BrowseByMetadataComponent,
4-
browseParamsToOptions,
5-
getBrowseSearchOptions
6-
} from '../browse-by-metadata/browse-by-metadata.component';
7-
import { combineLatest as observableCombineLatest } from 'rxjs';
2+
import { BrowseByMetadataComponent, browseParamsToOptions, getBrowseSearchOptions } from '../browse-by-metadata/browse-by-metadata.component';
3+
import { combineLatest as observableCombineLatest, Observable } from 'rxjs';
84
import { hasValue, isNotEmpty } from '../../shared/empty.util';
95
import { ActivatedRoute, Params, Router } from '@angular/router';
106
import { BrowseService } from '../../core/browse/browse.service';
@@ -87,12 +83,21 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
8783
* @param scope The scope under which to fetch the earliest item for
8884
*/
8985
updateStartsWithOptions(definition: string, metadataKeys: string[], scope?: string) {
90-
const firstItemRD = this.browseService.getFirstItemFor(definition, scope, SortDirection.ASC);
91-
const lastItemRD = this.browseService.getFirstItemFor(definition, scope, SortDirection.DESC);
86+
const firstItemRD$: Observable<RemoteData<Item>> = this.browseService.getFirstItemFor(definition, scope, SortDirection.ASC);
87+
const lastItemRD$: Observable<RemoteData<Item>> = this.browseService.getFirstItemFor(definition, scope, SortDirection.DESC);
88+
this.loading$ = observableCombineLatest([
89+
firstItemRD$,
90+
lastItemRD$,
91+
]).pipe(
92+
map(([firstItemRD, lastItemRD]: [RemoteData<Item>, RemoteData<Item>]) => firstItemRD.isLoading || lastItemRD.isLoading)
93+
);
9294
this.subs.push(
93-
observableCombineLatest([firstItemRD, lastItemRD]).subscribe(([firstItem, lastItem]) => {
94-
let lowerLimit = this.getLimit(firstItem, metadataKeys, this.appConfig.browseBy.defaultLowerLimit);
95-
let upperLimit = this.getLimit(lastItem, metadataKeys, new Date().getUTCFullYear());
95+
observableCombineLatest([
96+
firstItemRD$,
97+
lastItemRD$,
98+
]).subscribe(([firstItemRD, lastItemRD]: [RemoteData<Item>, RemoteData<Item>]) => {
99+
let lowerLimit = this.getLimit(firstItemRD, metadataKeys, this.appConfig.browseBy.defaultLowerLimit);
100+
let upperLimit = this.getLimit(lastItemRD, metadataKeys, new Date().getUTCFullYear());
96101
const options = [];
97102
const oneYearBreak = Math.floor((upperLimit - this.appConfig.browseBy.oneYearLimit) / 5) * 5;
98103
const fiveYearBreak = Math.floor((upperLimit - this.appConfig.browseBy.fiveYearLimit) / 10) * 10;

src/app/browse-by/browse-by-metadata/browse-by-metadata.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<section class="comcol-page-browse-section">
22
<div class="browse-by-metadata w-100">
3-
<ds-browse-by *ngIf="startsWithOptions" class="col-xs-12 w-100"
3+
<ds-browse-by *ngIf="!(loading$ | async)" class="col-xs-12 w-100"
44
title="{{'browse.title' | translate:{
55
field: 'browse.metadata.' + browseId | translate,
66
startsWith: (startsWith)? ('browse.startsWith' | translate: { startsWith: '&quot;' + startsWith + '&quot;' }) : '',
@@ -15,7 +15,7 @@
1515
(prev)="goPrev()"
1616
(next)="goNext()">
1717
</ds-browse-by>
18-
<ds-themed-loading *ngIf="!startsWithOptions"
18+
<ds-themed-loading *ngIf="loading$ | async"
1919
message="{{'loading.browse-by-page' | translate}}"></ds-themed-loading>
2020
</div>
2121
</section>

src/app/browse-by/browse-by-metadata/browse-by-metadata.component.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { PaginationService } from '../../core/pagination/pagination.service';
3030
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
3131
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
3232
import { APP_CONFIG } from '../../../config/app-config.interface';
33+
import { cold } from 'jasmine-marbles';
3334

3435
describe('BrowseByMetadataComponent', () => {
3536
let comp: BrowseByMetadataComponent;
@@ -147,9 +148,13 @@ describe('BrowseByMetadataComponent', () => {
147148
fixture.detectChanges();
148149
});
149150

150-
it('should fetch items', () => {
151+
it('should fetch items', (done: DoneFn) => {
152+
expect(comp.loading$).toBeObservable(cold('(a|)', {
153+
a: false,
154+
}));
151155
comp.items$.subscribe((result) => {
152156
expect(result.payload.page).toEqual(mockItems);
157+
done();
153158
});
154159
});
155160
});

src/app/browse-by/browse-by-metadata/browse-by-metadata.component.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription } from 'rxjs';
1+
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, Subscription, of as observableOf } from 'rxjs';
22
import { Component, Inject, OnInit, OnDestroy, Input, OnChanges } from '@angular/core';
33
import { RemoteData } from '../../core/data/remote-data';
44
import { PaginatedList } from '../../core/data/paginated-list.model';
@@ -133,6 +133,11 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
133133
*/
134134
fetchThumbnails: boolean;
135135

136+
/**
137+
* Observable determining if the loading animation needs to be shown
138+
*/
139+
loading$ = observableOf(true);
140+
136141
public constructor(protected route: ActivatedRoute,
137142
protected browseService: BrowseService,
138143
protected dsoService: DSpaceObjectDataService,
@@ -207,6 +212,9 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
207212
*/
208213
updatePage(searchOptions: BrowseEntrySearchOptions) {
209214
this.browseEntries$ = this.browseService.getBrowseEntriesFor(searchOptions);
215+
this.loading$ = this.browseEntries$.pipe(
216+
map((browseEntriesRD: RemoteData<PaginatedList<BrowseEntry>>) => browseEntriesRD.isLoading),
217+
);
210218
this.items$ = undefined;
211219
}
212220

@@ -221,6 +229,9 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
221229
*/
222230
updatePageWithItems(searchOptions: BrowseEntrySearchOptions, value: string, authority: string) {
223231
this.items$ = this.browseService.getBrowseItemsFor(value, authority, searchOptions);
232+
this.loading$ = this.items$.pipe(
233+
map((itemsRD: RemoteData<PaginatedList<Item>>) => itemsRD.isLoading),
234+
);
224235
}
225236

226237
/**

0 commit comments

Comments
 (0)