3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
import './index.css' ;
6
- import { renderTimelineEvent , getStatus , renderComment , PullRequestStateEnum } from './pullRequestOverviewRenderer' ;
6
+ import { renderTimelineEvent , getStatus , renderComment , PullRequestStateEnum , renderReview } from './pullRequestOverviewRenderer' ;
7
7
import md from './mdRenderer' ;
8
8
9
9
declare var acquireVsCodeApi : any ;
@@ -14,6 +14,8 @@ const ElementIds = {
14
14
CheckoutDefaultBranch : 'checkout-default-branch' ,
15
15
Close : 'close' ,
16
16
Reply : 'reply' ,
17
+ Approve : 'approve' ,
18
+ RequestChanges : 'request-changes' ,
17
19
Status : 'status' ,
18
20
CommentTextArea : 'comment-textarea' ,
19
21
TimelineEvents :'timeline-events' // If updating this value, change id in pullRequestOverview.ts as well.
@@ -33,6 +35,16 @@ function handleMessage(event: any) {
33
35
break ;
34
36
case 'pr.append-comment' :
35
37
appendComment ( message . value ) ;
38
+ break ;
39
+ case 'pr.append-review' :
40
+ appendReview ( message . value ) ;
41
+ break ;
42
+ case 'pr.enable-approve' :
43
+ ( < HTMLButtonElement > document . getElementById ( ElementIds . Approve ) ) . disabled = false ;
44
+ break ;
45
+ case 'pr.enable-request-changes' :
46
+ ( < HTMLButtonElement > document . getElementById ( ElementIds . RequestChanges ) ) . disabled = false ;
47
+ break ;
36
48
default :
37
49
break ;
38
50
}
@@ -93,19 +105,42 @@ function addEventListeners(pr: any) {
93
105
} ) ;
94
106
} ) ;
95
107
96
- // Enable 'Comment' button only when the user has entered text
108
+ // Enable 'Comment' and 'RequestChanges' button only when the user has entered text
97
109
document . getElementById ( ElementIds . CommentTextArea ) ! . addEventListener ( 'input' , ( e ) => {
98
- ( < HTMLButtonElement > document . getElementById ( ElementIds . Reply ) ) . disabled = ! ( < any > e . target ) . value ;
99
- } )
110
+ const hasNoText = ! ( < any > e . target ) . value ;
111
+ ( < HTMLButtonElement > document . getElementById ( ElementIds . Reply ) ) . disabled = hasNoText ;
112
+ ( < HTMLButtonElement > document . getElementById ( ElementIds . RequestChanges ) ) . disabled = hasNoText ;
113
+
114
+ } ) ;
100
115
101
116
document . getElementById ( ElementIds . Reply ) ! . addEventListener ( 'click' , ( ) => {
102
117
submitComment ( ) ;
103
118
} ) ;
104
119
105
120
document . getElementById ( ElementIds . Close ) ! . addEventListener ( 'click' , ( ) => {
106
121
( < HTMLButtonElement > document . getElementById ( ElementIds . Close ) ) . disabled = true ;
122
+ const inputBox = ( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ) ;
123
+ vscode . postMessage ( {
124
+ command : 'pr.close' ,
125
+ text : inputBox . value
126
+ } ) ;
127
+ } ) ;
128
+
129
+ document . getElementById ( ElementIds . Approve ) ! . addEventListener ( 'click' , ( ) => {
130
+ ( < HTMLButtonElement > document . getElementById ( ElementIds . Approve ) ) . disabled = true ;
131
+ const inputBox = ( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ) ;
132
+ vscode . postMessage ( {
133
+ command : 'pr.approve' ,
134
+ text : inputBox . value
135
+ } ) ;
136
+ } ) ;
137
+
138
+ document . getElementById ( ElementIds . RequestChanges ) ! . addEventListener ( 'click' , ( ) => {
139
+ ( < HTMLButtonElement > document . getElementById ( ElementIds . RequestChanges ) ) . disabled = true ;
140
+ const inputBox = ( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ) ;
107
141
vscode . postMessage ( {
108
- command : 'pr.close'
142
+ command : 'pr.request-changes' ,
143
+ text : inputBox . value
109
144
} ) ;
110
145
} ) ;
111
146
@@ -118,18 +153,31 @@ function addEventListeners(pr: any) {
118
153
} ) ;
119
154
}
120
155
156
+ function clearTextArea ( ) {
157
+ ( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ! ) . value = '' ;
158
+ ( < HTMLButtonElement > document . getElementById ( ElementIds . Reply ) ) . disabled = true ;
159
+ ( < HTMLButtonElement > document . getElementById ( ElementIds . RequestChanges ) ) . disabled = true ;
160
+ }
161
+
121
162
function submitComment ( ) {
122
163
( < HTMLButtonElement > document . getElementById ( ElementIds . Reply ) ) . disabled = true ;
123
164
vscode . postMessage ( {
124
165
command : 'pr.comment' ,
125
166
text : ( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ! ) . value
126
167
} ) ;
127
- ( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ! ) . value = '' ;
168
+
169
+ }
170
+
171
+ function appendReview ( review : any ) : void {
172
+ const newReview = renderReview ( review ) ;
173
+ document . getElementById ( ElementIds . TimelineEvents ) ! . insertAdjacentHTML ( 'beforeend' , newReview ) ;
174
+ clearTextArea ( ) ;
128
175
}
129
176
130
177
function appendComment ( comment : any ) {
131
178
let newComment = renderComment ( comment ) ;
132
179
document . getElementById ( ElementIds . TimelineEvents ) ! . insertAdjacentHTML ( 'beforeend' , newComment ) ;
180
+ clearTextArea ( ) ;
133
181
}
134
182
135
183
function updateCheckoutButton ( isCheckedOut : boolean ) {
@@ -138,7 +186,7 @@ function updateCheckoutButton(isCheckedOut: boolean) {
138
186
checkoutButton . disabled = isCheckedOut ;
139
187
checkoutMasterButton . disabled = false ;
140
188
const activeIcon = '<svg class="octicon octicon-check" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M12 5l-8 8-4-4 1.5-1.5L4 10l6.5-6.5L12 5z"></path></svg>' ;
141
- checkoutButton . innerHTML = isCheckedOut ? `${ activeIcon } Checked Out` : `Checkout ` ;
189
+ checkoutButton . innerHTML = isCheckedOut ? `${ activeIcon } Checked Out` : `Check out ` ;
142
190
143
191
const backButton = ( < HTMLButtonElement > document . getElementById ( ElementIds . CheckoutDefaultBranch ) ) ;
144
192
if ( isCheckedOut ) {
@@ -153,8 +201,10 @@ function updateCheckoutButton(isCheckedOut: boolean) {
153
201
function setTextArea ( ) {
154
202
document . getElementById ( 'comment-form' ) ! . innerHTML = `<textarea id="${ ElementIds . CommentTextArea } "></textarea>
155
203
<div class="form-actions">
156
- <button class="reply-button" id="${ ElementIds . Reply } " disabled="true"></button>
157
- <button class="close-button" id="${ ElementIds . Close } "></button>
204
+ <button id="${ ElementIds . Close } ">Close Pull Request</button>
205
+ <button id="${ ElementIds . RequestChanges } " disabled="true">Request Changes</button>
206
+ <button id="${ ElementIds . Approve } ">Approve</button>
207
+ <button class="reply-button" id="${ ElementIds . Reply } " disabled="true">Comment</button>
158
208
</div>` ;
159
209
160
210
( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ! ) . placeholder = 'Leave a comment' ;
@@ -164,11 +214,9 @@ function setTextArea() {
164
214
return ;
165
215
}
166
216
167
- if ( e . keyCode === 13 && e . ctrlKey ) {
217
+ if ( e . keyCode === 13 && ( e . metaKey || e . ctrlKey ) ) {
168
218
submitComment ( ) ;
169
219
return ;
170
220
}
171
221
} ) ;
172
- ( < HTMLButtonElement > document . getElementById ( ElementIds . Reply ) ! ) . textContent = 'Comment' ;
173
- ( < HTMLButtonElement > document . getElementById ( ElementIds . Close ) ! ) . textContent = 'Close Pull Request' ;
174
222
}
0 commit comments