refactor(views): centralize indexed row paging (#14878)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-11-27 22:00:16 +08:00
1 parent 09a5b9cef9
commit 544ec63f66
12 files changed
+153 -236

No files matched your search

+14 -23
View File
@@ -17,7 +17,7 @@ import {
completeWithinViewCoverage,
pageViewCoverage,
} from "./analysisViewCoverage.js";
import { selectIndexedViewRows, selectViewRows } from "./selectViewRows.js";
import { filterSet, selectViewRows } from "./selectViewRows.js";
const code = pythonPycSchema.shape.code_objects.element;
@@ -94,9 +94,8 @@ export const projectPythonPycView = (
summary,
coverage: completeWithinViewCoverage(code_objects.length),
});
const names = view.names === undefined ? undefined : new Set(view.names);
const indices =
view.indices === undefined ? undefined : new Set(view.indices);
const names = filterSet(view.names);
const indices = filterSet(view.indices);
const fields = new Set<string>(view.fields ?? code.keyof().options);
const projectRow = (row: PythonPycCodeObject, source_index: number) => ({
...Object.fromEntries(
@@ -104,25 +103,17 @@ export const projectPythonPycView = (
),
source_index,
});
const matches = (row: PythonPycCodeObject) =>
names === undefined || names.has(row.name);
const selected =
names === undefined && indices === undefined
? {
rows: code_objects
.slice(view.offset, view.offset + view.limit)
.map((row, index) => projectRow(row, view.offset + index)),
total: code_objects.length,
}
: indices !== undefined
? selectIndexedViewRows(
code_objects,
indices,
view,
matches,
projectRow,
)
: selectViewRows(code_objects, view, matches, projectRow);
const matches =
names === undefined
? undefined
: (row: PythonPycCodeObject) => names.has(row.name);
const selected = selectViewRows(
code_objects,
view,
matches,
projectRow,
indices,
);
return ok({
...shared,
kind: "python-pyc" as const,