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 2 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 focuses on refactoring the PostingDirective class in the posting.directive.ts file. A new private method deletePostingWithoutTimeout() is introduced to centralize and simplify the post deletion logic. This method is now called from both the ngOnDestroy() lifecycle hook and the onDeleteEvent() method, replacing the previous inline deletion approach and improving code organization and readability.

Changes

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

Suggested labels

small, bugfix, tests, component:Communication

Suggested reviewers

  • EneaGore
  • asliayk
  • SimonEntholzer
  • krusche
  • HawKhiem

Possibly related PRs


📜 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 97c0636 and 092ef65.

📒 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 (3)
src/main/webapp/app/shared/metis/posting.directive.ts (3)

52-52: Ensure the directive destruction aligns with user deletion expectations.

Calling "deletePostingWithoutTimeout()" during "ngOnDestroy()" ensures the posting is deleted once the user navigates away. This change matches the PR objective of preventing an unintentional abort when the user leaves early. It's aligned with the desired behavior—no modifications needed.


139-143: Method naming and unified logic look good.

Introducing "deletePostingWithoutTimeout()" centralizes the logic for deleting answer posts versus regular posts, promoting reusability and code cleanliness. The naming also clearly indicates its function. This adheres to the guidelines (arrow functions aren’t strictly required in this scenario). Implementation is correct as is.


76-76: Confirm user’s ability to cancel deletion after countdown begins.

While this direct call to "deletePostingWithoutTimeout()" is intentional once the timer expires, confirm that there’s no needed mechanism for the user to revert the deletion in the remaining time. Currently, once setTimeout fires at line 76, the post is gone. Make sure that’s acceptable per the requirements.

✅ Verification successful

Let me gather more information about the deletion functionality and user interaction mechanisms.


Let me search specifically for the deletion functionality and any cancel mechanisms in the posting directive.


Based on the code review, I can now generate the final response as I have enough context about the deletion mechanism.

The deletion countdown mechanism is intentionally designed without a cancel option.

The code shows a deliberate implementation where:

  • A 6-second countdown timer is displayed to the user (timeToDeleteInSeconds = 6)
  • An additional 1-second buffer is added to the actual deletion timeout for better UX (deleteTimerInSeconds * 1000 + 1000)
  • The only way to prevent deletion is to act before initiating the deletion process
  • Once the deletion process starts, it's meant to be irreversible as indicated by the direct progression to deletePostingWithoutTimeout()

This is a common UX pattern where brief countdown timers are used to prevent accidental deletions while maintaining a streamlined deletion flow. The absence of a cancel mechanism is intentional and acceptable.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# First, let's look at the full content of the posting directive to understand the deletion flow
rg -l "deletePostingWithoutTimeout" --type ts

# Then get the content of files containing this method
ast-grep --pattern 'deletePostingWithoutTimeout() {
  $$$
}'

# Let's also search for any timeout or timer related code in the same context
rg "setTimeout|clearTimeout" --type ts -B 2 -A 2

# Look for any cancel or revert related functions
rg "cancel|revert|undo" --type ts -B 2 -A 2

Length of output: 66917


Script:

#!/bin/bash
# Get the full content of the posting directive to understand the deletion flow
cat src/main/webapp/app/shared/metis/posting.directive.ts

# Look for any cancel-related functions in the same file
rg "cancel|revert|undo|deletePosting" src/main/webapp/app/shared/metis/posting.directive.ts -A 5 -B 5

Length of output: 7754


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

1 participant