@@ -5,45 +5,40 @@ import {Button} from '@gravity-ui/uikit';
5
5
6
6
import { useClusterBaseInfo } from '../../../../store/reducers/cluster/cluster' ;
7
7
import { traceApi } from '../../../../store/reducers/trace' ;
8
- import { SECOND_IN_MS } from '../../../../utils/constants' ;
9
- import { useDelayed } from '../../../../utils/hooks/useDelayed' ;
10
8
import { replaceParams } from '../utils/replaceParams' ;
11
9
12
10
import i18n from './i18n' ;
13
11
14
- const TIME_BEFORE_CHECK = 15 * SECOND_IN_MS ;
15
-
16
12
interface TraceUrlButtonProps {
17
13
traceId : string ;
14
+ isTraceReady ?: true ;
18
15
}
19
16
20
- export function TraceButton ( { traceId} : TraceUrlButtonProps ) {
17
+ export function TraceButton ( { traceId, isTraceReady } : TraceUrlButtonProps ) {
21
18
const { traceCheck, traceView} = useClusterBaseInfo ( ) ;
22
19
23
20
const checkTraceUrl = traceCheck ?. url ? replaceParams ( traceCheck . url , { traceId} ) : '' ;
24
21
const traceUrl = traceView ?. url ? replaceParams ( traceView . url , { traceId} ) : '' ;
25
22
26
- // We won't get any trace data at first 15 seconds for sure
27
- const [ readyToFetch , resetDelay ] = useDelayed ( TIME_BEFORE_CHECK ) ;
23
+ const [ checkTrace , { isLoading, isUninitialized} ] = traceApi . useCheckTraceMutation ( ) ;
28
24
29
25
React . useEffect ( ( ) => {
30
- resetDelay ( ) ;
31
- } , [ traceId , resetDelay ] ) ;
26
+ let checkTraceMutation : { abort : ( ) => void } | null ;
27
+ if ( checkTraceUrl && ! isTraceReady ) {
28
+ checkTraceMutation = checkTrace ( { url : checkTraceUrl } ) ;
29
+ }
32
30
33
- const { isFetching} = traceApi . useCheckTraceQuery (
34
- { url : checkTraceUrl } ,
35
- { skip : ! checkTraceUrl || ! readyToFetch } ,
36
- ) ;
31
+ return ( ) => checkTraceMutation ?. abort ( ) ;
32
+ } , [ checkTrace , checkTraceUrl , isTraceReady ] ) ;
37
33
38
- if ( ! traceUrl ) {
34
+ if ( ! traceUrl || ( isUninitialized && ! isTraceReady ) ) {
39
35
return null ;
40
36
}
41
37
42
- const loading = ! readyToFetch || isFetching ;
43
38
return (
44
39
< Button
45
- view = { loading ? 'flat-secondary' : 'flat-info' }
46
- loading = { loading }
40
+ view = { isLoading ? 'flat-secondary' : 'flat-info' }
41
+ loading = { isLoading }
47
42
href = { traceUrl }
48
43
target = "_blank"
49
44
>
0 commit comments