From bbdef0dddb8920b94f1c386fb9e019a525b3b872 Mon Sep 17 00:00:00 2001 From: nsemets Date: Wed, 15 Apr 2026 12:34:42 +0300 Subject: [PATCH] fix(preprint-recent-activity): fixed pagination --- ...int-recent-activity-list.component.spec.ts | 31 +++++++++++++++++-- ...preprint-recent-activity-list.component.ts | 13 ++++++-- .../mappers/preprint-moderation.mapper.ts | 4 +-- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/app/features/moderation/components/preprint-recent-activity-list/preprint-recent-activity-list.component.spec.ts b/src/app/features/moderation/components/preprint-recent-activity-list/preprint-recent-activity-list.component.spec.ts index e335bf57d..455bd275d 100644 --- a/src/app/features/moderation/components/preprint-recent-activity-list/preprint-recent-activity-list.component.spec.ts +++ b/src/app/features/moderation/components/preprint-recent-activity-list/preprint-recent-activity-list.component.spec.ts @@ -57,18 +57,45 @@ describe('PreprintRecentActivityListComponent', () => { component.onPageChange(mockEvent); - expect(component.pageChanged.emit).toHaveBeenCalledWith(2); + expect(component.first()).toBe(10); + expect(component.rows()).toBe(10); + expect(component.pageChanged.emit).toHaveBeenCalledWith(3); }); - it('should emit page 1 when page is undefined', () => { + it('should not emit page change when page is undefined', () => { vi.spyOn(component.pageChanged, 'emit'); const mockEvent = { page: undefined, first: 0, rows: 10 }; component.onPageChange(mockEvent); + expect(component.first()).toBe(0); + expect(component.rows()).toBe(10); + expect(component.pageChanged.emit).not.toHaveBeenCalled(); + }); + + it('should fallback first to 0 when event.first is undefined', () => { + vi.spyOn(component.pageChanged, 'emit'); + const mockEvent = { page: 0, first: undefined, rows: 10 }; + + component.onPageChange(mockEvent); + + expect(component.first()).toBe(0); + expect(component.rows()).toBe(10); expect(component.pageChanged.emit).toHaveBeenCalledWith(1); }); + it('should keep current rows when event.rows is undefined', () => { + vi.spyOn(component.pageChanged, 'emit'); + component.rows.set(25); + const mockEvent = { page: 1, first: 25, rows: undefined }; + + component.onPageChange(mockEvent); + + expect(component.first()).toBe(25); + expect(component.rows()).toBe(25); + expect(component.pageChanged.emit).toHaveBeenCalledWith(2); + }); + it('should accept custom input values', () => { const customReviews = [ ...mockReviews, diff --git a/src/app/features/moderation/components/preprint-recent-activity-list/preprint-recent-activity-list.component.ts b/src/app/features/moderation/components/preprint-recent-activity-list/preprint-recent-activity-list.component.ts index abd51ec05..14bb3f030 100644 --- a/src/app/features/moderation/components/preprint-recent-activity-list/preprint-recent-activity-list.component.ts +++ b/src/app/features/moderation/components/preprint-recent-activity-list/preprint-recent-activity-list.component.ts @@ -2,7 +2,6 @@ import { TranslatePipe } from '@ngx-translate/core'; import { PaginatorState } from 'primeng/paginator'; import { Skeleton } from 'primeng/skeleton'; -import { TableModule } from 'primeng/table'; import { DatePipe } from '@angular/common'; import { ChangeDetectionStrategy, Component, input, output, signal } from '@angular/core'; @@ -15,7 +14,7 @@ import { PreprintReviewActionModel } from '../../models'; @Component({ selector: 'osf-preprint-recent-activity-list', - imports: [TableModule, DatePipe, TranslatePipe, IconComponent, Skeleton, CustomPaginatorComponent], + imports: [Skeleton, DatePipe, TranslatePipe, IconComponent, CustomPaginatorComponent], templateUrl: './preprint-recent-activity-list.component.html', styleUrl: './preprint-recent-activity-list.component.scss', changeDetection: ChangeDetectionStrategy.OnPush, @@ -29,10 +28,18 @@ export class PreprintRecentActivityListComponent { first = signal(0); rows = signal(10); + readonly reviewStatusIcon = ReviewStatusIcon; readonly preprintReviewStatus = PreprintReviewStatus; onPageChange(event: PaginatorState) { - this.pageChanged.emit(event.page ?? 1); + this.first.set(event.first ?? 0); + this.rows.set(event.rows ?? this.rows()); + + if (event.page === undefined) { + return; + } + + this.pageChanged.emit(event.page + 1); } } diff --git a/src/app/features/moderation/mappers/preprint-moderation.mapper.ts b/src/app/features/moderation/mappers/preprint-moderation.mapper.ts index 5fb0cc752..621d929c1 100644 --- a/src/app/features/moderation/mappers/preprint-moderation.mapper.ts +++ b/src/app/features/moderation/mappers/preprint-moderation.mapper.ts @@ -28,8 +28,8 @@ export class PreprintModerationMapper { name: creator?.fullName || '', }, preprint: { - id: response.embeds.target.data.id, - name: response.embeds.target.data.attributes.title, + id: response.embeds.target?.data?.id || '', + name: response.embeds.target?.data?.attributes?.title || '', }, provider: { id: response.embeds.provider.data.id,