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

Lectures: Fix an issue with undefined units when processing lecture units #9452

Merged
merged 6 commits into from
Oct 12, 2024

Conversation

eceeeren
Copy link
Contributor

@eceeeren eceeeren commented Oct 11, 2024

Checklist

General

Client

  • Important: I implemented the changes with a very good performance, prevented too many (unnecessary) REST calls and made sure the UI is responsive, even with large data (e.g. using paging).
  • I strictly followed the client coding and design guidelines.
  • 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 screenshots/screencasts of my UI changes.

Motivation and Context

This issue is created because when a new Lecture is created and Lecture Unit Processing is executed, if the PDF file does not have a page titled "Outline", then the units can not be created, therefore they become 'undefined'. Since there was no checks on the HTML page regarding the units being undefined, these checks needed to be added.

Problem Video:
https://github.com/user-attachments/assets/660d1380-4fee-43c5-b275-925fdc0ffe78

Description

For createAttachmentUnits() button and noUnitDetected warning, one more check added, that checks if the units exists or not

Steps for Testing

Prerequisites:

  • 1 Instructor
  1. Navigate to 'Create Lecture' page
  2. Select 'Automatic Unit Processing'
  3. Upload a PDF file without an "Outline" slide
  4. Observe the page, it should not give an error and show "No units are found" warning
  5. There should be no lecture units and Submit button should be disabled until you add a unit
  6. Check if submits after creating at least 1 unit
  7. Create a Lecture again and upload a file with "Outline" slide
  8. The lecture units should be created, no warnings/errors should be shown

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

Screenshots

Before the Fix:

Screenshot 2024-10-11 at 02 26 15

Screenshot 2024-10-11 at 02 26 36

After the Fix:

Screenshot 2024-10-11 at 02 27 31

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced handling of the units array to ensure existing units are preserved if the response does not contain new units.
    • Updated button states for creating and deleting attachment units to simplify conditions related to the units array.

@eceeeren eceeeren requested a review from a team as a code owner October 11, 2024 00:23
@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Oct 11, 2024
Copy link

coderabbitai bot commented Oct 11, 2024

Walkthrough

The changes in this pull request involve modifications to the conditional logic in the attachment-units.component.html and attachment-units.component.ts files. Specifically, the conditions checking the units array have been simplified by removing checks for the array's initialization. Additionally, the handling of the units property in the AttachmentUnitsComponent class has been updated to retain previous values if the response from a service does not provide new units.

Changes

File Change Summary
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.component.html Simplified conditional checks for the units array and updated button disabled states accordingly.
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.component.ts Modified assignment of this.units to retain previous values if the response does not provide new units.

Possibly related PRs

Suggested labels

tests

Suggested reviewers

  • JohannesStoehr
  • MaximilianAnzinger
  • FelixTJDietrich
  • pzdr7

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between b6b47e7 and 60371b4.

📒 Files selected for processing (1)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.component.html (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.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 (2)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.component.html (2)

Line range hint 102-107: Improved robustness in handling undefined units

The change from @if (units && units.length < 1) to @if (!units || units.length < 1) enhances the code's ability to handle cases where units might be undefined or null. This modification ensures that the warning message is displayed not only when the units array is empty but also when it's not initialized.

The use of @if adheres to the new Angular syntax guidelines, which is excellent.


Line range hint 1-126: Summary: Improved handling of undefined units

The changes in this file successfully address the PR objectives by enhancing the robustness of the code when dealing with potentially undefined units. The use of the new Angular syntax (@if) is consistent with the coding guidelines.

The modifications effectively prevent errors that could occur when a PDF without an "Outline" slide is uploaded, as mentioned in the PR objectives. The code now gracefully handles cases where units might be undefined or empty.

No major issues were found, and the changes are approved with a minor suggestion for further improvement.

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 11, 2024
kaancayli
kaancayli previously approved these changes Oct 11, 2024
@eceeeren eceeeren dismissed stale reviews from kaancayli and coderabbitai[bot] via 5eb0fd7 October 11, 2024 10:50
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between cfe507a and f7829f1.

📒 Files selected for processing (2)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.component.html (1 hunks)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.component.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.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/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.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 (3)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.component.html (3)

Line range hint 1-124: Summary of changes and recommendations

The modifications in this file aim to simplify the handling of the units array and align with the new Angular syntax (@if). While these changes address the PR objectives of fixing the undefined units problem, there are opportunities to enhance robustness:

  1. Consider adding null checks using the safe navigation operator (?.) when accessing units.length.
  2. Ensure consistent handling of potential null or undefined values for units throughout the template.

These recommendations will help prevent potential runtime errors and improve the overall reliability of the component.


Line range hint 111-111: Ensure consistent and safe handling of the units property.

The change to [disabled]="units.length < 1" is consistent with the earlier modification. However, to maintain robustness and prevent potential runtime errors, consider using the safe navigation operator:

[disabled]="units?.length < 1"

This change ensures consistency with the earlier suggestion and provides a safeguard against potential undefined or null values for units.

To verify the necessity of this change, we can check if there are any other occurrences of units.length without a null check:

#!/bin/bash
# Search for usages of 'units.length' without null check
rg --type html "(?<!units\?)\bunits\.length" src/

102-102: ⚠️ Potential issue

Consider adding a null check for robustness.

While the simplification of the condition aligns with the new Angular syntax, it might introduce a potential runtime error if units is undefined or null. To ensure robustness, consider adding a null check:

@if (units?.length < 1) {

This change maintains the simplicity while safeguarding against potential undefined or null values for units.

To verify the necessity of this change, we can check if units is ever assigned a null or undefined value:

✅ Verification successful

Verification Successful: No null or undefined assignments for units.

Based on the analysis, the units property is never assigned null or undefined values within the codebase. Therefore, the current condition @if (units.length < 1) is safe and does not require a null check.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for assignments to 'units' property
rg --type typescript "this\.units\s*=\s*(null|undefined)" src/

Length of output: 283


Script:

#!/bin/bash
# Search for assignments to 'units' property using PCRE2
rg --pcre2 --type typescript "this\.units\s*=\s*(null|undefined)" src/

Length of output: 107


Script:

#!/bin/bash
# Search for assignments to 'units' property in .ts and .tsx files using PCRE2
rg --pcre2 "this\.units\s*=\s*(null|undefined)" --glob "*.ts" --glob "*.tsx" src/

Length of output: 83

coderabbitai[bot]
coderabbitai bot previously approved these changes Oct 11, 2024
ole-ve
ole-ve previously approved these changes Oct 11, 2024
Copy link
Contributor

@ole-ve ole-ve left a comment

Choose a reason for hiding this comment

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

code

@eceeeren eceeeren dismissed stale reviews from ole-ve and coderabbitai[bot] via c2d9f48 October 11, 2024 12:34
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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between f7829f1 and c2d9f48.

📒 Files selected for processing (1)
  • src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.component.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.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

🪛 Biome
src/main/webapp/app/lecture/lecture-unit/lecture-unit-management/attachment-units/attachment-units.component.ts

[error] 120-120: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

@edkaya edkaya added deploy:artemis-test3 and removed deployment-error Added by deployment workflows if an error occured labels Oct 11, 2024
Copy link

⚠️ Unable to deploy to test servers ⚠️

The docker build needs to run through before deploying.

@github-actions github-actions bot added the deployment-error Added by deployment workflows if an error occured label Oct 11, 2024
@edkaya edkaya removed the deployment-error Added by deployment workflows if an error occured label Oct 11, 2024
@magaupp magaupp temporarily deployed to artemis-test3.artemis.cit.tum.de October 12, 2024 08:16 — with GitHub Actions Inactive
@magaupp magaupp temporarily deployed to artemis-test4.artemis.cit.tum.de October 12, 2024 08:50 — with GitHub Actions Inactive
Copy link
Contributor

@magaupp magaupp 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. Works as expected.
PDFs without outline slides are processed without errors and the "No unit was detected" message is shown.
PDFs with outline slides are processed correctly.

@krusche krusche added this to the 7.6.0 milestone Oct 12, 2024
@krusche krusche changed the title Lectures: Fix undefined units problem in Processing Lecture Units Lectures: Fix an issue with undefined units when processing lecture units Oct 12, 2024
@krusche krusche merged commit 753f497 into develop Oct 12, 2024
59 of 67 checks passed
@krusche krusche deleted the feature/lectures/undefined-units-fix branch October 12, 2024 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix client Pull requests that update TypeScript code. (Added Automatically!) ready for review
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants