Skip to content

Commit 2b9d3a0

Browse files
authored
Merge pull request #4531 from atmire/w2p-119612_export-item-limit-8_x
[Port dspace-8_x] UI warning for export item limit
2 parents aabc0a1 + 2e26b4a commit 2b9d3a0

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
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
@@ -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
@@ -5,7 +5,9 @@ import {
55
import {
66
Component,
77
Input,
8+
OnChanges,
89
OnInit,
10+
SimpleChanges,
911
} from '@angular/core';
1012
import { Router } from '@angular/router';
1113
import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap';
@@ -21,10 +23,12 @@ import {
2123
switchMap,
2224
} from 'rxjs/operators';
2325

26+
import { ConfigurationDataService } from '../../../core/data/configuration-data.service';
2427
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
2528
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
2629
import { ScriptDataService } from '../../../core/data/processes/script-data.service';
2730
import { RemoteData } from '../../../core/data/remote-data';
31+
import { ConfigurationProperty } from '../../../core/shared/configuration-property.model';
2832
import { getFirstCompletedRemoteData } from '../../../core/shared/operators';
2933
import { getProcessDetailRoute } from '../../../process-page/process-page-routing.paths';
3034
import { Process } from '../../../process-page/processes/process.model';
@@ -46,13 +50,18 @@ import { SearchFilter } from '../models/search-filter.model';
4650
/**
4751
* Display a button to export the current search results as csv
4852
*/
49-
export class SearchExportCsvComponent implements OnInit {
53+
export class SearchExportCsvComponent implements OnInit, OnChanges {
5054

5155
/**
5256
* The current configuration of the search
5357
*/
5458
@Input() searchConfig: PaginatedSearchOptions;
5559

60+
/**
61+
* The total number of items in the search results which can be exported
62+
*/
63+
@Input() total: number;
64+
5665
/**
5766
* Observable used to determine whether the button should be shown
5867
*/
@@ -63,12 +72,18 @@ export class SearchExportCsvComponent implements OnInit {
6372
*/
6473
tooltipMsg = 'metadata-export-search.tooltip';
6574

75+
exportLimitExceededKey = 'metadata-export-search.submit.error.limit-exceeded';
76+
77+
exportLimitExceededMsg = '';
78+
79+
shouldShowWarning$: Observable<boolean>;
80+
6681
constructor(private scriptDataService: ScriptDataService,
6782
private authorizationDataService: AuthorizationDataService,
6883
private notificationsService: NotificationsService,
6984
private translateService: TranslateService,
7085
private router: Router,
71-
) {
86+
private configurationService: ConfigurationDataService) {
7287
}
7388

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

83123
/**

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
<div class="d-flex justify-content-between">
1414
<h1 *ngIf="!disableHeader">{{ (configuration ? configuration + '.search.results.head' : 'search.results.head') | translate }}</h1>
15-
<ds-search-export-csv *ngIf="showCsvExport" [searchConfig]="searchConfig"></ds-search-export-csv>
15+
<ds-search-export-csv *ngIf="showCsvExport" [total]="searchResults?.payload?.totalElements"
16+
[searchConfig]="searchConfig"></ds-search-export-csv>
1617
</div>
1718
<div *ngIf="searchResults && searchResults?.hasSucceeded && !searchResults?.isLoading && searchResults?.payload?.page.length > 0" @fadeIn>
1819
<ds-viewable-collection

src/assets/i18n/en.json5

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

68766876
"dynamic-form-array.sortable-list.label": "Sortable list",
6877+
6878+
"metadata-export-search.submit.error.limit-exceeded": "Only the first {{limit}} items will be exported",
68776879
}

0 commit comments

Comments
 (0)