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

Programming exercises: Fix table overflow in rendered markdown #9957

Conversation

rabeatwork
Copy link
Contributor

@rabeatwork rabeatwork commented Dec 6, 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.
  • I added multiple screenshots/screencasts of my UI changes.

Motivation and Context

When adding a large table to the problem statement the content of the exercise overflowed.

Description

Added logic to check if the rendered Markdown contains <table> elements and applied styles dynamically to prevent overflow issues. Ensured tables are responsive by setting max-width: 100% and enabling horizontal scrolling with overflow-x: scroll.

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Student
  • 1 Programming Exercise with a large table in the problem statement
  1. Log in to Artemis
  2. Navigate to the programming exercise
  3. Verify that the content does not overflow despite the large table
  4. Collapse the Sidebar
  5. Verify that the content does not overflow despite the large table

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

Screenshots

Before:
Screenshot 2024-12-06 at 12 03 46

After:
Screenshot 2024-12-06 at 12 03 59

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced markdown rendering with styled tables for improved readability.
    • Introduced new CSS classes for responsive layout adjustments of exercise content.
  • Bug Fixes

    • Adjusted layout and class bindings in the course exercises component for better styling and functionality.
  • Style

    • Added transition effects to new CSS classes for smoother width adjustments.

@rabeatwork rabeatwork requested a review from a team as a code owner December 6, 2024 11:13
@github-actions github-actions bot added the client Pull requests that update TypeScript code. (Added Automatically!) label Dec 6, 2024
Copy link

coderabbitai bot commented Dec 6, 2024

Walkthrough

The pull request introduces modifications to the ProgrammingExerciseInstructionComponent class by adding a method for styling tables within rendered markdown. The renderMarkdown method has been updated to utilize this new styling functionality. Additionally, the HTML structure and CSS classes in the course-exercises.component.html and course-overview.scss files have been modified to enhance the layout and responsive design of the exercise content area.

Changes

File Change Summary
src/main/webapp/app/exercises/programming/shared/instructions-render/programming-exercise-instruction.component.ts Added method addStylesForTables for styling tables in markdown; updated renderMarkdown to use this method.
src/main/webapp/app/overview/course-exercises/course-exercises.component.html Simplified outer <div> and updated class bindings for exercise content based on isCollapsed state.
src/main/webapp/app/overview/course-overview.scss Introduced new CSS classes: .exercise-content-sidebar-width and .exercise-content-width for layout control.

Possibly related PRs

Suggested labels

tests, bugfix, enhancement, ready for review

Suggested reviewers

  • florian-glombik
  • Jan-Thurner
  • az108
  • JohannesStoehr
  • 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

🧹 Outside diff range and nitpick comments (1)
src/main/webapp/app/overview/course-overview.scss (1)

193-197: Consider extracting the magic number into a CSS variable.

The width calculation uses a magic number (263px) which should be defined as a CSS variable for better maintainability.

+:root {
+    --sidebar-total-width: 263px; /* 255px sidebar + 8px margin */
+}
 .exercise-content-sidebar-width {
-    width: calc(100% - 263px) !important;
+    width: calc(100% - var(--sidebar-total-width)) !important;
     transition: width 0.1s 0s ease-in-out;
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8036d43 and d70d8ea.

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

17-21: LGTM! Responsive layout implementation looks good.

The class bindings effectively handle the responsive layout:

  • Base class exercise-content-width ensures full width by default
  • Dynamic exercise-content-sidebar-width adjusts width when sidebar is visible
src/main/webapp/app/overview/course-overview.scss (1)

198-201: LGTM! Consistent transition implementation.

The transition timing matches between both classes, ensuring smooth width changes.

src/main/webapp/app/exercises/programming/shared/instructions-render/programming-exercise-instruction.component.ts (1)

307-308: LGTM! Table styling integration looks good.

The integration of table styling in the markdown rendering process is implemented correctly.

Also applies to: 321-322

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 (2)
src/main/webapp/app/exercises/programming/shared/instructions-render/programming-exercise-instruction.component.ts (2)

333-335: Improve table detection condition readability.

The condition could be more explicit to better convey its intent.

-        if (!markdownWithoutTasks?.includes('<table')) {
+        if (!markdownWithoutTasks || !markdownWithoutTasks.includes('<table>')) {
             return;
-        } else {
+        }

332-347: Consider memory management in DOM manipulation.

The current implementation could lead to memory leaks. Consider cleaning up DOM references and using a more functional approach.

  1. Clear any references to DOM elements after use
  2. Consider using a more functional approach that doesn't mutate state
  3. Document the memory management considerations in the method's JSDoc

Example JSDoc:

/**
 * Applies responsive styles to tables in markdown content.
 * @param markdownWithoutTasks - The markdown content to process
 * @returns The processed markdown content or undefined if no tables found
 * @note This method creates temporary DOM elements which are automatically cleaned up
 */
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d70d8ea and f0e5cf6.

📒 Files selected for processing (1)
  • src/main/webapp/app/exercises/programming/shared/instructions-render/programming-exercise-instruction.component.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/main/webapp/app/exercises/programming/shared/instructions-render/programming-exercise-instruction.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 (2)
src/main/webapp/app/exercises/programming/shared/instructions-render/programming-exercise-instruction.component.ts (2)

307-308: LGTM! Table styling is correctly integrated into the markdown rendering pipeline.

The changes properly handle table styling before sanitization while maintaining security through sanitizer.bypassSecurityTrustHtml.

Also applies to: 321-322


340-344: 🛠️ Refactor suggestion

Replace inline styles with CSS classes for better maintainability.

Using CSS classes instead of inline styles would improve maintainability and follow Angular best practices.

+// Add to your component's scss file
+.markdown-table {
+    max-width: 100%;
+    overflow-x: scroll;
+    display: block;
+}

-            tables.forEach((table) => {
-                table.style.maxWidth = '100%';
-                table.style.overflowX = 'scroll';
-                table.style.display = 'block';
-            });
+            tables.forEach((table) => {
+                table.classList.add('markdown-table');
+            });

Likely invalid or redundant comment.

@rabeatwork rabeatwork changed the title Programming Exercises: Fix table overflow in rendered markdown Programming exercises: Fix table overflow in rendered markdown Dec 6, 2024
Copy link

@sachmii sachmii 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 fine.

Copy link
Contributor

@az108 az108 left a comment

Choose a reason for hiding this comment

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

image Works and Code 👍

Copy link

@HawKhiem HawKhiem 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

image

Copy link

@sawys777 sawys777 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 TS1, everything works accordingly to the description.

Copy link

@ahbitaqu ahbitaqu 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 TS3]

Works flawlessly for me, tested it on mobile form-factor, too.

Copy link

@SimonKaran13 SimonKaran13 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 TS1 with a big table. Works as expected
image

@bassner bassner added this to the 7.7.5 milestone Dec 10, 2024
@bassner bassner merged commit f01b5eb into develop Dec 10, 2024
111 of 117 checks passed
@bassner bassner deleted the chore/programming-exercises/add-styles-for-tables-in-problem-statements branch December 10, 2024 17:01
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 to merge
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

8 participants