1+ import { useEffect , useState } from 'react' ;
12import { RunDetailRouteParams } from '.' ;
2- import { runsActions } from '../../../../redux/actions' ;
3- import { billingSelectors , runSelectors } from '../../../../redux/selectors' ;
4- import { useParams , useRequestOnMount , useSelector } from '../../../hooks' ;
3+ import { runPagesActions , runsActions } from '../../../../redux/actions' ;
4+ import {
5+ billingSelectors ,
6+ runPagesSelectors ,
7+ runSelectors ,
8+ } from '../../../../redux/selectors' ;
9+ import {
10+ useDispatch ,
11+ useParams ,
12+ useRequestOnMount ,
13+ useSelector ,
14+ } from '../../../hooks' ;
515
616interface ServiceInterface {
717 runId : TId ;
818 pipelineId : TId ;
919 run : TRun ;
1020 billing : TBilling | Record < any , any > ;
21+ fetching : boolean ;
1122}
1223
1324export const useService = ( ) : ServiceInterface => {
25+ const dispatch = useDispatch ( ) ;
1426 const { id, pipelineId } = useParams < RunDetailRouteParams > ( ) ;
15-
27+ const [ isMounted , setIsMounted ] = useState ( false ) ;
1628 // useRequestOnMount(() =>
1729 // runsActions.runForId({
1830 // pipelineId,
1931 // runId: id,
2032 // }),
2133 // );
22- useRequestOnMount ( ( ) =>
23- runsActions . graphForRun ( {
24- runId : id ,
25- } ) ,
26- ) ;
34+
35+ useEffect ( ( ) => {
36+ if ( ! isMounted ) {
37+ setFetching ( true ) ;
38+ dispatch (
39+ runsActions . graphForRun ( {
40+ runId : id ,
41+ onSuccess : ( ) => setFetching ( false ) ,
42+ onFailure : ( ) => setFetching ( false ) ,
43+ } ) ,
44+ ) ;
45+ setIsMounted ( true ) ;
46+ }
47+ } , [ isMounted , setIsMounted ] ) ;
48+ // useRequestOnMount(() =>
49+ // runsActions.graphForRun({
50+ // runId: id,
51+ // onSuccess: () => setFetching(false),
52+ // onFailure: () => setFetching(false),
53+ // }),
54+ // );
55+ // useEffect(() => {
56+ // dispatch(
57+ // runsActions.graphForRun({
58+ // runId: id,
59+
60+ // }),
61+ // );
62+ // });
2763 const run = useSelector ( runSelectors . runForId ( id ) ) ;
2864
2965 // useRequestOnMount(() =>
@@ -33,7 +69,12 @@ export const useService = (): ServiceInterface => {
3369 // }),
3470 // );
3571
72+ const fetching = useSelector ( runPagesSelectors . fetching ) ;
73+ const setFetching = ( fetching : boolean ) => {
74+ dispatch ( runPagesActions . setFetching ( { fetching } ) ) ;
75+ } ;
76+
3677 const billing = useSelector ( billingSelectors . billingForRunId ( id ) ) ;
3778
38- return { runId : id , pipelineId, run, billing } ;
79+ return { runId : id , pipelineId, run, billing, fetching } ;
3980} ;
0 commit comments