Skip to content

Commit 9b3adea

Browse files
committed
Remove pagination service
1 parent cda4b4f commit 9b3adea

File tree

7 files changed

+59
-316
lines changed

7 files changed

+59
-316
lines changed

site/src/components/PaginationWidget/PaginationWidget.stories.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.

site/src/components/PaginationWidget/PaginationWidget.test.tsx

Lines changed: 0 additions & 28 deletions
This file was deleted.

site/src/components/PaginationWidget/PaginationWidget.tsx

Lines changed: 0 additions & 110 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { PaginationWidgetBase } from "./PaginationWidgetBase";
2+
import type { Meta, StoryObj } from "@storybook/react";
3+
4+
const meta: Meta<typeof PaginationWidgetBase> = {
5+
title: "components/PaginationWidgetBase",
6+
component: PaginationWidgetBase,
7+
args: {
8+
page: 1,
9+
limit: 12,
10+
count: 200,
11+
},
12+
};
13+
14+
export default meta;
15+
type Story = StoryObj<typeof PaginationWidgetBase>;
16+
17+
export const MoreThan8Pages: Story = {};
18+
19+
export const LessThan8Pages: Story = {
20+
args: {
21+
count: 84,
22+
},
23+
};
24+
25+
export const MoreThan7PagesWithActivePageCloseToStart: Story = {
26+
args: { page: 2, limit: 12 },
27+
};
28+
29+
export const MoreThan7PagesWithActivePageFarFromBoundaries: Story = {
30+
args: { page: 4, limit: 12 },
31+
};
32+
33+
export const MoreThan7PagesWithActivePageCloseToEnd: Story = {
34+
args: { page: 17, limit: 12 },
35+
};

site/src/components/PaginationWidget/utils.test.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
import { buildPagedList, getOffset } from "./utils";
22

3-
describe("unit/PaginationWidget", () => {
4-
describe("buildPagedList", () => {
5-
it.each<{
6-
numPages: number;
7-
activePage: number;
8-
expected: (string | number)[];
9-
}>([
10-
{ numPages: 7, activePage: 1, expected: [1, 2, 3, 4, 5, 6, 7] },
11-
{ numPages: 17, activePage: 1, expected: [1, 2, 3, 4, 5, "right", 17] },
12-
{
13-
numPages: 17,
14-
activePage: 9,
15-
expected: [1, "left", 8, 9, 10, "right", 17],
16-
},
17-
{
18-
numPages: 17,
19-
activePage: 17,
20-
expected: [1, "left", 13, 14, 15, 16, 17],
21-
},
22-
])(
23-
`buildPagedList($numPages, $activePage)`,
24-
({ numPages, activePage, expected }) => {
25-
expect(buildPagedList(numPages, activePage)).toEqual(expected);
26-
},
27-
);
28-
});
3+
describe("buildPagedList", () => {
4+
it.each<{
5+
numPages: number;
6+
activePage: number;
7+
expected: (string | number)[];
8+
}>([
9+
{ numPages: 7, activePage: 1, expected: [1, 2, 3, 4, 5, 6, 7] },
10+
{ numPages: 17, activePage: 1, expected: [1, 2, 3, 4, 5, "right", 17] },
11+
{
12+
numPages: 17,
13+
activePage: 9,
14+
expected: [1, "left", 8, 9, 10, "right", 17],
15+
},
16+
{
17+
numPages: 17,
18+
activePage: 17,
19+
expected: [1, "left", 13, 14, 15, 16, 17],
20+
},
21+
])(
22+
`buildPagedList($numPages, $activePage)`,
23+
({ numPages, activePage, expected }) => {
24+
expect(buildPagedList(numPages, activePage)).toEqual(expected);
25+
},
26+
);
2927
});
3028

3129
describe("getOffset", () => {

site/src/components/PaginationWidget/utils.ts

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
import {
2-
PaginationContext,
3-
paginationMachine,
4-
PaginationMachineRef,
5-
} from "xServices/pagination/paginationXService";
6-
import { spawn } from "xstate";
7-
81
/**
92
* Generates a ranged array with an option to step over values.
103
* Shamelessly stolen from:
@@ -63,46 +56,10 @@ export const buildPagedList = (
6356
return range(1, numPages);
6457
};
6558

66-
const getInitialPage = (page: string | null): number =>
67-
page ? Number(page) : 1;
68-
6959
// pages count from 1
7060
export const getOffset = (page: number, limit: number): number =>
7161
(page - 1) * limit;
7262

73-
interface PaginationData {
74-
offset: number;
75-
limit: number;
76-
}
77-
78-
export const getPaginationData = (
79-
ref: PaginationMachineRef,
80-
): PaginationData => {
81-
const snapshot = ref.getSnapshot();
82-
if (snapshot) {
83-
const { page, limit } = snapshot.context;
84-
const offset = getOffset(page, limit);
85-
return { offset, limit };
86-
} else {
87-
throw new Error("No pagination data");
88-
}
89-
};
90-
91-
export const getPaginationContext = (
92-
searchParams: URLSearchParams,
93-
limit: number = DEFAULT_RECORDS_PER_PAGE,
94-
): PaginationContext => ({
95-
page: getInitialPage(searchParams.get("page")),
96-
limit,
97-
});
98-
99-
// for storybook
100-
export const createPaginationRef = (
101-
context: PaginationContext,
102-
): PaginationMachineRef => {
103-
return spawn(paginationMachine.withContext(context));
104-
};
105-
10663
export const nonInitialPage = (searchParams: URLSearchParams): boolean => {
10764
const page = searchParams.get("page");
10865
const numberPage = page ? Number(page) : 1;

0 commit comments

Comments
 (0)