Skip to content
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

General: Migrate test run module to signals, inject and standalone #9914

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

coolchock
Copy link
Contributor

@coolchock coolchock commented Nov 29, 2024

Checklist

General

Client

Description

This pull request migrates test runs module to signals, inject and standalone.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Exam
  1. Log in to Artemis
  2. Navigate to Course Administration -> Select a course -> Exams -> Test Runs
  3. Click Create a Test Run
  4. Verify that modal works and it's possible to create a test run
  5. Verify that buttons and links on Test Run Management page work

Testserver 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

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Exam Mode Test

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

  • New Features

    • Enhanced dependency management in the Create Test Run and Test Run Management components using Angular's modern inject function.
    • Introduced a new observable for error handling in the Test Run Management component.
  • Bug Fixes

    • Streamlined initialization processes for components, improving overall readability and maintainability.
  • Refactor

    • Removed constructor parameters in favor of direct property assignment for injected services, reducing boilerplate code.

@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Nov 29, 2024
@coolchock coolchock changed the title Chore: Migrate test run module to signals, inject and standalone General: Migrate test run module to signals, inject and standalone Nov 29, 2024
Copy link

coderabbitai bot commented Dec 2, 2024

Walkthrough

The pull request introduces updates to the CreateTestRunModalComponent and TestRunManagementComponent in the Angular application. Both components transition from constructor-based dependency injection to using the inject function for service initialization, simplifying the code structure. The CreateTestRunModalComponent removes its constructor and directly assigns injected services to private properties. Similarly, the TestRunManagementComponent eliminates constructor parameters and initializes services using inject, while also introducing a new Subject for dialog error handling. The overall functionality of both components remains unchanged.

Changes

File Path Change Summary
src/main/webapp/app/exam/manage/test-runs/create-test-run-modal.component.ts Removed constructor; added private activeModal and private artemisDurationFromSecondsPipe.
src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts Removed constructor parameters; added services using inject; initialized dialogErrorSource.

Possibly related PRs

  • Development: Fix server test compilation #9421: The changes in the TestRunManagementComponent also involve transitioning from constructor-based dependency injection to using the inject function, similar to the changes made in the CreateTestRunModalComponent.
  • Development: Fix architecture tests for exam deletion summary #9458: The modifications in the AdminCourseResource class include changes to method signatures and access requirements, which may relate to the overall structure and dependency management in the application, akin to the changes in the CreateTestRunModalComponent.
  • Development: Fix exam assessment e2e tests failing #9462: The changes in the ExamAssessment.spec.ts file enhance the assessment process for exams, which may relate to the overall exam management functionality that includes the CreateTestRunModalComponent.
  • Development: Use signals in lecture unit wizard #9708: The updates in the LectureUpdateWizardUnitsComponent involve similar transitions to using signals and reactive programming, reflecting a broader trend in the codebase that aligns with the changes in the CreateTestRunModalComponent.

Suggested labels

tests, refactoring, code quality, ready to merge

Suggested reviewers

  • florian-glombik
  • JohannesStoehr
  • EneaGore
  • muradium
  • MaximilianAnzinger

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 cleanup

While 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 Subject

The 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 cleanup

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2611d04 and c255253.

📒 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)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/exam/manage/test-runs/test-run-management.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

🔇 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) ready for review small
Projects
Status: Work In Progress
Development

Successfully merging this pull request may close these issues.

1 participant