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

Communication: Migrate conversation components to use signals #10223

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

Conversation

PaRangger
Copy link
Contributor

@PaRangger PaRangger commented Jan 28, 2025

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the client coding and design guidelines.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the test guidelines.

Motivation and Context

This PR is part of the effort to migrate the communication module to use signals instead of decorators. A list of those components can be found on confluence.

Description

I changed the conversations-code-of-conduct.component.ts, course-conversations.component.ts, course-wide-search.component.ts, post.component.ts and answer-post.component.ts to use signals instead of decorators.

Steps for Testing

Prerequisites:

  • 1 Student/Tutor/Instructor
  1. Log in to Artemis
  2. Navigate to course
  3. Navigate to the communication tab
  4. Go to a channel
  5. Create messages there and answer posts in threads
  6. Edit messages, delete messages
  7. Search for messages and filter messages
  8. Everything should still work as it did before

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

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced component property management using Angular's new functional input/output syntax.
    • Improved type safety and dynamic property access across multiple components.
  • Technical Improvements

    • Migrated from decorator-based property declarations to functional input/output methods.
    • Updated component property access to use function calls instead of direct property references.
    • Streamlined view child and input property management.
  • Testing Enhancements

    • Updated test suites to support new component property initialization methods.
    • Improved mocking capabilities for component interactions.
  • Performance

    • Simplified component property declarations.
    • More flexible property access and initialization.

These changes represent a significant refactoring of the application's component architecture, focusing on modernizing the codebase and improving type safety.

@PaRangger PaRangger added client Pull requests that update TypeScript code. (Added Automatically!) chore communication Pull requests that affect the corresponding module labels Jan 28, 2025
@PaRangger PaRangger self-assigned this Jan 28, 2025
@github-actions github-actions bot added tests and removed communication Pull requests that affect the corresponding module labels Jan 28, 2025
@PaRangger PaRangger marked this pull request as ready for review January 28, 2025 13:09
@PaRangger PaRangger requested a review from a team as a code owner January 28, 2025 13:09
Copy link

coderabbitai bot commented Jan 28, 2025

Walkthrough

This pull request introduces a significant refactoring of Angular components across multiple files, focusing on transitioning from traditional decorator-based property declarations to a more functional approach using input(), output(), and viewChild() methods. The changes primarily affect components in the course conversations, post, and answer post modules, streamlining property initialization and access patterns while maintaining the existing component logic.

Changes

File Path Change Summary
src/main/webapp/app/overview/course-conversations/... Migrated input and view child properties to functional declarations in multiple components, including changes to how the course property is accessed.
src/main/webapp/app/shared/metis/answer-post/... Replaced @Input() and @Output() decorators with input() and output() functions, updating property access to function calls.
src/main/webapp/app/shared/metis/post/... Updated component property declarations to use new Angular functional syntax, including changes to how properties are accessed in templates.
src/test/javascript/spec/... Modified test setups to work with new component property initialization methods, including the use of fixture.componentRef.setInput for setting inputs.

Suggested labels

ready to merge, component:Communication

Suggested reviewers

  • sachmii
  • cremertim

Possibly related PRs

  • Development: Migrate suspicious behavior module to new client coding guidelines #9887: The changes in the main PR and the retrieved PR are related as both involve modifying property access from direct references to function calls within their respective components, specifically affecting how properties are accessed in HTML templates and TypeScript files.
  • Development: Migrate client code for pipes and loading indicator components #9880: The changes in the main PR, which involve modifying property access from direct references to function calls in the CourseConversationsCodeOfConductComponent, are related to the changes in the retrieved PR that also involve similar modifications to property access in the LoadingIndicatorContainerComponent, indicating a consistent shift towards using function calls for property access across different components.
  • Development: Migrate test run module to signals, inject and standalone #9914: The changes in the main PR, which involve modifying property access from direct references to function calls in the CourseConversationsCodeOfConductComponent, are related to the changes in the retrieved PR that also transition property accesses to function calls in the TestRunManagementComponent. Both PRs reflect a broader shift towards a functional approach in Angular components.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0d1bd6b and 3da10fd.

📒 Files selected for processing (1)
  • src/test/javascript/spec/component/overview/course-conversations/course-conversations-code-of-conduct.component.spec.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/javascript/spec/component/overview/course-conversations/course-conversations-code-of-conduct.component.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: client-tests-selected
  • GitHub Check: client-tests
  • GitHub Check: server-tests
  • GitHub Check: Analyse

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 4

🔭 Outside diff range comments (4)
src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts (1)

Line range hint 164-172: Migrate remaining tests from runInInjectionContext to setInput.

Some tests still use runInInjectionContext while others have been migrated to use setInput.

For consistency, migrate these tests to use setInput:

-runInInjectionContext(injector, () => {
-  post.answers = unsortedAnswerArray;
-  component.posting = input<Posting>(post);
-  metisServiceUserAuthorityStub.mockReturnValue(false);
-  component.ngOnInit();
-  expect(component.isAtLeastTutorInCourse).toBeFalse();
-  expect(component.createdAnswerPost.resolvesPost).toBeFalse();
-});
+post.answers = unsortedAnswerArray;
+fixture.componentRef.setInput('posting', post);
+metisServiceUserAuthorityStub.mockReturnValue(false);
+component.ngOnInit();
+fixture.detectChanges();
+expect(component.isAtLeastTutorInCourse).toBeFalse();
+expect(component.createdAnswerPost.resolvesPost).toBeFalse();

Also applies to: 244-250

🧰 Tools
🪛 GitHub Actions: Test

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/test/javascript/spec/component/overview/course-conversations/course-wide-search.component.spec.ts (1)

Line range hint 161-188: Add test cases to improve branch coverage.

The pipeline indicates that branch coverage is slightly below the threshold (74.46% vs 74.47%). Consider adding test cases for edge conditions in the fetchNextPage method.

+    it('should not fetch posts when total number of posts is less than current posts', fakeAsync(() => {
+        const getFilteredPostSpy = jest.spyOn(metisService, 'getFilteredPosts');
+        fixture.componentRef.setInput('courseWideSearchConfig', courseWideSearchConfig);
+        component.totalNumberOfPosts = 1;
+        component.posts = [examplePost];
+        component.fetchNextPage();
+        expect(getFilteredPostSpy).not.toHaveBeenCalled();
+    }));
🧰 Tools
🪛 GitHub Actions: Test

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/main/webapp/app/shared/metis/post/post.component.html (1)

Line range hint 1-216: **Migrate remaining ngIf and ngFor directives to new syntax.

While most of the file uses the new @if syntax, there are still instances of *ngIf and *ngFor. According to the coding guidelines, @if and @for should always be used over the old style.

For example:

-    [ngClass]="{ 'mx-0': !isThreadSidebar, 'pinned-message': isPinned(), 'is-saved': !isConsecutive() && posting.isSaved, 'non-consecutive': !isConsecutive() }"
+    [class]="{ 'mx-0': !isThreadSidebar, 'pinned-message': isPinned(), 'is-saved': !isConsecutive() && posting.isSaved, 'non-consecutive': !isConsecutive() }"
src/test/javascript/spec/component/shared/metis/post/post.component.spec.ts (1)

Line range hint 1-424: Add missing test coverage for signals.

The pipeline shows that branch coverage is slightly below the threshold (74.46% vs required 74.47%). Add tests for the new signal-based properties:

  1. Add tests for input signal initialization:
it('should initialize input signals with default values', () => {
    expect(component.lastReadDate()).toBeUndefined();
    expect(component.readOnlyMode()).toBeFalse();
    expect(component.previewMode()).toBeFalse();
    expect(component.modalRef()).toBeUndefined();
});
  1. Add tests for model signal:
it('should handle showAnswers model signal', () => {
    expect(component.showAnswers()).toBeFalse();
    component.showAnswers.set(true);
    expect(component.showAnswers()).toBeTrue();
});
  1. Add tests for viewChild signals:
it('should properly initialize viewChild signals', () => {
    fixture.detectChanges();
    expect(component.postFooterComponent()).toBeDefined();
    expect(component.reactionsBarComponent()).toBeDefined();
});
🧰 Tools
🪛 GitHub Actions: Test

[error] Coverage threshold for branches (74.47%) not met: 74.46%

🧹 Nitpick comments (6)
src/test/javascript/spec/component/shared/metis/postings-thread/postings-thread.component.spec.ts (2)

25-27: Improve documentation of the ng-mocks workaround.

The comment should explain why this workaround is necessary and how it works, not just reference an issue.

Consider adding a more detailed comment:

-// Workaround for mocked components with viewChild: https://github.com/help-me-mom/ng-mocks/issues/8634
+// When mocking components with @ViewChild that use signals, we need to initialize the signals
+// to prevent "signal not found" errors during testing.
+// See: https://github.com/help-me-mom/ng-mocks/issues/8634
🧰 Tools
🪛 GitHub Actions: Test

[error] Coverage threshold for branches (74.47%) not met: 74.46%


27-27: Improve type safety of the signal initialization.

The current cast to PostReactionsBarComponent bypasses type checking.

Consider creating a minimal mock implementation:

-MockInstance(PostComponent, 'reactionsBarComponent', signal({} as unknown as PostReactionsBarComponent));
+const mockReactionsBar = {
+  // Add minimal required properties
+} satisfies Partial<PostReactionsBarComponent>;
+MockInstance(PostComponent, 'reactionsBarComponent', signal(mockReactionsBar));
🧰 Tools
🪛 GitHub Actions: Test

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts (1)

90-91: Use more specific jest matchers.

According to the coding guidelines, use more specific matchers for better error messages:

-expect(component.groupedAnswerPosts.length).toBeGreaterThan(0);
+expect(component.groupedAnswerPosts).not.toHaveLength(0);

-expect(changeDetectorSpy).toHaveBeenCalled();
+expect(changeDetectorSpy).toHaveBeenCalledOnce();

-expect(createAnswerPostModalOpen).toHaveBeenCalledOnce();
+expect(createAnswerPostModalOpen).toHaveBeenCalledExactlyOnceWith();

-expect(group1.posts).toContainEqual(expect.objectContaining({ id: post1.id }));
+expect(group1.posts).toContainEntries([[0, expect.objectContaining({ id: post1.id })]]);

Also applies to: 103-106, 182-184, 197-199, 222-240

🧰 Tools
🪛 GitHub Actions: Test

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.ts (1)

142-153: Consider adding error handling for undefined searchConfig.

While the null check is present, consider adding error logging for debugging purposes when searchConfig is undefined.

 const searchConfig = this.courseWideSearchConfig();

-if (!searchConfig) return;
+if (!searchConfig) {
+    console.warn('Search config is undefined');
+    return;
+}
src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (1)

598-598: Consider using optional chaining for safer element access.

While the non-null assertion works, it could lead to runtime errors if the element doesn't exist. Consider using optional chaining for safer access:

-this.searchElement()!.nativeElement.focus();
+this.searchElement()?.nativeElement?.focus();
src/main/webapp/app/shared/metis/post/post.component.ts (1)

235-235: Fix potential null reference issues.

The optional chaining operator is used correctly with function calls, but consider adding null checks for better defensive programming.

-    this.modalRef()?.dismiss();
+    const modal = this.modalRef();
+    if (modal) {
+        modal.dismiss();
+    }

-    this.postFooterComponent()?.openCreateAnswerPostModal();
+    const footer = this.postFooterComponent();
+    if (footer) {
+        footer.openCreateAnswerPostModal();
+    }

-    this.postFooterComponent()?.closeCreateAnswerPostModal();
+    const footer = this.postFooterComponent();
+    if (footer) {
+        footer.closeCreateAnswerPostModal();
+    }

Also applies to: 244-244, 251-251

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8c93d2 and 42d3d81.

📒 Files selected for processing (16)
  • src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.component.html (1 hunks)
  • src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.component.ts (2 hunks)
  • src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (4 hunks)
  • src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.html (1 hunks)
  • src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.ts (8 hunks)
  • src/main/webapp/app/shared/metis/answer-post/answer-post.component.html (4 hunks)
  • src/main/webapp/app/shared/metis/answer-post/answer-post.component.ts (3 hunks)
  • src/main/webapp/app/shared/metis/post/post.component.html (8 hunks)
  • src/main/webapp/app/shared/metis/post/post.component.ts (5 hunks)
  • src/test/javascript/spec/component/overview/course-conversations/course-conversations-code-of-conduct.component.spec.ts (1 hunks)
  • src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts (3 hunks)
  • src/test/javascript/spec/component/overview/course-conversations/course-wide-search.component.spec.ts (8 hunks)
  • src/test/javascript/spec/component/shared/metis/post/post.component.spec.ts (2 hunks)
  • src/test/javascript/spec/component/shared/metis/postings-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.spec.ts (0 hunks)
  • src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts (3 hunks)
  • src/test/javascript/spec/component/shared/metis/postings-thread/postings-thread.component.spec.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • src/test/javascript/spec/component/shared/metis/postings-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.spec.ts
🧰 Additional context used
📓 Path-based instructions (15)
src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/test/javascript/spec/component/overview/course-conversations/course-conversations-code-of-conduct.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/test/javascript/spec/component/shared/metis/post/post.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.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/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/test/javascript/spec/component/overview/course-conversations/course-wide-search.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/overview/course-conversations/course-conversations.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/test/javascript/spec/component/shared/metis/postings-thread/postings-thread.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/shared/metis/post/post.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/main/webapp/app/shared/metis/answer-post/answer-post.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/main/webapp/app/shared/metis/post/post.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/shared/metis/answer-post/answer-post.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/overview/course-conversations/course-wide-search/course-wide-search.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

🪛 GitHub Actions: Test
src/test/javascript/spec/component/overview/course-conversations/course-conversations-code-of-conduct.component.spec.ts

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/test/javascript/spec/component/shared/metis/post/post.component.spec.ts

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/test/javascript/spec/component/overview/course-conversations/course-wide-search.component.spec.ts

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/test/javascript/spec/component/shared/metis/postings-thread/postings-thread.component.spec.ts

[error] Coverage threshold for branches (74.47%) not met: 74.46%

🔇 Additional comments (30)
src/test/javascript/spec/component/overview/course-conversations/course-conversations.component.spec.ts (2)

6-6: Good use of ng-mocks for component mocking!

The addition of MockInstance from ng-mocks and the setup of mock signals for content and messages properties follows best practices for Angular component testing.

Also applies to: 47-47, 86-88

🧰 Tools
🪛 GitHub Actions: Test

[error] Coverage threshold for branches (74.47%) not met: 74.46%


Line range hint 1-500: Increase branch coverage to meet the pipeline threshold.

The pipeline indicates that branch coverage (74.46%) is slightly below the required threshold (74.47%). Consider adding test cases for the following scenarios to improve coverage:

  1. Error handling paths in dialog opening tests
  2. Edge cases in query parameter handling
  3. Boundary conditions in conversation selection

Let's analyze the untested branches:

🧰 Tools
🪛 GitHub Actions: Test

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/test/javascript/spec/component/overview/course-conversations/course-conversations-code-of-conduct.component.spec.ts (1)

Line range hint 32-35: Improve test coverage by adding more test cases.

The current test suite only verifies component initialization. Consider adding test cases for:

  • Component behavior when course input changes
  • Error scenarios
  • Component interactions

This could help address the coverage threshold failure (74.46% vs required 74.47%).

🧰 Tools
🪛 GitHub Actions: Test

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.component.ts (2)

20-20: LGTM! Clean migration to input() signal.

The migration from @input decorator to input() signal follows Angular's new input API guidelines.


Line range hint 25-34: Verify null handling in the HTTP call.

The code uses optional chaining for the initial check but non-null assertions for the HTTP call. While this works, consider adding error handling for the HTTP call to improve robustness.

src/main/webapp/app/shared/metis/answer-post/answer-post.component.ts (3)

67-70: LGTM! Well-structured signal migrations with proper initialization.

The input properties are correctly migrated with appropriate default values.


72-74: LGTM! Clean output signal declarations.

The output signals are properly declared using the output() function.


76-77: LGTM! Proper use of viewChild with type safety.

The viewChild declarations use proper type annotations and the required flag where necessary.

src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.ts (1)

32-34: LGTM! Proper use of viewChildren with toObservable.

Good use of toObservable for reactive handling of viewChildren changes.

src/test/javascript/spec/component/overview/course-conversations/course-wide-search.component.spec.ts (1)

96-96: LGTM! Proper test setup for input signals.

Correctly using setInput for initializing the signal in tests.

🧰 Tools
🪛 GitHub Actions: Test

[error] Coverage threshold for branches (74.47%) not met: 74.46%

src/main/webapp/app/overview/course-conversations/course-conversations.component.ts (2)

174-175: LGTM! Good migration to signal-based viewChild.

The transition from decorator-based @ViewChild to signal-based viewChild aligns with modern Angular practices and should improve performance through better change detection.


421-421: LGTM! Proper signal access with null safety.

The optional chaining operator ensures safe access to the CourseWideSearchComponent instance when using the signal-based viewChild.

src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.component.html (1)

2-2: LGTM! Safe signal access with fallback.

The optional chaining with empty string fallback ensures safe rendering of the code of conduct content when using signal-based input.

src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.html (2)

1-5: LGTM! Consistent signal usage in template bindings.

The changes correctly implement signal-based property access with appropriate null safety checks in the template bindings.


9-15: LGTM! Proper signal usage in template logic.

The changes correctly implement signal-based property access in both conditional statements and translation value bindings.

src/main/webapp/app/shared/metis/answer-post/answer-post.component.html (4)

23-25: LGTM! Proper signal binding to child component.

The changes correctly implement signal-based property access for input bindings to the posting-header component.


48-50: LGTM! Consistent signal usage in reactions bar.

The changes correctly implement signal-based property access for input bindings to the first instance of answer-post-reactions-bar.


69-71: LGTM! Consistent signal usage across component instances.

The changes maintain consistent signal-based property access across multiple instances of the answer-post-reactions-bar component.


81-81: LGTM! Proper signal binding for modal component.

The change correctly implements signal-based property access for the containerRef input binding to the answer-post-create-edit-modal component.

src/main/webapp/app/shared/metis/post/post.component.html (8)

21-22: LGTM! Properties correctly migrated to signal syntax.

The properties previewMode, readOnlyMode, and lastReadDate have been properly converted to use function calls, aligning with Angular's signal-based reactivity.

Also applies to: 28-28


45-45: LGTM! Condition correctly uses signal syntax.

The condition properly uses previewMode() function call in the template expression.


80-80: LGTM! Consistent usage of signal syntax.

The previewMode property is consistently used as a function call in both property binding and class binding contexts.

Also applies to: 92-92


96-98: LGTM! Properties correctly migrated in reactions bar.

The properties lastReadDate, readOnlyMode, and previewMode have been properly converted to use function calls in the reactions bar component.


126-132: LGTM! Consistent signal usage in post reactions bar.

The properties previewMode, lastReadDate, and readOnlyMode are consistently using function calls in the post reactions bar section.


152-154: LGTM! Footer properties correctly use signal syntax.

All properties in the footer section (readOnlyMode, modalRef, previewMode, showAnswers, lastReadDate) have been properly converted to use function calls.

Also applies to: 156-156, 161-161


192-192: LGTM! Proper signal usage with optional chaining.

The reactionsBarComponent is correctly accessed as a function with optional chaining operator.


213-213: LGTM! Proper signal usage in emoji picker condition.

The readOnlyMode property is correctly accessed as a function in the emoji picker condition.

src/main/webapp/app/shared/metis/post/post.component.ts (3)

12-14: LGTM! Migration to signals.

The imports for model, input, output, and viewChild align with Angular's new signals API, improving reactivity and performance.


78-84: LGTM! Clean signal declarations.

The migration from decorators to signals is well-implemented:

  • Input properties are correctly initialized with default values
  • The model signal for showAnswers is appropriately used for two-way binding

86-89: Verify child component access patterns.

The ViewChild declarations look correct, but we should ensure consistent access patterns throughout the codebase.

✅ Verification successful

ViewChild declarations follow the new standardized pattern

The code uses the new viewChild<T>() function syntax which is consistently applied across the codebase, including similar usages in conversation components, form components, and exercise components. The required modifier is appropriately used for mandatory child components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other ViewChild usages to ensure consistent migration
ast-grep --pattern 'ViewChild($$$)'

Length of output: 41013


Script:

#!/bin/bash
# Search for documentation about viewChild function and similar usage patterns
rg -g '*.{ts,md}' -i "viewChild.*function|migrat.*viewChild"

# Search for similar viewChild function usage
ast-grep --pattern 'viewChild<$_>($$$)'

Length of output: 2947

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

🧹 Nitpick comments (3)
src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.component.ts (1)

25-26: Simplify the null checks.

The double null check with if (this.course().id) followed by this.course().id! can be simplified since input.required guarantees that course is defined.

Apply this diff to simplify the null checks:

-        if (this.course().id) {
-            this.conversationService.getResponsibleUsersForCodeOfConduct(this.course().id!).subscribe({
+        const courseId = this.course().id;
+        if (courseId) {
+            this.conversationService.getResponsibleUsersForCodeOfConduct(courseId).subscribe({
src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.ts (2)

103-104: Simplify content() null checks.

Multiple null checks for content() can be simplified by extracting the element reference.

Apply this pattern to simplify the null checks:

setPosts(posts: Post[]): void {
-        if (this.content()) {
-            this.previousScrollDistanceFromTop = this.content()!.nativeElement.scrollHeight - this.content()!.nativeElement.scrollTop;
+        const container = this.content();
+        if (container) {
+            this.previousScrollDistanceFromTop = container.nativeElement.scrollHeight - container.nativeElement.scrollTop;
         }
         this.posts = posts.slice().reverse();
     }

Also applies to: 110-113, 119-120, 129-130


142-153: Optimize configuration handling.

The configuration access and property updates can be optimized by destructuring and using a more functional approach.

Apply this pattern to optimize the configuration handling:

private refreshMetisConversationPostContextFilter(): void {
    const searchConfig = this.courseWideSearchConfig();
    if (!searchConfig) return;

+   const { searchTerm, filterToUnresolved, filterToOwn, filterToAnsweredOrReacted, sortingOrder } = searchConfig;
    this.currentPostContextFilter = {
        courseId: this.course?.id,
-       searchText: searchConfig.searchTerm ? searchConfig.searchTerm.trim() : undefined,
+       searchText: searchTerm?.trim(),
        postSortCriterion: PostSortCriterion.CREATION_DATE,
-       filterToUnresolved: searchConfig.filterToUnresolved,
-       filterToOwn: searchConfig.filterToOwn,
-       filterToAnsweredOrReacted: searchConfig.filterToAnsweredOrReacted,
-       sortingOrder: searchConfig.sortingOrder,
+       filterToUnresolved,
+       filterToOwn,
+       filterToAnsweredOrReacted,
+       sortingOrder,
        pagingEnabled: true,
        page: this.page - 1,
        pageSize: 50,
    };
}

Also applies to: 197-202

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42d3d81 and c1161bf.

📒 Files selected for processing (3)
  • src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.component.ts (2 hunks)
  • src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.html (1 hunks)
  • src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.ts (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.html
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.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/overview/course-conversations/course-wide-search/course-wide-search.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

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (2)
src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.component.ts (1)

20-20: LGTM! Good use of input.required.

The use of input.required<Course>() is a good practice as it enforces the requirement of a Course object and aligns with Angular's new functional approach.

src/main/webapp/app/overview/course-conversations/course-wide-search/course-wide-search.component.ts (1)

30-50: LGTM! Excellent use of Angular's functional approach and immutability.

The changes demonstrate good practices:

  • Using input.required for required inputs
  • Using viewChildren and viewChild for DOM references
  • Using output for event emitters
  • Marking properties as readonly for immutability

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 1, 2025
coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 1, 2025
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

🧹 Nitpick comments (5)
src/main/webapp/app/shared/metis/answer-post/answer-post.component.ts (1)

100-102: Add return type annotation to the getter.

Consider adding a return type annotation to the getter for better maintainability and type safety:

-    get reactionsBar() {
+    get reactionsBar(): PostingReactionsBarComponent<AnswerPost> | undefined {
         return this.reactionsBarComponent();
     }
src/main/webapp/app/shared/metis/post/post.component.ts (4)

84-84: Consider documenting the model usage.

The use of model() for showAnswers indicates two-way binding. Consider adding a comment explaining why this property needs two-way binding versus a regular input/output pair, as this pattern should be used sparingly.


81-83: Improve the modalRef comment.

The current comment could be more descriptive. Consider:

-    // if the post is previewed in the create/edit modal,
-    // we need to pass the ref in order to close it when navigating to the previewed post via post title
+    /**
+     * Reference to the modal when post is previewed in create/edit mode.
+     * Required to close the modal when navigating to the previewed post via post title.
+     */

Line range hint 234-245: Add error handling for modal and footer operations.

Consider adding error handling for cases where the modal reference or footer component is undefined:

     onNavigateToContext($event: MouseEvent) {
         if (!$event.metaKey) {
-            this.modalRef()?.dismiss();
+            const modal = this.modalRef();
+            if (!modal) {
+                console.warn('Modal reference is undefined');
+                return;
+            }
+            modal.dismiss();
             this.metisConversationService.setActiveConversation(this.contextInformation.queryParams!['conversationId']);
         }
     }

122-124: Add return type annotation to the getter.

Consider adding a return type annotation to the getter for better maintainability and type safety:

-    get reactionsBar() {
+    get reactionsBar(): PostingReactionsBarComponent<Post> {
         return this.reactionsBarComponent();
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1161bf and c9e2320.

📒 Files selected for processing (7)
  • src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.component.html (1 hunks)
  • src/main/webapp/app/shared/metis/answer-post/answer-post.component.html (4 hunks)
  • src/main/webapp/app/shared/metis/answer-post/answer-post.component.ts (3 hunks)
  • src/main/webapp/app/shared/metis/post/post.component.html (8 hunks)
  • src/main/webapp/app/shared/metis/post/post.component.ts (6 hunks)
  • src/test/javascript/spec/component/shared/metis/post/post.component.spec.ts (2 hunks)
  • src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/main/webapp/app/overview/course-conversations/code-of-conduct/course-conversations-code-of-conduct.component.html
  • src/test/javascript/spec/component/shared/metis/post/post.component.spec.ts
  • src/main/webapp/app/shared/metis/answer-post/answer-post.component.html
  • src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts
  • src/main/webapp/app/shared/metis/post/post.component.html
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/shared/metis/post/post.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/shared/metis/answer-post/answer-post.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 (1)
src/main/webapp/app/shared/metis/answer-post/answer-post.component.ts (1)

67-70: Consider using input.required() for mandatory inputs.

For inputs that are required for the component to function correctly, consider using input.required() instead of input() with a default value. This makes the contract more explicit and helps catch missing inputs at runtime.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore client Pull requests that update TypeScript code. (Added Automatically!) ready for review tests
Projects
Status: Ready For Review
Status: Todo
Development

Successfully merging this pull request may close these issues.