Skip to content

Commit ba3783b

Browse files
committed
Fix workspaces story
1 parent 35b0cd3 commit ba3783b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

site/src/components/PaginationWidget/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import {
22
PaginationContext,
3+
paginationMachine,
34
PaginationMachineRef,
45
} from "xServices/pagination/paginationXService"
6+
import { spawn } from "xstate"
57

68
/**
79
* Generates a ranged array with an option to step over values.
@@ -61,9 +63,10 @@ export const buildPagedList = (
6163
return range(1, numPages)
6264
}
6365

64-
export const getInitialPage = (page: string | null): number =>
66+
const getInitialPage = (page: string | null): number =>
6567
page ? Number(page) : 1
6668

69+
// pages count from 1
6770
export const getOffset = (page: number, limit: number): number =>
6871
(page - 1) * limit
6972

@@ -92,3 +95,8 @@ export const getPaginationContext = (
9295
page: getInitialPage(searchParams.get("page")),
9396
limit,
9497
})
98+
99+
// for storybook
100+
export const createPaginationRef = (context: PaginationContext): PaginationMachineRef => {
101+
return spawn(paginationMachine.withContext(context))
102+
}

site/src/pages/WorkspacesPage/WorkspacesPageView.stories.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ComponentMeta, Story } from "@storybook/react"
2+
import { createPaginationRef } from "components/PaginationWidget/utils"
23
import dayjs from "dayjs"
34
import { spawn } from "xstate"
45
import {
@@ -87,6 +88,9 @@ export default {
8788
title: "pages/WorkspacesPageView",
8889
component: WorkspacesPageView,
8990
argTypes: {
91+
paginationRef: {
92+
defaultValue: createPaginationRef({ page: 1, limit: 25 })
93+
},
9094
workspaceRefs: {
9195
options: [
9296
...Object.keys(workspaces),

0 commit comments

Comments
 (0)