Skip to content

Commit 0ade76a

Browse files
authored
Merge pull request #3753 from atmire/w2p-121787_Investigate-internal-server-error-on-browse-page-experiment
Get rid of unnecessary and failing REST requests when navigating between different browse indexes
2 parents b454e49 + a105bcd commit 0ade76a

File tree

8 files changed

+60
-26
lines changed

8 files changed

+60
-26
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import {
1818
combineLatest as observableCombineLatest,
1919
Observable,
2020
} from 'rxjs';
21-
import { map } from 'rxjs/operators';
21+
import {
22+
map,
23+
take,
24+
} from 'rxjs/operators';
2225
import { ThemedBrowseByComponent } from 'src/app/shared/browse-by/themed-browse-by.component';
2326

2427
import {
@@ -53,7 +56,6 @@ import { VarDirective } from '../../shared/utils/var.directive';
5356
import {
5457
BrowseByMetadataComponent,
5558
browseParamsToOptions,
56-
getBrowseSearchOptions,
5759
} from '../browse-by-metadata/browse-by-metadata.component';
5860

5961
@Component({
@@ -104,15 +106,18 @@ export class BrowseByDateComponent extends BrowseByMetadataComponent implements
104106
ngOnInit(): void {
105107
const sortConfig = new SortOptions('default', SortDirection.ASC);
106108
this.startsWithType = StartsWithType.date;
107-
// include the thumbnail configuration in browse search options
108-
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig, this.fetchThumbnails));
109109
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
110110
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
111111
this.subs.push(
112-
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.route.data,
113-
this.currentPagination$, this.currentSort$]).pipe(
114-
map(([routeParams, queryParams, scope, data, currentPage, currentSort]) => {
115-
return [Object.assign({}, routeParams, queryParams, data), scope, currentPage, currentSort];
112+
observableCombineLatest(
113+
[ this.route.params.pipe(take(1)),
114+
this.route.queryParams,
115+
this.scope$,
116+
this.currentPagination$,
117+
this.currentSort$,
118+
]).pipe(
119+
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
120+
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
116121
}),
117122
).subscribe(([params, scope, currentPage, currentSort]: [Params, string, PaginationComponentOptions, SortOptions]) => {
118123
const metadataKeys = params.browseDefinition ? params.browseDefinition.metadataKeys : this.defaultMetadataKeys;

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import {
2323
of as observableOf,
2424
Subscription,
2525
} from 'rxjs';
26-
import { map } from 'rxjs/operators';
26+
import {
27+
map,
28+
take,
29+
} from 'rxjs/operators';
2730
import { ThemedBrowseByComponent } from 'src/app/shared/browse-by/themed-browse-by.component';
2831

2932
import {
@@ -216,7 +219,13 @@ export class BrowseByMetadataComponent implements OnInit, OnChanges, OnDestroy {
216219
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
217220
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
218221
this.subs.push(
219-
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
222+
observableCombineLatest(
223+
[ this.route.params.pipe(take(1)),
224+
this.route.queryParams,
225+
this.scope$,
226+
this.currentPagination$,
227+
this.currentSort$,
228+
]).pipe(
220229
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
221230
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
222231
}),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { BrowseBySwitcherComponent } from '../browse-by-switcher/browse-by-switc
2323
})
2424
export class BrowseByPageComponent implements OnInit {
2525

26-
browseByType$: Observable<BrowseByDataType>;
26+
browseByType$: Observable<{type: BrowseByDataType }>;
2727

2828
constructor(
2929
protected route: ActivatedRoute,
@@ -35,7 +35,7 @@ export class BrowseByPageComponent implements OnInit {
3535
*/
3636
ngOnInit(): void {
3737
this.browseByType$ = this.route.data.pipe(
38-
map((data: { browseDefinition: BrowseDefinition }) => data.browseDefinition.getRenderType()),
38+
map((data: { browseDefinition: BrowseDefinition }) => ({ type: data.browseDefinition.getRenderType() })),
3939
);
4040
}
4141

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('BrowseBySwitcherComponent', () => {
8585
types.forEach((type: NonHierarchicalBrowseDefinition) => {
8686
describe(`when switching to a browse-by page for "${type.id}"`, () => {
8787
beforeEach(async () => {
88-
comp.browseByType = type.dataType;
88+
comp.browseByType = type as any;
8989
comp.ngOnChanges({
9090
browseByType: new SimpleChange(undefined, type.dataType, true),
9191
});

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent<
2424

2525
@Input() context: Context;
2626

27-
@Input() browseByType: BrowseByDataType;
27+
@Input() browseByType: { type: BrowseByDataType };
2828

2929
@Input() displayTitle: boolean;
3030

@@ -43,7 +43,7 @@ export class BrowseBySwitcherComponent extends AbstractComponentLoaderComponent<
4343
];
4444

4545
public getComponent(): GenericConstructor<Component> {
46-
return getComponentByBrowseByType(this.browseByType, this.context, this.themeService.getThemeName());
46+
return getComponentByBrowseByType(this.browseByType.type, this.context, this.themeService.getThemeName());
4747
}
4848

4949
}

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
import { Params } from '@angular/router';
1010
import { TranslateModule } from '@ngx-translate/core';
1111
import { combineLatest as observableCombineLatest } from 'rxjs';
12-
import { map } from 'rxjs/operators';
12+
import {
13+
map,
14+
take,
15+
} from 'rxjs/operators';
1316

1417
import {
1518
SortDirection,
@@ -28,7 +31,6 @@ import { VarDirective } from '../../shared/utils/var.directive';
2831
import {
2932
BrowseByMetadataComponent,
3033
browseParamsToOptions,
31-
getBrowseSearchOptions,
3234
} from '../browse-by-metadata/browse-by-metadata.component';
3335

3436
@Component({
@@ -58,12 +60,16 @@ export class BrowseByTitleComponent extends BrowseByMetadataComponent implements
5860

5961
ngOnInit(): void {
6062
const sortConfig = new SortOptions('dc.title', SortDirection.ASC);
61-
// include the thumbnail configuration in browse search options
62-
this.updatePage(getBrowseSearchOptions(this.defaultBrowseId, this.paginationConfig, sortConfig, this.fetchThumbnails));
6363
this.currentPagination$ = this.paginationService.getCurrentPagination(this.paginationConfig.id, this.paginationConfig);
6464
this.currentSort$ = this.paginationService.getCurrentSort(this.paginationConfig.id, sortConfig);
6565
this.subs.push(
66-
observableCombineLatest([this.route.params, this.route.queryParams, this.scope$, this.currentPagination$, this.currentSort$]).pipe(
66+
observableCombineLatest(
67+
[ this.route.params.pipe(take(1)),
68+
this.route.queryParams,
69+
this.scope$,
70+
this.currentPagination$,
71+
this.currentSort$,
72+
]).pipe(
6773
map(([routeParams, queryParams, scope, currentPage, currentSort]) => {
6874
return [Object.assign({}, routeParams, queryParams), scope, currentPage, currentSort];
6975
}),

src/app/menu-resolver.service.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
77
import {
88
combineLatest,
99
combineLatest as observableCombineLatest,
10+
mergeMap,
1011
Observable,
12+
of as observableOf,
1113
} from 'rxjs';
1214
import {
1315
filter,
@@ -17,6 +19,7 @@ import {
1719
} from 'rxjs/operators';
1820

1921
import { PUBLICATION_CLAIMS_PATH } from './admin/admin-notifications/admin-notifications-routing-paths';
22+
import { AuthService } from './core/auth/auth.service';
2023
import { BrowseService } from './core/browse/browse.service';
2124
import { ConfigurationDataService } from './core/data/configuration-data.service';
2225
import { AuthorizationDataService } from './core/data/feature-authorization/authorization-data.service';
@@ -62,6 +65,7 @@ export class MenuResolverService {
6265
protected modalService: NgbModal,
6366
protected scriptDataService: ScriptDataService,
6467
protected configurationDataService: ConfigurationDataService,
68+
protected authService: AuthService,
6569
) {
6670
}
6771

@@ -71,7 +75,7 @@ export class MenuResolverService {
7175
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
7276
return combineLatest([
7377
this.createPublicMenu$(),
74-
this.createAdminMenu$(),
78+
this.createAdminMenuIfLoggedIn$(),
7579
]).pipe(
7680
map((menusDone: boolean[]) => menusDone.every(Boolean)),
7781
);
@@ -147,6 +151,15 @@ export class MenuResolverService {
147151
return this.waitForMenu$(MenuID.PUBLIC);
148152
}
149153

154+
/**
155+
* Initialize all menu sections and items for {@link MenuID.ADMIN}, only if the user is logged in.
156+
*/
157+
createAdminMenuIfLoggedIn$() {
158+
return this.authService.isAuthenticated().pipe(
159+
mergeMap((isAuthenticated) => isAuthenticated ? this.createAdminMenu$() : observableOf(true)),
160+
);
161+
}
162+
150163
/**
151164
* Initialize all menu sections and items for {@link MenuID.ADMIN}
152165
*/
@@ -156,8 +169,6 @@ export class MenuResolverService {
156169
this.createExportMenuSections();
157170
this.createImportMenuSections();
158171
this.createAccessControlMenuSections();
159-
this.createReportMenuSections();
160-
161172
return this.waitForMenu$(MenuID.ADMIN);
162173
}
163174

src/app/menu.resolver.spec.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import { ConfigurationDataServiceStub } from './shared/testing/configuration-dat
2626
import { MenuServiceStub } from './shared/testing/menu-service.stub';
2727
import { createPaginatedList } from './shared/testing/utils.test';
2828
import createSpy = jasmine.createSpy;
29+
import { AuthService } from './core/auth/auth.service';
2930
import { MenuResolverService } from './menu-resolver.service';
31+
import { AuthServiceStub } from './shared/testing/auth-service.stub';
3032

3133
const BOOLEAN = { t: true, f: false };
3234
const MENU_STATE = {
@@ -80,6 +82,7 @@ describe('menuResolver', () => {
8082
{ provide: ScriptDataService, useValue: scriptService },
8183
{ provide: ConfigurationDataService, useValue: configurationDataService },
8284
{ provide: NgbModal, useValue: mockNgbModal },
85+
{ provide: AuthService, useValue: AuthServiceStub },
8386
MenuResolverService,
8487
],
8588
schemas: [NO_ERRORS_SCHEMA],
@@ -94,19 +97,19 @@ describe('menuResolver', () => {
9497
describe('resolve', () => {
9598
it('should create all menus', (done) => {
9699
spyOn(resolver, 'createPublicMenu$').and.returnValue(observableOf(true));
97-
spyOn(resolver, 'createAdminMenu$').and.returnValue(observableOf(true));
100+
spyOn(resolver, 'createAdminMenuIfLoggedIn$').and.returnValue(observableOf(true));
98101

99102
resolver.resolve(null, null).subscribe(resolved => {
100103
expect(resolved).toBeTrue();
101104
expect(resolver.createPublicMenu$).toHaveBeenCalled();
102-
expect(resolver.createAdminMenu$).toHaveBeenCalled();
105+
expect(resolver.createAdminMenuIfLoggedIn$).toHaveBeenCalled();
103106
done();
104107
});
105108
});
106109

107110
it('should return an Observable that emits true as soon as all menus are created', () => {
108111
spyOn(resolver, 'createPublicMenu$').and.returnValue(cold('--(t|)', BOOLEAN));
109-
spyOn(resolver, 'createAdminMenu$').and.returnValue(cold('----(t|)', BOOLEAN));
112+
spyOn(resolver, 'createAdminMenuIfLoggedIn$').and.returnValue(cold('----(t|)', BOOLEAN));
110113

111114
expect(resolver.resolve(null, null)).toBeObservable(cold('----(t|)', BOOLEAN));
112115
});

0 commit comments

Comments
 (0)