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

Text-exercises: Highlight selected result in result history timeline #9845

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

Conversation

EneaGore
Copy link
Contributor

@EneaGore EneaGore commented Nov 21, 2024

Checklist

General

- [ ] I tested all changes and their related features with all corresponding user types on a test server.

Server

No Server Changes

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.

Changes affecting Programming Exercises

No Changes

Motivation and Context

When using the result history timeline on the result view, it is unclear which submission has been selected by the student (apart from the id on the link).

Description

This PR addresses this issue by highlighting the chosen submission. The selected submission is passed on by the text editor component and is checked on the timeline componented whether the highlighted color for the icon is shown. (primary blue to not interfere with green/red/grey)

Also migrates text-editor.component.ts / text-editor.component.ts and result-history.component.ts / result-history.component.ts to using signals

Steps for Testing

Deploy to TS1 to create multiple AI Feedback

Prerequisites:

  • 1 Instructor
  • 1 Student
  • 1 Text Exercise with AI Feedback enabled
  1. Create multiple submissions and request AI Feedback
  2. Check that everything still works
  3. Select one of the last 5 results to view in the timeline (does not work for older)
  4. Confirm that the correct result is highleted in the timeline

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

Test Coverage

Screenshots

correctHighlight

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced dynamic behavior in the text editor and result history components with function-based property access.
    • Introduced new input binding for the latest result ID in the result history component.
  • Bug Fixes

    • Improved visibility and state management for UI elements based on dynamic conditions.
  • Tests

    • Updated test cases to align with new input handling methods, ensuring robust validation of component behavior.

@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Nov 21, 2024
@EneaGore EneaGore changed the title highlight selected result ´General´: Hihglight selected result in result history timeline Nov 21, 2024
@EneaGore EneaGore changed the title ´General´: Hihglight selected result in result history timeline General: Hihglight selected result in result history timeline Nov 21, 2024
@EneaGore EneaGore temporarily deployed to artemis-test1.artemis.cit.tum.de November 21, 2024 12:06 — with GitHub Actions Inactive
@EneaGore EneaGore temporarily deployed to artemis-test1.artemis.cit.tum.de November 21, 2024 12:41 — with GitHub Actions Inactive
@github-actions github-actions bot added deployment-error Added by deployment workflows if an error occured and removed deploy:artemis-test1 labels Nov 25, 2024
@EneaGore EneaGore removed the deployment-error Added by deployment workflows if an error occured label Nov 25, 2024
@FelixTJDietrich FelixTJDietrich changed the title General: Hihglight selected result in result history timeline General: Highlight selected result in result history timeline Nov 26, 2024
@github-actions github-actions bot added the tests label Nov 28, 2024
@EneaGore EneaGore marked this pull request as ready for review December 2, 2024 16:11
@EneaGore EneaGore requested a review from a team as a code owner December 2, 2024 16:11
Copy link

coderabbitai bot commented Dec 2, 2024

Walkthrough

The pull request introduces significant changes to the TextEditorComponent and ResultHistoryComponent, primarily shifting from static property access to dynamic function calls for handling input properties. This includes updating the HTML templates and TypeScript files to reflect the new input handling mechanism. Additionally, the test files for both components have been modified to align with these new practices, enhancing the context in which input properties are set during testing.

Changes

File Path Change Summary
src/main/webapp/app/exercises/text/participate/text-editor.component.html Updated properties to function calls: displayHeader and expandProblemStatement changed to displayHeader() and expandProblemStatement(), and isExamSummary is now invoked as a function in conditional rendering. Added new input binding for selectedResultId.
src/main/webapp/app/exercises/text/participate/text-editor.component.ts Replaced @Input() decorators with input() for properties like participationId, displayHeader, and others. Updated methods ngOnInit and inputValuesArePresent to accommodate these changes. Adjusted how input properties are checked and assigned in setupComponentWithInputValues.
src/main/webapp/app/overview/result-history/result-history.component.html Adjusted ngClass directive logic for result-score-icon div to use selectedResultId(). Updated exercise input property from a direct reference to a function call exercise().
src/main/webapp/app/overview/result-history/result-history.component.ts Updated @Input decorators to input() for results and exercise. Introduced selectedResultId. Modified ngOnChanges to reflect changes in how inputs are accessed.
src/test/javascript/spec/component/overview/result-history/result-history.component.spec.ts Modified tests to initialize component.results using input<Result[]>(...) within runInInjectionContext, updating various test cases to align with the new input method.
src/test/javascript/spec/component/text-editor/text-editor.component.spec.ts Added imports for input and runInInjectionContext. Updated tests to set input properties using runInInjectionContext instead of direct assignments, maintaining the overall structure and logic of the tests.

Possibly related PRs

Suggested labels

small, ready to merge, code quality, refactoring

Suggested reviewers

  • JohannesWt
  • SimonEntholzer
  • az108
  • florian-glombik
  • BBesrour

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

🧹 Outside diff range and nitpick comments (3)
src/main/webapp/app/overview/result-history/result-history.component.ts (1)

29-33: Consider memoizing filtered results

The filter operations in ngOnChanges are recreated on every change. Consider memoizing the filtered results to optimize performance.

+ private readonly filteredResults = computed(() => {
+   if (this.exercise()?.type === ExerciseType.TEXT || this.exercise()?.type === ExerciseType.MODELING) {
+     return this.results().filter((result) => result.successful !== undefined);
+   }
+   return this.results();
+ });

  ngOnChanges(): void {
    this.showPreviousDivider = this.results().length > MAX_RESULT_HISTORY_LENGTH;
-   if (this.exercise()?.type === ExerciseType.TEXT || this.exercise()?.type === ExerciseType.MODELING) {
-     this.displayedResults = this.results().filter((result) => result.successful !== undefined);
-   } else {
-     this.displayedResults = this.results();
-   }
+   this.displayedResults = this.filteredResults();
src/test/javascript/spec/component/overview/result-history/result-history.component.spec.ts (1)

Line range hint 1-108: Add test coverage for result highlighting

The test suite is missing coverage for the new highlighting functionality introduced by selectedResultId.

Add the following test:

it('should highlight selected result', () => {
    runInInjectionContext(TestBed, () => {
        component.results = input<Result[]>([
            { rated: true, id: 1 },
            { rated: true, id: 2 },
            { rated: true, id: 3 },
        ]);
        component.selectedResultId = input<number>(2);
    });
    component.ngOnChanges();
    fixture.detectChanges();
    
    const selectedResult = fixture.debugElement.query(By.css('.text-primary'));
    expect(selectedResult).toBeTruthy();
    expect(selectedResult.parent.componentInstance.result.id).toBe(2);
});
src/main/webapp/app/exercises/text/participate/text-editor.component.html (1)

82-82: Consider extracting the repeated condition into a template variable

The isExamSummary() function call is repeated in multiple [hidden] bindings. Consider extracting it into a template variable for better performance and maintainability.

+@if (submission && !submission.submitted && isExamSummary(); as isHidden) {
   <span
       class="badge bg-primary mb-2"
       id="word-count"
-      [hidden]="submission && !submission.submitted && isExamSummary()"
+      [hidden]="isHidden"
       jhiTranslate="artemisApp.textExercise.wordCount"
       [translateValues]="{ count: wordCount }">
   </span>
   <span
       class="badge bg-primary mb-2"
       id="character-count"
-      [hidden]="submission && !submission.submitted && isExamSummary()"
+      [hidden]="isHidden"
       jhiTranslate="artemisApp.textExercise.characterCount"
       [translateValues]="{ count: characterCount }">
   </span>
   <textarea
       id="text-editor"
       #textEditor
       class="text-editor-textarea"
       [maxLength]="MAX_CHARACTER_COUNT"
       [(ngModel)]="answer"
       [readOnly]="!isActive || !submission || !isOwnerOfParticipation || isReadOnlyWithShowResult"
       [disabled]="!isActive || !submission || !isOwnerOfParticipation"
       (keydown.tab)="onTextEditorTab(textEditor, $event)"
       (input)="onTextEditorInput($event)"
-      [hidden]="submission && !submission.submitted && isExamSummary()"
+      [hidden]="isHidden">
   </textarea>
+}

Also applies to: 90-90, 107-107

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between a82ca47 and 4b28054.

📒 Files selected for processing (6)
  • src/main/webapp/app/exercises/text/participate/text-editor.component.html (5 hunks)
  • src/main/webapp/app/exercises/text/participate/text-editor.component.ts (6 hunks)
  • src/main/webapp/app/overview/result-history/result-history.component.html (1 hunks)
  • src/main/webapp/app/overview/result-history/result-history.component.ts (2 hunks)
  • src/test/javascript/spec/component/overview/result-history/result-history.component.spec.ts (5 hunks)
  • src/test/javascript/spec/component/text-editor/text-editor.component.spec.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/main/webapp/app/overview/result-history/result-history.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/test/javascript/spec/component/text-editor/text-editor.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/main/webapp/app/exercises/text/participate/text-editor.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/test/javascript/spec/component/overview/result-history/result-history.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/main/webapp/app/overview/result-history/result-history.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/text/participate/text-editor.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

🔇 Additional comments (10)
src/main/webapp/app/overview/result-history/result-history.component.ts (1)

20-22: LGTM: Clean migration to signals

The migration from @input decorators to signals using input() follows Angular's latest best practices. The required/optional distinction is properly maintained.

src/main/webapp/app/overview/result-history/result-history.component.html (2)

8-16: LGTM: Clean implementation of result highlighting

The highlighting implementation correctly uses Angular's class binding and follows the PR objective of using primary blue for selected results.


20-20: LGTM: Proper signal usage

The exercise binding correctly uses the function call syntax required for signals.

src/test/javascript/spec/component/overview/result-history/result-history.component.spec.ts (1)

30-36: LGTM: Proper signal initialization in tests

The test setup correctly uses runInInjectionContext for signal initialization, following Angular testing best practices.

src/main/webapp/app/exercises/text/participate/text-editor.component.html (2)

57-57: LGTM: Result history timeline enhancement

The addition of selectedResultId binding aligns with the PR objective to highlight the selected submission in the timeline.


67-67: LGTM: Signal migration for expandProblemStatement

The change from property access to function call is part of the migration to signals for better performance.

src/test/javascript/spec/component/text-editor/text-editor.component.spec.ts (1)

1-1: LGTM: Test updates for signal migration

The test updates correctly use runInInjectionContext to set input properties, following Angular's testing best practices for signal-based inputs.

Also applies to: 113-117

src/main/webapp/app/exercises/text/participate/text-editor.component.ts (3)

61-67: LGTM: Signal-based input declarations

The input properties are correctly migrated to use signals with appropriate default values.


111-111: LGTM: Participation ID handling

The participation ID handling is updated to use the signal-based input while maintaining the fallback to route params.

Also applies to: 123-123


165-165: LGTM: Input value presence checks

The input value checks are correctly updated to use function calls for signal-based inputs.

Also applies to: 176-183

@EneaGore EneaGore changed the title General: Highlight selected result in result history timeline Text-exercises: Highlight selected result in result history timeline Dec 2, 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!) deploy:artemis-test1 ready for review tests
Projects
Status: Work In Progress
Development

Successfully merging this pull request may close these issues.

2 participants