Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion frontend/src/components/data-table/TableBottomBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ export const TableBottomBar = <TData,>({

return (
<span>
{prettifyRowColumnCount(table.getRowCount(), totalColumns, locale)}
{prettifyRowColumnCount({
numRows: table.getRowCount(),
totalColumns,
locale,
})}
</span>
);
};
Expand Down
178 changes: 46 additions & 132 deletions frontend/src/components/data-table/__tests__/pagination.test.tsx
Original file line number Diff line number Diff line change
@@ -1,144 +1,58 @@
/* Copyright 2026 Marimo. All rights reserved. */

import { expect, test } from "vitest";
import { getPageRanges } from "../pagination";
import type { PageRange } from "../types";
import { matchingPageRanges } from "../pagination";

function getLabels(currentPage: number): string[] {
const ranges = getPageRanges(currentPage, 200);
return ranges.map((item: PageRange) =>
item.type === "ellipsis" ? "..." : String(item.page),
);
}
test("empty prefix returns no ranges", () => {
expect(matchingPageRanges("", 500)).toEqual([]);
});

test("zero prefix returns no ranges", () => {
expect(matchingPageRanges("0", 500)).toEqual([]);
});

test("pagination start / middle / end", () => {
expect(getLabels(1)).toMatchInlineSnapshot(`
[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"...",
"96",
"97",
"98",
"99",
"100",
"101",
"102",
"103",
"104",
"105",
"...",
"191",
"192",
"193",
"194",
"195",
"196",
"197",
"198",
"199",
"200",
]
`);
test("leading-zero prefix returns no ranges", () => {
expect(matchingPageRanges("01", 500)).toEqual([]);
});

test("single digit prefix", () => {
expect(matchingPageRanges("5", 500)).toEqual([
[5, 5],
[50, 59],
[500, 500],
]);
});

// all fall in the top/middle/bottom 10
expect(getLabels(1)).toEqual(getLabels(10));
expect(getLabels(96)).toEqual(getLabels(105));
expect(getLabels(191)).toEqual(getLabels(200));
test("single digit prefix with exact totalPages boundary", () => {
expect(matchingPageRanges("5", 55)).toEqual([
[5, 5],
[50, 55],
]);
});

test("multi-digit prefix", () => {
expect(matchingPageRanges("12", 5000)).toEqual([
[12, 12],
[120, 129],
[1200, 1299],
]);
});

test("prefix larger than totalPages returns no ranges", () => {
expect(matchingPageRanges("999", 100)).toEqual([]);
});

// Check off by one
expect(getLabels(1)).not.toEqual(getLabels(11));
expect(getLabels(1)).not.toEqual(getLabels(95));
expect(getLabels(1)).not.toEqual(getLabels(106));
expect(getLabels(1)).not.toEqual(getLabels(190));
test("prefix equal to totalPages", () => {
expect(matchingPageRanges("100", 100)).toEqual([[100, 100]]);
});

test("pagination lower middle", () => {
expect(getLabels(50)).toMatchInlineSnapshot(`
[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"...",
"50",
"...",
"96",
"97",
"98",
"99",
"100",
"101",
"102",
"103",
"104",
"105",
"...",
"191",
"192",
"193",
"194",
"195",
"196",
"197",
"198",
"199",
"200",
]
`);
test("prefix 1 with small totalPages", () => {
expect(matchingPageRanges("1", 10)).toEqual([
[1, 1],
[10, 10],
]);
});

test("pagination upper middle", () => {
expect(getLabels(150)).toMatchInlineSnapshot(`
[
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"...",
"96",
"97",
"98",
"99",
"100",
"101",
"102",
"103",
"104",
"105",
"...",
"150",
"...",
"191",
"192",
"193",
"194",
"195",
"196",
"197",
"198",
"199",
"200",
]
`);
test("prefix 1 with totalPages=1", () => {
expect(matchingPageRanges("1", 1)).toEqual([[1, 1]]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const ColumnExplorerPanel = ({
return (
<div className="mb-3">
<span className="text-xs font-semibold ml-2 flex">
{prettifyRowColumnCount(totalRows, totalColumns, locale)}
{prettifyRowColumnCount({ numRows: totalRows, totalColumns, locale })}
<CopyClipboardIcon
tooltip="Copy column names"
value={columns?.map(([columnName]) => columnName).join(",\n") || ""}
Expand Down
Loading
Loading