diff --git a/webapp/src/components/sidebar_right/sidebar_right.jsx b/webapp/src/components/sidebar_right/sidebar_right.jsx index 567527929..7578db894 100644 --- a/webapp/src/components/sidebar_right/sidebar_right.jsx +++ b/webapp/src/components/sidebar_right/sidebar_right.jsx @@ -81,6 +81,15 @@ export default class SidebarRight extends React.PureComponent { }).isRequired, }; + constructor(props) { + super(props); + this.state = {selectedRepo: ''}; + } + + handleRepoFilterChange = (e) => { + this.setState({selectedRepo: e.target.value}); + } + componentDidMount() { if (this.props.yourPrs && this.props.rhsState === RHSStates.PRS) { this.props.actions.getYourPrsDetails(mapGithubItemListToPrList(this.props.yourPrs)); @@ -92,6 +101,11 @@ export default class SidebarRight extends React.PureComponent { } componentDidUpdate(prevProps) { + // Reset repo filter when switching RHS tabs + if (prevProps.rhsState !== this.props.rhsState) { + this.setState({selectedRepo: ''}); + } + if (shouldUpdateDetails(this.props.yourPrs, prevProps.yourPrs, RHSStates.PRS, this.props.rhsState, prevProps.rhsState)) { this.props.actions.getYourPrsDetails(mapGithubItemListToPrList(this.props.yourPrs)); } @@ -134,17 +148,42 @@ export default class SidebarRight extends React.PureComponent { githubItems = unreads; title = 'Unread Messages'; listUrl = baseURL + '/notifications'; + break; case RHSStates.ASSIGNMENTS: githubItems = yourAssignments; title = 'Your Assignments'; listUrl = baseURL + '/pulls?q=is%3Aopen+archived%3Afalse+assignee%3A' + username + orgQuery; + break; default: break; } + // Extract unique repo names for filter dropdown + const repoNames = [...new Set( + githubItems.map((item) => { + if (item.repository_url) { + return item.repository_url.replace(/.+\/repos\//, ''); + } else if (item.repository?.full_name) { + return item.repository.full_name; + } + return null; + }).filter(Boolean), + )].sort(); + + // Filter items by selected repo + const {selectedRepo} = this.state; + const filteredItems = selectedRepo ? + githubItems.filter((item) => { + const repoName = item.repository_url ? + item.repository_url.replace(/.+\/repos\//, '') : + item.repository?.full_name; + return repoName === selectedRepo; + }) : + githubItems; + return ( {title} + {repoNames.length > 1 && ( + + )}