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

Development: Fix console errors on course overview page #9526

Merged
merged 3 commits into from
Oct 19, 2024

Conversation

cremertim
Copy link
Contributor

@cremertim cremertim commented Oct 19, 2024

Checklist

General

Motivation and Context

If you are in the CourseOverview Page, every single components throws console errors at startup time due to missing undefined checks.

Description

I added the undefine check for every CourseOverviewComponent

Steps for Testing

Prerequisites:

  • 1 Student
  1. Log in to Artemis
  2. Navigate to Course Overview
  3. Open the console
  4. Click through every tab

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Performance Review

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Exam Mode Test

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Screenshots

image

Summary by CodeRabbit

  • Bug Fixes
    • Implemented null-safe checks for faqs and filteredFaqs in the course FAQ component to prevent runtime errors.
    • Enhanced dropdown menu functionality in the course overview component with null-safe operators to avoid errors when closing the menu.
    • Improved sidebar component robustness by adding null-safe navigation for sidebarData properties, preventing potential issues when accessing undefined values.

@cremertim cremertim requested a review from a team as a code owner October 19, 2024 13:25
@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Oct 19, 2024
@krusche krusche added this to the 7.6.1 milestone Oct 19, 2024
Copy link

coderabbitai bot commented Oct 19, 2024

Walkthrough

The changes involve the implementation of null-safe checks across multiple HTML template files in an Angular application. Specifically, the course-faq.component.html, course-overview.component.html, and sidebar.component.html files have been updated to use the optional chaining operator (?.) to prevent runtime errors when accessing potentially null or undefined objects. These modifications ensure that the application handles cases where data may not be present without crashing.

Changes

File Path Change Summary
src/main/webapp/app/overview/course-faq/course-faq.component.html Updated length checks for faqs and filteredFaqs arrays to use optional chaining (?.).
src/main/webapp/app/overview/course-overview.component.html Added null-safe operator (?.) to click event handlers for closing dropdown menus to prevent errors.
src/main/webapp/app/shared/sidebar/sidebar.component.html Introduced null-safe navigation for sidebarData properties to prevent errors when accessing potentially undefined values.

Possibly related PRs

Suggested labels

bugfix, ready for review, small

Suggested reviewers

  • JohannesStoehr
  • SimonEntholzer
  • krusche

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/course-faq/course-faq.component.html (1)

38-38: Approved with suggestion: Consider adding null check for faqs.length.

The change correctly implements a null-safe check using the optional chaining operator (?.) for the filteredFaqs array, which prevents potential runtime errors. The use of the @if directive adheres to the provided coding guidelines.

However, there's a potential issue with faqs.length > 0 not using the optional chaining operator. To ensure complete null safety, consider updating this part of the condition as well.

Consider applying this change:

-@if (filteredFaqs?.length === 0 && faqs.length > 0) {
+@if (filteredFaqs?.length === 0 && faqs?.length > 0) {

This will prevent potential runtime errors if faqs is null or undefined.

src/main/webapp/app/shared/sidebar/sidebar.component.html (1)

Line range hint 51-51: LGTM: Null-safe checks implemented correctly. Consider improving readability.

The changes in this line are well-implemented:

  1. Multiple null-safe checks for sidebarData using the optional chaining operator (?.) enhance the robustness of the code.
  2. The use of @if instead of *ngIf aligns with the provided coding guidelines for Angular syntax.

These modifications will help prevent runtime errors and keep the code up-to-date with modern Angular practices.

However, the line contains complex conditional logic. Consider breaking it down into smaller, more readable parts for improved maintainability.

Here's a suggestion to improve readability:

@if (shouldDisplayNoDataMessage()) {
  <div
    [ngClass]="{ 'content-height-dev': !isProduction || isTestServer }"
    [jhiTranslate]="getNoDataMessageKey()"
    class="mt-2 text-center scrollable-item-content"
  ></div>
}

// In the component class:
shouldDisplayNoDataMessage(): boolean {
  return !this.sidebarData?.ungroupedData || 
         !(this.sidebarData?.ungroupedData | searchFilter: ['title', 'type'] : this.searchValue)?.length;
}

getNoDataMessageKey(): string {
  return (this.sidebarDataBeforeFiltering?.ungroupedData?.length ?? 0) > 0 && this.sidebarData.ungroupedData?.length === 0
    ? 'artemisApp.courseOverview.general.noElementFoundWithAppliedFilter'
    : 'artemisApp.courseOverview.general.noDataFound';
}

This approach moves the complex logic to the component class, making the template more readable and easier to maintain.

src/main/webapp/app/overview/course-overview.component.html (1)

Line range hint 1-282: Good adherence to coding guidelines, consider component decomposition for improved maintainability.

The template consistently uses the new Angular syntax with @if and @for directives, adhering to the provided coding guidelines. This is a positive aspect of the implementation.

However, the template's complexity and length suggest that it might benefit from being broken down into smaller, more manageable components. This could improve maintainability and readability of the code.

Consider decomposing this large template into smaller, reusable components. This could make the code easier to maintain and understand in the long run. For example, you could create separate components for the sidebar, course title bar, and main content area.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 53692bc and 3ec9890.

📒 Files selected for processing (3)
  • src/main/webapp/app/overview/course-faq/course-faq.component.html (1 hunks)
  • src/main/webapp/app/overview/course-overview.component.html (2 hunks)
  • src/main/webapp/app/shared/sidebar/sidebar.component.html (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
src/main/webapp/app/overview/course-faq/course-faq.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/overview/course-overview.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/shared/sidebar/sidebar.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.

🔇 Additional comments (6)
src/main/webapp/app/overview/course-faq/course-faq.component.html (1)

30-30: LGTM! Null safety improved and modern Angular syntax used.

The change correctly implements a null-safe check using the optional chaining operator (?.) for the faqs array. This prevents potential runtime errors if faqs is null or undefined. Additionally, the use of the @if directive adheres to the provided coding guidelines, which recommend using @if over *ngIf.

src/main/webapp/app/shared/sidebar/sidebar.component.html (3)

28-28: LGTM: Null-safe check and new Angular syntax implemented correctly.

The changes in this line are well-implemented:

  1. The null-safe check for sidebarData using the optional chaining operator (?.) enhances the robustness of the code.
  2. The use of @if instead of *ngIf aligns with the provided coding guidelines for Angular syntax.

These modifications will help prevent runtime errors and keep the code up-to-date with modern Angular practices.


Line range hint 71-71: LGTM: Null-safe check and new Angular syntax implemented correctly.

The changes in this line are well-implemented:

  1. The null-safe check for sidebarData using the optional chaining operator (?.) enhances the robustness of the code.
  2. The use of @if instead of *ngIf aligns with the provided coding guidelines for Angular syntax.

These modifications will help prevent runtime errors and keep the code up-to-date with modern Angular practices.


Line range hint 28-71: Overall assessment: Improvements in code robustness and adherence to modern Angular practices.

The changes made to this file consistently implement the following improvements:

  1. Addition of null-safe checks using the optional chaining operator (?.) for sidebarData and its properties.
  2. Adoption of the new Angular syntax @if instead of *ngIf.

These modifications collectively enhance the code in the following ways:

  • Increased robustness by preventing potential runtime errors due to undefined or null values.
  • Improved alignment with modern Angular practices and syntax.
  • Better handling of edge cases where data might be missing or undefined.

The changes effectively address the PR objective of removing console errors on the CourseOverviewPage by implementing undefined checks. This will lead to a more stable user experience.

One area for potential further improvement is the readability of complex conditional logic, as noted in a previous comment.

Overall, these changes represent a positive step towards more reliable and maintainable code.

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

258-258: LGTM: Null-safe operator added to prevent potential errors.

The addition of the null-safe operator ?. to itemsDrop?.close() is a good practice. It prevents potential runtime errors if itemsDrop is undefined, aligning with the PR's objective of removing console errors on the Course Overview Page.


277-277: LGTM: Consistent use of null-safe operator.

The addition of the null-safe operator ?. to itemsDrop?.close() in this template is consistent with the previous change. It maintains a uniform approach to preventing potential runtime errors throughout the component.

@krusche krusche changed the title General: Remove console errors on CourseOverviewPage Development: Fix console errors on course overview page Oct 19, 2024
@HawKhiem HawKhiem temporarily deployed to artemis-test1.artemis.cit.tum.de October 19, 2024 14:26 — with GitHub Actions Inactive
Copy link
Member

@krusche krusche 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 👍

@krusche krusche merged commit b6f99a7 into develop Oct 19, 2024
45 of 52 checks passed
@krusche krusche deleted the bugfix/communication/remove-faq-console-errors branch October 19, 2024 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) ready for review
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants