From 93200d6b3c08434e7f6d0277795c074adda0bd46 Mon Sep 17 00:00:00 2001 From: Jens Vannerum Date: Mon, 20 Jan 2025 16:45:36 +0100 Subject: [PATCH 1/4] 119612: UI warning that only first part of configured items will be exported (cherry picked from commit b69b21af6c558f2fa4f2f694d3f2cb713ea625a6) --- .../search-export-csv.component.html | 17 ++++++++-- .../search-export-csv.component.ts | 34 ++++++++++++++++++- .../search-results.component.html | 3 +- src/assets/i18n/en.json5 | 2 ++ 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/app/shared/search/search-export-csv/search-export-csv.component.html b/src/app/shared/search/search-export-csv/search-export-csv.component.html index 7bf8704300..35ef89b728 100644 --- a/src/app/shared/search/search-export-csv/search-export-csv.component.html +++ b/src/app/shared/search/search-export-csv/search-export-csv.component.html @@ -1,7 +1,20 @@ + +
+

{{tooltipMsg | translate}}

+
+
+ + +
+

{{tooltipMsg | translate}}

+

{{exportLimitExceededMsg}}

+
+
+ \ No newline at end of file + diff --git a/src/app/shared/search/search-export-csv/search-export-csv.component.ts b/src/app/shared/search/search-export-csv/search-export-csv.component.ts index f8ec2012b1..8b6252ada7 100644 --- a/src/app/shared/search/search-export-csv/search-export-csv.component.ts +++ b/src/app/shared/search/search-export-csv/search-export-csv.component.ts @@ -21,10 +21,12 @@ import { switchMap, } from 'rxjs/operators'; +import { ConfigurationDataService } from '../../../core/data/configuration-data.service'; import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; import { FeatureID } from '../../../core/data/feature-authorization/feature-id'; import { ScriptDataService } from '../../../core/data/processes/script-data.service'; import { RemoteData } from '../../../core/data/remote-data'; +import { ConfigurationProperty } from '../../../core/shared/configuration-property.model'; import { getFirstCompletedRemoteData } from '../../../core/shared/operators'; import { getProcessDetailRoute } from '../../../process-page/process-page-routing.paths'; import { Process } from '../../../process-page/processes/process.model'; @@ -53,6 +55,11 @@ export class SearchExportCsvComponent implements OnInit { */ @Input() searchConfig: PaginatedSearchOptions; + /** + * The total number of items in the search results which can be exported + */ + @Input() total: number; + /** * Observable used to determine whether the button should be shown */ @@ -63,12 +70,18 @@ export class SearchExportCsvComponent implements OnInit { */ tooltipMsg = 'metadata-export-search.tooltip'; + exportLimitExceededKey = 'metadata-export-search.submit.error.limit-exceeded'; + + exportLimitExceededMsg = ''; + + shouldShowWarning$: Observable; + constructor(private scriptDataService: ScriptDataService, private authorizationDataService: AuthorizationDataService, private notificationsService: NotificationsService, private translateService: TranslateService, private router: Router, - ) { + private configurationService: ConfigurationDataService) { } ngOnInit(): void { @@ -78,6 +91,25 @@ export class SearchExportCsvComponent implements OnInit { map((canExecute: boolean) => canExecute), startWith(false), ); + this.shouldShowWarning$ = this.itemExceeds(); + } + + /** + * Checks if the export limit has been exceeded and updates the tooltip accordingly + */ + private itemExceeds(): Observable { + return this.configurationService.findByPropertyName('metadataexport.max.items').pipe( + getFirstCompletedRemoteData(), + map((response: RemoteData) => { + const limit = Number(response.payload?.values?.[0]); + if (response.hasSucceeded && limit < this.total) { + this.exportLimitExceededMsg = this.translateService.instant(this.exportLimitExceededKey, { limit: response.payload?.values?.[0] }); + return true; + } else { + return false; + } + }), + ); } /** diff --git a/src/app/shared/search/search-results/search-results.component.html b/src/app/shared/search/search-results/search-results.component.html index ecc4672b0a..91f8a010f1 100644 --- a/src/app/shared/search/search-results/search-results.component.html +++ b/src/app/shared/search/search-results/search-results.component.html @@ -12,7 +12,8 @@

{{ (configuration ? configuration + '.search.results.head' : 'search.results.head') | translate }}

- +
Date: Mon, 3 Feb 2025 10:11:28 +0100 Subject: [PATCH 2/4] 119612: Check if a warning should be shown on changes to the total elements of the search, default to 500 if no value for the configuration property was returned (cherry picked from commit e1b773c097289500de32ced24eeb1e8f2c0d25e9) --- .../search-export-csv.component.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/app/shared/search/search-export-csv/search-export-csv.component.ts b/src/app/shared/search/search-export-csv/search-export-csv.component.ts index 8b6252ada7..2727c6cce7 100644 --- a/src/app/shared/search/search-export-csv/search-export-csv.component.ts +++ b/src/app/shared/search/search-export-csv/search-export-csv.component.ts @@ -5,7 +5,9 @@ import { import { Component, Input, + OnChanges, OnInit, + SimpleChanges, } from '@angular/core'; import { Router } from '@angular/router'; import { NgbTooltipModule } from '@ng-bootstrap/ng-bootstrap'; @@ -48,7 +50,7 @@ import { SearchFilter } from '../models/search-filter.model'; /** * Display a button to export the current search results as csv */ -export class SearchExportCsvComponent implements OnInit { +export class SearchExportCsvComponent implements OnInit, OnChanges { /** * The current configuration of the search @@ -94,16 +96,22 @@ export class SearchExportCsvComponent implements OnInit { this.shouldShowWarning$ = this.itemExceeds(); } + ngOnChanges(changes: SimpleChanges): void { + if (changes.total) { + this.shouldShowWarning$ = this.itemExceeds(); + } + } + /** * Checks if the export limit has been exceeded and updates the tooltip accordingly */ private itemExceeds(): Observable { - return this.configurationService.findByPropertyName('metadataexport.max.items').pipe( + return this.configurationService.findByPropertyName('bulkedit.export.max.items').pipe( getFirstCompletedRemoteData(), map((response: RemoteData) => { - const limit = Number(response.payload?.values?.[0]); - if (response.hasSucceeded && limit < this.total) { - this.exportLimitExceededMsg = this.translateService.instant(this.exportLimitExceededKey, { limit: response.payload?.values?.[0] }); + const limit = Number(response.payload?.values?.[0]) || 500; + if (limit < this.total) { + this.exportLimitExceededMsg = this.translateService.instant(this.exportLimitExceededKey, { limit: String(limit) }); return true; } else { return false; From df8859d976a5fcc553afe719eb26c8e33a0acdd3 Mon Sep 17 00:00:00 2001 From: Jens Vannerum Date: Mon, 3 Feb 2025 11:20:18 +0100 Subject: [PATCH 3/4] 119612: aria-label to also include warning message if applicable (cherry picked from commit 8eaff7873761d8ef5c34af98780f28c16c374700) --- .../search/search-export-csv/search-export-csv.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/search/search-export-csv/search-export-csv.component.html b/src/app/shared/search/search-export-csv/search-export-csv.component.html index 35ef89b728..8c92ff8fbd 100644 --- a/src/app/shared/search/search-export-csv/search-export-csv.component.html +++ b/src/app/shared/search/search-export-csv/search-export-csv.component.html @@ -15,6 +15,6 @@ class="export-button btn btn-dark btn-sm" [ngbTooltip]="(shouldShowWarning$ | async) ? tipContentWarning : tipContent" (click)="export()" - [title]="tooltipMsg |translate" [attr.aria-label]="tooltipMsg |translate"> + [title]="tooltipMsg | translate" [attr.aria-label]="(shouldShowWarning$ | async) ? ((tooltipMsg | translate) + ' ' + exportLimitExceededMsg): (tooltipMsg | translate)"> From 2e26b4a50d22a3001f8d6ad65986f5cb74f28376 Mon Sep 17 00:00:00 2001 From: Jens Vannerum Date: Tue, 29 Apr 2025 12:20:25 +0200 Subject: [PATCH 4/4] 119612: fix spec test (cherry picked from commit 6232d4e9cf89b4fe42b7a975d6ac7d2050908fd4) --- .../search-export-csv/search-export-csv.component.spec.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/app/shared/search/search-export-csv/search-export-csv.component.spec.ts b/src/app/shared/search/search-export-csv/search-export-csv.component.spec.ts index 9abdd8d366..f067263712 100644 --- a/src/app/shared/search/search-export-csv/search-export-csv.component.spec.ts +++ b/src/app/shared/search/search-export-csv/search-export-csv.component.spec.ts @@ -9,6 +9,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { TranslateModule } from '@ngx-translate/core'; import { of as observableOf } from 'rxjs'; +import { ConfigurationDataService } from '../../../core/data/configuration-data.service'; import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; import { ScriptDataService } from '../../../core/data/processes/script-data.service'; import { getProcessDetailRoute } from '../../../process-page/process-page-routing.paths'; @@ -31,6 +32,7 @@ describe('SearchExportCsvComponent', () => { let authorizationDataService: AuthorizationDataService; let notificationsService; let router; + let configurationDataService: jasmine.SpyObj; const process = Object.assign(new Process(), { processId: 5, scriptName: 'metadata-export-search' }); @@ -45,6 +47,10 @@ describe('SearchExportCsvComponent', () => { ], }); + configurationDataService = jasmine.createSpyObj('ConfigurationDataService', { + findByPropertyName: observableOf({ payload: { value: '500' } }), + }); + function initBeforeEachAsync() { scriptDataService = jasmine.createSpyObj('scriptDataService', { scriptWithNameExistsAndCanExecute: observableOf(true), @@ -64,6 +70,7 @@ describe('SearchExportCsvComponent', () => { { provide: AuthorizationDataService, useValue: authorizationDataService }, { provide: NotificationsService, useValue: notificationsService }, { provide: Router, useValue: router }, + { provide: ConfigurationDataService, useValue: configurationDataService }, ], }).compileComponents(); }