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

Assessment: Fix an issue where grading criteria are not applied correctly on drag and drop #10127

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

Conversation

chrisknedl
Copy link
Contributor

@chrisknedl chrisknedl commented Jan 11, 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 a test related to the feature while following the test guidelines.
  • I documented the TypeScript code using JSDoc style.

Motivation and Context

Closes #9979.

Description

The current issue actually stems from another bugfix that solved a problem where a drag and drop of the assessment criteria caused duplicates (#8908). The problem was that, due to event bubbling, the drop event was triggered twice when a new grading criteria was dropped on an existing unreferenced feedback item, namely in the unreferenced-feedback.component.html and unreferenced-feedback-detail.component.html files. The solution is to call event.stopPropagation() on the sub-component to make sure that only the intended event handler is executed.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Exercise with manual assessment, due date in the future and at least one grading instruction/criterion
  1. Log in to Artemis
  2. Participate in the exercise, wait until the due date passed
  3. Start assessing your participation
  4. Make sure that the bugs described in File upload exercises: Drag and Drop feedback duplicates when applied to additional feedback #8908 and Assessment: Cannot drag and drop structured assessment criteria under certain circumstances  #9979 can't be replicated anymore

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

Summary by CodeRabbit

  • Bug Fixes

    • Improved event handling for feedback updates to prevent unintended event propagation.
    • Enhanced feedback validation to ensure accurate assessment creation.
  • Refactor

    • Streamlined feedback management logic by removing unnecessary tracking variables.
    • Introduced dedicated feedback validation method.
  • Tests

    • Updated test suite for unreferenced feedback component.
    • Added new stub component for more precise testing.
    • Improved test case scenarios for feedback interactions.

@chrisknedl chrisknedl added enhancement tests client Pull requests that update TypeScript code. (Added Automatically!) bugfix assessment Pull requests that affect the corresponding module labels Jan 11, 2025
@chrisknedl chrisknedl self-assigned this Jan 11, 2025
@github-actions github-actions bot removed the assessment Pull requests that affect the corresponding module label Jan 11, 2025
@chrisknedl chrisknedl added the assessment Pull requests that affect the corresponding module label Jan 11, 2025
@chrisknedl chrisknedl marked this pull request as ready for review January 11, 2025 12:03
@chrisknedl chrisknedl requested a review from a team as a code owner January 11, 2025 12:03
@github-actions github-actions bot added ready for review and removed assessment Pull requests that affect the corresponding module labels Jan 11, 2025
@chrisknedl chrisknedl added the assessment Pull requests that affect the corresponding module label Jan 11, 2025
Copy link

coderabbitai bot commented Jan 11, 2025

Walkthrough

The pull request introduces changes to enhance the drag-and-drop functionality for structured assessment criteria within the feedback management system. Key modifications include the addition of event.stopPropagation() in the UnreferencedFeedbackDetailComponent to prevent event bubbling during feedback updates, and the introduction of a dedicated validateFeedback() method in the UnreferencedFeedbackComponent for improved validation of feedback entries. Additionally, the test files have been updated to reflect these changes, ensuring proper validation and interaction of components.

Changes

File Change Summary
.../unreferenced-feedback-detail.component.ts Added event.stopPropagation() to prevent event bubbling during feedback drop
.../unreferenced-feedback.component.ts Removed feedbackDetailChanges property; added validateFeedback() method for improved feedback validation
.../unreferenced-feedback.component.spec.ts Updated test mocking, modified feedback update spy, added new test case for feedback replacement
.../loading-indicator-container-stub.component.ts Consolidated Angular core imports
.../unreferenced-feedback-detail-stub.component.ts Created new stub component for testing with input properties and event emitters

Assessment against linked issues

Objective Addressed Explanation
Drag and drop of assessment criteria
Consistent feedback addition
Works regardless of previous text input

Possibly related PRs

Suggested Labels

ready to merge, assessment

Suggested Reviewers

  • EneaGore
  • krusche
  • LeonWehrhahn
  • HawKhiem
  • b-fein

📜 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 3890193 and ffaeb5c.

📒 Files selected for processing (1)
  • src/test/javascript/spec/component/shared/unreferenced-feedback.component.spec.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/javascript/spec/component/shared/unreferenced-feedback.component.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: server-tests
  • GitHub Check: client-tests-selected
  • GitHub Check: client-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: 0

🔭 Outside diff range comments (1)
src/main/webapp/app/exercises/shared/unreferenced-feedback/unreferenced-feedback.component.ts (1)

Line range hint 134-142: Add event propagation handling to prevent duplicate events.

According to the PR objectives, the issue involves event bubbling causing duplicate grading criteria. Add event.stopPropagation() to prevent the event from bubbling up and triggering multiple handlers.

 createAssessmentOnDrop(event: Event) {
+    event.stopPropagation();
     this.addUnreferencedFeedback();
     const newFeedback: Feedback | undefined = this.unreferencedFeedback.last();
     if (newFeedback) {
         this.structuredGradingCriterionService.updateFeedbackWithStructuredGradingInstructionEvent(newFeedback, event);
         this.updateFeedback(newFeedback);
     }
 }
🧹 Nitpick comments (5)
src/main/webapp/app/exercises/shared/unreferenced-feedback/unreferenced-feedback.component.ts (4)

Line range hint 44-58: LGTM with minor suggestions for improvement.

The validation logic is well-structured with clear documentation. Consider these enhancements:

  1. Extract undefined check into a type guard
  2. Use number.isFinite() for more precise numeric validation
 validateFeedback() {
     if (!this.unreferencedFeedback || this.unreferencedFeedback.length === 0) {
         this.assessmentsAreValid = false;
         return;
     }
     for (const feedback of this.unreferencedFeedback) {
-        if (feedback.credits == undefined || isNaN(feedback.credits)) {
+        if (!this.isValidCredits(feedback.credits)) {
             this.assessmentsAreValid = false;
             return;
         }
     }
     this.assessmentsAreValid = true;
 }

+private isValidCredits(credits: number | undefined): credits is number {
+    return credits !== undefined && Number.isFinite(credits);
+}

Line range hint 35-44: Consider emitting changes after validation.

The event emission should occur after validation to ensure subscribers receive a valid state.

 public deleteFeedback(feedbackToDelete: Feedback): void {
     const indexToDelete = this.unreferencedFeedback.indexOf(feedbackToDelete);
     this.unreferencedFeedback.splice(indexToDelete, 1);
-    this.feedbacksChange.emit(this.unreferencedFeedback);
     this.validateFeedback();
+    this.feedbacksChange.emit(this.unreferencedFeedback);
 }

Line range hint 63-74: Consider emitting changes after validation.

Similar to deleteFeedback, move the event emission after validation to ensure subscribers receive a valid state.

 updateFeedback(feedback: Feedback) {
     const indexToUpdate = this.unreferencedFeedback.indexOf(feedback);
     if (indexToUpdate < 0) {
         this.unreferencedFeedback.push(feedback);
     } else {
         this.unreferencedFeedback[indexToUpdate] = feedback;
     }
     this.validateFeedback();
-    this.feedbacksChange.emit(this.unreferencedFeedback);
+    if (this.assessmentsAreValid) {
+        this.feedbacksChange.emit(this.unreferencedFeedback);
+    }
 }

Line range hint 1-142: Consider implementing OnDestroy for proper cleanup.

To prevent potential memory leaks, implement the OnDestroy interface to clean up event listeners and subscriptions.

-export class UnreferencedFeedbackComponent {
+export class UnreferencedFeedbackComponent implements OnDestroy {
+    ngOnDestroy(): void {
+        // Clean up any subscriptions or event listeners
+        this.feedbacksChange.complete();
+        this.onAcceptSuggestion.complete();
+        this.onDiscardSuggestion.complete();
+    }
src/test/javascript/spec/helpers/stubs/unreferenced-feedback-detail-stub.component.ts (1)

9-19: Consider adding type safety for boolean inputs.

While the implementation is correct, consider initializing boolean inputs with default values for better type safety.

-    @Input() isSuggestion: boolean;
-    @Input() public readOnly: boolean;
-    @Input() highlightDifferences: boolean;
-    @Input() useDefaultFeedbackSuggestionBadgeText: boolean;
+    @Input() isSuggestion = false;
+    @Input() public readOnly = false;
+    @Input() highlightDifferences = false;
+    @Input() useDefaultFeedbackSuggestionBadgeText = false;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e043031 and 9f47b23.

📒 Files selected for processing (5)
  • src/main/webapp/app/assessment/unreferenced-feedback-detail/unreferenced-feedback-detail.component.ts (1 hunks)
  • src/main/webapp/app/exercises/shared/unreferenced-feedback/unreferenced-feedback.component.ts (1 hunks)
  • src/test/javascript/spec/component/shared/unreferenced-feedback.component.spec.ts (4 hunks)
  • src/test/javascript/spec/helpers/stubs/loading-indicator-container-stub.component.ts (1 hunks)
  • src/test/javascript/spec/helpers/stubs/unreferenced-feedback-detail-stub.component.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/test/javascript/spec/helpers/stubs/loading-indicator-container-stub.component.ts
🧰 Additional context used
📓 Path-based instructions (4)
src/main/webapp/app/assessment/unreferenced-feedback-detail/unreferenced-feedback-detail.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/exercises/shared/unreferenced-feedback/unreferenced-feedback.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/unreferenced-feedback.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/helpers/stubs/unreferenced-feedback-detail-stub.component.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}}

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: client-tests-selected
  • GitHub Check: client-tests
  • GitHub Check: server-tests
  • GitHub Check: Build and Push Docker Image
  • GitHub Check: Analyse
  • GitHub Check: Mend Security Check
🔇 Additional comments (6)
src/test/javascript/spec/helpers/stubs/unreferenced-feedback-detail-stub.component.ts (2)

4-8: LGTM! Well-structured stub component.

The component follows Angular style guidelines with proper selector naming and minimal template implementation.


21-24: LGTM! Correct event handling implementation.

The updateFeedbackOnDrop method correctly stops event propagation, matching the behavior of the actual component.

src/main/webapp/app/assessment/unreferenced-feedback-detail/unreferenced-feedback-detail.component.ts (1)

79-82: LGTM! Correct fix for event bubbling.

The addition of event.stopPropagation() properly addresses the issue of duplicate grading criteria creation by preventing the drop event from bubbling up to parent components.

Let's verify there are no other drop handlers in parent components that might be affected:

✅ Verification successful

Verified: Event propagation stop is safe and correct

The event.stopPropagation() addition is safe because:

  • The drop handler exists only at the root level of the component
  • No other components in the assessment directory rely on this drop event
  • No nested handlers within the component are affected
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other drop event handlers in parent components
rg -l '\(drop\)=' src/main/webapp/app/assessment/

Length of output: 155


Script:

#!/bin/bash
# Check the template file content
cat src/main/webapp/app/assessment/unreferenced-feedback-detail/unreferenced-feedback-detail.component.html

Length of output: 5416

src/test/javascript/spec/component/shared/unreferenced-feedback.component.spec.ts (3)

19-19: LGTM! Proper test setup with stub component.

The test module correctly uses the new stub component instead of MockComponent, providing better control over the test scenarios.


91-95: LGTM! Clear and focused mock implementation.

The mock implementation directly updates the feedback object, making the test behavior clear and maintainable.


119-136: LGTM! Comprehensive test for event propagation.

The test case thoroughly verifies that:

  1. The drop event is handled by the detail component
  2. Event propagation is stopped
  3. No duplicate feedback is created

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 11, 2025
@chrisknedl
Copy link
Contributor Author

chrisknedl commented Jan 11, 2025

github-actions bot removed the assessment label

Third time's the charm. If github-actions decides one more time that the assessment label does not belong here, then I'll give up.

@chrisknedl chrisknedl changed the title Assessment: Fix an issue where grading criteria were not created correctly on drag and drop Assessment: Fix an issue where grading criteria are not created correctly on drag and drop Jan 11, 2025
@vinceclifford vinceclifford temporarily deployed to artemis-test5.artemis.cit.tum.de January 12, 2025 09:50 — with GitHub Actions Inactive
vinceclifford
vinceclifford previously approved these changes Jan 12, 2025
Copy link

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

b-fein
b-fein previously approved these changes Jan 14, 2025
@github-actions github-actions bot removed the assessment Pull requests that affect the corresponding module label Jan 16, 2025
sawys777
sawys777 previously approved these changes Jan 17, 2025
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 TS1, everything works as expected

Copy link
Contributor

@SimonEntholzer SimonEntholzer left a comment

Choose a reason for hiding this comment

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

Code

Copy link

@SindiBuklaji SindiBuklaji 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 TS2 and it works as excepted.

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!) enhancement lock:artemis-test2 ready to merge tests
Projects
Status: Developer Approved
Development

Successfully merging this pull request may close these issues.

Assessment: Cannot drag and drop structured assessment criteria under certain circumstances
10 participants