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

Add maxHeight toggle to CodeMirror Demo + Better demo docs showing diff algorithm bugs #2364

Merged
merged 3 commits into from
Oct 27, 2024

Conversation

VasylMarchuk
Copy link
Collaborator

@VasylMarchuk VasylMarchuk commented Oct 27, 2024

Related to #1231

Brief

This adds a toggle maxHeight to the CodeMirror's demo page, which allows limiting (or not) of the editor's height.

Details

Modified the demo text & SQL documents to better showcase the problems of CodeMirror's diff algorithm.

Video + Screenshot

2024-10-27.12.04.56.mov
Знімок екрана 2024-10-27 о 12 47 16

Checklist

  • I've thoroughly self-reviewed my changes
  • I've added tests for my changes, unless they affect admin-only areas (or are otherwise not worth testing)
  • I've verified any visual changes using Percy (add a commit with [percy] in the message to trigger)

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new "maxHeight" checkbox option in the CodeMirror settings, allowing users to control the maximum height of the editor.
    • Expanded example documents for various file types, enhancing the usability of the CodeMirror component.
  • Improvements

    • Updated the editor's layout to dynamically adjust based on the "maxHeight" setting, improving user experience.
    • Added a new query parameter, maxHeight, to enhance the controller's configuration options.

@VasylMarchuk VasylMarchuk added the enhancement New feature or request label Oct 27, 2024
@VasylMarchuk VasylMarchuk self-assigned this Oct 27, 2024
Copy link
Contributor

coderabbitai bot commented Oct 27, 2024

Walkthrough

The changes in this pull request enhance the DemoCodeMirrorController by adding new example documents and updating existing content. A new property, maxHeight, has been introduced in both the controller and the associated route, allowing for greater control over the editor's maximum height. Additionally, a checkbox for this new option has been added to the user interface in the template, enabling users to adjust the editor's display properties dynamically.

Changes

File Path Change Summary
app/controllers/demo/code-mirror.ts - Added maxHeight property in DemoCodeMirrorController and OPTION_DEFAULTS.
- Updated EXAMPLE_DOCUMENTS with new instances and content.
- Included maxHeight in queryParams.
app/routes/demo/code-mirror.ts - Added maxHeight to QUERY_PARAMS array for the DemoCodeMirrorRoute.
app/templates/demo/code-mirror.hbs - Introduced a checkbox for maxHeight in the CodeMirror options.
- Modified class attribute of CodeMirror component to conditionally apply max-h-96.

Possibly related PRs

Suggested reviewers

  • rohitpaulk

🐇 In the meadow, where bunnies play,
A new height option brightens the day!
With checkboxes added, oh what a sight,
CodeMirror's now a delight,
Hop in and adjust, make it just right!
Happy coding, frolic and sway! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6d3625d and f392d07.

📒 Files selected for processing (1)
  • app/controllers/demo/code-mirror.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/controllers/demo/code-mirror.ts

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 anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

codecov bot commented Oct 27, 2024

Bundle Report

Changes will increase total bundle size by 1.94kB (0.01%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
client-array-push 35.77MB 1.94kB (0.01%) ⬆️

Copy link
Contributor

@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 UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9b6c442 and fc929ba.

📒 Files selected for processing (3)
  • app/controllers/demo/code-mirror.ts (4 hunks)
  • app/routes/demo/code-mirror.ts (1 hunks)
  • app/templates/demo/code-mirror.hbs (2 hunks)
🔇 Additional comments (6)
app/routes/demo/code-mirror.ts (1)

30-30: LGTM! Verify integration with related components.

The addition of 'maxHeight' to QUERY_PARAMS is well-implemented and maintains consistency with the existing pattern.

Let's verify the integration with related components:

✅ Verification successful

Integration verified - maxHeight parameter is properly implemented across components

The verification confirms that:

  • Controller has the maxHeight property defined in OPTION_DEFAULTS and tracked for reactivity
  • Template includes both the checkbox toggle UI and applies the 'max-h-96' class conditionally
  • The implementation is consistent across route, controller, and template components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the maxHeight parameter integration across components

# Test 1: Verify controller handles the maxHeight parameter
echo "Checking controller implementation..."
rg -A 5 "maxHeight" "app/controllers/demo/code-mirror.ts"

# Test 2: Verify template includes maxHeight toggle
echo "Checking template implementation..."
rg -A 5 "maxHeight" "app/templates/demo/code-mirror.hbs"

Length of output: 1284

app/controllers/demo/code-mirror.ts (4)

56-58: LGTM: Example document changes effectively demonstrate diff behavior.

The modifications to the example text document, including new line insertions and text modifications, provide clear test cases for visualizing the CodeMirror diff algorithm's behavior.


133-133: LGTM: maxHeight option properly configured.

The maxHeight option is correctly added to OPTION_DEFAULTS with a sensible default value of true.


187-187: LGTM: maxHeight properly added to queryParams.

The maxHeight parameter is correctly added to queryParams array, maintaining alphabetical order and enabling URL persistence of the editor configuration.


239-239: LGTM: maxHeight tracked property properly implemented.

The maxHeight property is correctly implemented as a tracked property and initialized with the default value.

app/templates/demo/code-mirror.hbs (1)

179-184: LGTM: Well-structured maxHeight toggle implementation

The new maxHeight toggle follows the established pattern and maintains consistency with other option controls. The tooltip provides clear user guidance.

Comment on lines +351 to +353
class="block overflow-auto mt-4
{{if this.maxHeight 'max-h-96'}}
{{if this.outline 'outline outline-dotted outline-gray-200 dark:outline-gray-700'}}"
Copy link
Contributor

@coderabbitai coderabbitai bot Oct 27, 2024

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider making the maxHeight value configurable

While the implementation works, the hard-coded max-h-96 (24rem/384px) might be too restrictive for some use cases. Consider making this configurable similar to other numeric options like tabSize or unchangedMargin.

Example implementation:

- {{if this.maxHeight 'max-h-96'}}
+ {{if this.maxHeight (concat 'max-h-' this.selectedMaxHeight)}}

With corresponding controller changes:

maxHeights: ['72', '96', '128'], // 18rem, 24rem, 32rem
selectedMaxHeightIndex: 1, // default to 96 (24rem)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great idea, considered it too, but not very relevant for the context of the demo page, at the moment. Plus too much additional work: adding a select, checkbox for select, getter for selected index -> value conversion, handling selected index change, and adding both select + checkbox to the query params.

Copy link
Contributor

Choose a reason for hiding this comment

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

@VasylMarchuk, understood. Thank you for the clarification.

(_/)
(•_•)
💔


✏️ Learnings added
Learnt from: VasylMarchuk
PR: codecrafters-io/frontend#2364
File: app/templates/demo/code-mirror.hbs:351-353
Timestamp: 2024-10-27T10:18:53.775Z
Learning: In the context of the demo page, making `maxHeight` configurable is not necessary due to additional complexity and is not relevant at the moment.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link

github-actions bot commented Oct 27, 2024

Test Results

  1 files  ±0    1 suites  ±0   6m 29s ⏱️ - 1m 7s
582 tests ±0  542 ✅ ±0  40 💤 ±0  0 ❌ ±0 
597 runs  ±0  557 ✅ ±0  40 💤 ±0  0 ❌ ±0 

Results for commit f392d07. ± Comparison against base commit 9b6c442.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Oct 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files

📢 Thoughts on this report? Let us know!

@VasylMarchuk VasylMarchuk changed the title Add maxHeight toggle to CodeMirror Demo + Better demo doc showing diff algorithm bugs Add maxHeight toggle to CodeMirror Demo + Better demo docs showing diff algorithm bugs Oct 27, 2024
@VasylMarchuk VasylMarchuk merged commit d9846e1 into main Oct 27, 2024
8 of 9 checks passed
@VasylMarchuk VasylMarchuk deleted the code-mirror/better-text-diff-example branch October 27, 2024 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants