1
- import type { ReactElement } from 'react' ;
1
+ import { type MutableRefObject , type ReactElement , useCallback , useRef } from 'react' ;
2
2
import { type Theme , useTheme } from '@emotion/react' ;
3
3
import type {
4
4
CustomSeriesOption ,
@@ -43,6 +43,9 @@ interface CreateReleaseBubbleMouseListenersParams {
43
43
options : DrawerConfig [ 'options' ]
44
44
) => void ;
45
45
chartRenderer ?: ( rendererProps : {
46
+ chartRef :
47
+ | MutableRefObject < ReactEchartsRef | null >
48
+ | ( ( e : ReactEchartsRef | null ) => void ) ;
46
49
end : Date ;
47
50
releases : ReleaseMetaBasic [ ] ;
48
51
start : Date ;
@@ -322,10 +325,12 @@ ${t('Click to expand')}
322
325
}
323
326
324
327
interface UseReleaseBubblesParams {
325
- chartRef : React . RefObject < ReactEchartsRef | null > ;
326
328
bubblePadding ?: number ;
327
329
bubbleSize ?: number ;
328
330
chartRenderer ?: ( rendererProps : {
331
+ chartRef :
332
+ | MutableRefObject < ReactEchartsRef | null >
333
+ | ( ( e : ReactEchartsRef | null ) => void ) ;
329
334
end : Date ;
330
335
releases : ReleaseMetaBasic [ ] ;
331
336
start : Date ;
@@ -335,7 +340,6 @@ interface UseReleaseBubblesParams {
335
340
releases ?: ReleaseMetaBasic [ ] ;
336
341
}
337
342
export function useReleaseBubbles ( {
338
- chartRef,
339
343
chartRenderer,
340
344
releases,
341
345
minTime,
@@ -355,7 +359,16 @@ export function useReleaseBubbles({
355
359
const releasesMaxTime = defined ( selection . datetime . end )
356
360
? new Date ( selection . datetime . end ) . getTime ( )
357
361
: Date . now ( ) ;
362
+ const chartRef = useRef < ReactEchartsRef | null > ( null ) ;
358
363
const hasReleaseBubbles = organization . features . includes ( 'release-bubbles-ui' ) ;
364
+ const handleChartRef = useCallback ( ( e : ReactEchartsRef | null ) => {
365
+ chartRef . current = e ;
366
+
367
+ if ( e ?. getEchartsInstance ) {
368
+ createReleaseBubbleHighlighter ( e . getEchartsInstance ( ) ) ;
369
+ }
370
+ } , [ ] ) ;
371
+
359
372
const buckets =
360
373
( hasReleaseBubbles &&
361
374
releases ?. length &&
@@ -377,7 +390,7 @@ export function useReleaseBubbles({
377
390
const totalBubblePaddingY = bubblePadding * 2 ;
378
391
379
392
return {
380
- createReleaseBubbleHighlighter,
393
+ createReleaseBubbleHighlighter : handleChartRef ,
381
394
382
395
/**
383
396
* An object map of ECharts event handlers. These should be spread onto a Chart component
0 commit comments