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

Learning path: Introduce loading spinner for navigation between learning objects #9500

Merged
merged 6 commits into from
Oct 25, 2024

Conversation

JohannesWt
Copy link
Contributor

@JohannesWt JohannesWt commented Oct 16, 2024

Checklist

General

Client

  • 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 multiple screenshots/screencasts of my UI changes.

Motivation and Context

Although loading times when navigating between adjacent learning objects within the learning path feature are already quite fast, there is still a brief period where the user does not receive any visual feedback indicating that the system is loading or processing.

Description

This PR adds a small loading spinner next to the navigation buttons to inform the user when the system is loading the next or previous learning object. Additionally, the tests for the learning path navigation have been refactored for improved accuracy.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Students
  • at least one competency with at least two learning objects
  1. Log in to Artemis
  2. Navigate to the learning path student view
  3. Navigate between the learning objects
  4. verify that you see a small loading spinner within the "Previous" respectively "Next" Button when loading the next learning object

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

Client

Class/File Line Coverage Confirmation (assert/expect)
learning-path-student-nav.component.ts 100%
learning-path-navigation.service.ts 100%

Screenshots

Screen Recording 2024-10-21 at 08 15 51

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced navigation buttons with loading indicators for improved user feedback.
    • Updated interaction logic for selecting learning objects.
  • Bug Fixes

    • Resolved issues with button functionality during loading states.
  • Style

    • Improved visual appearance of dropdown menus and loading icons.
  • Tests

    • Updated test suite to reflect changes in navigation service and component behavior.

@JohannesWt JohannesWt self-assigned this Oct 16, 2024
@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) labels Oct 16, 2024
@JohannesWt JohannesWt marked this pull request as ready for review October 21, 2024 06:46
@JohannesWt JohannesWt requested a review from a team as a code owner October 21, 2024 06:46
Copy link

coderabbitai bot commented Oct 21, 2024

Walkthrough

The changes in this pull request involve updates to the LearningPathNavComponent and related services to enhance the user interface and interaction logic for learning paths. Key modifications include the addition of loading indicators, adjustments to button functionalities, and refinements in method signatures. The CSS styles have been updated to improve the visual presentation, while the test suite has been restructured to accommodate the new service interactions. Overall, these changes aim to streamline the component's logic and improve user feedback during navigation.

Changes

File Change Summary
src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.html Updated button methods to include boolean parameters for loading states; added loading indicators. Simplified conditional rendering for navigation overview button.
src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.scss Modified CSS styles for .progress, .dropdown-toggle::after, and .dropdown-menu; added new class .loading-icon-container.
src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.ts Updated method signatures and properties for loading states; refactored computed properties for clarity; added new loading signals.
src/main/webapp/app/course/learning-paths/services/learning-path-navigation.service.ts Simplified signal declarations; updated property initializations and types for improved readability.
src/test/javascript/spec/component/learning-paths/components/learning-path-nav.component.spec.ts Replaced LearningPathApiService with LearningPathNavigationService; updated test cases to align with new service methods and functionality.

Possibly related PRs

Suggested labels

enhancement, ready for review

Suggested reviewers

  • JohannesStoehr
  • MaximilianAnzinger
  • pzdr7
  • krusche
  • sarpsahinalp

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

🧹 Outside diff range and nitpick comments (11)
src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.scss (1)

15-17: LGTM! Consider using a CSS variable for width.

The .loading-icon-container class is well-implemented and aligns with the PR objective of adding a loading spinner. The width of 15px is appropriate for a small loading icon.

For improved flexibility and maintainability, consider using a CSS variable for the width:

 .loading-icon-container {
-    width: 15px;
+    width: var(--loading-icon-width, 15px);
 }

This allows for easy adjustments across the application if needed.

src/main/webapp/app/course/learning-paths/services/learning-path-navigation.service.ts (1)

8-9: LGTM: Improved dependency injection and signal declarations

The changes to the service properties are well-implemented:

  1. Using inject() for dependency injection improves code readability.
  2. Simplifying signal declarations makes the code more concise while maintaining functionality.

These updates align with modern Angular practices and our coding guidelines.

Consider adding type annotations to the signal declarations for improved code clarity:

readonly isLoading = signal<boolean>(false);
readonly learningPathNavigation = signal<LearningPathNavigationDTO | undefined>(undefined);
readonly isCurrentLearningObjectCompleted = signal<boolean>(false);

Also applies to: 11-11, 13-14, 16-16

src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.html (2)

7-19: LGTM! Consider adding aria-label for accessibility.

The changes look good. The loading indicator improves user feedback, and the new parameter in selectLearningObject aligns with the component changes. The use of @if adheres to the coding guidelines.

Consider adding an aria-label to the button for better accessibility:

 <button
     id="previous-button"
     (click)="selectLearningObject(predecessorLearningObject, false)"
     type="button"
     class="btn btn-secondary d-flex justify-content-center"
+    aria-label="Navigate to previous learning object"
 >

49-57: LGTM! Consider consistent button structure for better maintainability.

The changes look good. The loading indicator improves user feedback, and the new parameter in selectLearningObject aligns with the component changes. The use of @if adheres to the coding guidelines.

For better maintainability, consider structuring the next button similarly to the previous button:

-<button id="next-button" (click)="selectLearningObject(successorLearningObject, true)" type="button" class="btn btn-primary d-flex justify-content-center">
+<button
+    id="next-button"
+    (click)="selectLearningObject(successorLearningObject, true)"
+    type="button"
+    class="btn btn-primary d-flex justify-content-center"
+    aria-label="Navigate to next learning object"
+>
     <span jhiTranslate="artemisApp.learningPath.navigation.nextButton"></span>
     <div class="ms-1 loading-icon-container">
         @if (isLoadingSuccessor()) {
             <fa-icon [icon]="faSpinner" animation="spin" />
         } @else {
             <fa-icon [icon]="faChevronRight" />
         }
     </div>
 </button>

This change improves consistency with the previous button and adds an aria-label for accessibility.

src/test/javascript/spec/component/learning-paths/components/learning-path-nav.component.spec.ts (6)

48-64: LGTM: TestBed configuration updated correctly

The TestBed configuration has been appropriately updated to use MockComponent for LearningPathNavOverviewComponent and to provide a mock LearningPathNavigationService. This aligns with best practices for component testing in Angular.

Consider using jest.fn().mockReturnValue(of({})) for methods that are expected to return Observables, such as learningPathNavigation and currentLearningObject. This would more accurately represent the asynchronous nature of these methods in the actual service.


82-88: LGTM: Updated test case for initial navigation loading

The test case has been correctly updated to check for the loading of initial learning path navigation using the new loadLearningPathNavigation method. The use of toHaveBeenCalledExactlyOnceWith is a good practice for ensuring precise method calls.

Consider adding an expectation to verify that the component's properties are updated correctly after the navigation is loaded. This would ensure that the component state reflects the loaded data.


119-150: LGTM: Navigation test cases updated correctly

The test cases for next and previous button navigation have been well-updated to use the new loadRelativeLearningPathNavigation method. The checks for loading state changes are a good practice for ensuring proper UI feedback during navigation.

Consider adding expectations to verify that the component's learning object properties (predecessor, current, successor) are updated correctly after navigation. This would ensure that the component state reflects the new navigation state.


153-167: Good addition of complete button test case, but could be improved

The addition of a test case for the complete button functionality is good. It correctly checks for the call to completeLearningPath.

Consider enhancing this test case:

  1. Verify that the component's state is updated correctly after completion (e.g., progress should be 100%).
  2. Check if any navigation occurs after completion (e.g., moving to the next learning object).
  3. Ensure that the UI reflects the completed state (e.g., button disabled or hidden).

169-174: Good addition of navigation overview test, but could be expanded

The addition of a test case for showing the navigation overview is a good start. It correctly verifies that isDropdownOpen is set.

Consider enhancing this test case:

  1. Verify that the navigation overview component is actually rendered when isDropdownOpen is true.
  2. Add a test to check that the overview is hidden when isDropdownOpen is false.
  3. Test the toggle functionality if there's a method to switch the dropdown state.

Line range hint 1-174: Overall assessment: Well-updated test suite with room for minor enhancements

The test suite has been successfully updated to accommodate the new LearningPathNavigationService and the changes in component functionality. The test cases cover the main aspects of the component's behavior, including navigation, progress tracking, and UI interactions.

To further improve the test suite:

  1. Consider adding more assertions to verify component state changes after service method calls.
  2. Enhance UI-related tests to check for the actual rendering of elements, not just property changes.
  3. Add edge case scenarios, such as error handling and boundary conditions for navigation.

These enhancements would make the test suite more robust and comprehensive, ensuring better code quality and easier maintenance in the future.

src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.ts (1)

Line range hint 58-60: Add error handling to the completeLearningPath method

The completeLearningPath method calls a service without handling potential errors. To prevent unhandled exceptions and improve user feedback, consider adding a try-catch block around the service call.

Apply this diff to add error handling:

completeLearningPath(): void {
+   try {
        this.learningPathNavigationService.completeLearningPath();
+   } catch (error) {
+       // Handle error appropriately, e.g., show a notification to the user
+       console.error('Error completing learning path:', error);
+   }
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9d8b398 and 9df4c82.

📒 Files selected for processing (5)
  • src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.html (3 hunks)
  • src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.scss (1 hunks)
  • src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.ts (2 hunks)
  • src/main/webapp/app/course/learning-paths/services/learning-path-navigation.service.ts (1 hunks)
  • src/test/javascript/spec/component/learning-paths/components/learning-path-nav.component.spec.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.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/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.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/course/learning-paths/services/learning-path-navigation.service.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/learning-paths/components/learning-path-nav.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}}

🔇 Additional comments (13)
src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.scss (1)

Line range hint 1-13: Additional style changes look good.

The changes to .progress, .dropdown-toggle::after, and .dropdown-menu classes enhance the overall styling and user experience of the component:

  1. Adjusting the margins for .progress improves its alignment.
  2. Hiding the default dropdown toggle indicator allows for custom styling.
  3. Setting a fixed width and box shadow for .dropdown-menu improves its appearance and consistency.

These changes align well with the PR objectives of enhancing user experience and maintaining design consistency.

src/main/webapp/app/course/learning-paths/services/learning-path-navigation.service.ts (5)

1-1: LGTM: Updated imports for Angular signals

The import statement has been appropriately updated to include computed and signal from Angular core. This change aligns with modern Angular practices for efficient state management.


Line range hint 18-28: LGTM: Proper implementation of loading state management

The loadLearningPathNavigation method is well-implemented:

  1. It correctly manages the loading state using signal setters.
  2. Error handling is properly implemented with the alert service.
  3. The method aligns with the PR objectives by providing visual feedback during navigation.

Line range hint 30-42: LGTM: Correct implementation of relative navigation

The loadRelativeLearningPathNavigation method is correctly implemented:

  1. It handles navigation between learning objects as per the PR objectives.
  2. The method signature correctly includes all necessary parameters for relative navigation.
  3. Error handling is properly implemented with the alert service.
  4. The navigation state is updated using the appropriate signal setter.

Line range hint 44-51: LGTM: Concise implementation of completion methods

The completeLearningPath and setCurrentLearningObjectCompletion methods are well-implemented:

  1. Both methods use signal setters consistently to update state.
  2. The implementations are concise and focused, reducing the likelihood of errors.
  3. They align with the PR objectives by managing the completion state of learning objects.

Line range hint 1-51: Overall: Excellent implementation of LearningPathNavigationService

The changes to this service are well-implemented and align with both the PR objectives and our coding guidelines. Key points:

  1. Proper use of Angular signals for efficient state management.
  2. Consistent error handling and state updates throughout the service.
  3. Clear and concise method implementations that fulfill the required functionality.

The service now provides a robust foundation for managing learning path navigation, including loading states and completion tracking. Great job on improving the code quality and maintainability!

src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/learning-path-student-nav.component.html (2)

Line range hint 1-75: Overall, great improvements to user feedback and adherence to guidelines.

The changes consistently enhance user experience by adding loading indicators and using the new @if syntax as per coding guidelines. The modifications to selectLearningObject method calls align well with the component changes mentioned in the summary.

A few minor suggestions have been made for accessibility and consistency, which would further improve the code quality. Great work on this update!


28-37: LGTM! Consider performance impact of always rendering the button.

The changes simplify the template and improve readability. The use of @if adheres to the coding guidelines.

Consider the performance impact of always rendering the button, especially if there are many items. If performance is a concern, you might want to keep the outer conditional check. To verify the number of items, run the following script:

If the number of items is small, the current implementation is fine.

✅ Verification successful

Verified: Performance Impact Minimal with Few Learning Objects

The number of learning objects is small (3), so the performance impact of always rendering the button is negligible.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the number of learning objects in the component

# Test: Search for array declarations or assignments related to learning objects
rg -A 5 'learningObjects\s*=|learningObjects:\s*\[' src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/

Length of output: 133


Script:

#!/bin/bash
# Description: Search for declarations of currentLearningObject in the component

# Test: Search for function or variable declarations related to currentLearningObject
rg 'currentLearningObject\s*\(' src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/

Length of output: 666


Script:

#!/bin/bash
# Description: Count the number of learning objects used in the component

# Test: Extract all instances where learning objects are utilized
rg -o 'currentLearningObject\(\)' src/main/webapp/app/course/learning-paths/components/learning-path-student-nav/ | wc -l

Length of output: 125

src/test/javascript/spec/component/learning-paths/components/learning-path-nav.component.spec.ts (5)

7-8: LGTM: Appropriate imports added

The new imports for LearningPathNavigationService and MockComponent are appropriate for the changes made in this test file. Using MockComponent from ng-mocks is a good practice for mocking components in Angular tests.


13-14: LGTM: Test setup updated correctly

The test setup has been appropriately updated to use LearningPathNavigationService instead of the previous API service. Creating a spy for the learningPathNavigation method is a good practice for verifying service interactions in the tests.


70-71: LGTM: Service injection and spy setup

The injection of LearningPathNavigationService and the creation of a spy for the learningPathNavigation method are well-implemented. This setup facilitates effective mocking and verification of service method calls in the subsequent tests.


92-98: LGTM: Progress bar test case updated correctly

The progress bar test case has been well-updated to use the learningPathNavigationSpy for mocking the return value. Checking the width of the progress bar element is an effective way to verify the visual representation of progress.


101-106: LGTM: learningPathProgress test case updated correctly

The test case for learningPathProgress has been appropriately updated to use the learningPathNavigationSpy for mocking the return value. It correctly verifies that the component's learningPathProgress property is set to the expected value.

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 TS4. Everything works as described & expected. 👍

Copy link
Contributor

@pzdr7 pzdr7 left a comment

Choose a reason for hiding this comment

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

Code looks good 👍

Copy link
Contributor

@raffifasaro raffifasaro left a comment

Choose a reason for hiding this comment

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

Code LGTM

@sachmii sachmii temporarily deployed to artemis-test5.artemis.cit.tum.de October 21, 2024 17:45 — with GitHub Actions Inactive
Copy link

@Cathy0123456789 Cathy0123456789 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 TS5. Works as expected, nice detail

Copy link
Collaborator

@MaximilianAnzinger MaximilianAnzinger left a comment

Choose a reason for hiding this comment

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

Maintainer approved

Copy link

@Feras797 Feras797 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, showed me the small loading spinner when going back and forth. ✅

@bassner bassner added this to the 7.6.4 milestone Oct 25, 2024
@bassner bassner merged commit f785992 into develop Oct 25, 2024
153 of 164 checks passed
@bassner bassner deleted the feature/learning-paths/navigation-loading-spinnger branch October 25, 2024 19:41
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 to merge small tests
Projects
Archived in project
Status: Done
Development

Successfully merging this pull request may close these issues.