Skip to content

Commit d9c0401

Browse files
authored
Merge pull request #4530 from atmire/w2p-119612_export-item-limit-7_x
[Port dspace-7_x] UI warning for export item limit
2 parents 0d87a72 + 5a2702c commit d9c0401

File tree

5 files changed

+69
-8
lines changed

5 files changed

+69
-8
lines changed
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
<ng-template #tipContent>
2+
<div class="tooltip-content">
3+
<p class="m-0">{{tooltipMsg | translate}}</p>
4+
</div>
5+
</ng-template>
6+
7+
<ng-template #tipContentWarning>
8+
<div class="tooltip-content">
9+
<p class="m-0">{{tooltipMsg | translate}}</p>
10+
<p class="m-0 text-warning">{{exportLimitExceededMsg}}</p>
11+
</div>
12+
</ng-template>
13+
114
<button *ngIf="shouldShowButton$ | async"
215
class="export-button btn btn-dark btn-sm"
3-
[ngbTooltip]="tooltipMsg | translate"
16+
[ngbTooltip]="(shouldShowWarning$ | async) ? tipContentWarning : tipContent"
417
(click)="export()"
5-
[title]="tooltipMsg |translate" [attr.aria-label]="tooltipMsg |translate">
18+
[title]="tooltipMsg | translate" [attr.aria-label]="(shouldShowWarning$ | async) ? ((tooltipMsg | translate) + ' ' + exportLimitExceededMsg): (tooltipMsg | translate)">
619
<i class="fas fa-file-export fa-fw"></i>
7-
</button>
20+
</button>

src/app/shared/search/search-export-csv/search-export-csv.component.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
22
import { of as observableOf } from 'rxjs';
33
import { TranslateModule } from '@ngx-translate/core';
44
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
5+
import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
56
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
67
import { SearchExportCsvComponent } from './search-export-csv.component';
78
import { ScriptDataService } from '../../../core/data/processes/script-data.service';
@@ -23,6 +24,7 @@ describe('SearchExportCsvComponent', () => {
2324
let authorizationDataService: AuthorizationDataService;
2425
let notificationsService;
2526
let router;
27+
let configurationDataService: jasmine.SpyObj<ConfigurationDataService>;
2628

2729
const process = Object.assign(new Process(), {processId: 5, scriptName: 'metadata-export-search'});
2830

@@ -37,6 +39,10 @@ describe('SearchExportCsvComponent', () => {
3739
]
3840
});
3941

42+
configurationDataService = jasmine.createSpyObj('ConfigurationDataService', {
43+
findByPropertyName: observableOf({ payload: { value: '500' } }),
44+
});
45+
4046
function initBeforeEachAsync() {
4147
scriptDataService = jasmine.createSpyObj('scriptDataService', {
4248
scriptWithNameExistsAndCanExecute: observableOf(true),
@@ -57,6 +63,7 @@ describe('SearchExportCsvComponent', () => {
5763
{provide: AuthorizationDataService, useValue: authorizationDataService},
5864
{provide: NotificationsService, useValue: notificationsService},
5965
{provide: Router, useValue: router},
66+
{ provide: ConfigurationDataService, useValue: configurationDataService },
6067
]
6168
}).compileComponents();
6269
}

src/app/shared/search/search-export-csv/search-export-csv.component.ts

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnInit } from '@angular/core';
1+
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
22
import { Observable } from 'rxjs';
33
import { ScriptDataService } from '../../../core/data/processes/script-data.service';
44
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
@@ -14,6 +14,8 @@ import { TranslateService } from '@ngx-translate/core';
1414
import { Router } from '@angular/router';
1515
import { PaginatedSearchOptions } from '../models/paginated-search-options.model';
1616
import { SearchFilter } from '../models/search-filter.model';
17+
import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
18+
import { ConfigurationProperty } from '../../../core/shared/configuration-property.model';
1719

1820
@Component({
1921
selector: 'ds-search-export-csv',
@@ -23,13 +25,18 @@ import { SearchFilter } from '../models/search-filter.model';
2325
/**
2426
* Display a button to export the current search results as csv
2527
*/
26-
export class SearchExportCsvComponent implements OnInit {
28+
export class SearchExportCsvComponent implements OnInit, OnChanges {
2729

2830
/**
2931
* The current configuration of the search
3032
*/
3133
@Input() searchConfig: PaginatedSearchOptions;
3234

35+
/**
36+
* The total number of items in the search results which can be exported
37+
*/
38+
@Input() total: number;
39+
3340
/**
3441
* Observable used to determine whether the button should be shown
3542
*/
@@ -40,12 +47,18 @@ export class SearchExportCsvComponent implements OnInit {
4047
*/
4148
tooltipMsg = 'metadata-export-search.tooltip';
4249

50+
exportLimitExceededKey = 'metadata-export-search.submit.error.limit-exceeded';
51+
52+
exportLimitExceededMsg = '';
53+
54+
shouldShowWarning$: Observable<boolean>;
55+
4356
constructor(private scriptDataService: ScriptDataService,
4457
private authorizationDataService: AuthorizationDataService,
4558
private notificationsService: NotificationsService,
4659
private translateService: TranslateService,
47-
private router: Router
48-
) {
60+
private router: Router,
61+
private configurationService: ConfigurationDataService) {
4962
}
5063

5164
ngOnInit(): void {
@@ -55,6 +68,31 @@ export class SearchExportCsvComponent implements OnInit {
5568
map((canExecute: boolean) => canExecute),
5669
startWith(false),
5770
);
71+
this.shouldShowWarning$ = this.itemExceeds();
72+
}
73+
74+
ngOnChanges(changes: SimpleChanges): void {
75+
if (changes.total) {
76+
this.shouldShowWarning$ = this.itemExceeds();
77+
}
78+
}
79+
80+
/**
81+
* Checks if the export limit has been exceeded and updates the tooltip accordingly
82+
*/
83+
private itemExceeds(): Observable<boolean> {
84+
return this.configurationService.findByPropertyName('bulkedit.export.max.items').pipe(
85+
getFirstCompletedRemoteData(),
86+
map((response: RemoteData<ConfigurationProperty>) => {
87+
const limit = Number(response.payload?.values?.[0]) || 500;
88+
if (limit < this.total) {
89+
this.exportLimitExceededMsg = this.translateService.instant(this.exportLimitExceededKey, { limit: String(limit) });
90+
return true;
91+
} else {
92+
return false;
93+
}
94+
}),
95+
);
5896
}
5997

6098
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<div class="d-flex justify-content-between">
22
<h1 *ngIf="!disableHeader">{{ (configuration ? configuration + '.search.results.head' : 'search.results.head') | translate }}</h1>
3-
<ds-search-export-csv *ngIf="showCsvExport" [searchConfig]="searchConfig"></ds-search-export-csv>
3+
<ds-search-export-csv *ngIf="showCsvExport" [total]="searchResults?.payload?.totalElements"
4+
[searchConfig]="searchConfig"></ds-search-export-csv>
45
</div>
56
<div *ngIf="searchResults && searchResults?.hasSucceeded && !searchResults?.isLoading && searchResults?.payload?.page.length > 0" @fadeIn>
67
<ds-viewable-collection

src/assets/i18n/en.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5496,4 +5496,6 @@
54965496
"live-region.ordering.dropped": "{{ itemName }}, dropped at position {{ index }} of {{ length }}.",
54975497

54985498
"dynamic-form-array.sortable-list.label": "Sortable list",
5499+
5500+
"metadata-export-search.submit.error.limit-exceeded": "Only the first {{limit}} items will be exported",
54995501
}

0 commit comments

Comments
 (0)