From a48ea8c912f2f667020c6a6ffd860f4627a5ff12 Mon Sep 17 00:00:00 2001 From: SHRISHTISHUKLA-0 Date: Wed, 29 Jan 2025 19:21:37 +0530 Subject: [PATCH 1/2] Logout Refactor --- .../src/components/LogoutButton.react.js | 141 ++++++------------ 1 file changed, 47 insertions(+), 94 deletions(-) diff --git a/components/dash-core-components/src/components/LogoutButton.react.js b/components/dash-core-components/src/components/LogoutButton.react.js index b9c1e4d1d8..f2d47e1cc7 100644 --- a/components/dash-core-components/src/components/LogoutButton.react.js +++ b/components/dash-core-components/src/components/LogoutButton.react.js @@ -1,120 +1,73 @@ + +/**remove dcc.logoutbutton completely and +used fetch API to send a POST request to/logout and handle logout action using +javascript without a form and styled the button while keeping it functional + import React from 'react'; import PropTypes from 'prop-types'; import './css/logout.css'; /** - * Logout button to submit a form post request to the `logout_url` prop. - * Usage is intended for dash-deployment-server authentication. - * - * DDS usage: - * - * `dcc.LogoutButton(logout_url=os.getenv('DASH_LOGOUT_URL'))` - * - * Custom usage: - * - * - Implement a login mechanism. - * - Create a flask route with a post method handler. - * `@app.server.route('/logout', methods=['POST'])` - * - The logout route should perform what's necessary for the user to logout. - * - If you store the session in a cookie, clear the cookie: - * `rep = flask.Response(); rep.set_cookie('session', '', expires=0)` - * - * - Create a logout button component and assign it the logout_url - * `dcc.LogoutButton(logout_url='/logout')` - * - * See https://dash.plotly.com/dash-core-components/logout_button - * for more documentation and examples. + * LogoutButton component to handle user logout. + * Sends a POST request to the provided `logoutUrl` when clicked. */ export default class LogoutButton extends React.Component { - render() { - const {id, logout_url, label, className, style, method, loading_state} = - this.props; + constructor(props) { + super(props); + this.handleLogout = this.handleLogout.bind(this); + } - let url, submitMethod; - if (!logout_url) { - url = - logout_url || - 'https://dash.plotly.com/dash-core-components/logout_button'; - submitMethod = 'get'; - } else { - url = logout_url; - submitMethod = method; - } + handleLogout() { + const { logoutUrl, onLogout } = this.props; - return ( -
{ + if (response.ok) { + if (onLogout) { + onLogout(); // Trigger callback if provided + } else { + window.location.href = '/'; // Redirect to home by default + } + } else { + console.error('Logout failed:', response.statusText); } - action={url} - method={submitMethod} - className="dash-logout-frame" + }) + .catch(error => console.error('Logout error:', error)); + } + + render() { + const { id, label, className, style, loadingState } = this.props; + + return ( + -
+ {label} + ); } } +// Default Props LogoutButton.defaultProps = { label: 'Logout', - method: 'post', + logoutUrl: '/logout', // Default logout endpoint }; +// Prop Types LogoutButton.propTypes = { - /** - * Id of the button. - */ id: PropTypes.string, - - /** - * Text of the button - */ label: PropTypes.string, - /** - * Url to submit a post logout request. - */ - logout_url: PropTypes.string, - /** - * Style of the button - */ - style: PropTypes.object, - /** - * Http method to submit the logout form. - */ - method: PropTypes.string, - /** - * CSS class for the button. - */ + logoutUrl: PropTypes.string.isRequired, className: PropTypes.string, - /** - * Dash-assigned callback that gets fired when the value changes. - */ - setProps: PropTypes.func, - - /** - * Object that holds the loading state object coming from dash-renderer - */ - loading_state: PropTypes.shape({ - /** - * Determines if the component is loading or not - */ + style: PropTypes.object, + onLogout: PropTypes.func, // Callback after logout + loadingState: PropTypes.shape({ is_loading: PropTypes.bool, - /** - * Holds which property is loading - */ - prop_name: PropTypes.string, - /** - * Holds the name of the component that is loading - */ - component_name: PropTypes.string, }), -}; +}; \ No newline at end of file From ba5d537c66dcf249ae6815040e7ff516bf758b93 Mon Sep 17 00:00:00 2001 From: SHRISHTISHUKLA-0 Date: Wed, 29 Jan 2025 20:28:59 +0530 Subject: [PATCH 2/2] Tooltip Support --- .../src/components/RadioItems.react.js | 136 +++--------------- 1 file changed, 19 insertions(+), 117 deletions(-) diff --git a/components/dash-core-components/src/components/RadioItems.react.js b/components/dash-core-components/src/components/RadioItems.react.js index a62e2293ff..2527cf171f 100644 --- a/components/dash-core-components/src/components/RadioItems.react.js +++ b/components/dash-core-components/src/components/RadioItems.react.js @@ -1,3 +1,11 @@ +/** + * added support for title in option to provide tooltips + * and ensured compatibility with radioItems and checklist + * and maintained structure + */ +/** + * here updated the RadioItems.js + */ import PropTypes from 'prop-types'; import React, {Component} from 'react'; import './css/react-select@1.0.0-rc.3.min.css'; @@ -5,8 +13,8 @@ import {sanitizeOptions} from '../utils/optionTypes'; /** * RadioItems is a component that encapsulates several radio item inputs. - * The values and labels of the RadioItems is specified in the `options` - * property and the seleced item is specified with the `value` property. + * The values and labels of the RadioItems are specified in the `options` + * property, and the selected item is specified with the `value` property. * Each radio item is rendered as an input with a surrounding label. */ @@ -42,6 +50,7 @@ export default class RadioItems extends Component { > {sanitizeOptions(options).map(option => (