-
Notifications
You must be signed in to change notification settings - Fork 16
Feat(ENG-8625): add Recent Activity to registrations #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brianjgeiger
merged 4 commits into
CenterForOpenScience:main
from
sh-andriy:feat/8625-recent-activity-registrations
Sep 11, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
948dc34
feat(registration-recent-activity): add Recent Activity to registrations
sh-andriy e9f5c8d
feat(registration-recent-activity): code fixes regarding comments
sh-andriy 03215af
feat(registration-recent-activity): second round of code fixes regard…
sh-andriy 5ad3caa
feat(registration-recent-activity): run lint fix
sh-andriy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { InjectionToken } from '@angular/core'; | ||
|
||
import { AppEnvironment } from '@shared/models/environment.model'; | ||
|
||
import { environment } from 'src/environments/environment'; | ||
|
||
export const ENVIRONMENT = new InjectionToken<typeof environment>('App Environment', { | ||
export const ENVIRONMENT = new InjectionToken<AppEnvironment>('App Environment', { | ||
providedIn: 'root', | ||
factory: () => environment, | ||
factory: () => environment as AppEnvironment, | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 81 additions & 3 deletions
84
...pp/features/project/overview/components/recent-activity/recent-activity.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,100 @@ | ||
import { provideStore, Store } from '@ngxs/store'; | ||
|
||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
import { of } from 'rxjs'; | ||
|
||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; | ||
import { provideHttpClientTesting } from '@angular/common/http/testing'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
|
||
import { ActivityLogDisplayService } from '@shared/services'; | ||
import { GetActivityLogs } from '@shared/stores/activity-logs'; | ||
import { ActivityLogsState } from '@shared/stores/activity-logs/activity-logs.state'; | ||
|
||
import { RecentActivityComponent } from './recent-activity.component'; | ||
|
||
describe('RecentActivityComponent', () => { | ||
let component: RecentActivityComponent; | ||
let fixture: ComponentFixture<RecentActivityComponent>; | ||
let store: Store; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [RecentActivityComponent], | ||
providers: [ | ||
provideStore([ActivityLogsState]), | ||
|
||
provideHttpClient(withInterceptorsFromDi()), | ||
provideHttpClientTesting(), | ||
|
||
{ | ||
provide: TranslateService, | ||
useValue: { | ||
instant: (k: string) => k, | ||
get: () => of(''), | ||
stream: () => of(''), | ||
onLangChange: of({}), | ||
onDefaultLangChange: of({}), | ||
onTranslationChange: of({}), | ||
}, | ||
}, | ||
|
||
{ provide: ActivatedRoute, useValue: { snapshot: { params: { id: 'proj123' } }, parent: null } }, | ||
{ provide: ActivityLogDisplayService, useValue: { getActivityDisplay: jest.fn().mockReturnValue('FMT') } }, | ||
], | ||
}).compileComponents(); | ||
|
||
store = TestBed.inject(Store); | ||
store.reset({ | ||
activityLogs: { | ||
activityLogs: { data: [], isLoading: false, error: null, totalCount: 0 }, | ||
}, | ||
} as any); | ||
|
||
fixture = TestBed.createComponent(RecentActivityComponent); | ||
component = fixture.componentInstance; | ||
fixture.componentRef.setInput('pageSize', 10); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
expect(fixture.componentInstance).toBeTruthy(); | ||
}); | ||
|
||
it('formats activity logs using ActivityLogDisplayService', () => { | ||
store.reset({ | ||
activityLogs: { | ||
activityLogs: { | ||
data: [{ id: 'log1', date: '2024-01-01T00:00:00Z' }], | ||
isLoading: false, | ||
error: null, | ||
totalCount: 1, | ||
}, | ||
}, | ||
} as any); | ||
|
||
fixture.detectChanges(); | ||
|
||
const formatted = fixture.componentInstance.formattedActivityLogs(); | ||
expect(formatted.length).toBe(1); | ||
expect(formatted[0].formattedActivity).toBe('FMT'); | ||
}); | ||
|
||
it('dispatches GetActivityLogs with numeric page and pageSize on page change', () => { | ||
const dispatchSpy = jest.spyOn(store, 'dispatch'); | ||
fixture.componentInstance.onPageChange({ page: 2 } as any); | ||
|
||
expect(dispatchSpy).toHaveBeenCalled(); | ||
const action = dispatchSpy.mock.calls.at(-1)?.[0] as GetActivityLogs; | ||
|
||
expect(action).toBeInstanceOf(GetActivityLogs); | ||
expect(action.projectId).toBe('proj123'); | ||
expect(action.page).toBe(3); | ||
expect(action.pageSize).toBe(10); | ||
}); | ||
|
||
it('computes firstIndex correctly', () => { | ||
fixture.componentInstance['currentPage'].set(3); | ||
expect(fixture.componentInstance['firstIndex']()).toBe(20); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 50 additions & 5 deletions
55
src/app/features/project/overview/project-overview.component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,71 @@ | ||
import { MockComponent } from 'ng-mocks'; | ||
import { provideStore, Store } from '@ngxs/store'; | ||
|
||
import { TranslateService } from '@ngx-translate/core'; | ||
|
||
import { DialogService } from 'primeng/dynamicdialog'; | ||
|
||
import { of } from 'rxjs'; | ||
|
||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; | ||
import { provideHttpClientTesting } from '@angular/common/http/testing'; | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
import { SubHeaderComponent } from '@osf/shared/components'; | ||
import { DataciteService, ToastService } from '@osf/shared/services'; | ||
import { GetActivityLogs } from '@shared/stores/activity-logs'; | ||
|
||
import { ProjectOverviewComponent } from './project-overview.component'; | ||
|
||
describe('ProjectOverviewComponent', () => { | ||
let component: ProjectOverviewComponent; | ||
let fixture: ComponentFixture<ProjectOverviewComponent>; | ||
let component: ProjectOverviewComponent; | ||
let store: Store; | ||
|
||
beforeEach(async () => { | ||
TestBed.overrideComponent(ProjectOverviewComponent, { set: { template: '' } }); | ||
|
||
await TestBed.configureTestingModule({ | ||
imports: [ProjectOverviewComponent, MockComponent(SubHeaderComponent)], | ||
imports: [ProjectOverviewComponent, RouterTestingModule], | ||
providers: [ | ||
provideStore([]), | ||
|
||
{ provide: ActivatedRoute, useValue: { snapshot: { params: { id: 'proj123' } }, parent: null } }, | ||
|
||
provideHttpClient(withInterceptorsFromDi()), | ||
provideHttpClientTesting(), | ||
|
||
{ provide: DataciteService, useValue: {} }, | ||
{ provide: DialogService, useValue: { open: () => ({ onClose: of(null) }) } }, | ||
{ provide: TranslateService, useValue: { instant: (k: string) => k } }, | ||
{ provide: ToastService, useValue: { showSuccess: jest.fn() } }, | ||
], | ||
}).compileComponents(); | ||
|
||
store = TestBed.inject(Store); | ||
fixture = TestBed.createComponent(ProjectOverviewComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('dispatches GetActivityLogs with numeric page and pageSize on init', () => { | ||
const dispatchSpy = jest.spyOn(store, 'dispatch'); | ||
|
||
jest.spyOn(component as any, 'setupDataciteViewTrackerEffect').mockReturnValue(of(null)); | ||
|
||
component.ngOnInit(); | ||
|
||
const actions = dispatchSpy.mock.calls.map((c) => c[0]); | ||
const activityAction = actions.find((a) => a instanceof GetActivityLogs) as GetActivityLogs; | ||
|
||
expect(activityAction).toBeDefined(); | ||
expect(activityAction.projectId).toBe('proj123'); | ||
expect(activityAction.page).toBe(1); | ||
expect(activityAction.pageSize).toBe(5); | ||
expect(typeof activityAction.page).toBe('number'); | ||
expect(typeof activityAction.pageSize).toBe('number'); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/app/features/registry/pages/recent-activity/registration-recent-activity.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<div | ||
class="p-3 flex flex-column gap-3 border-1 surface-border border-round-xl text-color" | ||
role="region" | ||
aria-labelledby="recent-activity-title" | ||
> | ||
<h2 id="recent-activity-title" class="mb-2" data-test="recent-activity-title"> | ||
{{ 'project.overview.recentActivity.title' | translate }} | ||
</h2> | ||
|
||
@if (!isLoading()) { | ||
<div role="list" data-test="recent-activity-list"> | ||
@for (activityLog of formattedActivityLogs(); track activityLog.id) { | ||
<div | ||
class="flex justify-content-between gap-3 pb-2 align-items-center border-bottom-1 surface-border" | ||
role="listitem" | ||
data-test="recent-activity-item" | ||
> | ||
<div [innerHTML]="activityLog.formattedActivity" data-test="recent-activity-item-content"></div> | ||
|
||
<p class="hidden sm:block text-right white-space-nowrap flex-shrink-0" data-test="recent-activity-item-date"> | ||
{{ activityLog.date | date: 'MMM d, y hh:mm a' }} | ||
</p> | ||
</div> | ||
} @empty { | ||
<div class="text-center text-muted-color" role="status" aria-live="polite" data-test="recent-activity-empty"> | ||
{{ 'project.overview.recentActivity.noActivity' | translate }} | ||
</div> | ||
} | ||
</div> | ||
|
||
@if (totalCount() > pageSize) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this an Exoft pattern? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how other folks do this but did it to reduce visual noise and tab stops. |
||
<osf-custom-paginator | ||
data-test="recent-activity-paginator" | ||
[showFirstLastIcon]="true" | ||
[totalCount]="totalCount()" | ||
[rows]="pageSize" | ||
[first]="firstIndex()" | ||
(pageChanged)="onPageChange($event)" | ||
/> | ||
} | ||
} @else { | ||
<div class="flex flex-column gap-2" data-test="recent-activity-skeleton"> | ||
<p-skeleton width="100%" height="2rem" /> | ||
<p-skeleton width="100%" height="2rem" /> | ||
<p-skeleton width="100%" height="2rem" /> | ||
<p-skeleton width="100%" height="2rem" /> | ||
<p-skeleton width="100%" height="2rem" /> | ||
</div> | ||
} | ||
</div> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is the test for these changes?