Skip to content
Open
Changes from all commits
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
35 changes: 34 additions & 1 deletion webapp/src/components/sidebar_right/sidebar_right.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ export default class SidebarRight extends React.PureComponent {
}).isRequired,
};

constructor(props) {
super(props);
this.state = {sortBy: 'created'};
}

handleSortChange = (e) => {
this.setState({sortBy: e.target.value});
}

componentDidMount() {
if (this.props.yourPrs && this.props.rhsState === RHSStates.PRS) {
this.props.actions.getYourPrsDetails(mapGithubItemListToPrList(this.props.yourPrs));
Expand Down Expand Up @@ -145,6 +154,14 @@ export default class SidebarRight extends React.PureComponent {
break;
}

// Sort items by selected criteria
const {sortBy} = this.state;
const sortedItems = githubItems.slice().sort((a, b) => {
const dateA = sortBy === 'updated' ? a.updated_at : a.created_at;
const dateB = sortBy === 'updated' ? b.updated_at : b.created_at;
return new Date(dateB) - new Date(dateA);
});

return (
<React.Fragment>
<Scrollbars
Expand All @@ -163,10 +180,18 @@ export default class SidebarRight extends React.PureComponent {
rel='noopener noreferrer'
>{title}</a>
</strong>
<select
value={sortBy}
onChange={this.handleSortChange}
style={style.sortDropdown}
>
<option value='created'>Sort: Created</option>
<option value='updated'>Sort: Updated</option>
</select>
</div>
<div>
<GithubItems
items={githubItems}
items={sortedItems}
theme={this.props.theme}
showReviewSLA={rhsState === RHSStates.REVIEWS}
reviewTargetDays={this.props.reviewTargetDays || 0}
Expand All @@ -182,4 +207,12 @@ const style = {
sectionHeader: {
padding: '15px',
},
sortDropdown: {
marginLeft: '8px',
padding: '2px 4px',
fontSize: '12px',
borderRadius: '4px',
border: '1px solid rgba(0, 0, 0, 0.2)',
background: 'transparent',
},
};