@@ -24,6 +24,8 @@ import Statistics from "./components/statistics";
24
24
25
25
const { RangePicker } = DatePicker ;
26
26
27
+ const LOG_PAGE_SIZE = 100 ;
28
+
27
29
const AuditContent = styled . div `
28
30
font-size: 14px;
29
31
color: #8b8fa3;
@@ -134,7 +136,7 @@ export function AuditLogDashboard() {
134
136
findUniqueDataIds ( ) ;
135
137
} , [ allLogs ] ) ;
136
138
137
- const getCleanedParams = ( newPage ?: number ) => {
139
+ const getCleanedParams = ( newPage ?: number , newPageSize ?: number ) => {
138
140
const formValues = form . getFieldsValue ( ) ;
139
141
140
142
let cleanedParams = Object . fromEntries (
@@ -147,7 +149,7 @@ export function AuditLogDashboard() {
147
149
if ( newPage ) {
148
150
cleanedParams = {
149
151
...cleanedParams ,
150
- pageSize : 100 , // Always fetch 500 from API
152
+ pageSize : newPageSize || LOG_PAGE_SIZE , // Always fetch 500 from API
151
153
pageNum : newPage , // API page number
152
154
}
153
155
}
@@ -176,22 +178,29 @@ export function AuditLogDashboard() {
176
178
}
177
179
178
180
// Fetch Logs with all form values if set
179
- const fetchLogs = async ( newPage : number , resetData : boolean = false ) => {
180
- const cleanedParams = getCleanedParams ( newPage ) ;
181
+ const fetchLogs = async (
182
+ newPage : number ,
183
+ newPageSize : number = LOG_PAGE_SIZE ,
184
+ resetData : boolean = false ,
185
+ resetDataOnly : boolean = false ,
186
+ ) => {
187
+ const cleanedParams = getCleanedParams ( newPage , newPageSize ) ;
181
188
182
189
handleQueryParams ( cleanedParams as any ) ;
183
190
184
191
setLoading ( true ) ;
185
192
try {
186
193
const data = await getAuditLogs ( cleanedParams ) ;
187
194
// fetch statistics only when page is 1
188
- if ( newPage === 1 ) {
195
+ if ( newPage === 1 && ! resetDataOnly ) {
189
196
fetchStatistics ( ) ;
190
197
}
191
198
192
199
if ( resetData ) {
193
200
setAllLogs ( data . data || [ ] ) ;
194
201
setPagination ( { pageSize : 25 , current : 1 } ) ; // Reset pagination
202
+ } if ( resetDataOnly ) {
203
+ setAllLogs ( data . data || [ ] ) ;
195
204
} else {
196
205
setAllLogs ( ( prevLogs ) => [ ...prevLogs , ...( data ?. data || [ ] ) ] ) ;
197
206
}
@@ -215,7 +224,7 @@ export function AuditLogDashboard() {
215
224
setPagination ( { pageSize : 25 , current : 1 } ) ;
216
225
setAllLogs ( [ ] ) ;
217
226
setCurrentPageLogs ( [ ] ) ;
218
- fetchLogs ( 1 , true ) ;
227
+ fetchLogs ( 1 , LOG_PAGE_SIZE , true ) ;
219
228
} ;
220
229
221
230
// Debounce handler for input fields
@@ -224,7 +233,7 @@ export function AuditLogDashboard() {
224
233
setPagination ( { pageSize : 25 , current : 1 } ) ;
225
234
setAllLogs ( [ ] ) ;
226
235
setCurrentPageLogs ( [ ] ) ;
227
- fetchLogs ( 1 , true ) ;
236
+ fetchLogs ( 1 , LOG_PAGE_SIZE , true ) ;
228
237
} , 300 ) ,
229
238
[ ]
230
239
) ;
@@ -235,7 +244,7 @@ export function AuditLogDashboard() {
235
244
setPagination ( { pageSize : 25 , current : 1 } ) ;
236
245
setAllLogs ( [ ] ) ;
237
246
setCurrentPageLogs ( [ ] ) ;
238
- fetchLogs ( 1 , true ) ;
247
+ fetchLogs ( 1 , LOG_PAGE_SIZE , true ) ;
239
248
} ;
240
249
241
250
const handleDateChange = ( dates : any ) => {
@@ -254,7 +263,7 @@ export function AuditLogDashboard() {
254
263
setCurrentPageLogs ( [ ] ) ;
255
264
256
265
// Ensure fetchLogs is called only ONCE
257
- fetchLogs ( 1 , true ) ;
266
+ fetchLogs ( 1 , LOG_PAGE_SIZE , true ) ;
258
267
} ;
259
268
260
269
// Handle page change
@@ -273,8 +282,16 @@ export function AuditLogDashboard() {
273
282
setCurrentPageLogs ( allLogs . slice ( startIndex , endIndex ) ) ;
274
283
} else if ( allLogs . length < total ) {
275
284
// ✅ Fetch next set of logs and update state after fetch
276
- const nextApiPage = Math . floor ( allLogs . length / 100 ) + 1 ;
277
- fetchLogs ( nextApiPage ) . then ( ( ) => {
285
+ const originalNextApiPage = Math . floor ( ( newPage * pageSize ) / 100 ) + 1 ;
286
+ let nextApiPage = Math . floor ( allLogs . length / 100 ) + 1 ;
287
+ let logPageSize = LOG_PAGE_SIZE ;
288
+ let reset = false ;
289
+ if ( originalNextApiPage - pagination . current > 1 ) {
290
+ reset = true ;
291
+ nextApiPage = 1 ;
292
+ logPageSize = newPage * pageSize ; //(originalNextApiPage - pagination.current) * 100;
293
+ }
294
+ fetchLogs ( nextApiPage , logPageSize , false , reset ) . then ( ( ) => {
278
295
setCurrentPageLogs ( allLogs . slice ( startIndex , endIndex ) ) ;
279
296
} ) ;
280
297
}
@@ -403,7 +420,7 @@ export function AuditLogDashboard() {
403
420
handleInputChange ( ) ; // Debounced input change
404
421
} else {
405
422
// Avoid calling fetchLogs if `handleDateChange` already did
406
- fetchLogs ( 1 , true ) ;
423
+ fetchLogs ( 1 , LOG_PAGE_SIZE , true ) ;
407
424
}
408
425
} }
409
426
>
@@ -464,7 +481,7 @@ export function AuditLogDashboard() {
464
481
dataSource = { currentPageLogs }
465
482
size = "small" // Compact Layout
466
483
pagination = { {
467
- pageSize : 25 ,
484
+ pageSize : pagination . pageSize ,
468
485
current : pagination . current ,
469
486
total : total ,
470
487
} }
0 commit comments