Skip to content

Commit 3335774

Browse files
committed
[DSC-1053] Show donut metrics only on CSR
1 parent 65019fd commit 3335774

2 files changed

Lines changed: 45 additions & 14 deletions

File tree

src/app/shared/object-list/metric-donuts/metric-donuts.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="flex-row d-flex ml-4">
2-
<ng-container *ngFor="let metric of donuts() | async; trackBy: identify">
2+
<ng-container *ngFor="let metric of (metrics$ | async); trackBy: identify">
33
<ds-metric-loader
44
class="d-inline-block d-flex flex-col mr-1"
55
[metric]="metric"

src/app/shared/object-list/metric-donuts/metric-donuts.component.ts

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
import { ChangeDetectionStrategy, Component, Input, OnInit, ViewEncapsulation } from '@angular/core';
2-
import { Observable, of } from 'rxjs';
1+
import { isPlatformBrowser } from '@angular/common';
2+
import {
3+
ChangeDetectionStrategy,
4+
Component,
5+
Inject,
6+
Input,
7+
OnInit,
8+
PLATFORM_ID,
9+
ViewEncapsulation
10+
} from '@angular/core';
11+
12+
import { BehaviorSubject, Observable, of } from 'rxjs';
13+
314
import { Metric } from '../../../core/shared/metric.model';
4-
import { hasValue } from '../../empty.util';
5-
import { getFirstSucceededRemoteListPayload } from '../../../core/shared/operators';
15+
import { isEmpty } from '../../empty.util';
16+
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
617
import { map } from 'rxjs/operators';
718
import { Item } from '../../../core/shared/item.model';
819
import { LinkService } from '../../../core/cache/builders/link.service';
920
import { followLink } from '../../utils/follow-link-config.model';
21+
import { RemoteData } from '../../../core/data/remote-data';
22+
import { PaginatedList } from '../../../core/data/paginated-list.model';
1023

1124
export const allowedDonuts = ['altmetric', 'dimensions', 'plumX'];
1225

@@ -21,27 +34,45 @@ export const allowedDonuts = ['altmetric', 'dimensions', 'plumX'];
2134
*/
2235
export class MetricDonutsComponent implements OnInit {
2336

37+
/**
38+
* The item object for which to show the metrics donuts
39+
*/
2440
@Input() item: Item;
2541

26-
constructor(private linkService: LinkService) {
42+
/**
43+
* The list of metric donuts to load
44+
*/
45+
metrics$: BehaviorSubject<Metric[]> = new BehaviorSubject<Metric[]>([]);
46+
47+
constructor(private linkService: LinkService, @Inject(PLATFORM_ID) protected platformId: Object) {
2748
}
2849

2950
ngOnInit() {
3051
this.linkService.resolveLink(this.item, followLink('metrics'));
52+
if (isPlatformBrowser(this.platformId)) {
53+
this.retrieveMetrics().subscribe((metrics: Metric[]) => {
54+
this.metrics$.next(metrics);
55+
})
56+
}
3157
}
3258

3359
/**
34-
* Filter metrics with a positive metricCount value.
60+
* Retrieve metrics from item object.
3561
*/
36-
donuts(): Observable<Metric[]> {
37-
if (!hasValue(this.item.metrics)) {
62+
private retrieveMetrics(): Observable<Metric[]> {
63+
if (isEmpty(this.item.metrics)) {
3864
return of([]);
65+
} else {
66+
return this.item.metrics.pipe(
67+
getFirstCompletedRemoteData(),
68+
map((metricsRD: RemoteData<PaginatedList<Metric>>) => {
69+
if (metricsRD.hasSucceeded) {
70+
return metricsRD.payload.page.filter(metric => allowedDonuts.includes(metric.metricType));
71+
} else {
72+
return [];
73+
}
74+
}));
3975
}
40-
return this.item.metrics.pipe(
41-
getFirstSucceededRemoteListPayload(),
42-
map((metrics: Metric[]) => {
43-
return metrics.filter(metric => allowedDonuts.includes(metric.metricType));
44-
}));
4576
}
4677

4778
identify(index, item) {

0 commit comments

Comments
 (0)