-
Notifications
You must be signed in to change notification settings - Fork 303
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
Development
: Migrate test run module to signals, inject and standalone
#9914
Conversation
Chore
: Migrate test run module to signals, inject and standaloneGeneral
: Migrate test run module to signals, inject and standalone
WalkthroughThe pull request modifies the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (4)
src/main/webapp/app/exam/manage/test-runs/create-test-run-modal.component.ts (1)
19-24
: Consider implementing OnDestroy for proper cleanupWhile the component looks good, it's handling exam data and form controls which should be properly cleaned up.
Consider implementing OnDestroy:
-export class CreateTestRunModalComponent implements OnInit { +export class CreateTestRunModalComponent implements OnInit, OnDestroy { + private destroy$ = new Subject<void>(); + + ngOnDestroy(): void { + this.destroy$.next(); + this.destroy$.complete(); + }src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts (3)
Line range hint
38-39
: Implement proper cleanup for dialogErrorSource SubjectThe dialogErrorSource Subject needs proper cleanup to prevent memory leaks.
Add cleanup in ngOnDestroy:
+ private destroy$ = new Subject<void>(); private dialogErrorSource = new Subject<string>(); dialogError$ = this.dialogErrorSource.asObservable(); + ngOnDestroy(): void { + this.dialogErrorSource.complete(); + this.destroy$.next(); + this.destroy$.complete(); + }
Line range hint
51-67
: Use destroy$ Subject to manage subscription cleanupThe HTTP subscriptions in ngOnInit should be properly managed to prevent memory leaks.
Implement proper subscription management:
ngOnInit(): void { - this.examManagementService.find(/*...*/).subscribe({ + this.examManagementService.find(/*...*/) + .pipe(takeUntil(this.destroy$)) + .subscribe({ next: (response: HttpResponse<Exam>) => { this.exam = response.body!; this.isExamStarted = this.exam.started!; this.course = this.exam.course!; this.course.isAtLeastInstructor = this.accountService.isAtLeastInstructorInCourse(this.course); - this.examManagementService.findAllTestRunsForExam(/*...*/).subscribe({ + this.examManagementService.findAllTestRunsForExam(/*...*/) + .pipe(takeUntil(this.destroy$)) + .subscribe({ next: (res: HttpResponse<StudentExam[]>) => { this.testRuns = res.body!; },
Line range hint
89-93
: Consider using async pipe for dialogError$Since you're using an Observable for dialog errors, consider leveraging the async pipe in the template for automatic subscription management.
Update the template to use async pipe:
<div *ngIf="dialogError$ | async as error" class="alert alert-danger"> {{ error }} </div>
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
src/main/webapp/app/exam/manage/test-runs/create-test-run-modal.component.ts
(2 hunks)src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/exam/manage/test-runs/create-test-run-modal.component.ts (1)
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts (1)
🔇 Additional comments (2)
src/main/webapp/app/exam/manage/test-runs/create-test-run-modal.component.ts (1)
1-1
: LGTM: Clean migration to inject() pattern
The migration from constructor injection to the new inject() pattern is well implemented. This change:
- Reduces boilerplate code
- Follows modern Angular practices
- Maintains proper encapsulation with private members
Also applies to: 17-18
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts (1)
23-28
: LGTM: Clean service injection implementation
The migration to inject() for all services is well implemented and follows a consistent pattern.
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.
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.
injection change lgtm, but you still need to migrate to standalone and use signals
src/main/webapp/app/exam/manage/test-runs/create-test-run-modal.component.ts
Outdated
Show resolved
Hide resolved
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts
Outdated
Show resolved
Hide resolved
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts
Outdated
Show resolved
Hide resolved
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts
Outdated
Show resolved
Hide resolved
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.
we prefer undefined
over null
in the client code, see the client coding guidelines
a4c5605
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.
Actionable comments posted: 0
🔭 Outside diff range comments (3)
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts (3)
Line range hint
63-82
: Improve initialization with proper error handling and cleanupConsider these improvements:
- Replace non-null assertions with proper null checks
- Use RxJS operators to flatten nested subscriptions
- Consider cleanup for HTTP subscriptions
ngOnInit(): void { - this.examManagementService.find(Number(this.route.snapshot.paramMap.get('courseId')), Number(this.route.snapshot.paramMap.get('examId')), false, true).subscribe({ + const courseId = Number(this.route.snapshot.paramMap.get('courseId')); + const examId = Number(this.route.snapshot.paramMap.get('examId')); + if (isNaN(courseId) || isNaN(examId)) { + this.alertService.error('artemisApp.exam.error.invalidIds'); + return; + } + this.examManagementService.find(courseId, examId, false, true).pipe( + switchMap(response => { + if (!response.body) { + throw new Error('No exam data received'); + } + this.exam.set(response.body); + const examData = response.body; + this.course.set(examData.course); + const course = examData.course; + if (!course) { + throw new Error('No course data available'); + } + course.isAtLeastInstructor = this.accountService.isAtLeastInstructorInCourse(course); + return this.examManagementService.findAllTestRunsForExam(course.id, examData.id); + }) + ).subscribe({ + next: (res: HttpResponse<StudentExam[]>) => { + if (res.body) { + this.testRuns.set(res.body); + } + }, + error: (error: HttpErrorResponse) => onError(this.alertService, error), + }); }
Line range hint
88-104
: Improve modal handling with better type safetyThe modal handling uses unsafe type assertions and non-null assertions. Consider these improvements:
openCreateTestRunModal() { - const modalRef: NgbModalRef = this.modalService.open(CreateTestRunModalComponent as Component, { size: 'lg', backdrop: 'static' }); + const modalRef = this.modalService.open(CreateTestRunModalComponent, { size: 'lg', backdrop: 'static' }); - modalRef.componentInstance.exam = this.exam(); + const currentExam = this.exam(); + if (!currentExam) { + this.alertService.error('artemisApp.exam.error.noExamData'); + return; + } + modalRef.componentInstance.exam = currentExam; modalRef.result .then((testRunConfiguration: StudentExam) => { - this.examManagementService.createTestRun(this.course()?.id!, this.exam()?.id!, testRunConfiguration) + const courseId = this.course()?.id; + const examId = this.exam()?.id; + if (!courseId || !examId) { + this.alertService.error('artemisApp.exam.error.invalidIds'); + return; + } + this.examManagementService.createTestRun(courseId, examId, testRunConfiguration)🧰 Tools
🪛 GitHub Check: client-style
[warning] 93-93:
Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
[warning] 93-93:
Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
Line range hint
111-118
: Improve error handling in deleteTestRunConsider adding proper null checks and error handling:
deleteTestRun(testRunId: number) { + const courseId = this.course()?.id; + const examId = this.exam()?.id; + if (!courseId || !examId) { + this.dialogErrorSource.next('artemisApp.exam.error.invalidIds'); + return; + } - this.examManagementService.deleteTestRun(this.course()!.id!, this.exam()!.id!, testRunId) + this.examManagementService.deleteTestRun(courseId, examId, testRunId)
🧹 Nitpick comments (3)
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts (3)
Line range hint
1-19
: Consider organizing imports by categoryWhile the imports are functional, consider organizing them into categories for better maintainability:
- Angular core
- Angular features
- Application models
- Application services
- Third-party libraries
- Shared components/modules
35-53
: Consider strengthening signal typingThe signal implementation looks good, but consider adding more specific types for better type safety:
- course = signal<Course | undefined>(undefined); + readonly course = signal<Course | undefined>(undefined); - exam = signal<Exam | undefined>(undefined); + readonly exam = signal<Exam | undefined>(undefined); - isLoading = signal(false); + readonly isLoading = signal<boolean>(false); - testRuns = signal<StudentExam[]>([]); + readonly testRuns = signal<readonly StudentExam[]>([]);The
readonly
modifier prevents accidental reassignment of the signal itself, while usingreadonly
arrays prevents accidental mutations of the array reference.
130-132
: LGTM with a minor suggestionThe sorting implementation is good. Consider adding type safety to the predicate:
-predicate = signal<string>('id'); +type SortPredicate = 'id' | 'user' | 'submitted'; +predicate = signal<SortPredicate>('id');
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts
(6 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts (1)
🪛 GitHub Check: client-style
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts
[warning] 93-93:
Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
[warning] 93-93:
Optional chain expressions can return undefined by design - using a non-null assertion is unsafe and wrong
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: server-tests
- GitHub Check: client-tests
- GitHub Check: Analyse
🔇 Additional comments (1)
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts (1)
28-33
: Well-implemented dependency injection usinginject()
!Good use of the modern
inject()
function for dependency injection, which aligns with current Angular best practices and reduces boilerplate code.
We postpone this PR until #10124 is merged |
# Conflicts: # src/main/webapp/app/exam/manage/test-runs/create-test-run-modal.component.ts # src/main/webapp/app/exam/manage/test-runs/test-run-management.component.html # src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts # src/main/webapp/app/exam/manage/test-runs/test-run-ribbon.component.ts # src/main/webapp/app/exam/participate/exam-participation.module.ts # src/test/javascript/spec/component/exam/test-run/create-test-run-modal.component.spec.ts
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.
Code
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.
Reapprove after merge conflict fixes
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.
re-approve
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.
Reapprove
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.
code-reapprove after adapting Angular 19 migration changes
Checklist
General
Client
Description
This pull request migrates test runs module to signals, inject and standalone.
Steps for Testing
Prerequisites:
Create a Test Run
Test Run Management
page workTestserver States
Note
These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.
Review Progress
Performance Review
Code Review
Manual Tests
Summary by CodeRabbit
Summary by CodeRabbit
New Features
inject
function.Bug Fixes
Refactor
Tests