refactor(mobile): remove obsolete review list builder (#10039)
This commit is contained in:
1 parent
07fb04dc63
commit
c059d09b9b
2 files changed
-191
No files matched your search
@@ -8,7 +8,6 @@ import {
|
||||
} from "@t3tools/contracts";
|
||||
|
||||
import {
|
||||
buildReviewListItems,
|
||||
buildReviewParsedDiff,
|
||||
buildReviewSectionItems,
|
||||
getDefaultReviewSectionId,
|
||||
@@ -271,84 +270,4 @@ describe("buildReviewParsedDiff", () => {
|
||||
actionLabel: "Load diff",
|
||||
});
|
||||
});
|
||||
|
||||
it("flattens expanded file rows into virtualized review items", () => {
|
||||
const file = makeRenderableFile({
|
||||
path: "apps/mobile/src/a.ts",
|
||||
rows: [
|
||||
{
|
||||
kind: "hunk",
|
||||
id: "hunk-1",
|
||||
header: "@@ -1,1 +1,2 @@",
|
||||
context: null,
|
||||
},
|
||||
{
|
||||
kind: "line",
|
||||
id: "line-1",
|
||||
change: "add",
|
||||
oldLineNumber: null,
|
||||
newLineNumber: 1,
|
||||
content: "const after = 2;",
|
||||
additionTokenIndex: 0,
|
||||
deletionTokenIndex: null,
|
||||
comparison: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const items = buildReviewListItems({
|
||||
files: [file],
|
||||
expandedFileIds: [file.id],
|
||||
revealedLargeFileIds: [],
|
||||
});
|
||||
|
||||
expect(items).toEqual([
|
||||
expect.objectContaining({ kind: "file-header", fileId: file.id, expanded: true }),
|
||||
expect.objectContaining({
|
||||
kind: "hunk",
|
||||
fileId: file.id,
|
||||
file,
|
||||
row: file.rows[0],
|
||||
}),
|
||||
expect.objectContaining({
|
||||
kind: "line",
|
||||
fileId: file.id,
|
||||
file,
|
||||
row: file.rows[1],
|
||||
lineIndex: 0,
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps large diffs collapsed into a placeholder item until revealed", () => {
|
||||
const file = makeRenderableFile({
|
||||
path: "apps/mobile/src/big.ts",
|
||||
rows: Array.from({ length: 401 }, (_, index) => ({
|
||||
kind: "line" as const,
|
||||
id: `line-${index}`,
|
||||
change: "add" as const,
|
||||
oldLineNumber: null,
|
||||
newLineNumber: index + 1,
|
||||
content: `const line${index} = ${index};`,
|
||||
additionTokenIndex: index,
|
||||
deletionTokenIndex: null,
|
||||
comparison: null,
|
||||
})),
|
||||
});
|
||||
|
||||
const items = buildReviewListItems({
|
||||
files: [file],
|
||||
expandedFileIds: [file.id],
|
||||
revealedLargeFileIds: [],
|
||||
});
|
||||
|
||||
expect(items).toEqual([
|
||||
expect.objectContaining({ kind: "file-header", fileId: file.id, expanded: true }),
|
||||
expect.objectContaining({
|
||||
kind: "file-suppressed",
|
||||
fileId: file.id,
|
||||
actionLabel: "Load diff",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -58,45 +58,6 @@ export interface ReviewRenderableFile {
|
||||
readonly rows: ReadonlyArray<ReviewRenderableRow>;
|
||||
}
|
||||
|
||||
export interface ReviewFileHeaderListItem {
|
||||
readonly kind: "file-header";
|
||||
readonly id: string;
|
||||
readonly fileId: string;
|
||||
readonly file: ReviewRenderableFile;
|
||||
readonly expanded: boolean;
|
||||
}
|
||||
|
||||
export interface ReviewFileSuppressedListItem {
|
||||
readonly kind: "file-suppressed";
|
||||
readonly id: string;
|
||||
readonly fileId: string;
|
||||
readonly message: string;
|
||||
readonly actionLabel: string | null;
|
||||
}
|
||||
|
||||
export interface ReviewHunkListItem {
|
||||
readonly kind: "hunk";
|
||||
readonly id: string;
|
||||
readonly fileId: string;
|
||||
readonly file: ReviewRenderableFile;
|
||||
readonly row: ReviewRenderableHunkRow;
|
||||
}
|
||||
|
||||
export interface ReviewLineListItem {
|
||||
readonly kind: "line";
|
||||
readonly id: string;
|
||||
readonly fileId: string;
|
||||
readonly file: ReviewRenderableFile;
|
||||
readonly row: ReviewRenderableLineRow;
|
||||
readonly lineIndex: number;
|
||||
}
|
||||
|
||||
export type ReviewListItem =
|
||||
| ReviewFileHeaderListItem
|
||||
| ReviewFileSuppressedListItem
|
||||
| ReviewHunkListItem
|
||||
| ReviewLineListItem;
|
||||
|
||||
export type ReviewFilePreviewState =
|
||||
| {
|
||||
readonly kind: "render";
|
||||
@@ -316,77 +277,6 @@ export function getReviewFilePreviewState(file: ReviewRenderableFile): ReviewFil
|
||||
return { kind: "render" };
|
||||
}
|
||||
|
||||
// The flattened review list item model is inspired by pierre/diffs' iterator-first
|
||||
// virtualization architecture, adapted here for React Native virtualization.
|
||||
// Original project: https://github.com/pingdotgg/pierre/tree/main/packages/diffs
|
||||
// Reference files:
|
||||
// - src/utils/iterateOverDiff.ts
|
||||
// - src/components/VirtualizedFileDiff.ts
|
||||
export function buildReviewListItems(input: {
|
||||
readonly files: ReadonlyArray<ReviewRenderableFile>;
|
||||
readonly expandedFileIds: ReadonlyArray<string>;
|
||||
readonly revealedLargeFileIds: ReadonlyArray<string>;
|
||||
}): ReadonlyArray<ReviewListItem> {
|
||||
const expandedFileIds = new Set(input.expandedFileIds);
|
||||
const revealedLargeFileIds = new Set(input.revealedLargeFileIds);
|
||||
const items: ReviewListItem[] = [];
|
||||
|
||||
input.files.forEach((file) => {
|
||||
const expanded = expandedFileIds.has(file.id);
|
||||
items.push({
|
||||
kind: "file-header",
|
||||
id: `${file.id}:header`,
|
||||
fileId: file.id,
|
||||
file,
|
||||
expanded,
|
||||
});
|
||||
|
||||
if (!expanded) {
|
||||
return;
|
||||
}
|
||||
|
||||
const previewState = getReviewFilePreviewState(file);
|
||||
if (previewState.kind === "suppressed") {
|
||||
if (previewState.reason !== "large" || !revealedLargeFileIds.has(file.id)) {
|
||||
items.push({
|
||||
kind: "file-suppressed",
|
||||
id: `${file.id}:suppressed`,
|
||||
fileId: file.id,
|
||||
message: previewState.message,
|
||||
actionLabel: previewState.actionLabel,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let lineIndex = 0;
|
||||
file.rows.forEach((row, rowIndex) => {
|
||||
if (row.kind === "hunk") {
|
||||
items.push({
|
||||
kind: "hunk",
|
||||
id: `${file.id}:row:${rowIndex}:${row.id}`,
|
||||
fileId: file.id,
|
||||
file,
|
||||
row,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
items.push({
|
||||
kind: "line",
|
||||
id: `${file.id}:row:${rowIndex}:${row.id}`,
|
||||
fileId: file.id,
|
||||
file,
|
||||
row,
|
||||
lineIndex,
|
||||
});
|
||||
lineIndex += 1;
|
||||
});
|
||||
});
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
function fallbackHunkHeader(hunk: FileDiffMetadata["hunks"][number]): string {
|
||||
return `@@ -${hunk.deletionStart},${hunk.deletionCount} +${hunk.additionStart},${hunk.additionCount} @@`;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user