Skip to content

Commit 09e5dd0

Browse files
committed
[DSC-1454] limit metadata value list in the full item page
1 parent d7c331a commit 09e5dd0

3 files changed

Lines changed: 124 additions & 4 deletions

File tree

src/app/item-page/full/full-item-page.component.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@
2020
<table class="table table-striped">
2121
<tbody>
2222
<ng-container *ngFor="let mdEntry of (metadata$ | async) | keyvalue">
23-
<tr *ngFor="let mdValue of mdEntry.value">
23+
<tr *ngFor="let mdValue of mdEntry.value | slice:0:(metadataMapLimit$ | async).get(mdEntry.key)">
2424
<td>{{mdEntry.key}}</td>
2525
<td>{{mdValue.value}}</td>
2626
<td>{{mdValue.language}}</td>
2727
</tr>
28+
<tr *ngIf="mdEntry.value.length > (metadataMapLimit$ | async).get(mdEntry.key)">
29+
<td class="text-center" colspan="3">
30+
<button class="btn btn-link" (click)="increaseLimit(mdEntry.key)" data-test="btn-more">
31+
{{'item.truncatable-part.show-more' | translate}}
32+
</button>
33+
</td>
34+
</tr>
2835
</ng-container>
2936
</tbody>
3037
</table>

src/app/item-page/full/full-item-page.component.spec.ts

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,77 @@ const mockItem: Item = Object.assign(new Item(), {
3232
language: 'en_US',
3333
value: 'test item'
3434
}
35+
],
36+
'dc.contributor.author': [
37+
{
38+
value: 'author1'
39+
},
40+
{
41+
value: 'author2'
42+
},
43+
{
44+
value: 'author3'
45+
},
46+
{
47+
value: 'author4'
48+
},
49+
{
50+
value: 'author5'
51+
},
52+
{
53+
value: 'author6'
54+
},
55+
{
56+
value: 'author7'
57+
},
58+
{
59+
value: 'author8'
60+
},
61+
{
62+
value: 'author9'
63+
},
64+
{
65+
value: 'author10'
66+
},
67+
{
68+
value: 'author11'
69+
},
70+
{
71+
value: 'author12'
72+
},
73+
{
74+
value: 'author13'
75+
},
76+
{
77+
value: 'author14'
78+
},
79+
{
80+
value: 'author15'
81+
},
82+
{
83+
value: 'author16'
84+
},
85+
{
86+
value: 'author17'
87+
},
88+
{
89+
value: 'author18'
90+
},
91+
{
92+
value: 'author19'
93+
},
94+
{
95+
value: 'author20'
96+
},
97+
{
98+
value: 'author21'
99+
},
100+
{
101+
value: 'author22'
102+
},
103+
{
104+
value: 'author23'
105+
}
35106
]
36107
}
37108
});
@@ -142,7 +213,7 @@ describe('FullItemPageComponent', () => {
142213

143214
it('should display the item\'s metadata', () => {
144215
const table = fixture.debugElement.query(By.css('table'));
145-
for (const metadatum of mockItem.allMetadata(Object.keys(mockItem.metadata))) {
216+
for (const metadatum of mockItem.allMetadata('dc.title')) {
146217
expect(table.nativeElement.innerHTML).toContain(metadatum.value);
147218
}
148219
});
@@ -227,4 +298,28 @@ describe('FullItemPageComponent', () => {
227298
expect(linkHeadService.addTag).toHaveBeenCalledTimes(2);
228299
});
229300
});
301+
302+
describe('when the item has many metadata values', () => {
303+
beforeEach(() => {
304+
comp.itemRD$ = new BehaviorSubject<RemoteData<Item>>(createSuccessfulRemoteDataObject(mockItem));
305+
fixture.detectChanges();
306+
});
307+
308+
it('should not display all the item\'s metadata', () => {
309+
const table = fixture.debugElement.query(By.css('table'));
310+
const visibleValues = mockItem.allMetadata('dc.contributor.author').slice(0, 20);
311+
const hiddenValues = mockItem.allMetadata('dc.contributor.author').slice(20, 40);
312+
for (const metadatum of visibleValues) {
313+
expect(table.nativeElement.innerHTML).toContain(metadatum.value);
314+
}
315+
for (const metadatum of hiddenValues) {
316+
expect(table.nativeElement.innerHTML).not.toContain(metadatum.value);
317+
}
318+
});
319+
320+
it('should display show more button', () => {
321+
const btn = fixture.debugElement.query(By.css('button[data-test="btn-more"]'));
322+
expect(btn).not.toBeNull();
323+
});
324+
});
230325
});

src/app/item-page/full/full-item-page.component.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { filter, map } from 'rxjs/operators';
1+
import { filter, map, tap } from 'rxjs/operators';
22
import { ChangeDetectionStrategy, Component, Inject, OnDestroy, OnInit, PLATFORM_ID } from '@angular/core';
33
import { ActivatedRoute, Data, Router } from '@angular/router';
44

@@ -38,6 +38,10 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
3838

3939
metadata$: Observable<MetadataMap>;
4040

41+
metadataMapLimit$: BehaviorSubject<Map<string, number>> = new BehaviorSubject<Map<string, number>>(new Map<string, number>());
42+
43+
limitSize = 20;
44+
4145
/**
4246
* True when the itemRD has been originated from its workspaceite/workflowitem, false otherwise.
4347
*/
@@ -66,7 +70,15 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
6670
this.metadata$ = this.itemRD$.pipe(
6771
map((rd: RemoteData<Item>) => rd.payload),
6872
filter((item: Item) => hasValue(item)),
69-
map((item: Item) => item.metadata),);
73+
map((item: Item) => item.metadata),
74+
tap((metadataMap: MetadataMap) => {
75+
const metadataMapLimit: Map<string, number> = new Map<string, number>();
76+
Object.keys(metadataMap).forEach((key: string) => {
77+
metadataMapLimit.set(key, this.limitSize);
78+
});
79+
this.metadataMapLimit$.next(metadataMapLimit);
80+
})
81+
);
7082

7183
this.subs.push(this.route.data.subscribe((data: Data) => {
7284
this.fromSubmissionObject = hasValue(data.wfi) || hasValue(data.wsi);
@@ -84,4 +96,10 @@ export class FullItemPageComponent extends ItemPageComponent implements OnInit,
8496
ngOnDestroy() {
8597
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
8698
}
99+
100+
increaseLimit(key: string) {
101+
const tmpMap: Map<string, number> = this.metadataMapLimit$.value;
102+
tmpMap.set(key, tmpMap.get(key) + this.limitSize);
103+
this.metadataMapLimit$.next(tmpMap);
104+
}
87105
}

0 commit comments

Comments
 (0)