Repository navigation
feat(web): resolve review threads from the Summary and Timeline tabs #15257
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
Open
TonybynMp4
wants to merge
4
commits into
pingdotgg:main
Choose a base branch
from
TonybynMp4:feat/pr-resolve-from-conversation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+155
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9d47291
feat(web): resolve review threads from the Summary and Timeline tabs
TonybynMp4 510a712
fix(web): resolve button stays disabled until the thread shows its ne…
TonybynMp4 a0811b2
fix(web): a stale refresh no longer leaves the resolve button disabled
TonybynMp4 b573402
fix(web): resolve button respects per-thread resolve permission
TonybynMp4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
apps/web/src/components/pullRequest/PullRequestResolveThreadButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import type { | ||
| EnvironmentId, | ||
| PullRequestDetailView, | ||
| PullRequestRef, | ||
| PullRequestReviewThread, | ||
| } from "@t3tools/contracts"; | ||
| import { useState } from "react"; | ||
|
|
||
| import { useAtomCommand } from "~/state/use-atom-command"; | ||
| import { pullRequestEnvironment } from "~/state/pullRequests"; | ||
|
|
||
| import { Button } from "../ui/button"; | ||
| import { toastManager } from "../ui/toast"; | ||
| import { canResolvePullRequestThread } from "./pullRequestEditing.logic"; | ||
|
|
||
| /** | ||
| * Resolve or unresolve a review thread from a conversation entry rather than from its line in the | ||
| * Code tab. Callers render it on the thread's first comment only, so a thread with five replies | ||
| * offers one control, not five. Renders nothing where the host or this account cannot resolve the | ||
| * thread. | ||
| */ | ||
| export function PullRequestResolveThreadButton({ | ||
| environmentId, | ||
| reference, | ||
| detail, | ||
| thread, | ||
| className, | ||
| onRefresh, | ||
| }: { | ||
| environmentId: EnvironmentId; | ||
| reference: PullRequestRef; | ||
| detail: PullRequestDetailView; | ||
| thread: PullRequestReviewThread; | ||
| className?: string | undefined; | ||
| onRefresh: () => void; | ||
| }) { | ||
| // The state asked for, held until the thread shows it so the button stays disabled through the | ||
| // refetch instead of re-enabling on the old label. `sent` is the thread as it was when the update | ||
| // succeeded: any refreshed copy also ends the wait, so a refetch that still reports the old | ||
| // state cannot leave the button disabled. | ||
| const [requested, setRequested] = useState<{ | ||
| readonly resolved: boolean; | ||
| readonly sent: PullRequestReviewThread | null; | ||
| } | null>(null); | ||
| if ( | ||
| requested !== null && | ||
| (thread.isResolved === requested.resolved || | ||
| (requested.sent !== null && thread !== requested.sent)) | ||
| ) { | ||
| setRequested(null); | ||
| } | ||
| const pending = requested !== null; | ||
| const setThreadResolution = useAtomCommand(pullRequestEnvironment.setThreadResolution, { | ||
| reportFailure: false, | ||
| }); | ||
| if (!detail.capabilities.review.resolve || !canResolvePullRequestThread(detail, thread)) | ||
| return null; | ||
|
|
||
| const toggle = async () => { | ||
| if (pending) return; | ||
| const resolved = !thread.isResolved; | ||
| setRequested({ resolved, sent: null }); | ||
| const result = await setThreadResolution({ | ||
| environmentId, | ||
| input: { ...reference, threadId: thread.id, resolved }, | ||
| }); | ||
| if (result._tag === "Failure") { | ||
| setRequested(null); | ||
| toastManager.add({ type: "error", title: "The conversation could not be updated" }); | ||
| return; | ||
| } | ||
| setRequested({ resolved, sent: thread }); | ||
| onRefresh(); | ||
| }; | ||
|
|
||
| return ( | ||
| <Button | ||
| size="xs" | ||
| variant="ghost" | ||
| className={className} | ||
| disabled={pending} | ||
| onClick={() => void toggle()} | ||
| > | ||
| {thread.isResolved ? "Unresolve" : "Resolve"} | ||
| </Button> | ||
| ); | ||
| } | ||
|
|
||
| /** The thread a comment opens, or null for replies and for remarks on no thread at all. */ | ||
| export function pullRequestThreadOpenedBy( | ||
| threadByCommentId: ReadonlyMap<string, PullRequestReviewThread>, | ||
| commentId: string, | ||
| ): PullRequestReviewThread | null { | ||
| const thread = threadByCommentId.get(commentId); | ||
| return thread?.comments[0]?.id === commentId ? thread : null; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.