Skip to content

Bind all CodeMirror Demo options to query params & allow resetting them #2273

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

Merged
merged 3 commits into from
Sep 29, 2024

Conversation

VasylMarchuk
Copy link
Collaborator

@VasylMarchuk VasylMarchuk commented Sep 29, 2024

Related to #1231

Brief

This makes all options selected on the CodeMirror Demo page be stored in queryParams, so that a specific editor configuration can be easily linked to.

Details

Since refreshing the page no longer resets all options to defaults, due to them being stored in queryParams, added a control for resetting them manually.

Demo

2024-09-29.13.15.04.mov

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

Summary by CodeRabbit

  • New Features

    • Introduced a reset button for users to easily revert all CodeMirror options to their default settings.
    • Enhanced URL query parameters for dynamic configuration of CodeMirror editor features.
  • Bug Fixes

    • Adjusted styling for improved layout and accessibility.
  • Chores

    • Centralized default options management for easier maintenance and configuration.

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

coderabbitai bot commented Sep 29, 2024

Walkthrough

The changes introduce a new configuration object, OPTION_DEFAULTS, to manage default settings for the CodeMirror editor. The DemoCodeMirrorController class is updated to initialize tracked properties using this object, and a new method, resetAllOptions, is added for resetting these properties. The DemoCodeMirrorRoute class expands its query parameters to enhance configurability, while the template adds a clickable element for resetting options. These modifications improve the management and usability of the CodeMirror editor features.

Changes

Files Change Summary
app/controllers/demo/code-mirror.ts Introduced OPTION_DEFAULTS for default options, updated tracked properties, added resetAllOptions method.
app/routes/demo/code-mirror.ts Expanded DemoCodeMirrorRoute with multiple query parameters for enhanced configurability.
app/templates/demo/code-mirror.hbs Added a clickable <span> for resetting options and modified an existing element's margin class.

Possibly related PRs

Suggested reviewers

  • rohitpaulk

🐰 In the land of code where options bloom,
A rabbit hops in with a joyful tune.
With defaults set and a reset near,
CodeMirror shines, bringing cheer!
Click and play, let creativity flow,
In this vibrant editor, watch ideas grow! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dac38fb and 4af2754.

📒 Files selected for processing (1)
  • app/routes/demo/code-mirror.ts (1 hunks)
🔇 Additional comments (4)
app/routes/demo/code-mirror.ts (4)

3-45: LGTM! Well-structured constant for query parameters.

The QUERY_PARAMS constant is a well-organized list of CodeMirror editor options and configuration parameters. This approach centralizes the query parameters, improving maintainability and adhering to the DRY principle. It will make it easier to add, remove, or modify parameters in the future.


47-51: LGTM! Well-defined interface for query parameter options.

The QueryParamOptions interface provides type safety for the queryParams object. It allows for flexible key names while ensuring each value has a replace property. This addresses the TypeScript-related concern raised in the past review comments and improves the overall type safety of the code.


53-59: LGTM! Efficient and type-safe implementation of queryParams.

The DemoCodeMirrorRoute class efficiently initializes the queryParams property using reduce on the QUERY_PARAMS array. This implementation:

  1. Follows the suggestion from the past review comments to reduce repetition.
  2. Properly uses TypeScript generics with QueryParamOptions to ensure type safety.
  3. Provides a concise and maintainable way to set { replace: true } for each parameter.

Great job on implementing this improvement!


1-59: Great implementation that achieves the PR objectives!

This implementation successfully binds all CodeMirror Demo options to query parameters, as outlined in the PR objectives. The code is well-structured, type-safe, and maintainable. It addresses the concerns raised in past review comments and provides an efficient solution for storing and managing editor configurations.

Key achievements:

  1. Centralized list of query parameters (QUERY_PARAMS) for easy management.
  2. Type-safe interface (QueryParamOptions) for query parameter options.
  3. Efficient initialization of queryParams using reduce.

These changes will indeed allow users to easily link to specific editor configurations and preserve options when refreshing the page, enhancing the usability of the CodeMirror Demo.


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

github-actions bot commented Sep 29, 2024

Test Results

  1 files  ±0    1 suites  ±0   6m 7s ⏱️ - 1m 13s
575 tests ±0  539 ✅ ±0  36 💤 ±0  0 ❌ ±0 
590 runs  ±0  554 ✅ ±0  36 💤 ±0  0 ❌ ±0 

Results for commit 4af2754. ± Comparison against base commit 0ed1d24.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Sep 29, 2024

Codecov Report

Attention: Patch coverage is 97.91667% with 1 line in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/controllers/demo/code-mirror.ts 97.72% 1 Missing ⚠️
Additional details and impacted files

📢 Thoughts on this report? Let us know!

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

🧹 Outside diff range and nitpick comments (3)
app/controllers/demo/code-mirror.ts (2)

19-61: LGTM with suggestions for improvement

The introduction of OPTION_DEFAULTS is a good practice for centralizing default values. However, consider the following suggestions:

  1. For index-based defaults (e.g., selectedDocumentIndex, selectedThemeIndex), consider using named constants or computed values to make the code more resilient to changes in the underlying arrays.
  2. Consider grouping similar options (e.g., all boolean flags together, all index-based options together) for better readability.
  3. Add comments explaining the purpose of less obvious options to improve maintainability.

288-290: LGTM with a suggestion for improvement

The resetAllOptions action effectively fulfills the PR objective of allowing users to reset configurations. Using Object.assign is an efficient way to reset multiple properties at once.

Suggestion: Consider explicitly listing the properties to be reset instead of using Object.assign with the entire OPTION_DEFAULTS object. This approach would provide more control over which properties are reset and prevent accidentally overwriting properties that shouldn't be changed.

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

301-307: LGTM! Consider adding keyboard accessibility.

The addition of the "Reset all options" button aligns perfectly with the PR objective. The styling and positioning look good, and the use of role="button" enhances accessibility.

To further improve accessibility, consider adding keyboard support:

 <span
   role="button"
+  tabindex="0"
   class="text-xs text-blue-600 hover:text-blue-800 dark:text-blue-200 dark:hover:text-blue-400 underline cursor-pointer"
   {{on "click" this.resetAllOptions}}
+  {{on "keydown" (fn this.handleKeyDown this.resetAllOptions)}}
 >Reset all options</span>

You'll need to implement the handleKeyDown method in the component's JavaScript file:

handleKeyDown(action, event) {
  if (event.key === 'Enter' || event.key === ' ') {
    event.preventDefault();
    action();
  }
}

This change will allow users to activate the reset button using the keyboard (Enter or Space key), improving accessibility.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0ed1d24 and f8c9f17.

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

89-131: LGTM with a note on URL length

The expansion of queryParams to include all options from OPTION_DEFAULTS aligns well with the PR objective of binding all CodeMirror Demo options to query parameters. This change enhances the demo's flexibility and shareability.

Note: Be aware that with so many query parameters, URLs could become quite long. Consider implementing a way to compress or encode the parameters for sharing if this becomes an issue in practice.


204-208: LGTM: Consistent initialization of tracked properties

The update of tracked properties to use values from OPTION_DEFAULTS is a good practice. It ensures consistency between the default values and the initial state of the controller, reducing duplication and improving maintainability.

Also applies to: 240-276


Line range hint 19-290: Overall LGTM: PR objectives successfully implemented

The changes in this file successfully implement the PR objectives:

  1. All CodeMirror Demo options are now bound to query parameters, allowing easy sharing of specific editor configurations.
  2. A reset functionality has been added to allow users to revert to default settings.

The implementation is generally well-structured and consistent. The introduction of OPTION_DEFAULTS centralizes default values, improving maintainability. The expansion of queryParams and the update of tracked properties ensure that all options can be controlled via URL parameters and are properly initialized.

While there are some minor suggestions for improvement in the previous comments, the overall implementation is solid and achieves the intended goals.

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

298-298: LGTM! Verify visual alignment.

The change from my-4 to mt-4 removes the bottom margin while maintaining the top margin. This adjustment aligns with the PR's goal of enhancing the CodeMirror Demo page.

Please verify that this change doesn't negatively impact the visual layout of the component and its surrounding elements.


Line range hint 1-308: Great job implementing the CodeMirror Demo enhancements!

The changes in this file successfully achieve the PR objectives:

  1. The CodeMirror component's styling has been adjusted for better visual alignment.
  2. A "Reset all options" button has been added, allowing users to easily reset configurations.

These modifications enhance the usability of the CodeMirror Demo page by providing a way to reset options and potentially improving the layout. The implementation is clean and well-integrated into the existing structure.

A minor suggestion has been made to further improve accessibility for keyboard users. Overall, this is a solid contribution to the project.

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