Skip to content

Commit ceedfbe

Browse files
committed
[DSC-1053] Show search chart only on CSR
1 parent 8d8dac4 commit ceedfbe

2 files changed

Lines changed: 35 additions & 21 deletions

File tree

src/app/shared/search/search-charts/search-charts.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div *ngIf="(filters | async)?.hasSucceeded && (filters | async)?.payload?.length > 0" class="container">
1+
<div *ngIf="isPlatformBrowser && (filters | async)?.hasSucceeded && (filters | async)?.payload?.length > 0" class="container">
22
<div class="row">
33
<div class="col-md-12 mb-40">
44
<div class="d-flex align-items-center mb-2">

src/app/shared/search/search-charts/search-charts.component.ts

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { getRemoteDataPayload } from './../../../core/shared/operators';
2-
import { SEARCH_CONFIG_SERVICE } from './../../../my-dspace-page/my-dspace-page.component';
3-
import { SearchConfigurationService } from './../../../core/shared/search/search-configuration.service';
4-
import { SearchService } from './../../../core/shared/search/search.service';
5-
import { Component, Inject, Input, OnInit } from '@angular/core';
1+
import { isPlatformBrowser } from '@angular/common';
2+
import { ChangeDetectorRef, Component, Inject, Input, OnInit, PLATFORM_ID } from '@angular/core';
63

74
import { BehaviorSubject, Observable, of } from 'rxjs';
8-
import { filter, map, switchMap, take, tap, mergeMap } from 'rxjs/operators';
5+
import { filter, map, mergeMap, switchMap, take, tap } from 'rxjs/operators';
6+
97
import { RemoteData } from '../../../core/data/remote-data';
108
import { SearchFilterConfig } from '../models/search-filter-config.model';
119
import { shrinkInOut } from '../../animations/shrink';
1210
import { hasValue, isNotEmpty } from '../../empty.util';
11+
import { getRemoteDataPayload } from '../../../core/shared/operators';
12+
import { SEARCH_CONFIG_SERVICE } from '../../../my-dspace-page/my-dspace-page.component';
13+
import { SearchConfigurationService } from '../../../core/shared/search/search-configuration.service';
14+
import { SearchService } from '../../../core/shared/search/search.service';
1315

1416
@Component({
1517
selector: 'ds-search-charts',
@@ -57,25 +59,37 @@ export class SearchChartsComponent implements OnInit {
5759
*/
5860
selectedFilter: SearchFilterConfig;
5961

62+
/**
63+
* Whether a platform id represents a browser platform.
64+
*/
65+
isPlatformBrowser: boolean;
6066

61-
constructor(private searchService: SearchService,
67+
constructor(
68+
private cdr: ChangeDetectorRef,
69+
private searchService: SearchService,
70+
@Inject(PLATFORM_ID) protected platformId: Object,
6271
@Inject(SEARCH_CONFIG_SERVICE) private searchConfigService: SearchConfigurationService) {
6372
}
6473

6574
ngOnInit(): void {
66-
this.filters.pipe(
67-
filter((rd: RemoteData<SearchFilterConfig[]>) => isNotEmpty(rd)),
68-
take(1),
69-
mergeMap((rd: RemoteData<SearchFilterConfig[]>) => {
70-
return this.hasFacetValues(rd.payload[0]).pipe(
71-
tap((hasValues) => {
72-
this.selectedFilter = this.selectedFilter
73-
? this.selectedFilter
74-
: rd.hasSucceeded && hasValues ? rd.payload[0] : null;
75-
})
76-
);
77-
}),
78-
).subscribe();
75+
this.isPlatformBrowser = isPlatformBrowser(this.platformId);
76+
77+
if (isPlatformBrowser(this.platformId)) {
78+
this.filters.pipe(
79+
filter((rd: RemoteData<SearchFilterConfig[]>) => isNotEmpty(rd)),
80+
take(1),
81+
mergeMap((rd: RemoteData<SearchFilterConfig[]>) => {
82+
return this.hasFacetValues(rd.payload[0]).pipe(
83+
tap((hasValues) => {
84+
this.selectedFilter = this.selectedFilter
85+
? this.selectedFilter
86+
: rd.hasSucceeded && hasValues ? rd.payload[0] : null;
87+
this.cdr.detectChanges();
88+
})
89+
);
90+
}),
91+
).subscribe();
92+
}
7993
}
8094

8195
/**

0 commit comments

Comments
 (0)