Skip to content

Commit c659061

Browse files
authored
Merge pull request DSpace#3253 from alexandrevryghem/w2p-117287_fix-item-version-performance-issues_contribute-main
Fixed Edit Item's Version History crashing
2 parents 843056d + 04bbaf9 commit c659061

2 files changed

Lines changed: 68 additions & 79 deletions

File tree

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<div *ngVar="(versionsRD$ | async)?.payload as versions">
2-
<div *ngVar="(versionRD$ | async)?.payload as itemVersion">
3-
<div class="mb-2" *ngIf="versions?.page?.length > 0 || displayWhenEmpty">
1+
<div *ngIf="(versionsDTO$ | async) as versionsDTO; else noItemVersion">
2+
<div *ngIf="(versionRD$ | async)?.payload as itemVersion">
3+
<div class="mb-2" *ngIf="versionsDTO.versionDTOs.length > 0 || displayWhenEmpty">
44
<h2 *ngIf="displayTitle" class="h4">{{"item.version.history.head" | translate}}</h2>
5-
<ds-alert [type]="AlertTypeEnum.Info" *ngIf="itemVersion">
5+
<ds-alert [type]="AlertTypeEnum.Info">
66
{{ "item.version.history.selected.alert" | translate : {version: itemVersion.version} }}
77
</ds-alert>
8-
<ds-pagination *ngIf="versions?.page?.length > 0"
8+
<ds-pagination *ngIf="versionsDTO.versionDTOs.length > 0"
99
(paginationChange)="onPageChange()"
1010
[hideGear]="true"
1111
[hidePagerWhenSinglePage]="true"
1212
[paginationOptions]="options"
13-
[collectionSize]="versions?.totalElements"
13+
[collectionSize]="versionsDTO.totalElements"
1414
[retainScrollPosition]="true">
1515
<table class="table table-striped table-bordered align-middle my-2">
1616
<thead>
@@ -22,70 +22,71 @@ <h2 *ngIf="displayTitle" class="h4">{{"item.version.history.head" | translate}}<
2222
</tr>
2323
</thead>
2424
<tbody>
25-
<tr *ngFor="let version of versions?.page" [id]="'version-row-' + version.id">
25+
<tr *ngFor="let versionDTO of versionsDTO.versionDTOs" [id]="'version-row-' + versionDTO.version.id">
2626
<td class="version-row-element-version">
2727
<ds-item-versions-row-element-version [hasDraftVersion]="hasDraftVersion$ | async"
28-
[version]="version"
28+
[version]="versionDTO.version"
2929
[item]="item" [displayActions]="displayActions"
3030
[itemVersion]="itemVersion"
3131
[versionBeingEditedNumber]="versionBeingEditedNumber"
3232
(versionsHistoryChange)="getAllVersions($event)"
3333
></ds-item-versions-row-element-version>
3434
</td>
3535
<td class="version-row-element-editor" *ngIf="(showSubmitter$ | async)">
36-
{{version?.submitterName}}
36+
{{versionDTO.version.submitterName}}
3737
</td>
3838
<td class="version-row-element-date">
39-
{{version?.created | date : 'yyyy-MM-dd HH:mm:ss'}}
39+
{{versionDTO.version.created | date : 'yyyy-MM-dd HH:mm:ss'}}
4040
</td>
4141
<td class="version-row-element-summary">
4242
<div class="float-left">
43-
<ng-container *ngIf="isThisBeingEdited(version); then editSummary else showSummary"></ng-container>
44-
<ng-template #showSummary>{{version?.summary}}</ng-template>
43+
<ng-container *ngIf="isThisBeingEdited(versionDTO.version); then editSummary else showSummary"></ng-container>
44+
<ng-template #showSummary>{{versionDTO.version.summary}}</ng-template>
4545
<ng-template #editSummary>
4646
<input [attr.aria-label]="'item.version.history.table.action.editSummary' | translate"
4747
[(ngModel)]="versionBeingEditedSummary" (keyup.enter)="onSummarySubmit()"
4848
class="form-control" type="text"/>
4949
</ng-template>
5050
</div>
5151

52-
<div class="float-right btn-group edit-field space-children-mr" *ngIf="displayActions">
53-
<!--DISCARD EDIT -->
54-
<ng-container *ngIf="(canEditVersion$(version) | async) && isThisBeingEdited(version)">
55-
<button class="btn btn-sm"
56-
[ngClass]="isThisBeingEdited(version) ? 'btn-outline-warning' : 'btn-outline-primary'"
52+
<div class="float-right btn-group edit-field space-children-mr" *ngIf="displayActions && versionDTO.canEditVersion | async">
53+
<ng-container *ngIf="isThisBeingEdited(versionDTO.version); else notThisBeingEdited">
54+
<!--DISCARD EDIT-->
55+
<button class="btn btn-sm btn-outline-warning"
5756
(click)="disableVersionEditing()"
5857
title="{{'item.version.history.table.action.discardSummary' | translate}}">
5958
<i class="fas fa-undo-alt fa-fw"></i>
6059
</button>
61-
</ng-container>
62-
<!--EDIT / SAVE-->
63-
<ng-container *ngIf="canEditVersion$(version) | async">
64-
<button class="btn btn-outline-primary btn-sm version-row-element-edit"
65-
*ngIf="!isThisBeingEdited(version)"
66-
[disabled]="isAnyBeingEdited()"
67-
(click)="enableVersionEditing(version)"
68-
title="{{'item.version.history.table.action.editSummary' | translate}}">
69-
<i class="fas fa-edit fa-fw"></i>
70-
</button>
60+
<!--SAVE-->
7161
<button class="btn btn-outline-success btn-sm"
72-
*ngIf="isThisBeingEdited(version)"
7362
(click)="onSummarySubmit()"
7463
title="{{'item.version.history.table.action.saveSummary' | translate}}">
7564
<i class="fas fa-check fa-fw"></i>
7665
</button>
7766
</ng-container>
67+
<ng-template #notThisBeingEdited>
68+
<!--EDIT-->
69+
<button class="btn btn-outline-primary btn-sm version-row-element-edit"
70+
[disabled]="isAnyBeingEdited()"
71+
(click)="enableVersionEditing(versionDTO.version)"
72+
title="{{'item.version.history.table.action.editSummary' | translate}}">
73+
<i class="fas fa-edit fa-fw"></i>
74+
</button>
75+
</ng-template>
7876
</div>
79-
80-
8177
</td>
8278
</tr>
8379
</tbody>
8480
</table>
8581
<div>*&nbsp;{{"item.version.history.selected" | translate}}</div>
8682
</ds-pagination>
87-
<ds-alert *ngIf="!itemVersion || versions?.page?.length === 0" [content]="'item.version.history.empty'"
88-
[type]="AlertTypeEnum.Info"></ds-alert>
8983
</div>
9084
</div>
9185
</div>
86+
87+
<ng-template #noItemVersion>
88+
<ds-alert *ngIf="displayWhenEmpty"
89+
[content]="'item.version.history.empty'"
90+
[type]="AlertTypeEnum.Info">
91+
</ds-alert>
92+
</ng-template>

src/app/item-page/versions/item-versions.component.ts

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import {
1212
OnInit,
1313
} from '@angular/core';
1414
import { FormsModule } from '@angular/forms';
15-
import { RouterLink } from '@angular/router';
1615
import {
1716
TranslateModule,
1817
TranslateService,
1918
} from '@ngx-translate/core';
2019
import {
21-
BehaviorSubject,
2220
combineLatest,
2321
Observable,
2422
Subscription,
@@ -41,7 +39,6 @@ import { PaginationService } from '../../core/pagination/pagination.service';
4139
import { Item } from '../../core/shared/item.model';
4240
import {
4341
getAllSucceededRemoteData,
44-
getAllSucceededRemoteDataPayload,
4542
getFirstCompletedRemoteData,
4643
getFirstSucceededRemoteData,
4744
getFirstSucceededRemoteDataPayload,
@@ -60,16 +57,35 @@ import { PaginationComponent } from '../../shared/pagination/pagination.componen
6057
import { PaginationComponentOptions } from '../../shared/pagination/pagination-component-options.model';
6158
import { PaginatedSearchOptions } from '../../shared/search/models/paginated-search-options.model';
6259
import { followLink } from '../../shared/utils/follow-link-config.model';
63-
import { VarDirective } from '../../shared/utils/var.directive';
64-
import { getItemPageRoute } from '../item-page-routing-paths';
6560
import { ItemVersionsRowElementVersionComponent } from './item-versions-row-element-version/item-versions-row-element-version.component';
6661

62+
interface VersionsDTO {
63+
totalElements: number;
64+
versionDTOs: VersionDTO[];
65+
}
66+
67+
interface VersionDTO {
68+
version: Version;
69+
canEditVersion: Observable<boolean>;
70+
}
71+
6772
@Component({
6873
selector: 'ds-item-versions',
6974
templateUrl: './item-versions.component.html',
7075
styleUrls: ['./item-versions.component.scss'],
7176
standalone: true,
72-
imports: [VarDirective, NgIf, AlertComponent, PaginationComponent, NgFor, RouterLink, NgClass, FormsModule, AsyncPipe, DatePipe, TranslateModule, ItemVersionsRowElementVersionComponent],
77+
imports: [
78+
AlertComponent,
79+
AsyncPipe,
80+
DatePipe,
81+
FormsModule,
82+
ItemVersionsRowElementVersionComponent,
83+
NgClass,
84+
NgFor,
85+
NgIf,
86+
PaginationComponent,
87+
TranslateModule,
88+
],
7389
})
7490

7591
/**
@@ -128,13 +144,7 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
128144
/**
129145
* The version history's list of versions
130146
*/
131-
versionsRD$: BehaviorSubject<RemoteData<PaginatedList<Version>>> = new BehaviorSubject<RemoteData<PaginatedList<Version>>>(null);
132-
133-
/**
134-
* Verify if the list of versions has at least one e-person to display
135-
* Used to hide the "Editor" column when no e-persons are present to display
136-
*/
137-
hasEpersons$: Observable<boolean>;
147+
versionsDTO$: Observable<VersionsDTO>;
138148

139149
/**
140150
* Verify if there is an inprogress submission in the version history
@@ -162,15 +172,6 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
162172
pageSize: this.pageSize,
163173
});
164174

165-
/**
166-
* The routes to the versions their item pages
167-
* Key: Item ID
168-
* Value: Route to item page
169-
*/
170-
itemPageRoutes$: Observable<{
171-
[itemId: string]: string
172-
}>;
173-
174175
/**
175176
* The number of the version whose summary is currently being edited
176177
*/
@@ -186,9 +187,6 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
186187
*/
187188
versionBeingEditedSummary: string;
188189

189-
canCreateVersion$: Observable<boolean>;
190-
createVersionTitle$: Observable<string>;
191-
192190
constructor(private versionHistoryService: VersionHistoryDataService,
193191
private versionService: VersionDataService,
194192
private paginationService: PaginationService,
@@ -257,8 +255,7 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
257255
this.notificationsService.warning(null, this.translateService.get(failureMessageKey, { 'version': this.versionBeingEditedNumber }));
258256
}
259257
this.disableVersionEditing();
260-
},
261-
);
258+
});
262259
}
263260

264261
/**
@@ -305,16 +302,22 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
305302
*/
306303
getAllVersions(versionHistory$: Observable<VersionHistory>): void {
307304
const currentPagination = this.paginationService.getCurrentPagination(this.options.id, this.options);
308-
combineLatest([versionHistory$, currentPagination]).pipe(
305+
this.versionsDTO$ = combineLatest([versionHistory$, currentPagination]).pipe(
309306
switchMap(([versionHistory, options]: [VersionHistory, PaginationComponentOptions]) => {
310307
return this.versionHistoryService.getVersions(versionHistory.id,
311308
new PaginatedSearchOptions({ pagination: Object.assign({}, options, { currentPage: options.currentPage }) }),
312309
false, true, followLink('item'), followLink('eperson'));
313310
}),
314311
getFirstCompletedRemoteData(),
315-
).subscribe((res: RemoteData<PaginatedList<Version>>) => {
316-
this.versionsRD$.next(res);
317-
});
312+
getRemoteDataPayload(),
313+
map((versions: PaginatedList<Version>) => ({
314+
totalElements: versions.totalElements,
315+
versionDTOs: (versions?.page ?? []).map((version: Version) => ({
316+
version: version,
317+
canEditVersion: this.canEditVersion$(version),
318+
})),
319+
})),
320+
);
318321
}
319322

320323
/**
@@ -348,22 +351,6 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
348351
);
349352

350353
this.getAllVersions(this.versionHistory$);
351-
this.hasEpersons$ = this.versionsRD$.pipe(
352-
getAllSucceededRemoteData(),
353-
getRemoteDataPayload(),
354-
hasValueOperator(),
355-
map((versions: PaginatedList<Version>) => versions.page.filter((version: Version) => version.eperson !== undefined).length > 0),
356-
startWith(false),
357-
);
358-
this.itemPageRoutes$ = this.versionsRD$.pipe(
359-
getAllSucceededRemoteDataPayload(),
360-
switchMap((versions) => combineLatest(versions.page.map((version) => version.item.pipe(getAllSucceededRemoteDataPayload())))),
361-
map((versions) => {
362-
const itemPageRoutes = {};
363-
versions.forEach((item) => itemPageRoutes[item.uuid] = getItemPageRoute(item));
364-
return itemPageRoutes;
365-
}),
366-
);
367354
}
368355
}
369356

@@ -380,3 +367,4 @@ export class ItemVersionsComponent implements OnDestroy, OnInit {
380367
}
381368

382369
}
370+

0 commit comments

Comments
 (0)