@@ -24,6 +24,8 @@ import Statistics from "./components/statistics";
2424
2525const { RangePicker } = DatePicker ;
2626
27+ const LOG_PAGE_SIZE = 100 ;
28+
2729const AuditContent = styled . div `
2830 font-size: 14px;
2931 color: #8b8fa3;
@@ -134,7 +136,7 @@ export function AuditLogDashboard() {
134136 findUniqueDataIds ( ) ;
135137 } , [ allLogs ] ) ;
136138
137- const getCleanedParams = ( newPage ?: number ) => {
139+ const getCleanedParams = ( newPage ?: number , newPageSize ?: number ) => {
138140 const formValues = form . getFieldsValue ( ) ;
139141
140142 let cleanedParams = Object . fromEntries (
@@ -147,7 +149,7 @@ export function AuditLogDashboard() {
147149 if ( newPage ) {
148150 cleanedParams = {
149151 ...cleanedParams ,
150- pageSize : 100 , // Always fetch 500 from API
152+ pageSize : newPageSize || LOG_PAGE_SIZE , // Always fetch 500 from API
151153 pageNum : newPage , // API page number
152154 }
153155 }
@@ -176,22 +178,29 @@ export function AuditLogDashboard() {
176178 }
177179
178180 // 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 ) ;
181188
182189 handleQueryParams ( cleanedParams as any ) ;
183190
184191 setLoading ( true ) ;
185192 try {
186193 const data = await getAuditLogs ( cleanedParams ) ;
187194 // fetch statistics only when page is 1
188- if ( newPage === 1 ) {
195+ if ( newPage === 1 && ! resetDataOnly ) {
189196 fetchStatistics ( ) ;
190197 }
191198
192199 if ( resetData ) {
193200 setAllLogs ( data . data || [ ] ) ;
194201 setPagination ( { pageSize : 25 , current : 1 } ) ; // Reset pagination
202+ } if ( resetDataOnly ) {
203+ setAllLogs ( data . data || [ ] ) ;
195204 } else {
196205 setAllLogs ( ( prevLogs ) => [ ...prevLogs , ...( data ?. data || [ ] ) ] ) ;
197206 }
@@ -215,7 +224,7 @@ export function AuditLogDashboard() {
215224 setPagination ( { pageSize : 25 , current : 1 } ) ;
216225 setAllLogs ( [ ] ) ;
217226 setCurrentPageLogs ( [ ] ) ;
218- fetchLogs ( 1 , true ) ;
227+ fetchLogs ( 1 , LOG_PAGE_SIZE , true ) ;
219228 } ;
220229
221230 // Debounce handler for input fields
@@ -224,7 +233,7 @@ export function AuditLogDashboard() {
224233 setPagination ( { pageSize : 25 , current : 1 } ) ;
225234 setAllLogs ( [ ] ) ;
226235 setCurrentPageLogs ( [ ] ) ;
227- fetchLogs ( 1 , true ) ;
236+ fetchLogs ( 1 , LOG_PAGE_SIZE , true ) ;
228237 } , 300 ) ,
229238 [ ]
230239 ) ;
@@ -235,7 +244,7 @@ export function AuditLogDashboard() {
235244 setPagination ( { pageSize : 25 , current : 1 } ) ;
236245 setAllLogs ( [ ] ) ;
237246 setCurrentPageLogs ( [ ] ) ;
238- fetchLogs ( 1 , true ) ;
247+ fetchLogs ( 1 , LOG_PAGE_SIZE , true ) ;
239248 } ;
240249
241250 const handleDateChange = ( dates : any ) => {
@@ -254,7 +263,7 @@ export function AuditLogDashboard() {
254263 setCurrentPageLogs ( [ ] ) ;
255264
256265 // Ensure fetchLogs is called only ONCE
257- fetchLogs ( 1 , true ) ;
266+ fetchLogs ( 1 , LOG_PAGE_SIZE , true ) ;
258267 } ;
259268
260269 // Handle page change
@@ -273,8 +282,16 @@ export function AuditLogDashboard() {
273282 setCurrentPageLogs ( allLogs . slice ( startIndex , endIndex ) ) ;
274283 } else if ( allLogs . length < total ) {
275284 // ✅ 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 ( ( ) => {
278295 setCurrentPageLogs ( allLogs . slice ( startIndex , endIndex ) ) ;
279296 } ) ;
280297 }
@@ -403,7 +420,7 @@ export function AuditLogDashboard() {
403420 handleInputChange ( ) ; // Debounced input change
404421 } else {
405422 // Avoid calling fetchLogs if `handleDateChange` already did
406- fetchLogs ( 1 , true ) ;
423+ fetchLogs ( 1 , LOG_PAGE_SIZE , true ) ;
407424 }
408425 } }
409426 >
@@ -464,7 +481,7 @@ export function AuditLogDashboard() {
464481 dataSource = { currentPageLogs }
465482 size = "small" // Compact Layout
466483 pagination = { {
467- pageSize : 25 ,
484+ pageSize : pagination . pageSize ,
468485 current : pagination . current ,
469486 total : total ,
470487 } }
0 commit comments