Skip to content

Commit aacedd2

Browse files
authored
Merge pull request DSpace#3892 from atmire/w2p-119612_export-item-limit
UI warning for export item limit
2 parents ea6f640 + 6232d4e commit aacedd2

5 files changed

Lines changed: 68 additions & 6 deletions

File tree

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
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
@if (shouldShowButton$ | async) {
215
<button
316
class="export-button btn btn-dark btn-sm"
4-
[ngbTooltip]="tooltipMsg | translate"
17+
[ngbTooltip]="(shouldShowWarning$ | async) ? tipContentWarning : tipContent"
518
(click)="export()"
6-
[title]="tooltipMsg |translate" [attr.aria-label]="tooltipMsg |translate">
19+
[title]="tooltipMsg | translate" [attr.aria-label]="(shouldShowWarning$ | async) ? ((tooltipMsg | translate) + ' ' + exportLimitExceededMsg): (tooltipMsg | translate)">
720
<i class="fas fa-file-export fa-fw"></i>
821
</button>
9-
}
22+
}

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
@@ -9,6 +9,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
99
import { TranslateModule } from '@ngx-translate/core';
1010
import { of as observableOf } from 'rxjs';
1111

12+
import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
1213
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
1314
import { ScriptDataService } from '../../../core/data/processes/script-data.service';
1415
import { getProcessDetailRoute } from '../../../process-page/process-page-routing.paths';
@@ -31,6 +32,7 @@ describe('SearchExportCsvComponent', () => {
3132
let authorizationDataService: AuthorizationDataService;
3233
let notificationsService;
3334
let router;
35+
let configurationDataService: jasmine.SpyObj<ConfigurationDataService>;
3436

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

@@ -45,6 +47,10 @@ describe('SearchExportCsvComponent', () => {
4547
],
4648
});
4749

50+
configurationDataService = jasmine.createSpyObj('ConfigurationDataService', {
51+
findByPropertyName: observableOf({ payload: { value: '500' } }),
52+
});
53+
4854
function initBeforeEachAsync() {
4955
scriptDataService = jasmine.createSpyObj('scriptDataService', {
5056
scriptWithNameExistsAndCanExecute: observableOf(true),
@@ -64,6 +70,7 @@ describe('SearchExportCsvComponent', () => {
6470
{ provide: AuthorizationDataService, useValue: authorizationDataService },
6571
{ provide: NotificationsService, useValue: notificationsService },
6672
{ provide: Router, useValue: router },
73+
{ provide: ConfigurationDataService, useValue: configurationDataService },
6774
],
6875
}).compileComponents();
6976
}

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

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { AsyncPipe } from '@angular/common';
22
import {
33
Component,
44
Input,
5+
OnChanges,
56
OnInit,
7+
SimpleChanges,
68
} from '@angular/core';
79
import { Router } from '@angular/router';
810
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
@@ -18,10 +20,12 @@ import {
1820
switchMap,
1921
} from 'rxjs/operators';
2022

23+
import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
2124
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
2225
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
2326
import { ScriptDataService } from '../../../core/data/processes/script-data.service';
2427
import { RemoteData } from '../../../core/data/remote-data';
28+
import { ConfigurationProperty } from '../../../core/shared/configuration-property.model';
2529
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
2630
import { getProcessDetailRoute } from '../../../process-page/process-page-routing.paths';
2731
import { Process } from '../../../process-page/processes/process.model';
@@ -43,13 +47,18 @@ import { SearchFilter } from '../models/search-filter.model';
4347
/**
4448
* Display a button to export the current search results as csv
4549
*/
46-
export class SearchExportCsvComponent implements OnInit {
50+
export class SearchExportCsvComponent implements OnInit, OnChanges {
4751

4852
/**
4953
* The current configuration of the search
5054
*/
5155
@Input() searchConfig: PaginatedSearchOptions;
5256

57+
/**
58+
* The total number of items in the search results which can be exported
59+
*/
60+
@Input() total: number;
61+
5362
/**
5463
* Observable used to determine whether the button should be shown
5564
*/
@@ -60,12 +69,18 @@ export class SearchExportCsvComponent implements OnInit {
6069
*/
6170
tooltipMsg = 'metadata-export-search.tooltip';
6271

72+
exportLimitExceededKey = 'metadata-export-search.submit.error.limit-exceeded';
73+
74+
exportLimitExceededMsg = '';
75+
76+
shouldShowWarning$: Observable<boolean>;
77+
6378
constructor(private scriptDataService: ScriptDataService,
6479
private authorizationDataService: AuthorizationDataService,
6580
private notificationsService: NotificationsService,
6681
private translateService: TranslateService,
6782
private router: Router,
68-
) {
83+
private configurationService: ConfigurationDataService) {
6984
}
7085

7186
ngOnInit(): void {
@@ -75,6 +90,31 @@ export class SearchExportCsvComponent implements OnInit {
7590
map((canExecute: boolean) => canExecute),
7691
startWith(false),
7792
);
93+
this.shouldShowWarning$ = this.itemExceeds();
94+
}
95+
96+
ngOnChanges(changes: SimpleChanges): void {
97+
if (changes.total) {
98+
this.shouldShowWarning$ = this.itemExceeds();
99+
}
100+
}
101+
102+
/**
103+
* Checks if the export limit has been exceeded and updates the tooltip accordingly
104+
*/
105+
private itemExceeds(): Observable<boolean> {
106+
return this.configurationService.findByPropertyName('bulkedit.export.max.items').pipe(
107+
getFirstCompletedRemoteData(),
108+
map((response: RemoteData<ConfigurationProperty>) => {
109+
const limit = Number(response.payload?.values?.[0]) || 500;
110+
if (limit < this.total) {
111+
this.exportLimitExceededMsg = this.translateService.instant(this.exportLimitExceededKey, { limit: String(limit) });
112+
return true;
113+
} else {
114+
return false;
115+
}
116+
}),
117+
);
78118
}
79119

80120
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<h1>{{ (configuration ? configuration + '.search.results.head' : 'search.results.head') | translate }}</h1>
1616
}
1717
@if (showCsvExport) {
18-
<ds-search-export-csv [searchConfig]="searchConfig"></ds-search-export-csv>
18+
<ds-search-export-csv [searchConfig]="searchConfig" [total]="searchResults?.payload?.totalElements"></ds-search-export-csv>
1919
}
2020
</div>
2121
@if (searchResults && searchResults?.hasSucceeded && !searchResults?.isLoading && searchResults?.payload?.page.length > 0) {

src/assets/i18n/en.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7050,4 +7050,6 @@
70507050
"metadata-export-filtered-items.columns.warning": "CSV export automatically includes all relevant fields, so selections in this list are not taken into account.",
70517051

70527052
"embargo.listelement.badge": "Embargo until {{ date }}",
7053+
7054+
"metadata-export-search.submit.error.limit-exceeded": "Only the first {{limit}} items will be exported",
70537055
}

0 commit comments

Comments
 (0)