Skip to content

Commit 7c850dd

Browse files
committed
feat(review): review selected files from the diff tree
1 parent f92fe4d commit 7c850dd

3 files changed

Lines changed: 55 additions & 42 deletions

File tree

‎apps/web/src/components/diffs/DiffFileTree.tsx‎

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ import {
1919
collectDirectoryPaths,
2020
diffFileTreeModel,
2121
diffFileTreePositions,
22+
diffFileTreeReviewEntries,
2223
type DiffFileTreeEntry,
2324
} from "./diffFileTree.logic";
2425

2526
export type { DiffFileTreeEntry } from "./diffFileTree.logic";
2627

2728
interface DiffFileTreeProps {
2829
readonly entries: ReadonlyArray<DiffFileTreeEntry>;
29-
/** All files affected by a folder review action, including files hidden by filters. */
30+
/** All files affected by review actions, including folder descendants hidden by filters. */
3031
readonly reviewEntries?: ReadonlyArray<DiffFileTreeEntry>;
3132
/** Called with the file's path when the reader picks a file row. */
3233
readonly onSelectFile: (path: string) => void;
@@ -37,7 +38,7 @@ interface DiffFileTreeProps {
3738
readonly footer?: ReactNode;
3839
readonly className?: string;
3940
readonly headerLabel?: string;
40-
readonly onReviewFolder?: ((path: string, reviewed: boolean) => void) | undefined;
41+
readonly onReviewFiles?: ((paths: ReadonlyArray<string>, reviewed: boolean) => void) | undefined;
4142
}
4243

4344
export function DiffFileTree({
@@ -51,7 +52,7 @@ export function DiffFileTree({
5152
footer,
5253
className,
5354
headerLabel = "Files",
54-
onReviewFolder,
55+
onReviewFiles,
5556
}: DiffFileTreeProps) {
5657
const { resolvedTheme } = useTheme();
5758
const paths = entries.map((entry) => entry.path);
@@ -282,16 +283,18 @@ export function DiffFileTree({
282283
}}
283284
className="min-h-0 flex-1 overflow-hidden"
284285
style={pierreTreeStyle(resolvedTheme)}
285-
{...(onReviewFolder
286+
{...(onReviewFiles
286287
? {
287288
renderContextMenu: (item, context) => {
288-
if (item.kind !== "directory" || !onReviewFolder) return null;
289-
const prefix = item.path.endsWith("/") ? item.path : `${item.path}/`;
290-
const descendants = reviewEntriesRef.current.filter((entry) =>
291-
entry.path.startsWith(prefix),
289+
const matches = diffFileTreeReviewEntries(
290+
reviewEntriesRef.current,
291+
model.getSelectedPaths(),
292+
item.path,
292293
);
293-
const canMarkReviewed = descendants.some((entry) => !entry.reviewed);
294-
const canMarkUnreviewed = descendants.some((entry) => entry.reviewed);
294+
if (matches.length === 0) return null;
295+
const paths = matches.map((entry) => entry.path);
296+
const canMarkReviewed = matches.some((entry) => !entry.reviewed);
297+
const canMarkUnreviewed = matches.some((entry) => entry.reviewed);
295298
return (
296299
<Menu
297300
open
@@ -304,29 +307,25 @@ export function DiffFileTree({
304307
data-file-tree-context-menu-root="true"
305308
align="start"
306309
>
307-
{onReviewFolder ? (
308-
<>
309-
{canMarkReviewed ? (
310-
<MenuItem
311-
onClick={() => {
312-
onReviewFolder(item.path, true);
313-
context.close();
314-
}}
315-
>
316-
Mark as reviewed
317-
</MenuItem>
318-
) : null}
319-
{canMarkUnreviewed ? (
320-
<MenuItem
321-
onClick={() => {
322-
onReviewFolder(item.path, false);
323-
context.close();
324-
}}
325-
>
326-
Mark as unreviewed
327-
</MenuItem>
328-
) : null}
329-
</>
310+
{canMarkReviewed ? (
311+
<MenuItem
312+
onClick={() => {
313+
onReviewFiles(paths, true);
314+
context.close();
315+
}}
316+
>
317+
Mark as reviewed
318+
</MenuItem>
319+
) : null}
320+
{canMarkUnreviewed ? (
321+
<MenuItem
322+
onClick={() => {
323+
onReviewFiles(paths, false);
324+
context.close();
325+
}}
326+
>
327+
Mark as unreviewed
328+
</MenuItem>
330329
) : null}
331330
</MenuPopup>
332331
</Menu>

‎apps/web/src/components/diffs/diffFileTree.logic.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ export interface DiffFileTreeEntry {
1616
readonly unresolvedComments?: number;
1717
}
1818

19+
/** Pierre folder ids end with a slash; a selected folder includes its hidden descendants. */
20+
export function diffFileTreeReviewEntries(
21+
entries: ReadonlyArray<DiffFileTreeEntry>,
22+
selectedPaths: ReadonlyArray<string>,
23+
clickedPath: string,
24+
): ReadonlyArray<DiffFileTreeEntry> {
25+
const contains = (target: string, path: string) =>
26+
target.endsWith("/") ? path.startsWith(target) : path === target;
27+
const targets = selectedPaths.some((path) => contains(path, clickedPath))
28+
? selectedPaths
29+
: [clickedPath];
30+
const exact = new Set(targets);
31+
const folders = targets.filter((path) => path.endsWith("/"));
32+
return entries.filter(
33+
(entry) => exact.has(entry.path) || folders.some((path) => entry.path.startsWith(path)),
34+
);
35+
}
36+
1937
function toGitStatus(file: FileDiffMetadata): GitStatus {
2038
switch (file.type) {
2139
case "new":

‎apps/web/src/components/pullRequest/PullRequestCodeTab.tsx‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import { useResizableWidth } from "~/hooks/useResizableWidth";
4949
import { RightPanelResizeHandle } from "../preview/RightPanelResizeHandle";
5050
import {
5151
isReviewFileVisible,
52-
reviewFolderContains,
5352
reviewCommentCounts,
5453
toggleReviewCommit,
5554
reviewCommitSelection,
@@ -2141,15 +2140,12 @@ function PullRequestCodeTab({
21412140
: folderReviewEntries
21422141
}
21432142
onSelectFile={revealFile}
2144-
onReviewFolder={
2145-
filesViewed.enabled
2146-
? (path, reviewed) => {
2147-
const prefix = path.endsWith("/") ? path : `${path}/`;
2143+
onReviewFiles={
2144+
filesViewed.enabled && canSetChapterViewed
2145+
? (paths, reviewed) => {
2146+
const selectedPaths = new Set(paths);
21482147
for (const item of annotatedFiles) {
2149-
if (
2150-
reviewFolderContains(prefix, item.path) &&
2151-
(chapter === null || reviewFileGroup(item.path) === chapter.id)
2152-
)
2148+
if (selectedPaths.has(item.path))
21532149
setFileViewed(item.fileKey, item.path, reviewed);
21542150
}
21552151
}

0 commit comments

Comments
 (0)