-
Notifications
You must be signed in to change notification settings - Fork 175
feat: add refresh ability to GitHub RHS sidebar #1026
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import Scrollbars from 'react-custom-scrollbars-2'; | ||
| import {OverlayTrigger, Tooltip} from 'react-bootstrap'; | ||
|
|
||
| import {RHSStates} from '../../constants'; | ||
|
|
||
|
|
@@ -78,10 +79,31 @@ export default class SidebarRight extends React.PureComponent { | |
| actions: PropTypes.shape({ | ||
| getYourPrsDetails: PropTypes.func.isRequired, | ||
| getReviewsDetails: PropTypes.func.isRequired, | ||
| getSidebarContent: PropTypes.func.isRequired, | ||
| }).isRequired, | ||
| }; | ||
|
|
||
| constructor(props) { | ||
| super(props); | ||
| this.state = {refreshing: false}; | ||
| } | ||
|
|
||
| handleRefresh = async (e) => { | ||
| if (e) { | ||
| e.preventDefault(); | ||
| } | ||
| if (this.state.refreshing) { | ||
| return; | ||
| } | ||
| this.setState({refreshing: true}); | ||
| await this.props.actions.getSidebarContent(); | ||
| this.setState({refreshing: false}); | ||
| }; | ||
|
|
||
| componentDidMount() { | ||
| // Auto-refresh on open to guarantee latest data (issue #131) | ||
| this.handleRefresh(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The auto refresh on mount is redundant because getSidebarContent() is already dispatched from This adds an extra GitHub search call every time the user opens the RHS, which is expensive. I'd suggest removing the auto refresh entirely and relying on the manual button and existing WS-driven updates. If you want to keep it, please mirror the E2E guard from sidebar_buttons.jsx. |
||
|
|
||
| if (this.props.yourPrs && this.props.rhsState === RHSStates.PRS) { | ||
| this.props.actions.getYourPrsDetails(mapGithubItemListToPrList(this.props.yourPrs)); | ||
| } | ||
|
|
@@ -163,6 +185,19 @@ export default class SidebarRight extends React.PureComponent { | |
| rel='noopener noreferrer' | ||
| >{title}</a> | ||
| </strong> | ||
| <OverlayTrigger | ||
| key='rhsRefreshButton' | ||
| placement='left' | ||
| overlay={<Tooltip id='rhsRefreshTooltip'>{'Refresh'}</Tooltip>} | ||
| > | ||
| <a | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| href='#' | ||
| style={style.refreshButton} | ||
| onClick={this.handleRefresh} | ||
| > | ||
| <i className={'fa fa-refresh' + (this.state.refreshing ? ' fa-spin' : '')}/> | ||
| </a> | ||
| </OverlayTrigger> | ||
| </div> | ||
| <div> | ||
| <GithubItems | ||
|
|
@@ -181,5 +216,12 @@ export default class SidebarRight extends React.PureComponent { | |
| const style = { | ||
| sectionHeader: { | ||
| padding: '15px', | ||
| display: 'flex', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This switches every RHS state's header to flex layout not just the ones with the refresh button. Could you attach screenshots of all four states (PRS, REVIEWS, UNREADS, ASSIGNMENTS) on both light and dark themes? Want to make sure the title alignment doesn't regress anywhere. |
||
| justifyContent: 'space-between', | ||
| alignItems: 'center', | ||
| }, | ||
| refreshButton: { | ||
| color: 'rgba(0, 0, 0, 0.4)', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hard-coded color will be invisible on dark themes. this.props.theme is already available on the component please derive the color the same way sidebar_buttons.jsx does. Please convert the bottom-of-file style object to a memoized factory: |
||
| cursor: 'pointer', | ||
| }, | ||
| }; | ||
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.
I see a couple of issues here.
setStateis async so two fast clicks can both pass the this.state.refreshing check before either update lands. Use an instance flag for the gate. We also need unmount safety.Suggested rewrite: