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

use html5 details element instead of javascript #2531

Merged
merged 4 commits into from
Mar 2, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 17 additions & 35 deletions static/js/api_endpoint.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,27 @@ import React from 'react';
// Styles for this element is defined in src/css/custom.css

export default class ApiEndpoint extends React.Component {
constructor(props){
super(props);
this.state = {
open: false
}
this.toggleInfo = this.toggleInfo.bind(this);
}

toggleInfo(e){
this.setState({open: !this.state.open})
}

render() {
return (
<div className="api-endpoint">
<div
onClick={this.toggleInfo}
className="api-endpoint-header"
>
<div className={`api-endpoint-method ${ this.props.method }`}>
<details className="api-endpoint">
<summary onClick={this.toggleInfo} className="api-endpoint-header">
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 14, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

Suggested change
<details className="api-endpoint">
<summary onClick={this.toggleInfo} className="api-endpoint-header">
<details className="api-endpoint">
<summary className="api-endpoint-header">

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot, Robot 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@remy Thanks for the confirmation! Happy to help! 🤖


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

<div className={`api-endpoint-method ${this.props.method}`}>
{this.props.method}
</div>
<code>{this.props.path}</code>
<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 ? ("🔓") : ("🔒")}
</div>
<code>{this.props.path}</code>
<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 ? '🔓' : '🔒'}
</div>
{this.state.open ? (
<div className="api-endpoint-content">
{this.props.children}
</div>
): null}
</div>
</summary>

<div className="api-endpoint-content">{this.props.children}</div>
</details>
);
}
}
}