66 Toolbar ,
77 Typography ,
88} from "@mui/material" ;
9- import { FC , useCallback , useEffect , useRef , useState } from "react" ;
9+ import { FC , useCallback , useEffect , useMemo , useRef , useState } from "react" ;
1010import CloseIcon from "@mui/icons-material/Close" ;
1111import FilterIcon from "@mui/icons-material/FilterList" ;
1212import RefreshIcon from "@mui/icons-material/Refresh" ;
@@ -25,48 +25,60 @@ import {
2525 stringifySearchParams ,
2626 useSearchParams ,
2727} from "~/utils/search-params" ;
28- import { useAppDispatch , useAppSelector } from "~/hooks/redux" ;
29- import {
30- fetchDeploymentTraces ,
31- fetchMoreDeploymentTraces ,
32- } from "~/modules/deploymentTrace" ;
3328import useGroupedDeploymentTrace from "./useGroupedDeploymentTrace" ;
3429import DeploymentTraceItem from "./deployment-trace-item" ;
3530import { useInView } from "react-intersection-observer" ;
31+ import { useGetDeploymentTracesInfinite } from "~/queries/deployment-traces/use-deployment-traces-infinite" ;
3632
3733const DeploymentTracePage : FC = ( ) => {
3834 const [ openFilter , setOpenFilter ] = useState ( true ) ;
39- const dispatch = useAppDispatch ( ) ;
40- const status = useAppSelector ( ( state ) => state . deploymentTrace . status ) ;
41- const hasMore = useAppSelector ( ( state ) => state . deploymentTrace . hasMore ) ;
4235 const navigate = useNavigate ( ) ;
4336 const filterValues = useSearchParams ( ) ;
44- const { dates, deploymentTracesMap } = useGroupedDeploymentTrace ( ) ;
45- const isLoading = status === "loading" ;
4637
4738 const listRef = useRef ( null ) ;
4839 const [ ref , inView ] = useInView ( {
4940 rootMargin : "400px" ,
5041 root : listRef . current ,
5142 } ) ;
5243
53- useEffect ( ( ) => {
54- dispatch ( fetchDeploymentTraces ( filterValues ) ) ;
55- } , [ dispatch , filterValues ] ) ;
44+ const {
45+ data : deploymentTracesData ,
46+ isFetching,
47+ fetchNextPage : fetchMoreDeploymentTraces ,
48+ refetch : refetchDeploymentTraces ,
49+ isSuccess,
50+ } = useGetDeploymentTracesInfinite ( filterValues ) ;
51+
52+ const deploymentTracesList = useMemo ( ( ) => {
53+ return deploymentTracesData ?. pages . flatMap ( ( item ) => item . tracesList ) || [ ] ;
54+ } , [ deploymentTracesData ] ) ;
55+
56+ const hasMore = useMemo ( ( ) => {
57+ if ( ! deploymentTracesData || deploymentTracesData . pages . length === 0 ) {
58+ return false ;
59+ }
60+ const lastIndex = deploymentTracesData ?. pages . length - 1 ;
61+ return deploymentTracesData ?. pages ?. [ lastIndex ] ?. hasMore || false ;
62+ } , [ deploymentTracesData ] ) ;
63+
64+ const { dates, deploymentTracesMap } = useGroupedDeploymentTrace (
65+ deploymentTracesList || [ ]
66+ ) ;
5667
5768 useEffect ( ( ) => {
58- if ( inView && hasMore && isLoading === false ) {
59- dispatch ( fetchMoreDeploymentTraces ( filterValues || { } ) ) ;
69+ if ( inView && hasMore && isFetching === false ) {
70+ fetchMoreDeploymentTraces ;
6071 }
61- } , [ dispatch , inView , hasMore , isLoading , filterValues ] ) ;
72+ } , [ fetchMoreDeploymentTraces , hasMore , inView , isFetching ] ) ;
6273
6374 const handleRefreshClick = ( ) : void => {
64- dispatch ( fetchDeploymentTraces ( filterValues ) ) ;
75+ refetchDeploymentTraces ( ) ;
6576 } ;
6677
6778 const handleMoreClick = useCallback ( ( ) => {
68- dispatch ( fetchMoreDeploymentTraces ( filterValues || { } ) ) ;
69- } , [ dispatch , filterValues ] ) ;
79+ // dispatch(fetchMoreDeploymentTraces(filterValues || {}));
80+ fetchMoreDeploymentTraces ( ) ;
81+ } , [ fetchMoreDeploymentTraces ] ) ;
7082
7183 const handleFilterChange = ( options : { commitHash ?: string } ) : void => {
7284 navigate (
@@ -101,10 +113,10 @@ const DeploymentTracePage: FC = () => {
101113 color = "primary"
102114 startIcon = { < RefreshIcon /> }
103115 onClick = { handleRefreshClick }
104- disabled = { isLoading }
116+ disabled = { isFetching }
105117 >
106118 { UI_TEXT_REFRESH }
107- { isLoading && < SpinnerIcon /> }
119+ { isFetching && < SpinnerIcon /> }
108120 </ Button >
109121 < Button
110122 color = "primary"
@@ -134,7 +146,7 @@ const DeploymentTracePage: FC = () => {
134146 } }
135147 ref = { listRef }
136148 >
137- { dates . length === 0 && isLoading && (
149+ { dates . length === 0 && isFetching && (
138150 < Box
139151 sx = { {
140152 display : "flex" ,
@@ -145,7 +157,7 @@ const DeploymentTracePage: FC = () => {
145157 < CircularProgress />
146158 </ Box >
147159 ) }
148- { dates . length === 0 && ! isLoading && (
160+ { dates . length === 0 && ! isFetching && (
149161 < Box
150162 sx = { {
151163 display : "flex" ,
@@ -181,18 +193,18 @@ const DeploymentTracePage: FC = () => {
181193 </ Box >
182194 </ Box >
183195 ) ) }
184- { status === "succeeded" && < div ref = { ref } /> }
196+ { isSuccess && < div ref = { ref } /> }
185197 { ! hasMore && (
186198 < Button
187199 color = "primary"
188200 variant = "outlined"
189201 size = "large"
190202 fullWidth
191203 onClick = { handleMoreClick }
192- disabled = { isLoading }
204+ disabled = { isFetching }
193205 >
194206 { UI_TEXT_MORE }
195- { isLoading && < SpinnerIcon /> }
207+ { isFetching && < SpinnerIcon /> }
196208 </ Button >
197209 ) }
198210 </ Box >
0 commit comments