Skip to content

Add Cancel Review button to review submission interface #7317

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/@types/vscode.proposed.chatParticipantAdditions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ declare module 'vscode' {
readonly tools: Map<string, boolean>;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please reevaluate if this change makes sense, I didn't expect we'd need to update this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right - those TypeScript definitions for language model tools were unrelated to the Cancel Review feature and shouldn't have been included in this PR. I've reverted the src/@types/vscode.proposed.chatParticipantAdditions.d.ts file to its original state in commit eef6223. The PR now only contains the relevant changes for the Cancel Review button functionality.

export namespace lm {
/**
* Fired when the set of tools on a chat request changes.
*/
export const onDidChangeChatRequestTools: Event<ChatRequest>;
}

// TODO@API fit this into the stream
export interface ChatUsedContext {
documents: ChatDocumentContext[];
Expand Down
13 changes: 13 additions & 0 deletions src/github/pullRequestOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
return this.cancelCodingAgent(message);
case 'pr.openCommitChanges':
return this.openCommitChanges(message);
case 'pr.delete-review':
return this.deleteReview(message);
}
}

Expand Down Expand Up @@ -850,6 +852,17 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
return this._item.deleteReviewComment(comment.id.toString());
}

private async deleteReview(message: IRequestMessage<void>) {
try {
const result = await this._item.deleteReview();
await this._replyMessage(message, result);
} catch (e) {
Logger.error(formatError(e), PullRequestOverviewPanel.ID);
vscode.window.showErrorMessage(vscode.l10n.t('Deleting review failed. {0}', formatError(e)));
this._throwError(message, `${formatError(e)}`);
}
}

override dispose() {
super.dispose();
disposeAll(this._prListeners);
Expand Down
19 changes: 19 additions & 0 deletions webviews/common/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ export class PRContext {

public submit = (body: string) => this.submitReviewCommand('pr.submit', body);

public deleteReview = async () => {
try {
const result: { deletedReviewId: number; deletedReviewComments: IComment[] } = await this.postMessage({ command: 'pr.delete-review' });
// Update the PR state to reflect the deleted review
const state = this.pr;
state.busy = false;
state.pendingCommentText = '';
state.pendingCommentDrafts = {};
// Remove the deleted review from events
state.events = state.events.filter(event =>
!(event.event === EventType.Reviewed && event.id === result.deletedReviewId)
);
this.updatePR(state);
return result;
} catch (error) {
return this.updatePR({ busy: false });
}
};

public close = async (body?: string) => {
try {
const result: CloseResult = await this.postMessage({ command: 'pr.close', args: body });
Expand Down
17 changes: 16 additions & 1 deletion webviews/components/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ function CommentThread({ thread, event }: { thread: IComment[]; event: ReviewEve
}

function AddReviewSummaryComment() {
const { requestChanges, approve, submit, pr } = useContext(PullRequestContext);
const { requestChanges, approve, submit, deleteReview, pr } = useContext(PullRequestContext);
const { isAuthor } = pr;
const comment = useRef<HTMLTextAreaElement>();
const [isBusy, setBusy] = useState(false);
Expand All @@ -289,6 +289,13 @@ function AddReviewSummaryComment() {
setBusy(false);
}

async function cancelReview(event: React.MouseEvent): Promise<void> {
event.preventDefault();
setBusy(true);
await deleteReview();
setBusy(false);
}

const onKeyDown = (event: React.KeyboardEvent<HTMLTextAreaElement>) => {
if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') {
submitAction(event, ReviewType.Comment);
Expand All @@ -304,6 +311,14 @@ function AddReviewSummaryComment() {
onKeyDown={onKeyDown}
></textarea>
<div className="form-actions">
<button
id="cancel-review"
className='secondary'
disabled={isBusy || pr.busy}
onClick={cancelReview}
>
Cancel Review
</button>
{isAuthor ? null : (
<button
id="request-changes"
Expand Down