@@ -12,6 +12,12 @@ const DEFAULT_PIVOT_CONFIG: PivotConfig = {
1212 filters : [ ] ,
1313} ;
1414
15+ // Default pagination configuration
16+ const DEFAULT_PAGINATION_CONFIG = {
17+ currentPage : 1 ,
18+ pageSize : 25 ,
19+ } ;
20+
1521export class GlobalState {
1622 isConnected : boolean = false ;
1723 // rollout_id -> EvaluationRow
@@ -20,10 +26,17 @@ export class GlobalState {
2026 expandedRows : Record < string , boolean > = { } ;
2127 // Pivot configuration
2228 pivotConfig : PivotConfig ;
29+ // Pagination configuration
30+ currentPage : number ;
31+ pageSize : number ;
2332
2433 constructor ( ) {
2534 // Load pivot config from localStorage or use defaults
2635 this . pivotConfig = this . loadPivotConfig ( ) ;
36+ // Load pagination config from localStorage or use defaults
37+ const paginationConfig = this . loadPaginationConfig ( ) ;
38+ this . currentPage = paginationConfig . currentPage ;
39+ this . pageSize = paginationConfig . pageSize ;
2740 makeAutoObservable ( this ) ;
2841 }
2942
@@ -42,6 +55,21 @@ export class GlobalState {
4255 return { ...DEFAULT_PIVOT_CONFIG } ;
4356 }
4457
58+ // Load pagination configuration from localStorage
59+ private loadPaginationConfig ( ) {
60+ try {
61+ const stored = localStorage . getItem ( "paginationConfig" ) ;
62+ if ( stored ) {
63+ const parsed = JSON . parse ( stored ) ;
64+ // Merge with defaults to handle any missing properties
65+ return { ...DEFAULT_PAGINATION_CONFIG , ...parsed } ;
66+ }
67+ } catch ( error ) {
68+ console . warn ( "Failed to load pagination config from localStorage:" , error ) ;
69+ }
70+ return { ...DEFAULT_PAGINATION_CONFIG } ;
71+ }
72+
4573 // Save pivot configuration to localStorage
4674 private savePivotConfig ( ) {
4775 try {
@@ -51,12 +79,35 @@ export class GlobalState {
5179 }
5280 }
5381
82+ // Save pagination configuration to localStorage
83+ private savePaginationConfig ( ) {
84+ try {
85+ localStorage . setItem ( "paginationConfig" , JSON . stringify ( {
86+ currentPage : this . currentPage ,
87+ pageSize : this . pageSize ,
88+ } ) ) ;
89+ } catch ( error ) {
90+ console . warn ( "Failed to save pagination config to localStorage:" , error ) ;
91+ }
92+ }
93+
5494 // Update pivot configuration and save to localStorage
5595 updatePivotConfig ( updates : Partial < PivotConfig > ) {
5696 Object . assign ( this . pivotConfig , updates ) ;
5797 this . savePivotConfig ( ) ;
5898 }
5999
100+ // Update pagination configuration and save to localStorage
101+ updatePaginationConfig ( updates : Partial < { currentPage : number ; pageSize : number } > ) {
102+ if ( updates . currentPage !== undefined ) {
103+ this . currentPage = updates . currentPage ;
104+ }
105+ if ( updates . pageSize !== undefined ) {
106+ this . pageSize = updates . pageSize ;
107+ }
108+ this . savePaginationConfig ( ) ;
109+ }
110+
60111 // Reset pivot configuration to defaults
61112 resetPivotConfig ( ) {
62113 this . pivotConfig = {
@@ -66,13 +117,36 @@ export class GlobalState {
66117 this . savePivotConfig ( ) ;
67118 }
68119
120+ // Reset pagination configuration to defaults
121+ resetPaginationConfig ( ) {
122+ this . currentPage = DEFAULT_PAGINATION_CONFIG . currentPage ;
123+ this . pageSize = DEFAULT_PAGINATION_CONFIG . pageSize ;
124+ this . savePaginationConfig ( ) ;
125+ }
126+
127+ // Set current page
128+ setCurrentPage ( page : number ) {
129+ this . currentPage = page ;
130+ this . savePaginationConfig ( ) ;
131+ }
132+
133+ // Set page size
134+ setPageSize ( size : number ) {
135+ this . pageSize = size ;
136+ this . currentPage = 1 ; // Reset to first page when changing page size
137+ this . savePaginationConfig ( ) ;
138+ }
139+
69140 upsertRows ( dataset : EvaluationRow [ ] ) {
70141 dataset . forEach ( ( row ) => {
71142 if ( ! row . execution_metadata ?. rollout_id ) {
72143 return ;
73144 }
74145 this . dataset [ row . execution_metadata . rollout_id ] = row ;
75146 } ) ;
147+ // Reset to first page when dataset changes
148+ this . currentPage = 1 ;
149+ this . savePaginationConfig ( ) ;
76150 }
77151
78152 toggleRowExpansion ( rolloutId ?: string ) {
@@ -122,4 +196,16 @@ export class GlobalState {
122196 get totalCount ( ) {
123197 return Object . keys ( this . dataset ) . length ;
124198 }
199+
200+ get totalPages ( ) {
201+ return Math . ceil ( this . totalCount / this . pageSize ) ;
202+ }
203+
204+ get startRow ( ) {
205+ return ( this . currentPage - 1 ) * this . pageSize + 1 ;
206+ }
207+
208+ get endRow ( ) {
209+ return Math . min ( this . currentPage * this . pageSize , this . totalCount ) ;
210+ }
125211}
0 commit comments