Skip to content

chore(site): remove users and pagination services #9932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove pagination service
  • Loading branch information
BrunoQuaresma committed Sep 28, 2023
commit 9b3adeac2c09958c59c028a701ff44218fe40919
43 changes: 0 additions & 43 deletions site/src/components/PaginationWidget/PaginationWidget.stories.tsx

This file was deleted.

28 changes: 0 additions & 28 deletions site/src/components/PaginationWidget/PaginationWidget.test.tsx

This file was deleted.

110 changes: 0 additions & 110 deletions site/src/components/PaginationWidget/PaginationWidget.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { PaginationWidgetBase } from "./PaginationWidgetBase";
import type { Meta, StoryObj } from "@storybook/react";

const meta: Meta<typeof PaginationWidgetBase> = {
title: "components/PaginationWidgetBase",
component: PaginationWidgetBase,
args: {
page: 1,
limit: 12,
count: 200,
},
};

export default meta;
type Story = StoryObj<typeof PaginationWidgetBase>;

export const MoreThan8Pages: Story = {};

export const LessThan8Pages: Story = {
args: {
count: 84,
},
};

export const MoreThan7PagesWithActivePageCloseToStart: Story = {
args: { page: 2, limit: 12 },
};

export const MoreThan7PagesWithActivePageFarFromBoundaries: Story = {
args: { page: 4, limit: 12 },
};

export const MoreThan7PagesWithActivePageCloseToEnd: Story = {
args: { page: 17, limit: 12 },
};
50 changes: 24 additions & 26 deletions site/src/components/PaginationWidget/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import { buildPagedList, getOffset } from "./utils";

describe("unit/PaginationWidget", () => {
describe("buildPagedList", () => {
it.each<{
numPages: number;
activePage: number;
expected: (string | number)[];
}>([
{ numPages: 7, activePage: 1, expected: [1, 2, 3, 4, 5, 6, 7] },
{ numPages: 17, activePage: 1, expected: [1, 2, 3, 4, 5, "right", 17] },
{
numPages: 17,
activePage: 9,
expected: [1, "left", 8, 9, 10, "right", 17],
},
{
numPages: 17,
activePage: 17,
expected: [1, "left", 13, 14, 15, 16, 17],
},
])(
`buildPagedList($numPages, $activePage)`,
({ numPages, activePage, expected }) => {
expect(buildPagedList(numPages, activePage)).toEqual(expected);
},
);
});
describe("buildPagedList", () => {
it.each<{
numPages: number;
activePage: number;
expected: (string | number)[];
}>([
{ numPages: 7, activePage: 1, expected: [1, 2, 3, 4, 5, 6, 7] },
{ numPages: 17, activePage: 1, expected: [1, 2, 3, 4, 5, "right", 17] },
{
numPages: 17,
activePage: 9,
expected: [1, "left", 8, 9, 10, "right", 17],
},
{
numPages: 17,
activePage: 17,
expected: [1, "left", 13, 14, 15, 16, 17],
},
])(
`buildPagedList($numPages, $activePage)`,
({ numPages, activePage, expected }) => {
expect(buildPagedList(numPages, activePage)).toEqual(expected);
},
);
});

describe("getOffset", () => {
Expand Down
43 changes: 0 additions & 43 deletions site/src/components/PaginationWidget/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
import {
PaginationContext,
paginationMachine,
PaginationMachineRef,
} from "xServices/pagination/paginationXService";
import { spawn } from "xstate";

/**
* Generates a ranged array with an option to step over values.
* Shamelessly stolen from:
Expand Down Expand Up @@ -63,46 +56,10 @@ export const buildPagedList = (
return range(1, numPages);
};

const getInitialPage = (page: string | null): number =>
page ? Number(page) : 1;

// pages count from 1
export const getOffset = (page: number, limit: number): number =>
(page - 1) * limit;

interface PaginationData {
offset: number;
limit: number;
}

export const getPaginationData = (
ref: PaginationMachineRef,
): PaginationData => {
const snapshot = ref.getSnapshot();
if (snapshot) {
const { page, limit } = snapshot.context;
const offset = getOffset(page, limit);
return { offset, limit };
} else {
throw new Error("No pagination data");
}
};

export const getPaginationContext = (
searchParams: URLSearchParams,
limit: number = DEFAULT_RECORDS_PER_PAGE,
): PaginationContext => ({
page: getInitialPage(searchParams.get("page")),
limit,
});

// for storybook
export const createPaginationRef = (
context: PaginationContext,
): PaginationMachineRef => {
return spawn(paginationMachine.withContext(context));
};

export const nonInitialPage = (searchParams: URLSearchParams): boolean => {
const page = searchParams.get("page");
const numberPage = page ? Number(page) : 1;
Expand Down
Loading