Skip to content

Commit 268d2e5

Browse files
108555: Refactored CollectionSelectComponent to not call canSelect every time changes are detected
1 parent 59197cf commit 268d2e5

2 files changed

Lines changed: 27 additions & 16 deletions

File tree

src/app/shared/object-select/collection-select/collection-select.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
</tr>
1616
</thead>
1717
<tbody>
18-
<tr *ngFor="let collection of collectionsRD?.payload?.page">
19-
<td><input class="collection-checkbox" [ngModel]="getSelected(collection.id) | async" (change)="switch(collection.id)" type="checkbox" name="{{collection.id}}"></td>
20-
<td><a [routerLink]="['/collections', collection.id]">{{ dsoNameService.getName(collection) }}</a></td>
18+
<tr *ngFor="let selectCollection of selectCollections$ | async">
19+
<td><input [disabled]="(selectCollection.canSelect$ | async) === false" class="collection-checkbox" [ngModel]="selectCollection.selected$ | async" (change)="switch(selectCollection.dso.id)" type="checkbox" name="{{selectCollection.dso.id}}"></td>
20+
<td><a [routerLink]="selectCollection.route">{{ dsoNameService.getName(selectCollection.dso) }}</a></td>
2121
</tr>
2222
</tbody>
2323
</table>
Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnInit } from '@angular/core';
22
import { Collection } from '../../../core/shared/collection.model';
33
import { ObjectSelectComponent } from '../object-select/object-select.component';
4-
import { isNotEmpty } from '../../empty.util';
5-
import { ObjectSelectService } from '../object-select.service';
6-
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
7-
import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
4+
import { isNotEmpty, hasValueOperator } from '../../empty.util';
5+
import { Observable } from 'rxjs';
6+
import { DSpaceObjectSelect } from '../object-select.model';
7+
import { getAllSucceededRemoteDataPayload } from '../../../core/shared/operators';
8+
import { map } from 'rxjs/operators';
9+
import { PaginatedList } from '../../../core/data/paginated-list.model';
10+
import { getCollectionPageRoute } from '../../../collection-page/collection-page-routing-paths';
811

912
@Component({
1013
selector: 'ds-collection-select',
@@ -15,21 +18,29 @@ import { DSONameService } from '../../../core/breadcrumbs/dso-name.service';
1518
/**
1619
* A component used to select collections from a specific list and returning the UUIDs of the selected collections
1720
*/
18-
export class CollectionSelectComponent extends ObjectSelectComponent<Collection> {
21+
export class CollectionSelectComponent extends ObjectSelectComponent<Collection> implements OnInit {
1922

20-
constructor(
21-
protected objectSelectService: ObjectSelectService,
22-
protected authorizationService: AuthorizationDataService,
23-
public dsoNameService: DSONameService,
24-
) {
25-
super(objectSelectService, authorizationService);
26-
}
23+
/**
24+
* Collection of all the data that is used to display the {@link Collection} in the HTML.
25+
* By collecting this data here it doesn't need to be recalculated on evey change detection.
26+
*/
27+
selectCollections$: Observable<DSpaceObjectSelect<Collection>[]>;
2728

2829
ngOnInit(): void {
2930
super.ngOnInit();
3031
if (!isNotEmpty(this.confirmButton)) {
3132
this.confirmButton = 'collection.select.confirm';
3233
}
34+
this.selectCollections$ = this.dsoRD$.pipe(
35+
hasValueOperator(),
36+
getAllSucceededRemoteDataPayload(),
37+
map((collections: PaginatedList<Collection>) => collections.page.map((collection: Collection) => Object.assign(new DSpaceObjectSelect<Collection>(), {
38+
dso: collection,
39+
canSelect$: this.canSelect(collection),
40+
selected$: this.getSelected(collection.id),
41+
route: getCollectionPageRoute(collection.id),
42+
} as DSpaceObjectSelect<Collection>))),
43+
);
3344
}
3445

3546
}

0 commit comments

Comments
 (0)