-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathsidebar_right.jsx
More file actions
190 lines (160 loc) · 5.78 KB
/
sidebar_right.jsx
File metadata and controls
190 lines (160 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import PropTypes from 'prop-types';
import Scrollbars from 'react-custom-scrollbars';
import {RHSStates} from '../../constants';
import GithubItems from './github_items';
export function renderView(props) {
return (
<div
{...props}
className='scrollbar--view'
/>);
}
export function renderThumbHorizontal(props) {
return (
<div
{...props}
className='scrollbar--horizontal'
/>);
}
export function renderThumbVertical(props) {
return (
<div
{...props}
className='scrollbar--vertical'
/>);
}
function mapGithubItemListToPrList(gilist) {
if (!gilist) {
return [];
}
return gilist.map((pr) => {
return {url: pr.repository_url, number: pr.number};
});
}
function shouldUpdateDetails(prs, prevPrs, targetState, currentState, prevState) {
if (currentState === targetState) {
if (currentState !== prevState) {
return true;
}
if (prs.length !== prevPrs.length) {
return true;
}
for (let i = 0; i < prs.length; i++) {
if (prs[i].id !== prevPrs[i].id) {
return true;
}
}
}
return false;
}
export default class SidebarRight extends React.PureComponent {
static propTypes = {
username: PropTypes.string,
orgs: PropTypes.array.isRequired,
enterpriseURL: PropTypes.string,
mentions: PropTypes.arrayOf(PropTypes.object),
reviews: PropTypes.arrayOf(PropTypes.object),
unreads: PropTypes.arrayOf(PropTypes.object),
yourPrs: PropTypes.arrayOf(PropTypes.object),
yourAssignments: PropTypes.arrayOf(PropTypes.object),
rhsState: PropTypes.string,
theme: PropTypes.object.isRequired,
actions: PropTypes.shape({
getYourPrsDetails: PropTypes.func.isRequired,
getReviewsDetails: PropTypes.func.isRequired,
}).isRequired,
};
componentDidMount() {
if (this.props.yourPrs && this.props.rhsState === RHSStates.PRS) {
this.props.actions.getYourPrsDetails(mapGithubItemListToPrList(this.props.yourPrs));
}
if (this.props.reviews && this.props.rhsState === RHSStates.REVIEWS) {
this.props.actions.getReviewsDetails(mapGithubItemListToPrList(this.props.reviews));
}
}
componentDidUpdate(prevProps) {
if (shouldUpdateDetails(this.props.yourPrs, prevProps.yourPrs, RHSStates.PRS, this.props.rhsState, prevProps.rhsState)) {
this.props.actions.getYourPrsDetails(mapGithubItemListToPrList(this.props.yourPrs));
}
if (shouldUpdateDetails(this.props.reviews, prevProps.reviews, RHSStates.REVIEWS, this.props.rhsState, prevProps.rhsState)) {
this.props.actions.getReviewsDetails(mapGithubItemListToPrList(this.props.reviews));
}
}
render() {
const baseURL = this.props.enterpriseURL ? this.props.enterpriseURL : 'https://github.com';
let orgQuery = '';
this.props.orgs.map((org) => {
orgQuery += ('+org%3A' + org);
return orgQuery;
});
const {yourPrs, mentions, reviews, unreads, yourAssignments, username, rhsState} = this.props;
let title = '';
let githubItems = [];
let listUrl = '';
switch (rhsState) {
case RHSStates.PRS:
githubItems = yourPrs;
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:
githubItems = reviews;
listUrl = baseURL + '/pulls?q=is%3Aopen+is%3Apr+review-requested%3A' + username + '+archived%3Afalse' + orgQuery;
title = 'Pull Requests Needing Review';
break;
case RHSStates.UNREADS:
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;
}
return (
<React.Fragment>
<Scrollbars
autoHide={true}
autoHideTimeout={500}
autoHideDuration={500}
renderThumbHorizontal={renderThumbHorizontal}
renderThumbVertical={renderThumbVertical}
renderView={renderView}
>
<div style={style.sectionHeader}>
<strong>
<a
href={listUrl}
target='_blank'
rel='noopener noreferrer'
>{title}</a>
</strong>
</div>
<div>
<GithubItems
items={githubItems}
theme={this.props.theme}
/>
</div>
</Scrollbars>
</React.Fragment>
);
}
}
const style = {
sectionHeader: {
padding: '15px',
},
};