Skip to content

Commit 1f4d69f

Browse files
authored
When a review fails to submit, the buttons stay disabled and you have to re-open the webview to get them back. (#6946)
Fixes #6913
1 parent 0c1c168 commit 1f4d69f

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

webviews/common/context.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,20 @@ export class PRContext {
126126
this.updatePR({ pendingCommentDrafts: pendingCommentDrafts });
127127
};
128128

129-
public requestChanges = async (body: string) =>
130-
this.appendReview(await this.postMessage({ command: 'pr.request-changes', args: body }));
129+
private async submitReviewCommand(command: string, body: string) {
130+
try {
131+
const result: SubmitReviewReply = await this.postMessage({ command, args: body });
132+
return this.appendReview(result);
133+
} catch (error) {
134+
return this.updatePR({ busy: false });
135+
}
136+
}
137+
138+
public requestChanges = (body: string) => this.submitReviewCommand('pr.request-changes', body);
131139

132-
public approve = async (body: string) =>
133-
this.appendReview(await this.postMessage({ command: 'pr.approve', args: body }));
140+
public approve = (body: string) => this.submitReviewCommand('pr.approve', body);
134141

135-
public submit = async (body: string) =>
136-
this.appendReview(await this.postMessage({ command: 'pr.submit', args: body }));
142+
public submit = (body: string) => this.submitReviewCommand('pr.submit', body);
137143

138144
public close = async (body?: string) => {
139145
try {

webviews/components/timeline.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function AddReviewSummaryComment() {
209209
const comment = useRef<HTMLTextAreaElement>();
210210
const [isBusy, setBusy] = useState(false);
211211

212-
async function submitAction(event: React.MouseEvent, action: ReviewType): Promise<void> {
212+
async function submitAction(event: React.MouseEvent | React.KeyboardEvent, action: ReviewType): Promise<void> {
213213
event.preventDefault();
214214
const { value } = comment.current!;
215215
setBusy(true);
@@ -226,9 +226,20 @@ function AddReviewSummaryComment() {
226226
setBusy(false);
227227
}
228228

229+
const onKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
230+
if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') {
231+
submitAction(event, ReviewType.Comment);
232+
}
233+
};
234+
229235
return (
230236
<form>
231-
<textarea id='pending-review' ref={comment} placeholder="Leave a review summary comment"></textarea>
237+
<textarea
238+
id='pending-review'
239+
ref={comment}
240+
placeholder="Leave a review summary comment"
241+
onKeyDown={onKeyDown}
242+
></textarea>
232243
<div className="form-actions">
233244
{isAuthor ? null : (
234245
<button

0 commit comments

Comments
 (0)