File tree 2 files changed +13
-1
lines changed 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
2
PaginationContext ,
3
+ paginationMachine ,
3
4
PaginationMachineRef ,
4
5
} from "xServices/pagination/paginationXService"
6
+ import { spawn } from "xstate"
5
7
6
8
/**
7
9
* Generates a ranged array with an option to step over values.
@@ -61,9 +63,10 @@ export const buildPagedList = (
61
63
return range ( 1 , numPages )
62
64
}
63
65
64
- export const getInitialPage = ( page : string | null ) : number =>
66
+ const getInitialPage = ( page : string | null ) : number =>
65
67
page ? Number ( page ) : 1
66
68
69
+ // pages count from 1
67
70
export const getOffset = ( page : number , limit : number ) : number =>
68
71
( page - 1 ) * limit
69
72
@@ -92,3 +95,8 @@ export const getPaginationContext = (
92
95
page : getInitialPage ( searchParams . get ( "page" ) ) ,
93
96
limit,
94
97
} )
98
+
99
+ // for storybook
100
+ export const createPaginationRef = ( context : PaginationContext ) : PaginationMachineRef => {
101
+ return spawn ( paginationMachine . withContext ( context ) )
102
+ }
Original file line number Diff line number Diff line change 1
1
import { ComponentMeta , Story } from "@storybook/react"
2
+ import { createPaginationRef } from "components/PaginationWidget/utils"
2
3
import dayjs from "dayjs"
3
4
import { spawn } from "xstate"
4
5
import {
@@ -87,6 +88,9 @@ export default {
87
88
title : "pages/WorkspacesPageView" ,
88
89
component : WorkspacesPageView ,
89
90
argTypes : {
91
+ paginationRef : {
92
+ defaultValue : createPaginationRef ( { page : 1 , limit : 25 } )
93
+ } ,
90
94
workspaceRefs : {
91
95
options : [
92
96
...Object . keys ( workspaces ) ,
You can’t perform that action at this time.
0 commit comments