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: Update thread when switching reply context #9842

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

Conversation

badkeyy
Copy link
Contributor

@badkeyy badkeyy commented Nov 21, 2024

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 principle of data economy for all client-server REST calls.
  • 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 guidelines.
  • I added authorities to all new routes and checked the course groups for displaying navigation elements (links, buttons).
  • I documented the TypeScript code using JSDoc style.
  • I added multiple screenshots/screencasts of my UI changes.
  • I translated all newly inserted strings into English and German.

Motivation and Context

When using the “Show X Replies” button in the Communication section to open threads, switching between threads does not update the displayed chat text in the thread view. Instead, the chat text from the first opened thread remains visible, which can lead to confusion.
Fixes #9754 and #9803

Description

After many hours of debugging I found that a ngOnChanges lifecycle hook in PostingContentPartComponent was missing. I added the hook and it now the threads work as expected.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Course with existing communications
  1. Log in to Artemis
  2. Navigate to Course Communication section
  3. Click on “Show X Replies” to open a thread.
  4. Switch to another thread using the same method.
  5. Observe that the chat text in the thread view does update

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

Screenshots

video

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced the PostingContentPart component to react dynamically to changes in input properties, ensuring content is processed and updated in real-time.

@badkeyy badkeyy requested a review from a team as a code owner November 21, 2024 03:19
@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Nov 21, 2024
Copy link

coderabbitai bot commented Nov 21, 2024

Walkthrough

The changes implement the OnChanges lifecycle hook in the PostingContentPartComponent class, enabling it to react to changes in the postingContentPart input property. A new ngOnChanges method is added, which invokes the processContent method when the input changes and is not the first change. The ngOnInit method is also updated to specify a return type of void. The overall structure of the component remains unchanged.

Changes

File Change Summary
src/main/webapp/app/shared/metis/posting-content/posting-content-part/posting-content-part.components.ts - Updated class to implement OnChanges.
- Added ngOnChanges() method to handle input changes.
- Changed ngOnInit() to specify return type as void.

Assessment against linked issues

Objective Addressed Explanation
Ensure thread view updates correctly when switching threads (#9754)

Possibly related PRs

Suggested labels

tests, component:Communication, ready to merge

Suggested reviewers

  • krusche
  • SimonEntholzer
  • florian-glombik
  • PaRangger
  • HawKhiem

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1552b59 and e233630.

📒 Files selected for processing (1)
  • src/main/webapp/app/shared/metis/posting-content/posting-content-part/posting-content-part.components.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/webapp/app/shared/metis/posting-content/posting-content-part/posting-content-part.components.ts

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

🧹 Outside diff range and nitpick comments (1)
src/main/webapp/app/shared/metis/posting-content/posting-content-part/posting-content-part.components.ts (1)

Line range hint 94-102: Prevent potential memory leaks from dialog references.

The dialog opening implementation could lead to memory leaks if the component is frequently recreated without proper cleanup.

Consider tracking and cleaning up dialog references:

+    private dialogRef: MatDialogRef<EnlargeSlideImageComponent> | null = null;
+
     enlargeImage(slideToReference: string) {
-        this.dialog.open(EnlargeSlideImageComponent, {
+        this.dialogRef = this.dialog.open(EnlargeSlideImageComponent, {
             data: { slideToReference },
             maxWidth: '95vw',
         });
     }
+
+    ngOnDestroy(): void {
+        if (this.dialogRef) {
+            this.dialogRef.close();
+        }
+    }

Don't forget to implement OnDestroy in the component signature:

-export class PostingContentPartComponent implements OnInit, OnChanges {
+export class PostingContentPartComponent implements OnInit, OnChanges, OnDestroy {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5024862 and fe673fb.

📒 Files selected for processing (1)
  • src/main/webapp/app/shared/metis/posting-content/posting-content-part/posting-content-part.components.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/app/shared/metis/posting-content/posting-content-part/posting-content-part.components.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/shared/metis/posting-content/posting-content-part/posting-content-part.components.ts (2)

1-1: LGTM! Clean implementation of OnChanges.

The addition of OnChanges to both the imports and class signature follows Angular best practices.

Also applies to: 29-29


29-31: Verify component usage in templates.

While the implementation looks correct, let's verify that the component is properly bound in parent templates.

✅ Verification successful

Component bindings and change detection are properly implemented

Based on the verification results:

  • The component is correctly used in templates with proper property bindings ([postingContentPart])
  • Event emitters are properly bound in parent templates (userReferenceClicked)
  • Component is well-tested with various PostingContentPart configurations as shown in the spec files
  • The implementation with OnChanges and Input decorator will ensure proper change detection for thread view updates
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of posting-content-part component in templates
rg -t html "jhi-posting-content-part.*\[postingContentPart\]" src/main/webapp/

# Search for any direct manipulation of postingContentPart in parent components
ast-grep --pattern 'postingContentPart = $_' src/main/webapp/

Length of output: 144


Script:

#!/bin/bash
# Search for usage of posting-content-part component with more flexible pattern
rg -t html "jhi-posting-content-part" -A 3 src/main/webapp/

# Search for PostingContentPart type usage in components
ast-grep --pattern 'class $_ {
  $$$
  postingContentPart: PostingContentPart
  $$$
}'

# Search for any assignments to postingContentPart property
ast-grep --pattern '$_.postingContentPart = $_'

Length of output: 7789


Script:

#!/bin/bash
# Let's check the parent component implementation
ast-grep --pattern 'class PostingContentComponent {
  $$$
}'

# Also check for OnChanges implementation in the parent
ast-grep --pattern 'implements OnChanges {
  $$$
  ngOnChanges($_) {
    $$$
  }
  $$$
}'

Length of output: 278

@badkeyy badkeyy changed the title Communication: Implement ngOnChanges lifecycle hook in PostingContentPartComponent Communication: Update thread when switching reply context Nov 21, 2024
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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fe673fb and f6f4c8d.

📒 Files selected for processing (1)
  • src/main/webapp/app/shared/metis/posting-content/posting-content-part/posting-content-part.components.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/app/shared/metis/posting-content/posting-content-part/posting-content-part.components.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/posting-content/posting-content-part/posting-content-part.components.ts (1)

57-59: ⚠️ Potential issue

Prevent potential memory leaks in ngOnChanges

While the implementation works, it could lead to unnecessary processing and potential memory leaks if postingContentPart contains large content or complex objects. The component should clean up any subscriptions or large objects when destroyed.

Let's verify if there are any subscriptions or event listeners that need cleanup:

Consider implementing OnDestroy:

-export class PostingContentPartComponent implements OnInit, OnChanges {
+export class PostingContentPartComponent implements OnInit, OnChanges, OnDestroy {
+    private destroy$ = new Subject<void>();
+
+    ngOnDestroy(): void {
+        this.destroy$.next();
+        this.destroy$.complete();
+    }

coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 21, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Nov 22, 2024
@SimonEntholzer SimonEntholzer changed the title Communication: Update thread when switching reply context Communication: Update thread when switching reply context Nov 25, 2024
BBesrour
BBesrour previously approved these changes Nov 26, 2024
Copy link
Member

@BBesrour BBesrour left a comment

Choose a reason for hiding this comment

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

code lgtm. Just a small nitpick

…nt-part/posting-content-part.components.ts

Co-authored-by: Mohamed Bilel Besrour <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix client Pull requests that update TypeScript code. (Added Automatically!) ready for review small
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

Thread view shows message from wrong thread
10 participants