forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreviews-item.js
More file actions
117 lines (96 loc) · 2.94 KB
/
Copy pathreviews-item.js
File metadata and controls
117 lines (96 loc) · 2.94 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
import React from 'react';
import PropTypes from 'prop-types';
import {Emitter} from 'event-kit';
import {GithubLoginModelPropType, WorkdirContextPoolPropType} from '../prop-types';
import Repository from '../models/repository';
import {getEndpoint} from '../models/endpoint';
import ReviewsContainer from '../containers/reviews-container';
export default class ReviewsItem extends React.Component {
static propTypes = {
// Parsed from URI
host: PropTypes.string.isRequired,
owner: PropTypes.string.isRequired,
repo: PropTypes.string.isRequired,
number: PropTypes.number.isRequired,
workdir: PropTypes.string.isRequired,
// Package models
workdirContextPool: WorkdirContextPoolPropType.isRequired,
loginModel: GithubLoginModelPropType.isRequired,
// Atom environment
workspace: PropTypes.object.isRequired,
config: PropTypes.object.isRequired,
commands: PropTypes.object.isRequired,
tooltips: PropTypes.object.isRequired,
confirm: PropTypes.func.isRequired,
// Action methods
reportRelayError: PropTypes.func.isRequired,
}
static uriPattern = 'atom-github://reviews/{host}/{owner}/{repo}/{number}?workdir={workdir}'
static buildURI({host, owner, repo, number, workdir}) {
return 'atom-github://reviews/' +
encodeURIComponent(host) + '/' +
encodeURIComponent(owner) + '/' +
encodeURIComponent(repo) + '/' +
encodeURIComponent(number) +
'?workdir=' + encodeURIComponent(workdir || '');
}
constructor(props) {
super(props);
this.emitter = new Emitter();
this.isDestroyed = false;
this.state = {
initThreadID: null,
};
}
render() {
const endpoint = getEndpoint(this.props.host);
const repository = this.props.workdir.length > 0
? this.props.workdirContextPool.add(this.props.workdir).getRepository()
: Repository.absent();
return (
<ReviewsContainer
endpoint={endpoint}
repository={repository}
initThreadID={this.state.initThreadID}
{...this.props}
/>
);
}
getTitle() {
return `Reviews #${this.props.number}`;
}
getDefaultLocation() {
return 'right';
}
getPreferredWidth() {
return 400;
}
destroy() {
/* istanbul ignore else */
if (!this.isDestroyed) {
this.emitter.emit('did-destroy');
this.isDestroyed = true;
}
}
onDidDestroy(callback) {
return this.emitter.on('did-destroy', callback);
}
serialize() {
return {
deserializer: 'ReviewsStub',
uri: ReviewsItem.buildURI({
host: this.props.host,
owner: this.props.owner,
repo: this.props.repo,
number: this.props.number,
workdir: this.props.workdir,
}),
};
}
async jumpToThread(id) {
if (this.state.initThreadID === id) {
await new Promise(resolve => this.setState({initThreadID: null}, resolve));
}
return new Promise(resolve => this.setState({initThreadID: id}, resolve));
}
}