-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
use html5 details element instead of javascript #2531
base: master
Are you sure you want to change the base?
Conversation
Reduces reliance on JS for content. I found when the JS didn't full load (flaky connection), I couldn't open these detail blocks.
📝 WalkthroughWalkthroughThe pull request introduces a refactoring of the Changes
Sequence DiagramsequenceDiagram
participant User
participant ApiEndpoint
participant HTMLDetails
User->>ApiEndpoint: Interact with summary
ApiEndpoint->>HTMLDetails: Native toggle triggered
HTMLDetails-->>User: Content expands/collapses
Finishing Touches
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 (
|
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 comments (1)
static/js/api_endpoint.jsx (1)
Remove unnecessary onClick handler
The
onClick={this.toggleInfo}
handler references a non-existent method. Since the<details>
element handles toggling natively, this handler should be removed:
- Remove
onClick={this.toggleInfo}
from the<summary>
element instatic/js/api_endpoint.jsx
🔗 Analysis chain
Line range hint
1-29
: Verify removal of old implementation.Let's ensure all related JavaScript toggle implementation has been removed and no other components depend on it.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any remaining references to the old toggle implementation rg -l "toggleInfo|isOpen.*ApiEndpoint" --type js # Search for any components extending ApiEndpoint ast-grep --pattern 'class $_ extends ApiEndpoint'Length of output: 129
Script:
#!/bin/bash # Search for test files related to ApiEndpoint fd "api_endpoint.*test" --type f # Search for documentation files mentioning ApiEndpoint toggle behavior rg -l "ApiEndpoint.*toggle|toggle.*ApiEndpoint" --type md --type txtLength of output: 105
🧹 Nitpick comments (1)
static/js/api_endpoint.jsx (1)
14-22
: Consider using semantic icons instead of emojis.While emojis are functional, using proper semantic icons (e.g., Font Awesome, Material Icons) would be more professional for security status indicators. This would also ensure consistent rendering across different platforms and browsers.
Example implementation using Font Awesome icons:
- {this.props.unprotected ? '🔓' : '🔒'} + <i className={`fa ${this.props.unprotected ? 'fa-unlock' : 'fa-lock'}`} aria-hidden="true"></i>
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
static/js/api_endpoint.jsx
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Redirect rules - developers-home-assistant
- GitHub Check: Header rules - developers-home-assistant
- GitHub Check: Pages changed - developers-home-assistant
🔇 Additional comments (1)
static/js/api_endpoint.jsx (1)
8-26
: Great implementation of native HTML5 details element!The refactoring successfully achieves the PR objective by:
- Eliminating JavaScript dependency for toggle functionality
- Maintaining existing styling capabilities
- Improving accessibility with native HTML elements
static/js/api_endpoint.jsx
Outdated
<details className="api-endpoint"> | ||
<summary onClick={this.toggleInfo} className="api-endpoint-header"> |
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.
Remove redundant onClick handler.
The onClick={this.toggleInfo}
handler is unnecessary and will cause runtime errors since the method isn't defined. The native <details>
element handles the toggle behavior automatically without JavaScript.
Apply this diff to fix the issue:
<details className="api-endpoint">
- <summary onClick={this.toggleInfo} className="api-endpoint-header">
+ <summary className="api-endpoint-header">
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
<details className="api-endpoint"> | |
<summary onClick={this.toggleInfo} className="api-endpoint-header"> | |
<details className="api-endpoint"> | |
<summary className="api-endpoint-header"> |
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.
Good spot, Robot 👍
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.
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: 0
🧹 Nitpick comments (1)
static/js/api_endpoint.jsx (1)
14-22
: Consider enhancing accessibility and maintainability.While the implementation works, consider these improvements:
- Add ARIA labels for the lock emojis
- Extract the protection status text to constants
+ const PROTECTION_STATUS = { + protected: { + title: 'Authentication is required for this endpoint', + icon: '🔒', + ariaLabel: 'Protected endpoint' + }, + unprotected: { + title: 'Authentication is not required for this endpoint', + icon: '🔓', + ariaLabel: 'Unprotected endpoint' + } + }; <div className="api-endpoint-protection" - title={ - this.props.unprotected - ? 'Authentication is not required for this endpoint' - : 'Authentication is required for this endpoint' - }> - {this.props.unprotected ? '🔓' : '🔒'} + title={PROTECTION_STATUS[this.props.unprotected ? 'unprotected' : 'protected'].title} + aria-label={PROTECTION_STATUS[this.props.unprotected ? 'unprotected' : 'protected'].ariaLabel}> + {PROTECTION_STATUS[this.props.unprotected ? 'unprotected' : 'protected'].icon} </div>
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
static/js/api_endpoint.jsx
(1 hunks)
🔇 Additional comments (4)
static/js/api_endpoint.jsx (4)
8-9
: Great use of native HTML5 elements!The switch to
<details>
and<summary>
elements is an excellent choice as it:
- Ensures content accessibility even when JavaScript fails to load
- Reduces code complexity by leveraging native browser functionality
- Maintains styling through existing CSS classes
10-13
: LGTM! Clean implementation of the method display.The template literal usage for dynamic class names is elegant and the code is well-structured.
25-25
: LGTM! Clean content rendering.The content section is implemented cleanly with proper class name for styling.
8-26
: Overall excellent refactoring!The implementation successfully:
- Removes JavaScript dependency by using native HTML5 elements
- Maintains all existing functionality
- Preserves styling through existing CSS classes
- Improves accessibility by ensuring content is available without JavaScript
This aligns perfectly with the PR objectives and represents a significant improvement in the codebase.
Reduces reliance on JS for content. I found when the JS didn't full load (flaky connection), I couldn't open these detail blocks.
Proposed change
Changed from using JavaScript for the details block to using the native details and summary element from HTML.
This (very slightly) reduces the reliance on JavaScript for content - specifically I found when the JS didn't full load (because of my flaky connection), I couldn't open these detail blocks and then content was fully hidden (can be replicated by disabling JavaScript and trying to read the details on this and other pages).
Also means the accessibility features come for "free" with a native details element.
Type of change
Additional information
Summary by CodeRabbit
<details>
and<summary>
elements for toggle functionality.