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

Development: Migrate client code for edit modals of posts #10198

Merged
merged 3 commits into from
Jan 27, 2025

Conversation

cremertim
Copy link
Contributor

@cremertim cremertim commented Jan 24, 2025

Checklist

General

Client

  • I strictly followed the client coding and design guidelines.
  • Following the theming guidelines, I specified colors only in the theming variable files and checked that the changes look consistent in both the light and the dark theme.
  • I added multiple integration tests (Jest) related to the features (with a high test coverage), while following the [test

Motivation and Context

This PR migrates existing code to the new Client guidelines using signals

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 2 Students
  • 1 Programming Exercise with Complaints enabled
  1. Log in to Artemis
  2. Navigate to the communication of a course
  3. Try to edit normal posts and answer posts. Everything should work as 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

Summary by CodeRabbit

  • Refactor

    • Updated input and output property declarations in Angular components using new functional syntax.
    • Replaced @Input() and @Output() decorators with input() and output() functions.
    • Modified method calls to use function invocation instead of property access for improved clarity.
  • Tests

    • Updated test suites to accommodate new component property declaration styles.
    • Enhanced test mocking for view container references, transitioning to a signal-based approach for better lifecycle management.

@cremertim cremertim requested a review from a team as a code owner January 24, 2025 10:10
@cremertim cremertim requested a review from asliayk January 24, 2025 10:10
@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) labels Jan 24, 2025
@cremertim cremertim requested a review from PaRangger January 24, 2025 10:10
Copy link

coderabbitai bot commented Jan 24, 2025

Walkthrough

The pull request involves modifications to several Angular components within the Metis shared module, focusing on updating property decorators and method calls. The changes primarily transition from using @Input() and @Output() decorators to the newer input() and output() functions. Additionally, there are updates to how properties are accessed, changing from direct property access to method calls, particularly for createEditAnswerPostContainerRef. These modifications appear to be part of an Angular framework update or refactoring effort, maintaining the existing component functionality while adopting newer syntax.

Changes

File Change Summary
src/main/webapp/app/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.ts Replaced @Input() and @Output() decorators with input<>() and output<>(). Updated method calls to use createEditAnswerPostContainerRef() instead of direct property access.
src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.html Updated conditional checks to call isCommunicationPage() as a function instead of accessing it as a property.
src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.ts Replaced @Input() isCommunicationPage with input<boolean>(false)
src/main/webapp/app/shared/metis/posting-footer/posting-footer.component.ts Modified ngOnDestroy method to use createEditAnswerPostContainerRef() method call instead of property access

Suggested labels

ready to merge, refactoring, component:Communication

Suggested reviewers

  • JohannesWt
  • florian-glombik
  • sachmii
  • HawKhiem
  • rabeatwork
  • anian03
  • Feras797

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 bot commented Jan 24, 2025

Warning

Rate limit exceeded

@github-actions[bot] has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 18 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc01b6 and 254aabf.

📒 Files selected for processing (6)
  • src/main/webapp/app/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.ts (4 hunks)
  • src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.html (2 hunks)
  • src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.ts (2 hunks)
  • src/main/webapp/app/shared/metis/posting-footer/posting-footer.component.ts (1 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 (3 hunks)
  • src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts (6 hunks)

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 bot commented Jan 24, 2025

Walkthrough

The pull request involves modifications to several Angular components within the Metis application, focusing on updating input and output property declarations and method calls. The changes primarily transition from using traditional Angular decorators like @Input() and @Output() to using the newer input() and output() functions. This refactoring affects components such as AnswerPostCreateEditModalComponent, PostCreateEditModalComponent, and PostingFooterComponent. The modifications also include adjustments to method calls and optional chaining to improve type safety and reactivity.

Changes

File Change Summary
src/main/webapp/app/shared/metis/.../answer-post-create-edit-modal.component.ts Replaced @Input() and @Output() decorators with input<>() and output<>() functions for createEditAnswerPostContainerRef and postingUpdated properties
src/main/webapp/app/shared/metis/.../post-create-edit-modal.component.html Updated conditional statements to use method calls for isCommunicationPage instead of direct property access
src/main/webapp/app/shared/metis/.../post-create-edit-modal.component.ts Replaced @Input() isCommunicationPage with isCommunicationPage = input<boolean>(false)
src/main/webapp/app/shared/metis/.../posting-footer.component.ts Modified ngOnDestroy method to use optional chaining and method invocation for createEditAnswerPostContainerRef
Test files Updated test cases to use new property declaration methods and mock implementations

Sequence Diagram

sequenceDiagram
    participant Parent as Parent Component
    participant Modal as Create/Edit Modal
    participant Container as View Container

    Parent ->> Modal: Set input properties
    Modal ->> Container: Initialize container reference
    Modal ->> Container: Create/Clear embedded views
    Modal -->> Parent: Emit updates via output events
Loading

Possibly related PRs

Suggested labels

tests, client, small, refactoring, ready to merge, component:Communication

Suggested reviewers

  • HawKhiem
  • sachmii
  • SimonEntholzer
  • FelberMartin
  • anian03
  • eylulnc
  • ItsaaaMeMario
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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: 0

🧹 Nitpick comments (3)
src/main/webapp/app/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.ts (1)

19-20: Adopt Angular Signals naming conventions for clarity
Great job replacing @Input() and @Output() with input<>() and output<>(). To further align with Angular's recommended best practices when using Signals, consider adopting naming patterns (such as $ suffix) to help future maintainers easily distinguish signals from standard properties or methods.

src/main/webapp/app/shared/metis/posting-footer/posting-footer.component.ts (1)

67-67: Validate container reference before clearing on destroy
Calling this.answerPostCreateEditModal?.createEditAnswerPostContainerRef()?.clear(); is consistent with the new approach. Make sure that other code paths cannot hold references to the container after ngOnDestroy to prevent unexpected lifecycle issues.

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

84-87: Reduce code duplication for mock container references
These lines repeat the same mockContainerRef setup. Consider introducing a helper function or fixture setup method to improve maintainability and reduce code repetition.

Example:

-            const mockContainerRef = { clear: jest.fn() } as any;
-            component.answerPostCreateEditModal = {
-                createEditAnswerPostContainerRef: signal(mockContainerRef),
-            } as unknown as AnswerPostCreateEditModalComponent;

+            const mockContainerRef = createMockContainerRef();
+            component.answerPostCreateEditModal = {
+                createEditAnswerPostContainerRef: signal(mockContainerRef),
+            } as unknown as AnswerPostCreateEditModalComponent;

Then define a reusable function:

function createMockContainerRef() {
    return { clear: jest.fn() } as any;
}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc01b6 and 254aabf.

📒 Files selected for processing (6)
  • src/main/webapp/app/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.ts (4 hunks)
  • src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.html (2 hunks)
  • src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.ts (2 hunks)
  • src/main/webapp/app/shared/metis/posting-footer/posting-footer.component.ts (1 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 (3 hunks)
  • src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts (6 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/main/webapp/app/shared/metis/posting-footer/posting-footer.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/shared/metis/postings-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.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/posting-create-edit-modal/post-create-edit-modal/post-create-edit-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/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-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/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.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.

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: server-tests
  • GitHub Check: Build and Push Docker Image
  • GitHub Check: Analyse
🔇 Additional comments (18)
src/main/webapp/app/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.ts (4)

28-28: Clarify optional chaining for createEmbeddedView
Using this.createEditAnswerPostContainerRef()?.createEmbeddedView() is correct and prevents runtime errors if the reference is undefined. Ensure all calling sites handle the potential undefined scenario.


36-36: Check if container is initialized before clearing
Again, optional chaining is a good safety measure here. Confirm that no code path ever needs to handle the scenario where clearing is attempted but createEditAnswerPostContainerRef() remains uninitialized.


63-63: Reinforce consistency with container clearing
Repeated usage of this.createEditAnswerPostContainerRef()?.clear(); maintains consistency in approach. No issues here.


82-82: Ensure consistent cleanup flow
Clearing the container in updatePosting() is a good practice to visibly finalize the edit process. Just verify the user experience remains smooth if createEditAnswerPostContainerRef() is unexpectedly nonexistent.

src/test/javascript/spec/component/shared/metis/postings-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.spec.ts (4)

11-11: Leverage structured imports for clarity
Importing input, runInInjectionContext, and ViewContainerRef behind a single destructuring is concise. Ensure that future contributors are aware of the significance of each import to avoid confusion.


40-40: Mock usage of component methods
jest.spyOn(component, 'updatePosting') is a clean way to verify side effects. Keep an eye on potential performance overhead if many methods are spied on.


65-77: Improve mocking logic for container references
You are correctly isolating the createEditAnswerPostContainerRef functionality with runInInjectionContext. This approach ensures minimal coupling to ViewContainerRef internals and leads to more robust tests.


82-94: Assert container clearing is called once
Verifying mockClear is called confirms the embedded view is cleaned up properly. This is an excellent example of a targeted test.

src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.ts (1)

41-41: Use of functional input property
Replacing @Input() isCommunicationPage with isCommunicationPage = input<boolean>(false) showcases the new Signals-based approach. Confirm all template references invoke isCommunicationPage() where needed.

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

20-20: Check Angular version for signals
This import of signal and input from @angular/core requires Angular v16+ or higher. Ensure that your environment is using a compatible Angular version to leverage these features properly.


98-101: Repeated code usage


110-111: Repeated code usage


176-179: Repeated code usage


187-190: Repeated code usage


195-197: Repeated code usage


216-219: Repeated code usage

src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.html (2)

9-9: Ensure method purity
Switching from a property to a method call (isCommunicationPage()) can be beneficial if the method is pure. Verify that no unexpected side effects or performance bottlenecks might occur from repeated invocations.


23-23: Logic appears consistent
Updating !isCommunicationPage to !isCommunicationPage() aligns with your functional approach. The existing condition remains logically sound as long as the method returns the same boolean values as the former property.

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 comments (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 (1)

Line range hint 19-19: Remove unused variable to fix pipeline failure.

The viewContainerRef variable is declared but never used, causing a pipeline failure.

-    let viewContainerRef: ViewContainerRef;
🧹 Nitpick comments (8)
src/main/webapp/app/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.ts (3)

1-1: LGTM! Consider adding explicit signal types.

The transition to the new input/output syntax is correct. For better type safety, consider explicitly typing the signals:

-    createEditAnswerPostContainerRef = input<ViewContainerRef>();
-    postingUpdated = output<Posting>();
+    createEditAnswerPostContainerRef = input.required<ViewContainerRef>();
+    postingUpdated = output<Posting>({ alias: 'postingUpdated' });

Also applies to: 19-20


28-28: Consider adding error handling for container operations.

The changes to method call syntax are correct. However, consider adding error handling for cases where the container reference is undefined.

-        this.createEditAnswerPostContainerRef()?.createEmbeddedView(this.postingEditor);
+        const containerRef = this.createEditAnswerPostContainerRef();
+        if (!containerRef) {
+            console.warn('Container reference is undefined');
+            return;
+        }
+        containerRef.createEmbeddedView(this.postingEditor);

Also applies to: 36-36, 63-63, 82-82


Line range hint 52-68: Enhance error handling in async operations.

While basic error handling exists, consider adding more detailed error handling and logging.

     error: () => {
+        console.error('Failed to create/update answer post');
         this.isLoading = false;
+        // Consider showing a user-friendly error message
+        this.showErrorMessage('artemisApp.metis.error.saveFailed');
     },

Also applies to: 73-87

src/main/webapp/app/shared/metis/posting-footer/posting-footer.component.ts (1)

67-67: Consider implementing a complete cleanup pattern.

While the change to method call syntax is correct, consider implementing a more comprehensive cleanup pattern.

+    private readonly destroy$ = new Subject<void>();

     ngOnDestroy(): void {
         this.answerPostCreateEditModal?.createEditAnswerPostContainerRef()?.clear();
+        this.destroy$.next();
+        this.destroy$.complete();
     }
src/test/javascript/spec/component/shared/metis/postings-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.spec.ts (1)

65-94: Consider extracting mock setup to a helper function.

The mock setup is repeated across tests. Consider extracting it to a reusable helper function.

+    function setupMockContainerRef(component: AnswerPostCreateEditModalComponent, fixture: ComponentFixture<AnswerPostCreateEditModalComponent>) {
+        const mockClear = jest.fn();
+        const mockCreateEmbeddedView = jest.fn();
+        
+        runInInjectionContext(fixture.debugElement.injector, () => {
+            component.createEditAnswerPostContainerRef = input<ViewContainerRef>({
+                clear: mockClear,
+                createEmbeddedView: mockCreateEmbeddedView,
+            } as unknown as ViewContainerRef);
+        });
+        
+        return { mockClear, mockCreateEmbeddedView };
+    }
src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.ts (1)

41-41: Add JSDoc and explicit typing for the signal.

While the change to signal syntax is correct, consider adding documentation and explicit typing.

-    isCommunicationPage = input<boolean>(false);
+    /**
+     * Indicates whether the modal is being used in the communication page context.
+     * @default false
+     */
+    isCommunicationPage = input<boolean, false>(false);
src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts (1)

84-87: Refactor duplicate test setup code.

The initialization of answerPostCreateEditModal with mockContainerRef is duplicated across multiple test cases. Consider extracting this setup into a beforeEach block or a helper function to improve maintainability.

 describe('PostingFooterComponent', () => {
     let component: PostingFooterComponent;
     let fixture: ComponentFixture<PostingFooterComponent>;
     let metisService: MetisService;
     let metisServiceUserAuthorityStub: jest.SpyInstance;
     let injector: Injector;
+    let mockContainerRef: { clear: jest.Mock };
 
     beforeEach(() => {
         return TestBed.configureTestingModule({
             // ... existing setup ...
         })
             .compileComponents()
             .then(() => {
                 fixture = TestBed.createComponent(PostingFooterComponent);
                 component = fixture.componentInstance;
                 metisService = TestBed.inject(MetisService);
                 metisServiceUserAuthorityStub = jest.spyOn(metisService, 'metisUserIsAtLeastTutorInCourse');
                 injector = fixture.debugElement.injector;
+                mockContainerRef = { clear: jest.fn() } as any;
+                component.answerPostCreateEditModal = {
+                    createEditAnswerPostContainerRef: signal(mockContainerRef),
+                } as unknown as AnswerPostCreateEditModalComponent;
             });
     });

Also applies to: 98-101, 110-111, 176-179, 187-190, 195-197, 216-219

src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.html (1)

9-11: LGTM! Modern Angular syntax usage.

The template correctly uses the new @if syntax instead of *ngIf, following Angular's latest best practices. The conditions are properly structured as function calls.

Consider extracting complex condition into a component method.

The condition on line 23 is complex and could be moved to the component class for better maintainability:

+// In component class
+shouldShowTagSelector(): boolean {
+    return this.pageType !== PageType.PLAGIARISM_CASE_INSTRUCTOR && 
+           this.pageType !== PageType.PLAGIARISM_CASE_STUDENT && 
+           !this.isCommunicationPage() && 
+           !this.posting.conversation;
+}

-@if (pageType !== PageType.PLAGIARISM_CASE_INSTRUCTOR && pageType !== PageType.PLAGIARISM_CASE_STUDENT && !isCommunicationPage() && !posting.conversation) {
+@if (shouldShowTagSelector()) {

Also applies to: 23-32

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc01b6 and 254aabf.

📒 Files selected for processing (6)
  • src/main/webapp/app/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.ts (4 hunks)
  • src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.html (2 hunks)
  • src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.component.ts (2 hunks)
  • src/main/webapp/app/shared/metis/posting-footer/posting-footer.component.ts (1 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 (3 hunks)
  • src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts (6 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/main/webapp/app/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-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/shared/metis/posting-create-edit-modal/post-create-edit-modal/post-create-edit-modal.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/posting-footer/posting-footer.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-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.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/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/main/webapp/app/shared/metis/posting-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-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

🪛 GitHub Actions: Test
src/test/javascript/spec/component/shared/metis/postings-create-edit-modal/answer-post-create-edit-modal/answer-post-create-edit-modal.component.spec.ts

[error] 19-19: 'viewContainerRef' is declared but its value is never read.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (1)
src/test/javascript/spec/component/shared/metis/postings-footer/posting-footer.component.spec.ts (1)

Line range hint 110-116: LGTM! Test coverage for signal behavior.

The test case properly verifies that the container is cleared on component destruction, which is crucial for preventing memory leaks when using signals.

Copy link
Contributor

@asliayk asliayk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested on ts1, everything works as expected

Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS1. Works as expected

Copy link

@Cathy0123456789 Cathy0123456789 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS1. Everything works as expected

Copy link

@flbrgit flbrgit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS1, everything worked as fine as before

Copy link
Contributor

@PaRangger PaRangger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on TS1, everything still works as it did before. Code LGTM (left a small comment - not sure which way is preffered in the end) ✅

@krusche krusche added this to the 7.9.1 milestone Jan 27, 2025
@krusche krusche changed the title Communicaition: Migrate client code for edit modals of Posts Development: Migrate client code for edit modals of posts Jan 27, 2025
@krusche krusche merged commit a98da8c into develop Jan 27, 2025
47 of 69 checks passed
@krusche krusche deleted the chore/communication/create-edit-modal-migration branch January 27, 2025 21:18
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 to merge tests
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

8 participants