-
Notifications
You must be signed in to change notification settings - Fork 19
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
Bind all CodeMirror Demo options to query params & allow resetting them #2273
Conversation
WalkthroughThe changes introduce a new configuration object, Changes
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (4)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
Additional details and impacted files📢 Thoughts on this report? Let us know! |
There was a problem hiding this 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 improvementThe introduction of
OPTION_DEFAULTS
is a good practice for centralizing default values. However, consider the following suggestions:
- 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.- Consider grouping similar options (e.g., all boolean flags together, all index-based options together) for better readability.
- Add comments explaining the purpose of less obvious options to improve maintainability.
288-290
: LGTM with a suggestion for improvementThe
resetAllOptions
action effectively fulfills the PR objective of allowing users to reset configurations. UsingObject.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 entireOPTION_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
📒 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 lengthThe expansion of
queryParams
to include all options fromOPTION_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 propertiesThe 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 implementedThe changes in this file successfully implement the PR objectives:
- All CodeMirror Demo options are now bound to query parameters, allowing easy sharing of specific editor configurations.
- 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 ofqueryParams
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
tomt-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:
- The CodeMirror component's styling has been adjusted for better visual alignment.
- 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.
dac38fb
to
4af2754
Compare
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
[percy]
in the message to trigger)Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Chores