33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55import './index.css' ;
6- import { renderTimelineEvent , getStatus , renderComment , PullRequestStateEnum } from './pullRequestOverviewRenderer' ;
6+ import { renderTimelineEvent , getStatus , renderComment , PullRequestStateEnum , renderReview } from './pullRequestOverviewRenderer' ;
77import md from './mdRenderer' ;
88
99declare var acquireVsCodeApi : any ;
@@ -14,6 +14,8 @@ const ElementIds = {
1414 CheckoutDefaultBranch : 'checkout-default-branch' ,
1515 Close : 'close' ,
1616 Reply : 'reply' ,
17+ Approve : 'approve' ,
18+ RequestChanges : 'request-changes' ,
1719 Status : 'status' ,
1820 CommentTextArea : 'comment-textarea' ,
1921 TimelineEvents :'timeline-events' // If updating this value, change id in pullRequestOverview.ts as well.
@@ -33,6 +35,16 @@ function handleMessage(event: any) {
3335 break ;
3436 case 'pr.append-comment' :
3537 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 ;
3648 default :
3749 break ;
3850 }
@@ -93,10 +105,13 @@ function addEventListeners(pr: any) {
93105 } ) ;
94106 } ) ;
95107
96- // Enable 'Comment' button only when the user has entered text
108+ // Enable 'Comment' and 'RequestChanges' button only when the user has entered text
97109 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+ } ) ;
100115
101116 document . getElementById ( ElementIds . Reply ) ! . addEventListener ( 'click' , ( ) => {
102117 submitComment ( ) ;
@@ -111,6 +126,24 @@ function addEventListeners(pr: any) {
111126 } ) ;
112127 } ) ;
113128
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+
114147 document . getElementById ( ElementIds . CheckoutDefaultBranch ) ! . addEventListener ( 'click' , ( ) => {
115148 ( < HTMLButtonElement > document . getElementById ( ElementIds . CheckoutDefaultBranch ) ) . disabled = true ;
116149 vscode . postMessage ( {
@@ -120,6 +153,12 @@ function addEventListeners(pr: any) {
120153 } ) ;
121154}
122155
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+
123162function submitComment ( ) {
124163 ( < HTMLButtonElement > document . getElementById ( ElementIds . Reply ) ) . disabled = true ;
125164 vscode . postMessage ( {
@@ -129,10 +168,16 @@ function submitComment() {
129168
130169}
131170
171+ function appendReview ( review : any ) : void {
172+ const newReview = renderReview ( review ) ;
173+ document . getElementById ( ElementIds . TimelineEvents ) ! . insertAdjacentHTML ( 'beforeend' , newReview ) ;
174+ clearTextArea ( ) ;
175+ }
176+
132177function appendComment ( comment : any ) {
133178 let newComment = renderComment ( comment ) ;
134179 document . getElementById ( ElementIds . TimelineEvents ) ! . insertAdjacentHTML ( 'beforeend' , newComment ) ;
135- ( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ! ) . value = '' ;
180+ clearTextArea ( ) ;
136181}
137182
138183function updateCheckoutButton ( isCheckedOut : boolean ) {
@@ -156,8 +201,10 @@ function updateCheckoutButton(isCheckedOut: boolean) {
156201function setTextArea ( ) {
157202 document . getElementById ( 'comment-form' ) ! . innerHTML = `<textarea id="${ ElementIds . CommentTextArea } "></textarea>
158203 <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>
161208 </div>` ;
162209
163210 ( < HTMLTextAreaElement > document . getElementById ( ElementIds . CommentTextArea ) ! ) . placeholder = 'Leave a comment' ;
@@ -172,6 +219,4 @@ function setTextArea() {
172219 return ;
173220 }
174221 } ) ;
175- ( < HTMLButtonElement > document . getElementById ( ElementIds . Reply ) ! ) . textContent = 'Comment' ;
176- ( < HTMLButtonElement > document . getElementById ( ElementIds . Close ) ! ) . textContent = 'Close Pull Request' ;
177222}
0 commit comments