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

Allow more flexible reuse of annotations across different courses/exercises #5648

Merged
merged 6 commits into from
Aug 1, 2024

Conversation

jorg-vr
Copy link
Contributor

@jorg-vr jorg-vr commented Jun 26, 2024

This pull request allows updating a saved annotation such that it is reusable in all your courses and/or for all exercises within a course.

The default values remain the limited scope. A user has to explicitly make an annotation more general.

This setting is currently only available on edit and not on create.
This avoids making the interface to save an annotation more complex at the cost of making the feature less discoverable. I would suggest releasing like this and improving discoverability at a later stage after receiving some feedback from users.

image
image

Closes #4993

@jorg-vr jorg-vr added the feature New feature or request label Jun 26, 2024
@jorg-vr jorg-vr self-assigned this Jun 26, 2024
@pdawyndt pdawyndt changed the title Allow more flexible reuse of annotaions accros different courses/exercises Allow more flexible reuse of annotations across different courses/exercises Jun 26, 2024
@jorg-vr jorg-vr marked this pull request as ready for review June 27, 2024 07:39
@jorg-vr jorg-vr requested a review from bmesuere as a code owner June 27, 2024 07:39
@bmesuere
Copy link
Member

@coderabbitai review

Copy link

coderabbitai bot commented Jul 29, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

coderabbitai bot commented Jul 29, 2024

Walkthrough

The recent changes enhance the flexibility and robustness of the SavedAnnotation model and related components. Key updates include allowing nullable associations with courses and exercises, improving conditional rendering in views, and expanding filtering capabilities. These modifications aim to support annotations that can be relevant across different contexts, enhancing usability for users managing saved annotations.

Changes

File(s) Change Summary
app/assets/javascripts/components/... Conditional rendering for filter buttons based on data presence.
app/controllers/saved_annotations_controller.rb Added instance variables for courses and exercises relevant to the current user.
app/javascript/packs/saved_annotation.js Imported a new component, datalist_input, for enhanced functionality.
app/models/activity_read_state.rb, app/models/submission.rb Added series_id attribute to both models for better data organization.
app/models/saved_annotation.rb Made exercise and course associations optional; updated filtering scopes accordingly.
app/policies/saved_annotation_policy.rb Expanded permitted attributes to include course_id and exercise_id.
app/views/saved_annotations/edit.html.erb Introduced input fields for selecting courses and exercises in the edit form.
app/views/saved_annotations/index.json.jbuilder Conditional checks added before JSON rendering for exercises and courses.
app/views/saved_annotations/show.html.erb Refactored usage information display with conditional rendering based on associated objects.
config/locales/views/saved_annotations/... Updated localization keys for clarity and added placeholders for courses and exercises.
db/migrate/..., db/schema.rb Migration to allow null values for exercise_id and course_id; updated schema accordingly.
test/factories/saved_annotations.rb, test/factories/submissions.rb Updated factory definitions to reflect schema changes (nullable fields).
test/models/saved_annotation_test.rb Added test cases for filtering annotations with nullable associations.

Assessment against linked issues

Objective Addressed Explanation
More flexible scoping for saved annotations (#4993)
Support annotations relevant to multiple contexts (#4993)
Allow saved annotations to exist without mandatory links

🐰 In the meadow, where rabbits play,
New annotations brighten the day.
With courses and exercises, oh so fine,
Flexibility hops in, how divine!
Nulls are welcome, no more dread,
A joyful update, let’s go ahead! 🌸


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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, codebase verification and nitpick comments (1)
db/migrate/20240626093130_allow_null_for_saved_annotation_exercise_and_course.rb (1)

1-1: Use a more descriptive class name.

The class name should be more descriptive to reflect the changes made by the migration.

-class AllowNullForSavedAnnotationExerciseAndCourse < ActiveRecord::Migration[7.1]
+class ChangeSavedAnnotationsToAllowNullForExerciseAndCourse < ActiveRecord::Migration[7.1]
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between aad8e5d and c9450c4.

Files selected for processing (19)
  • app/assets/javascripts/components/saved_annotations/saved_annotation_list.ts (1 hunks)
  • app/controllers/saved_annotations_controller.rb (2 hunks)
  • app/javascript/packs/saved_annotation.js (1 hunks)
  • app/models/activity_read_state.rb (1 hunks)
  • app/models/saved_annotation.rb (2 hunks)
  • app/models/submission.rb (1 hunks)
  • app/policies/saved_annotation_policy.rb (1 hunks)
  • app/views/saved_annotations/edit.html.erb (1 hunks)
  • app/views/saved_annotations/index.json.jbuilder (1 hunks)
  • app/views/saved_annotations/show.html.erb (1 hunks)
  • config/locales/views/saved_annotations/en.yml (1 hunks)
  • config/locales/views/saved_annotations/nl.yml (1 hunks)
  • db/migrate/20240626093130_allow_null_for_saved_annotation_exercise_and_course.rb (1 hunks)
  • db/schema.rb (4 hunks)
  • test/factories/saved_annotations.rb (1 hunks)
  • test/factories/submissions.rb (1 hunks)
  • test/models/activity_read_state_test.rb (1 hunks)
  • test/models/saved_annotation_test.rb (2 hunks)
  • test/models/submission_test.rb (1 hunks)
Files skipped from review due to trivial changes (2)
  • app/javascript/packs/saved_annotation.js
  • test/models/submission_test.rb
Additional context used
GitHub Check: codecov/patch
app/controllers/saved_annotations_controller.rb

[warning] 88-89: app/controllers/saved_annotations_controller.rb#L88-L89
Added lines #L88 - L89 were not covered by tests

Additional comments not posted (37)
db/migrate/20240626093130_allow_null_for_saved_annotation_exercise_and_course.rb (1)

2-5: LGTM! Ensure the migration is reversible.

The migration correctly allows null values for exercise_id and course_id. Ensure you have a down method if needed.

test/factories/saved_annotations.rb (1)

9-10: Ensure consistency with schema changes.

The exercise_id and course_id fields are now nullable, which is consistent with the migration changes.

app/policies/saved_annotation_policy.rb (1)

41-41: LGTM! Ensure proper validation.

The permitted_attributes method now includes course_id and exercise_id, which aligns with the new requirements.

app/views/saved_annotations/index.json.jbuilder (2)

9-14: Good practice: Conditional check for exercise presence.

The check ensures robustness by preventing potential errors from accessing properties of nil objects.


16-21: Good practice: Conditional check for course presence.

The check ensures robustness by preventing potential errors from accessing properties of nil objects.

config/locales/views/saved_annotations/en.yml (2)

7-9: Improved clarity: Split usage_info_html into distinct keys.

The restructuring enhances readability and maintainability of the localization strings.


17-18: Enhanced UI: Added course_placeholder and exercise_placeholder.

The additions clarify the reusability of comments across courses and exercises, improving the user interface.

config/locales/views/saved_annotations/nl.yml (2)

7-9: Improved clarity: Split usage_info_html into distinct keys.

The restructuring enhances readability and maintainability of the localization strings.


17-18: Enhanced UI: Added course_placeholder and exercise_placeholder.

The additions clarify the reusability of comments across courses and exercises, improving the user interface.

app/models/saved_annotation.rb (4)

20-20: Verify the impact of making exercise association optional.

Making the exercise association optional allows for more flexible reuse of annotations. Ensure that this change does not introduce any unintended side effects in other parts of the application.

Verification successful

Verify the impact of making exercise association optional.

Making the exercise association optional allows for more flexible reuse of annotations. Ensure that this change does not introduce any unintended side effects in other parts of the application.


Verified: The impact of making exercise association optional.

The saved_annotation.rb model does not have validations dependent on the presence of exercise, and the by_exercise scope already handles cases where exercise_id is nil. Therefore, making the exercise association optional does not introduce any unintended side effects.

  • app/models/saved_annotation.rb: No issues found.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of making `exercise` association optional.

# Test: Search for the usage of `exercise` association in the codebase. Expect: No unintended side effects.
rg --type ruby -A 5 $'belongs_to :exercise'

Length of output: 1218


Script:

#!/bin/bash
# Description: Verify the impact of making `exercise` association optional in saved_annotation.rb.

# Test: Search for validations in saved_annotation.rb that depend on the presence of exercise.
rg 'validates' app/models/saved_annotation.rb

# Test: Search for business logic in saved_annotation.rb that depends on the presence of exercise.
rg 'exercise' app/models/saved_annotation.rb

Length of output: 341


21-21: Verify the impact of making course association optional.

Making the course association optional allows for more flexible reuse of annotations. Ensure that this change does not introduce any unintended side effects in other parts of the application.

Verification successful

Verified the impact of making course association optional.

The course association in saved_annotation.rb is used in a manner that already accounts for the possibility of it being nil. Thus, making it optional should not introduce any unintended side effects.

  • scope :by_course, ->(course_id) { where(course_id: course_id).or(where(course_id: nil)) }
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of making `course` association optional.

# Test: Search for the usage of `course` association in the codebase. Expect: No unintended side effects.
rg --type ruby -A 5 $'belongs_to :course'

Length of output: 3052


Script:

#!/bin/bash
# Description: Verify the impact of making `course` association optional in saved_annotation.rb.

# Test: Search for the usage of `course` association in saved_annotation.rb. Expect: No unintended side effects.
rg --type ruby 'course' app/models/saved_annotation.rb

Length of output: 213


27-27: Verify the functionality of the updated by_course scope.

The updated by_course scope now includes conditions that account for null values, allowing for more flexible querying. Ensure that this updated scope works as intended.

Verification successful

Verify the functionality of the updated by_course scope.

The updated by_course scope now includes conditions that account for null values, allowing for more flexible querying. Ensure that this updated scope works as intended by checking for relevant test cases.


Verify the functionality of the updated by_course scope.

The updated by_course scope now includes conditions that account for null values, allowing for more flexible querying. Ensure that this updated scope works as intended by checking for relevant test cases.


The functionality of the updated by_course scope is verified.

The test cases in test/models/saved_annotation_test.rb confirm that the by_course scope includes annotations with the specified course and excludes those without it, covering the new condition for null values.

  • test/models/saved_annotation_test.rb
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the functionality of the updated `by_course` scope.

# Test: Search for the usage of `by_course` scope in the codebase. Expect: No unintended side effects.
rg --type ruby -A 5 $'scope :by_course'

Length of output: 8196


Script:

#!/bin/bash
# Description: Verify the functionality of the updated `by_course` scope by finding related test cases.

# Test: Search for test cases related to the `by_course` scope in the `SavedAnnotationsController`.
rg --type ruby 'SavedAnnotationsController' -A 5 | rg 'by_course'

Length of output: 63


Script:

#!/bin/bash
# Description: Verify the functionality of the updated `by_course` scope by finding related test cases.

# Test: Search for test files related to `saved_annotations` and look for references to `by_course`.
fd -t f 'saved_annotation' | xargs rg 'by_course'

Length of output: 547


28-28: Verify the functionality of the updated by_exercise scope.

The updated by_exercise scope now includes conditions that account for null values, allowing for more flexible querying. Ensure that this updated scope works as intended.

test/factories/submissions.rb (1)

17-17: Verify the impact of adding series_id attribute.

The addition of the series_id attribute enhances the data model for submissions. Ensure that this change does not introduce any unintended side effects in other parts of the application.

app/views/saved_annotations/show.html.erb (6)

15-15: Verify the existence and correctness of the t ".usage_info" translation key.

The addition of the t ".usage_info" translation key simplifies the display of usage information. Ensure that this translation key is correctly defined.

Verification successful

The t ".usage_info" translation key is correctly defined.

The translation key usage_info is present in both config/locales/views/saved_annotations/en.yml and config/locales/views/saved_annotations/nl.yml, with appropriate translations.

  • config/locales/views/saved_annotations/en.yml: usage_info: This comment can be reused on all submissions
  • config/locales/views/saved_annotations/nl.yml: usage_info: Deze opmerking kan worden hergebruikt op alle ingediende oplossingen
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and correctness of the `t ".usage_info"` translation key.

# Test: Search for the definition of `".usage_info"` translation key. Expect: Correct definition.
rg --type yaml $'usage_info'

Length of output: 270


17-20: Verify the existence and correctness of the t ".exercise_info_html" translation key.

The addition of the t ".exercise_info_html" translation key ensures that exercise-specific information is displayed correctly. Ensure that this translation key is correctly defined.

Verification successful

The t ".exercise_info_html" translation key is correctly defined and used.

The translation key exercise_info_html exists in the locale files nl.yml and en.yml, ensuring that exercise-specific information is displayed correctly in both Dutch and English.

  • config/locales/views/saved_annotations/nl.yml
  • config/locales/views/saved_annotations/en.yml
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and correctness of the `t ".exercise_info_html"` translation key.

# Test: Search for the definition of `".exercise_info_html"` translation key. Expect: Correct definition.
rg --type yaml $'exercise_info_html'

Length of output: 309


23-26: Verify the existence and correctness of the t ".course_info_html" translation key.

The addition of the t ".course_info_html" translation key ensures that course-specific information is displayed correctly. Ensure that this translation key is correctly defined.

Verification successful

The t ".course_info_html" translation key is correctly defined.

The translation key course_info_html exists and is properly defined in the following files:

  • config/locales/views/saved_annotations/nl.yml
  • config/locales/views/saved_annotations/en.yml

Both definitions include the necessary placeholders for course_path and course_name.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and correctness of the `t ".course_info_html"` translation key.

# Test: Search for the definition of `".course_info_html"` translation key. Expect: Correct definition.
rg --type yaml $'course_info_html'

Length of output: 288


27-27: Verify the existence and correctness of the t ".count_info_html" translation key.

The addition of the t ".count_info_html" translation key ensures that the count information is displayed correctly. Ensure that this translation key is correctly defined.

Verification successful

The t ".count_info_html" translation key is correctly defined.

The count_info_html translation key exists in both the Dutch and English locale files, ensuring that the count information will be displayed correctly in the show.html.erb view.

  • config/locales/views/saved_annotations/nl.yml: count_info_html: Deze opmerking wordt <strong>%{count}</strong> keer gebruikt.
  • config/locales/views/saved_annotations/en.yml: count_info_html: This comment is used %{count} times.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and correctness of the `t ".count_info_html"` translation key.

# Test: Search for the definition of `".count_info_html"` translation key. Expect: Correct definition.
rg --type yaml $'count_info_html'

Length of output: 269


16-21: Verify the functionality of the conditional block for @saved_annotation.exercise.

The conditional block ensures that exercise-specific information is displayed only when an exercise is present. Ensure that this conditional block works as intended.

Verification successful

Verify the functionality of the conditional block for @saved_annotation.exercise.

The conditional block ensures that exercise-specific information is displayed only when an exercise is present. The usage of @saved_annotation.exercise in the controller confirms that the exercise attribute is being set correctly.

  • app/controllers/saved_annotations_controller.rb: Multiple instances where @saved_annotation.exercise is used, ensuring it is correctly assigned.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the functionality of the conditional block for `@saved_annotation.exercise`.

# Test: Search for the usage of `@saved_annotation.exercise` in the codebase. Expect: No unintended side effects.
rg --type ruby -A 5 $'@saved_annotation.exercise'

Length of output: 48


Script:

#!/bin/bash
# Description: Search for the usage of `@saved_annotation` in the codebase to understand its context and usage.

# Test: Search for the usage of `@saved_annotation` in the codebase.
rg --type ruby -A 5 $'@saved_annotation'

Length of output: 5771


22-27: Verify the functionality of the conditional block for @saved_annotation.course.

The conditional block ensures that course-specific information is displayed only when a course is present. Ensure that this conditional block works as intended.

Verification successful

The conditional block for @saved_annotation.course works as intended.

The search results confirm that the conditional block ensures course-specific information is displayed only when a course is present, with no unintended side effects observed.

  • app/views/saved_annotations/show.html.erb: The conditional block checks for the presence of @saved_annotation.course and displays the course information accordingly.
  • app/views/saved_annotations/edit.html.erb: The references to @saved_annotation.course do not impact the conditional block in show.html.erb.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the functionality of the conditional block for `@saved_annotation.course`.

# Test: Search for the usage of `@saved_annotation.course` in the codebase. Expect: No unintended side effects.
rg --type ruby -A 5 $'@saved_annotation.course'

Length of output: 46


Script:

#!/bin/bash
# Description: Verify the functionality of the conditional block for `@saved_annotation.course`.

# Test: Search for the usage of `@saved_annotation.course` in the codebase across different file types.
rg --type-add 'erb:*.{erb,html.erb}' --type-add 'ruby:*.{rb,erb}' -t erb -t ruby -A 5 '@saved_annotation.course'

Length of output: 2433

test/models/saved_annotation_test.rb (3)

9-10: Schema changes approved.

The exercise_id and course_id fields are now nullable, aligning with the PR objectives to allow more flexible reuse of annotations.


22-32: Test case for filtering by course_id approved.

The test case correctly validates that saved annotations with nil values for course_id are included when filtering.


34-44: Test case for filtering by exercise_id approved.

The test case correctly validates that saved annotations with nil values for exercise_id are included when filtering.

test/models/activity_read_state_test.rb (2)

11-11: Schema change approved.

The series_id field is added, aligning with the PR objectives to enhance the data structure.


Line range hint 13-58:
Test cases approved.

The existing test cases are not negatively impacted by the addition of the series_id attribute.

app/models/activity_read_state.rb (2)

11-11: Schema change approved.

The series_id field is added, aligning with the PR objectives to enhance the data structure.


Line range hint 13-57:
Model definitions approved.

The model definitions correctly accommodate the new series_id attribute and the new scope in_series is correctly defined.

app/views/saved_annotations/edit.html.erb (2)

36-43: LGTM!

The new input field for selecting a course is correctly implemented and follows best practices.


44-51: LGTM!

The new input field for selecting an exercise is correctly implemented and follows best practices.

app/assets/javascripts/components/saved_annotations/saved_annotation_list.ts (2)

76-78: LGTM!

The conditional rendering logic for the course filter button is correctly implemented and follows best practices.


79-81: LGTM!

The conditional rendering logic for the exercise filter button is correctly implemented and follows best practices.

app/controllers/saved_annotations_controller.rb (1)

58-59: LGTM!

The new instance variables @courses and @exercises are correctly implemented in the edit method and follow best practices.

app/models/submission.rb (1)

17-17: Verify series_id integration.

The addition of the series_id attribute looks good. Ensure that this attribute is properly integrated into the model's logic and that any necessary validations or associations are added.

db/schema.rb (4)

13-13: Schema version update.

The schema version update to 2024_06_26_093130 is noted and expected with the changes.


85-85: Verify series_id integration in activity_read_states.

The addition of the series_id column looks good. Ensure that this column is properly integrated into the table's logic and that any necessary validations or associations are added.


424-424: Verify exercise_id integration in saved_annotations.

The addition of the exercise_id column looks good. Ensure that this column is properly integrated into the table's logic and that any necessary validations or associations are added.


425-425: Verify course_id integration in saved_annotations.

The addition of the course_id column looks good. Ensure that this column is properly integrated into the table's logic and that any necessary validations or associations are added.

@jorg-vr jorg-vr merged commit 2efb800 into main Aug 1, 2024
12 of 13 checks passed
@jorg-vr jorg-vr deleted the feat/more-flexible-scoping branch August 1, 2024 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

More flexible scoping for saved annotations
2 participants