Show only commented files in the review view

Even out the page's vertical rhythm while there: one gap owns the
spacing between blocks, so it holds whichever blocks a review has.
This commit is contained in:
Rūdolfs Ošiņš
2026-08-14 17:30:46 +02:00
parent 75ebece30d
commit 01e057b5d6
3 changed files with 110 additions and 42 deletions
+17 -3
View File
@@ -52,6 +52,9 @@
deleteComment?: (commentId: string) => Promise<void>;
rid: string;
activityItems?: ActivityItem<A>[];
/// Drops the outer margin, for a host that owns the spacing between its own
/// blocks. The default keeps the spacing the timeline pages rely on.
flush?: boolean;
renderActivity?: Snippet<[A, { hideAuthor: boolean }]>;
authorOf?: (data: A) => Author | undefined;
afterActivity?: Snippet;
@@ -69,6 +72,7 @@
deleteComment,
rid,
activityItems,
flush = false,
renderActivity,
authorOf,
afterActivity,
@@ -203,13 +207,19 @@
</script>
<style>
.discussion {
margin: 1.5rem 0 2.5rem;
}
.discussion.flush {
margin: 0;
}
.timeline-rail {
position: relative;
}
.activity-stream {
position: relative;
}
.activity-stream::before {
.activity-stream.has-runs::before {
content: "";
position: absolute;
top: 0.5rem;
@@ -275,11 +285,15 @@
.reply-wrapper {
margin-top: 1rem;
}
/* Nothing above it to connect to, so the host's own spacing is the whole gap. */
.activity-stream:not(.has-runs) + .reply-wrapper {
margin-top: 0;
}
</style>
<div style:margin="1.5rem 0 2.5rem 0">
<div class="discussion" class:flush>
<div class="timeline-rail">
<div class="activity-stream">
<div class="activity-stream" class:has-runs={runs.length > 0}>
{#each runs as run, runIndex (runIndex)}
{#if run.kind === "thread"}
<ThreadComponent
+57 -13
View File
@@ -109,6 +109,8 @@
filesHeader?: Snippet;
// Files (by new-side path) that start collapsed.
collapsedPaths?: ReadonlySet<string>;
// Restricts the diff to these files (by new-side path).
includePaths?: ReadonlySet<string>;
// Files (by new-side path) marked reviewed. Providing this shows the
// reviewed toggle in every file header; leave unset to hide it.
reviewedPaths?: ReadonlySet<string>;
@@ -147,6 +149,7 @@
stickyTop = undefined,
filesHeader = undefined,
collapsedPaths = undefined,
includePaths = undefined,
reviewedPaths = undefined,
onToggleReviewed = undefined,
commentCounts = undefined,
@@ -331,9 +334,19 @@
}
const lineHeightPx = $derived(codeLineHeight(fontSettings.size));
let view = $state.raw<CodeView<LineAnnotation> | undefined>(undefined);
// The parsed files, kept so `scrollToFile` can map a path to its diff item.
// Everything the patch parsed to, kept so `includePaths` can be re-applied
// without re-parsing.
let allFiles = $state.raw<FileDiffMetadata[]>([]);
// The files actually on screen, which is what `scrollToFile` and the comment
// layer walk.
let parsedFiles = $state.raw<FileDiffMetadata[]>([]);
function visibleFiles(files: FileDiffMetadata[]): FileDiffMetadata[] {
return includePaths
? files.filter(file => includePaths.has(file.name))
: files;
}
// Scroll to a logical position in the scroll content, where 0 is the top of
// the `header`. Pierre reuses a paged scroll scaffold, so the logical position
// is not the container's `scrollTop` and has to go through `scrollTo`.
@@ -359,8 +372,9 @@
let pendingScroll: { path: string; anchor?: CommentAnchor } | undefined;
function applyScroll(target: { path: string; anchor?: CommentAnchor }): void {
const index = parsedFiles.findIndex(file => file.name === target.path);
if (index < 0) {
const id = target.path;
const item = view?.getItem(id);
if (!item) {
// The patch is parsed off the main thread, so a caller that switches the
// diff and immediately scrolls arrives before there are any items. Hold
// the target and apply it once they exist.
@@ -368,8 +382,6 @@
return;
}
pendingScroll = undefined;
const id = String(index);
const item = view?.getItem(id);
// A collapsed file has no line to arrive at (a lockfile or one already
// marked reviewed starts that way), so open it first.
if (item?.type === "diff" && item.collapsed === true) {
@@ -415,8 +427,8 @@
if (!instance) {
return;
}
for (let index = 0; index < parsedFiles.length; index++) {
const item = instance.getItem(String(index));
for (const file of parsedFiles) {
const item = instance.getItem(file.name);
if (item) {
instance.updateItem({
...item,
@@ -883,8 +895,8 @@
function buildItems(
files: FileDiffMetadata[],
): CodeViewItem<LineAnnotation>[] {
return files.map((fileDiff, index) => ({
id: String(index),
return files.map(fileDiff => ({
id: fileDiff.name,
type: "diff",
fileDiff,
collapsed: collapsedPaths?.has(fileDiff.name) === true,
@@ -1049,8 +1061,8 @@
}
untrack(() => {
let changed = false;
for (let index = 0; index < parsedFiles.length; index++) {
const item = instance.getItem(String(index));
for (const file of parsedFiles) {
const item = instance.getItem(file.name);
if (item?.type !== "diff") {
continue;
}
@@ -1074,6 +1086,32 @@
});
});
// `includePaths` is a live filter: deleting the last comment on a file should
// take the file with it, not leave it behind until the next reload. Compared
// by name rather than by set identity, since the host rebuilds the set on
// every reload whether or not its contents moved.
$effect(() => {
void includePaths;
const instance = view;
if (!instance) {
return;
}
untrack(() => {
if (allFiles.length === 0) {
return;
}
const shown = visibleFiles(allFiles);
const before = parsedFiles.map(file => file.name).join("\u0000");
const after = shown.map(file => file.name).join("\u0000");
if (before === after) {
return;
}
parsedFiles = shown;
instance.setItems(buildItems(shown));
instance.render(true);
});
});
// Structural rebuild: only when the patch text or the container changes.
//
// Everything past those two reads is untracked, and has to stay that way. The
@@ -1115,8 +1153,10 @@
if (cancelled) {
return;
}
parsedFiles = files;
instance.setItems(buildItems(files));
allFiles = files;
const shown = visibleFiles(files);
parsedFiles = shown;
instance.setItems(buildItems(shown));
instance.render(true);
if (pendingScroll !== undefined) {
applyScroll(pendingScroll);
@@ -1131,6 +1171,10 @@
return () => {
cancelled = true;
view = undefined;
// Cleared so the `includePaths` filter cannot fire against the outgoing
// patch's files while the next one is still parsing.
allFiles = [];
parsedFiles = [];
pendingSlotItems = undefined;
unmountHeaders();
unmountAnnotations();
+36 -26
View File
@@ -388,8 +388,9 @@
return origins;
});
// File paths that carry review comments; those files start expanded, the
// rest of the changed files render collapsed.
// The files this review says something about. The diff below is restricted to
// these: a review is a record of what someone had to say, and a file they said
// nothing about is context they can already read on the Changes tab.
const commentedPaths = $derived(new Set(fileGroups.map(g => g.path)));
@@ -461,19 +462,6 @@
),
);
// Only the files this review says something about are worth opening; the rest
// are context, and so are the lockfiles either way.
const collapsedPaths = $derived.by(() => {
// eslint-disable-next-line svelte/prefer-svelte-reactivity -- rebuilt fresh each derivation
const paths = new Set(fileMeta.ignored);
for (const path of fileMeta.statuses.keys()) {
if (!commentedPaths.has(path)) {
paths.add(path);
}
}
return paths;
});
const commentCounts = $derived(
commentCountsByPath(
reviewCodeComments.threads,
@@ -506,7 +494,6 @@
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
margin-bottom: 0.75rem;
}
.back {
background-color: var(--color-surface-canvas);
@@ -530,7 +517,6 @@
align-items: center;
flex-wrap: wrap;
gap: 0.5rem;
margin-bottom: 1.5rem;
color: var(--color-text-secondary);
font: var(--txt-body-m-regular);
}
@@ -565,8 +551,9 @@
position: relative;
border: 1px solid var(--color-border-subtle);
border-radius: var(--border-radius-md);
padding: 0.75rem 1rem;
margin-bottom: 1.5rem;
/* Matches the reply box and `Comment`'s own body inset, so the summary text
and the comment placeholder start on the same line. */
padding: 0.75rem;
font: var(--txt-body-m-regular);
}
.summary-empty {
@@ -584,9 +571,7 @@
.summary-edit:focus-visible {
opacity: 1;
}
.summary-editor {
margin-bottom: 1.5rem;
}
.action-icon {
background: none;
border: 1px solid transparent;
@@ -649,10 +634,28 @@
}
/* The chrome is full width inside the diff's scroll content, so it carries
its own horizontal padding — the same as the patch view's own header. */
/* One rhythm for the whole review header: every block below is a direct child
and carries no vertical margin of its own, so the spacing stays even
whichever blocks a given review actually has. */
.chrome {
display: flex;
flex-direction: column;
padding: 1rem 1rem 0;
gap: 1.5rem;
/* The bottom padding is the same step as the gap: it is what separates the
last block from the first file, now that nothing in here carries a margin
of its own. */
padding: 1rem 1rem 1.5rem;
}
/* Where the file list would be. Without it the page just stops after the
discussion, which reads as something having failed to load. Indented past
the cards' border to start on the same line as the text inside them, rather
than level with their edges. */
.no-line-comments {
/* Just short of where the cards' text starts (their border plus padding).
Optically that reads as aligned: this line has no box around it, so the
mathematical offset looks a touch too far right. */
padding-left: 0.75rem;
color: var(--color-text-tertiary);
}
.timestamp {
color: var(--color-text-quaternary);
@@ -818,7 +821,7 @@
</div>
{#if editingSummary}
<div class="summary-editor">
<div>
<ExtendedTextarea
{rid}
body={review.summary ?? ""}
@@ -858,7 +861,14 @@
createComment={createDiscussionComment}
editComment={codeActions.editComment}
deleteComment={codeActions.deleteComment}
reactOnComment={codeActions.reactOnComment} />
reactOnComment={codeActions.reactOnComment}
flush />
{#if loadedDiff && commentedPaths.size === 0}
<div class="no-line-comments txt-body-m-regular">
This review has no line comments.
</div>
{/if}
</div>
{/snippet}
@@ -879,7 +889,7 @@
? path =>
getDiffText(rid, reviewedRevision.base, reviewedRevision.head, 3, path)
: undefined}
{collapsedPaths}
includePaths={commentedPaths}
{commentCounts}
codeComments={reviewCodeComments}
commentCommit={reviewedRevision?.head}