fix(mobile): skip move indexes for empty and single-thread sections (#16115)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-10-07 22:48:54 -07:00
1 parent 70eeb3996d
commit 12a4c057f3
2 files changed
+33

No files matched your search

@@ -134,6 +134,11 @@ export function computeThreadMoveAvailability(input: {
// A reorder in flight locks the whole list until its receipt lands.
if (input.pendingOrder != null) return result;
const rows = input.ordered;
// With no neighbor there is no up/down move, so skip the allThreads indexes.
if (rows.length < 2) {
for (const row of rows) result.set(rowId(row), { canMoveUp: false, canMoveDown: false });
return result;
}
const orderedIds = rows.map(rowId);
const indexById = new Map(orderedIds.map((id, index) => [id, index] as const));
const keysById = new Map(
@@ -208,6 +208,34 @@ describe("computeThreadMoveAvailability matches the reference planner", () => {
expect(batch.get("env-w:t0")).toEqual({ canMoveUp: false, canMoveDown: false });
});
it("answers empty and single-row sections without consulting hidden rows", () => {
const hidden = [makeRow("h0", "env-w", "b", true), makeRow("h1", "env-x", null, true)];
expect(
computeThreadMoveAvailability({
ordered: [],
allThreads: hidden,
section: "pinned",
reorderableEnvironmentIds: WRITABLE,
}).size,
).toBe(0);
for (const environment of ["env-w", "env-x"]) {
const ordered = [makeRow("t0", environment, "a", true)];
const allThreads = [...ordered, ...hidden];
const batch = computeThreadMoveAvailability({
ordered,
allThreads,
section: "pinned",
reorderableEnvironmentIds: WRITABLE,
});
expect(Object.fromEntries(batch)).toEqual({
[`${environment}:t0`]: { canMoveUp: false, canMoveDown: false },
});
expect(Object.fromEntries(batch)).toEqual(
Object.fromEntries(referenceAvailability(ordered, allThreads, WRITABLE)),
);
}
});
it("denies rows whose section has non-writable neighbours when the fast path fails", () => {
// Keyless neighbors force the section-rewrite fallback; a non-writable
// neighbor makes the rewrite illegal for every row in the section.