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

[GHG-654] Added mentions on sidebar buttons / rhs bar #775

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
12 changes: 7 additions & 5 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type SidebarContent struct {
PRs []*github.Issue `json:"prs"`
Reviews []*github.Issue `json:"reviews"`
Assignments []*github.Issue `json:"assignments"`
Mentions []*github.Issue `json:"mentions"`
Unreads []*FilteredNotification `json:"unreads"`
}

Expand Down Expand Up @@ -938,19 +939,19 @@ func (p *Plugin) createIssueComment(c *UserContext, w http.ResponseWriter, r *ht
p.writeJSON(w, result)
}

func (p *Plugin) getLHSData(c *UserContext) (reviewResp []*github.Issue, assignmentResp []*github.Issue, openPRResp []*github.Issue, err error) {
func (p *Plugin) getLHSData(c *UserContext) (reviewResp []*github.Issue, assignmentResp []*github.Issue, openPRResp []*github.Issue, mentionsResp []*github.Issue, err error) {
cyrusjc marked this conversation as resolved.
Show resolved Hide resolved
graphQLClient := p.graphQLConnect(c.GHInfo)

reviewResp, assignmentResp, openPRResp, err = graphQLClient.GetLHSData(c.Context.Ctx)
reviewResp, assignmentResp, openPRResp, mentionsResp, err = graphQLClient.GetLHSData(c.Context.Ctx)
if err != nil {
return []*github.Issue{}, []*github.Issue{}, []*github.Issue{}, err
return []*github.Issue{}, []*github.Issue{}, []*github.Issue{}, []*github.Issue{}, err
}

return reviewResp, assignmentResp, openPRResp, nil
return reviewResp, assignmentResp, openPRResp, mentionsResp, nil
}

func (p *Plugin) getSidebarData(c *UserContext) (*SidebarContent, error) {
reviewResp, assignmentResp, openPRResp, err := p.getLHSData(c)
reviewResp, assignmentResp, openPRResp, mentionsResp, err := p.getLHSData(c)
if err != nil {
return nil, err
}
Expand All @@ -959,6 +960,7 @@ func (p *Plugin) getSidebarData(c *UserContext) (*SidebarContent, error) {
PRs: openPRResp,
Assignments: assignmentResp,
Reviews: reviewResp,
Mentions: mentionsResp,
Unreads: p.getUnreadsData(c),
}, nil
}
Expand Down
9 changes: 9 additions & 0 deletions server/plugin/graphql/lhs_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,13 @@ var mainQuery struct {
HasNextPage bool
}
} `graphql:"graphql: search(first:100, after:$openPrsCursor, query: $prOpenQueryArg, type: ISSUE)"`

Mentions struct {
IssueCount int
Nodes []prSearchNodes
PageInfo struct {
EndCursor githubv4.String
HasNextPage bool
}
} `graphql:"mentions: search(first:100, after:$mentionsCursor, query: $prMentionsQueryArg, type: ISSUE)"`
}
31 changes: 25 additions & 6 deletions server/plugin/graphql/lhs_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,57 @@ const (
queryParamReviewsCursor = "reviewsCursor"
queryParamAssignmentsCursor = "assignmentsCursor"
queryParamOpenPRsCursor = "openPrsCursor"
queryParamMentionsCursor = "mentionsCursor"

queryParamOpenPRQueryArg = "prOpenQueryArg"
queryParamReviewPRQueryArg = "prReviewQueryArg"
queryParamAssigneeQueryArg = "assigneeQueryArg"
queryParamMentionsQueryArg = "prMentionsQueryArg"
)

func (c *Client) GetLHSData(ctx context.Context) ([]*github.Issue, []*github.Issue, []*github.Issue, error) {
func (c *Client) GetLHSData(ctx context.Context) ([]*github.Issue, []*github.Issue, []*github.Issue, []*github.Issue, error) {
params := map[string]interface{}{
queryParamOpenPRQueryArg: githubv4.String(fmt.Sprintf("author:%s is:pr is:%s archived:false", c.username, githubv4.PullRequestStateOpen)),
queryParamReviewPRQueryArg: githubv4.String(fmt.Sprintf("review-requested:%s is:pr is:%s archived:false", c.username, githubv4.PullRequestStateOpen)),
queryParamAssigneeQueryArg: githubv4.String(fmt.Sprintf("assignee:%s is:%s archived:false", c.username, githubv4.PullRequestStateOpen)),
queryParamMentionsQueryArg: githubv4.String(fmt.Sprintf("mentions:%s is:%s is:pr archived:false", c.username, githubv4.PullRequestStateOpen)),
queryParamReviewsCursor: (*githubv4.String)(nil),
queryParamAssignmentsCursor: (*githubv4.String)(nil),
queryParamOpenPRsCursor: (*githubv4.String)(nil),
queryParamMentionsCursor: (*githubv4.String)(nil),
}

if c.org != "" {
params[queryParamOpenPRQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", c.org, params[queryParamOpenPRQueryArg]))
params[queryParamReviewPRQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", c.org, params[queryParamReviewPRQueryArg]))
params[queryParamAssigneeQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", c.org, params[queryParamAssigneeQueryArg]))
params[queryParamMentionsQueryArg] = githubv4.String(fmt.Sprintf("org:%s %s", c.org, params[queryParamMentionsQueryArg]))
}

var resultReview, resultAssignee, resultOpenPR []*github.Issue
allReviewRequestsFetched, allAssignmentsFetched, allOpenPRsFetched := false, false, false
var resultReview, resultAssignee, resultOpenPR, resultMentions []*github.Issue
cyrusjc marked this conversation as resolved.
Show resolved Hide resolved
allReviewRequestsFetched, allAssignmentsFetched, allOpenPRsFetched, allMentionsFetched := false, false, false, false

for {
if allReviewRequestsFetched && allAssignmentsFetched && allOpenPRsFetched {
if allReviewRequestsFetched && allAssignmentsFetched && allOpenPRsFetched && allMentionsFetched {
break
}

if err := c.executeQuery(ctx, &mainQuery, params); err != nil {
return nil, nil, nil, errors.Wrap(err, "Not able to excute the query")
return nil, nil, nil, nil, errors.Wrap(err, "Not able to excute the query")
}

if !allMentionsFetched {
for i := range mainQuery.Mentions.Nodes {
resp := mainQuery.Mentions.Nodes[i]
pr := getPR(&resp)
resultMentions = append(resultMentions, pr)
}

if !mainQuery.Mentions.PageInfo.HasNextPage {
allMentionsFetched = true
}

params[queryParamMentionsCursor] = githubv4.NewString(mainQuery.Mentions.PageInfo.EndCursor)
}

if !allReviewRequestsFetched {
Expand Down Expand Up @@ -90,7 +109,7 @@ func (c *Client) GetLHSData(ctx context.Context) ([]*github.Issue, []*github.Iss
}
}

return resultReview, resultAssignee, resultOpenPR, nil
return resultReview, resultAssignee, resultOpenPR, resultMentions, nil
}

func getPR(prResp *prSearchNodes) *github.Issue {
Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/sidebar_buttons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function mapStateToProps(state) {
return {
connected: state[`plugins-${pluginId}`].connected,
clientId: state[`plugins-${pluginId}`].clientId,
mentions: state[`plugins-${pluginId}`].sidebarContent.mentions,
reviews: state[`plugins-${pluginId}`].sidebarContent.reviews,
yourPrs: state[`plugins-${pluginId}`].sidebarContent.prs,
yourAssignments: state[`plugins-${pluginId}`].sidebarContent.assignments,
Expand Down
17 changes: 17 additions & 0 deletions webapp/src/components/sidebar_buttons/sidebar_buttons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class SidebarButtons extends React.PureComponent {
connected: PropTypes.bool,
clientId: PropTypes.string,
enterpriseURL: PropTypes.string,
mentions: PropTypes.arrayOf(PropTypes.object),
reviews: PropTypes.arrayOf(PropTypes.object),
unreads: PropTypes.arrayOf(PropTypes.object),
yourPrs: PropTypes.arrayOf(PropTypes.object),
Expand Down Expand Up @@ -117,6 +118,7 @@ export default class SidebarButtons extends React.PureComponent {
return null;
}

const mentions = this.props.mentions || [];
const reviews = this.props.reviews || [];
const yourPrs = this.props.yourPrs || [];
const unreads = this.props.unreads || [];
Expand Down Expand Up @@ -152,6 +154,21 @@ export default class SidebarButtons extends React.PureComponent {
{' ' + yourPrs.length}
</a>
</OverlayTrigger>

<OverlayTrigger
key='githubMentionsLink'
placement={placement}
overlay={<Tooltip id='mentionTooltip'>{'Mentions on Pull Requests'}</Tooltip>}
>
<a
onClick={() => this.openRHS(RHSStates.MENTIONS)}
style={button}
>
<i className='fa fa-comment-o'/>
{' ' + mentions.length}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm leaning towards not showing the number of mentions.

There are users who are keen on keeping their inboxes empty. Given that they have no control over this number and can't reduce it, I wonder if we should omit the number. The button would still allow the user to check in on their conversation but would no longer nag them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point. I think it makes sense to remove the number. Would we then want to change the ordering of the mentions icon? I was thinking since it would be just an icon we can move it next to the refresh button

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would look something like this:

image

Copy link
Contributor

Choose a reason for hiding this comment

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

@hanzei Is it possible to "remove" mentions? Maybe unsubscribing to the issue/PR does this?

Copy link
Contributor

Choose a reason for hiding this comment

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

@cyrusjc Do you know?

Copy link
Contributor

Choose a reason for hiding this comment

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

It would look something like this:

image

I like the suggestion 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't sorry.

</a>
</OverlayTrigger>

<OverlayTrigger
key='githubReviewsLink'
placement={placement}
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/sidebar_right/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {getSidebarData} from 'src/selectors';
import SidebarRight from './sidebar_right.jsx';

function mapStateToProps(state) {
const {username, reviews, yourPrs, yourAssignments, unreads, enterpriseURL, org, rhsState} = getSidebarData(state);
const {username, mentions, reviews, yourPrs, yourAssignments, unreads, enterpriseURL, org, rhsState} = getSidebarData(state);
return {
username,
reviews,
yourPrs,
mentions,
yourAssignments,
unreads,
enterpriseURL,
Expand Down
10 changes: 9 additions & 1 deletion webapp/src/components/sidebar_right/sidebar_right.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default class SidebarRight extends React.PureComponent {
username: PropTypes.string,
org: PropTypes.string,
enterpriseURL: PropTypes.string,
mentions: PropTypes.arrayOf(PropTypes.object),
reviews: PropTypes.arrayOf(PropTypes.object),
unreads: PropTypes.arrayOf(PropTypes.object),
yourPrs: PropTypes.arrayOf(PropTypes.object),
Expand Down Expand Up @@ -103,7 +104,7 @@ export default class SidebarRight extends React.PureComponent {
render() {
const baseURL = this.props.enterpriseURL ? this.props.enterpriseURL : 'https://github.com';
const orgQuery = this.props.org ? '+org%3A' + this.props.org : '';
const {yourPrs, reviews, unreads, yourAssignments, username, rhsState} = this.props;
const {yourPrs, mentions, reviews, unreads, yourAssignments, username, rhsState} = this.props;

let title = '';
let githubItems = [];
Expand All @@ -116,6 +117,13 @@ export default class SidebarRight extends React.PureComponent {
title = 'Your Open Pull Requests';
listUrl = baseURL + '/pulls?q=is%3Aopen+is%3Apr+author%3A' + username + '+archived%3Afalse' + orgQuery;

break;
case RHSStates.MENTIONS:

githubItems = mentions;
title = 'Your mentions';
listUrl = baseURL + '/pulls?q=is%3Aopen+is%3Apr+mentions%3A' + username + '+archived%3Afalse' + orgQuery;

break;
case RHSStates.REVIEWS:

Expand Down
1 change: 1 addition & 0 deletions webapp/src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export const RHSStates = {
REVIEWS: 'reviews',
UNREADS: 'unreads',
ASSIGNMENTS: 'assignments',
MENTIONS: 'mentions',
};
1 change: 1 addition & 0 deletions webapp/src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ const defaultSidebarContent = {
prs: [],
assignments: [],
unreads: [],
mentions: [],
};

function sidebarContent(state = defaultSidebarContent, action) {
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ function mapPrsToDetails(prs, details) {
export const getSidebarData = createSelector(
getPluginState,
(pluginState) => {
const {username, sidebarContent, reviewDetails, yourPrDetails, organization, rhsState} = pluginState;
const {username, mentionsDetails, sidebarContent, reviewDetails, yourPrDetails, organization, rhsState} = pluginState;
cyrusjc marked this conversation as resolved.
Show resolved Hide resolved
return {
username,
mentions: mapPrsToDetails(sidebarContent.mentions || emptyArray, mentionsDetails),
reviews: mapPrsToDetails(sidebarContent.reviews || emptyArray, reviewDetails),
yourPrs: mapPrsToDetails(sidebarContent.prs || emptyArray, yourPrDetails),
yourAssignments: sidebarContent.assignments || emptyArray,
Expand Down
Loading