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: Change posting deletion logic to not abort when deconstructing a post #10073

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

Conversation

badkeyy
Copy link
Contributor

@badkeyy badkeyy commented Dec 23, 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

Proposed by: #9848
Currently when one deletes a message and switches the chat or generally leaves the communication area before the deletion countdown has expired the delete operation gets aborted. In my opinion this should not be the intended behaviour as I as a user expect a message to get deleted when I press the delete button and leave the page.

Description

When the posting gets deconstructed the client now stops the delete timeout and instantly deletes the posting as it would have once the timeout expired

Steps for Testing

Prerequisites:

  • 2 Students
  • Course with communication enabled
  1. Log in to Artemis
  2. Navigate to Course Communication
  3. Post any message
  4. Delete the message and switch to another chat/page etc... before the delete time runs out
  5. Go back to where you originally posted the message and find it to be deleted

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

  • Bug Fixes

    • Improved the post deletion process to ensure posts are deleted correctly when the directive is destroyed or when a delete event occurs.
  • Refactor

    • Streamlined the post deletion logic by centralizing it into a single method for better clarity and maintainability.

@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Dec 23, 2024
@badkeyy badkeyy marked this pull request as ready for review December 23, 2024 14:49
@badkeyy badkeyy requested a review from a team as a code owner December 23, 2024 14:49
Copy link

coderabbitai bot commented Dec 23, 2024

Walkthrough

The pull request introduces a new private method deletePostingWithoutTimeout() in the PostingDirective class within the posting.directive.ts file. This method consolidates the deletion logic for both answer and regular posts. It is called in the ngOnDestroy() lifecycle hook and the onDeleteEvent() method, replacing the previous inline deletion logic. This change enhances code readability and maintainability by reducing duplication.

Changes

File Change Summary
src/main/webapp/app/shared/metis/posting.directive.ts - Added private method deletePostingWithoutTimeout()
- Updated ngOnDestroy() to call the new deletion method
- Refactored onDeleteEvent() to use the new deletion method

Suggested labels

small, bugfix, ready to merge, component:Communication

Suggested reviewers

  • krusche
  • EneaGore
  • asliayk
  • edkaya
  • HawKhiem

Possibly related PRs

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


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.

@badkeyy badkeyy changed the title Communication: Change posting deletion logic to not abort when deconstructing a post Communication: Change posting deletion logic to not abort when deconstructing a post Dec 23, 2024
coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 23, 2024
Copy link

⚠️ Unable to deploy to test servers ⚠️

The docker build needs to run through before deploying.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Dec 25, 2024
@HawKhiem HawKhiem added deploy:artemis-test3 and removed deployment-error Added by deployment workflows if an error occured labels Dec 25, 2024
Copy link

⚠️ Unable to deploy to test servers ⚠️

The docker build needs to run through before deploying.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Dec 25, 2024
@HawKhiem HawKhiem removed the deployment-error Added by deployment workflows if an error occured label Dec 25, 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: 0

🧹 Nitpick comments (2)
src/main/webapp/app/shared/metis/posting.directive.ts (2)

139-145: Consider enhancing error handling and state management.

While the method successfully consolidates the deletion logic, consider these improvements for better robustness:

  1. Add error handling for service calls
  2. Clean up local state after successful deletion
  3. Handle subscription lifecycle

Consider this enhanced implementation:

 private deletePostingWithoutTimeout() {
+    const deleteOperation = this.isAnswerPost
+        ? this.metisService.deleteAnswerPost(this.posting)
+        : this.metisService.deletePost(this.posting);
+
+    deleteOperation.subscribe({
+        next: () => {
+            // Clean up local state
+            this.content = undefined;
+            this.isDeleted = true;
+        },
+        error: (error) => {
+            console.error('Failed to delete posting:', error);
+            this.isDeleted = false;
+        }
+    }).add(() => {
+        // Ensure timers are cleared
+        if (this.deleteTimer) {
+            clearTimeout(this.deleteTimer);
+            this.deleteTimer = undefined;
+        }
+        if (this.deleteInterval) {
+            clearInterval(this.deleteInterval);
+            this.deleteInterval = undefined;
+        }
+    });
-    if (this.isAnswerPost) {
-        this.metisService.deleteAnswerPost(this.posting);
-    } else {
-        this.metisService.deletePost(this.posting);
-    }
 }

139-139: Add JSDoc documentation for the new method.

Following Angular style guide best practices, consider adding JSDoc documentation to describe the method's purpose and behavior.

Add documentation above the method:

+    /**
+     * Immediately deletes the posting without waiting for the deletion timeout.
+     * This is called when the directive is destroyed or when the deletion timer expires.
+     * @private
+     */
     private deletePostingWithoutTimeout() {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 092ef65 and e6b5030.

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

52-52: LGTM! Ensures deletion completion during directive destruction.

The change properly handles the deletion operation when the directive is destroyed, preventing unintended abortion of the deletion process.


76-76: LGTM! Improves code maintainability.

The change centralizes the deletion logic by using the new deletePostingWithoutTimeout method while preserving the existing timer behavior.

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 TS3. Works as described

Copy link

@sawys777 sawys777 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 TS4, everything works as intended

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

Successfully merging this pull request may close these issues.

3 participants