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,10 +105,13 @@ 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 ( ) ;
@@ -111,6 +126,24 @@ function addEventListeners(pr: any) {
111
126
} ) ;
112
127
} ) ;
113
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 ) ) ;
141
+ vscode . postMessage ( {
142
+ command : 'pr.request-changes' ,
143
+ text : inputBox . value
144
+ } ) ;
145
+ } ) ;
146
+
114
147
document . getElementById ( ElementIds . CheckoutDefaultBranch ) ! . addEventListener ( 'click' , ( ) => {
115
148
( < HTMLButtonElement > document . getElementById ( ElementIds . CheckoutDefaultBranch ) ) . disabled = true ;
116
149
vscode . postMessage ( {
@@ -120,6 +153,12 @@ function addEventListeners(pr: any) {
120
153
} ) ;
121
154
}
122
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
+
123
162
function submitComment ( ) {
124
163
( < HTMLButtonElement > document . getElementById ( ElementIds . Reply ) ) . disabled = true ;
125
164
vscode . postMessage ( {
@@ -129,10 +168,16 @@ function submitComment() {
129
168
130
169
}
131
170
171
+ function appendReview ( review : any ) : void {
172
+ const newReview = renderReview ( review ) ;
173
+ document . getElementById ( ElementIds . TimelineEvents ) ! . insertAdjacentHTML ( 'beforeend' , newReview ) ;
174
+ clearTextArea ( ) ;
175
+ }
176
+
132
177
function appendComment ( comment : any ) {
133
178
let newComment = renderComment ( comment ) ;
134
179
document . getElementById ( ElementIds . TimelineEvents ) ! . insertAdjacentHTML ( 'beforeend' , newComment ) ;
135
- ( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ! ) . value = '' ;
180
+ clearTextArea ( ) ;
136
181
}
137
182
138
183
function updateCheckoutButton ( isCheckedOut : boolean ) {
@@ -156,8 +201,10 @@ function updateCheckoutButton(isCheckedOut: boolean) {
156
201
function setTextArea ( ) {
157
202
document . getElementById ( 'comment-form' ) ! . innerHTML = `<textarea id="${ ElementIds . CommentTextArea } "></textarea>
158
203
<div class="form-actions">
159
- <button class="reply-button" id="${ ElementIds . Reply } " disabled="true"></button>
160
- <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>
161
208
</div>` ;
162
209
163
210
( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ! ) . placeholder = 'Leave a comment' ;
@@ -172,6 +219,4 @@ function setTextArea() {
172
219
return ;
173
220
}
174
221
} ) ;
175
- ( < HTMLButtonElement > document . getElementById ( ElementIds . Reply ) ! ) . textContent = 'Comment' ;
176
- ( < HTMLButtonElement > document . getElementById ( ElementIds . Close ) ! ) . textContent = 'Close Pull Request' ;
177
222
}
0 commit comments