From 268d2e54fcb0c35216669e52022564a9c5a651d1 Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Thu, 18 Apr 2024 19:44:17 +0200 Subject: [PATCH] 108555: Refactored CollectionSelectComponent to not call canSelect every time changes are detected --- .../collection-select.component.html | 6 +-- .../collection-select.component.ts | 37 ++++++++++++------- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/app/shared/object-select/collection-select/collection-select.component.html b/src/app/shared/object-select/collection-select/collection-select.component.html index 953f540d59..8142c35b53 100644 --- a/src/app/shared/object-select/collection-select/collection-select.component.html +++ b/src/app/shared/object-select/collection-select/collection-select.component.html @@ -15,9 +15,9 @@ - - - {{ dsoNameService.getName(collection) }} + + + {{ dsoNameService.getName(selectCollection.dso) }} diff --git a/src/app/shared/object-select/collection-select/collection-select.component.ts b/src/app/shared/object-select/collection-select/collection-select.component.ts index 2d36f80274..e9edf19304 100644 --- a/src/app/shared/object-select/collection-select/collection-select.component.ts +++ b/src/app/shared/object-select/collection-select/collection-select.component.ts @@ -1,10 +1,13 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; import { Collection } from '../../../core/shared/collection.model'; import { ObjectSelectComponent } from '../object-select/object-select.component'; -import { isNotEmpty } from '../../empty.util'; -import { ObjectSelectService } from '../object-select.service'; -import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service'; -import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; +import { isNotEmpty, hasValueOperator } from '../../empty.util'; +import { Observable } from 'rxjs'; +import { DSpaceObjectSelect } from '../object-select.model'; +import { getAllSucceededRemoteDataPayload } from '../../../core/shared/operators'; +import { map } from 'rxjs/operators'; +import { PaginatedList } from '../../../core/data/paginated-list.model'; +import { getCollectionPageRoute } from '../../../collection-page/collection-page-routing-paths'; @Component({ selector: 'ds-collection-select', @@ -15,21 +18,29 @@ import { DSONameService } from '../../../core/breadcrumbs/dso-name.service'; /** * A component used to select collections from a specific list and returning the UUIDs of the selected collections */ -export class CollectionSelectComponent extends ObjectSelectComponent { +export class CollectionSelectComponent extends ObjectSelectComponent implements OnInit { - constructor( - protected objectSelectService: ObjectSelectService, - protected authorizationService: AuthorizationDataService, - public dsoNameService: DSONameService, - ) { - super(objectSelectService, authorizationService); - } + /** + * Collection of all the data that is used to display the {@link Collection} in the HTML. + * By collecting this data here it doesn't need to be recalculated on evey change detection. + */ + selectCollections$: Observable[]>; ngOnInit(): void { super.ngOnInit(); if (!isNotEmpty(this.confirmButton)) { this.confirmButton = 'collection.select.confirm'; } + this.selectCollections$ = this.dsoRD$.pipe( + hasValueOperator(), + getAllSucceededRemoteDataPayload(), + map((collections: PaginatedList) => collections.page.map((collection: Collection) => Object.assign(new DSpaceObjectSelect(), { + dso: collection, + canSelect$: this.canSelect(collection), + selected$: this.getSelected(collection.id), + route: getCollectionPageRoute(collection.id), + } as DSpaceObjectSelect))), + ); } }