@@ -24,7 +24,7 @@ import { ColumnsType } from 'antd/lib/table';
2424import { AxiosError } from 'axios' ;
2525import { isEmpty } from 'lodash' ;
2626import QueryString from 'qs' ;
27- import { useCallback , useEffect , useMemo , useState } from 'react' ;
27+ import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
2828import { useTranslation } from 'react-i18next' ;
2929import { Link , useNavigate , useParams } from 'react-router-dom' ;
3030import { INITIAL_PAGING_VALUE } from '../../../../constants/constants' ;
@@ -120,6 +120,7 @@ export const TestSuites = () => {
120120 } = usePaging ( ) ;
121121
122122 const [ isLoading , setIsLoading ] = useState < boolean > ( true ) ;
123+ const latestRequestId = useRef ( 0 ) ;
123124
124125 const ownerFilterValue = useMemo ( ( ) => {
125126 return selectedOwner
@@ -212,41 +213,56 @@ export const TestSuites = () => {
212213 return data ;
213214 } , [ ] ) ;
214215
215- const fetchTestSuites = async (
216- currentPage = INITIAL_PAGING_VALUE ,
217- params ?: ListTestSuitePramsBySearch
218- ) => {
219- setIsLoading ( true ) ;
220- try {
221- const result = await getListTestSuitesBySearch ( {
222- ...params ,
223- fields : [ TabSpecificField . OWNERS , TabSpecificField . SUMMARY ] ,
224- q : searchValue ? `*${ searchValue } *` : undefined ,
225- owner : ownerFilterValue ?. key ,
226- offset : ( currentPage - 1 ) * pageSize ,
227- includeEmptyTestSuites : subTab !== DataQualitySubTabs . TABLE_SUITES ,
228- testSuiteType :
229- subTab === DataQualitySubTabs . TABLE_SUITES
230- ? TestSuiteType . basic
231- : TestSuiteType . logical ,
232- sortField : 'lastResultTimestamp' ,
233- sortType : SORT_ORDER . DESC ,
234- } ) ;
235- setTestSuites ( result . data ) ;
236- handlePagingChange ( result . paging ) ;
237- } catch ( error ) {
238- showErrorToast ( error as AxiosError ) ;
239- } finally {
240- setIsLoading ( false ) ;
241- }
242- } ;
216+ const fetchTestSuites = useCallback (
217+ async (
218+ currentPage = INITIAL_PAGING_VALUE ,
219+ params ?: ListTestSuitePramsBySearch
220+ ) => {
221+ const requestId = latestRequestId . current + 1 ;
222+ latestRequestId . current = requestId ;
223+
224+ setIsLoading ( true ) ;
225+ try {
226+ const result = await getListTestSuitesBySearch ( {
227+ ...params ,
228+ fields : [ TabSpecificField . OWNERS , TabSpecificField . SUMMARY ] ,
229+ q : searchValue ? `*${ searchValue } *` : undefined ,
230+ owner : ownerFilterValue ?. key ,
231+ offset : ( currentPage - 1 ) * pageSize ,
232+ includeEmptyTestSuites : subTab !== DataQualitySubTabs . TABLE_SUITES ,
233+ testSuiteType :
234+ subTab === DataQualitySubTabs . TABLE_SUITES
235+ ? TestSuiteType . basic
236+ : TestSuiteType . logical ,
237+ sortField : 'lastResultTimestamp' ,
238+ sortType : SORT_ORDER . DESC ,
239+ } ) ;
240+
241+ if ( requestId !== latestRequestId . current ) {
242+ return ;
243+ }
244+
245+ setTestSuites ( result . data ) ;
246+ handlePagingChange ( result . paging ) ;
247+ } catch ( error ) {
248+ if ( requestId === latestRequestId . current ) {
249+ showErrorToast ( error as AxiosError ) ;
250+ }
251+ } finally {
252+ if ( requestId === latestRequestId . current ) {
253+ setIsLoading ( false ) ;
254+ }
255+ }
256+ } ,
257+ [ searchValue , ownerFilterValue ?. key , pageSize , subTab , handlePagingChange ]
258+ ) ;
243259
244260 const handleTestSuitesPageChange = useCallback (
245261 ( { currentPage } : PagingHandlerParams ) => {
246262 fetchTestSuites ( currentPage , { limit : pageSize } ) ;
247263 handlePageChange ( currentPage ) ;
248264 } ,
249- [ pageSize , handlePageChange ]
265+ [ fetchTestSuites , pageSize , handlePageChange ]
250266 ) ;
251267
252268 const handleSearchParam = (
@@ -324,7 +340,15 @@ export const TestSuites = () => {
324340 } else {
325341 setIsLoading ( false ) ;
326342 }
327- } , [ testSuitePermission , pageSize , searchValue , owner , subTab , currentPage ] ) ;
343+ } , [
344+ testSuitePermission ,
345+ pageSize ,
346+ searchValue ,
347+ owner ,
348+ subTab ,
349+ currentPage ,
350+ fetchTestSuites ,
351+ ] ) ;
328352
329353 if ( ! testSuitePermission ?. ViewAll && ! testSuitePermission ?. ViewBasic ) {
330354 return (
0 commit comments