@@ -11,34 +11,50 @@ import {
1111 ChartTooltip ,
1212 ChartVoronoiContainer ,
1313} from '@patternfly/react-charts/victory' ;
14- import { Bullseye , Card , CardBody , CardTitle , Spinner } from '@patternfly/react-core' ;
1514import {
16- createIncidentsChartBars ,
17- formatDate ,
18- generateDateArray ,
19- updateBrowserUrl ,
20- } from '../utils' ;
21- import { getResizeObserver } from '@patternfly/react-core' ;
22- import { useDispatch , useSelector } from 'react-redux' ;
23- import { setChooseIncident } from '../../../actions/observe' ;
15+ Bullseye ,
16+ Card ,
17+ CardBody ,
18+ CardTitle ,
19+ getResizeObserver ,
20+ Spinner ,
21+ } from '@patternfly/react-core' ;
2422import {
2523 t_global_color_status_danger_default ,
2624 t_global_color_status_info_default ,
2725 t_global_color_status_warning_default ,
2826} from '@patternfly/react-tokens' ;
29- import { setAlertsAreLoading } from '../../../actions/observe' ;
27+ import { useDispatch , useSelector } from 'react-redux' ;
28+ import { setAlertsAreLoading , setChooseIncident } from '../../../actions/observe' ;
29+ import { MonitoringState } from '../../../reducers/observe' ;
30+ import { Incident } from '../model' ;
31+ import {
32+ createIncidentsChartBars ,
33+ formatDate ,
34+ generateDateArray ,
35+ updateBrowserUrl ,
36+ } from '../utils' ;
37+ import { VictoryPortal } from 'victory' ;
3038
31- const IncidentsChart = ( { incidentsData, chartDays, theme } ) => {
39+ const IncidentsChart = ( {
40+ incidentsData,
41+ chartDays,
42+ theme,
43+ } : {
44+ incidentsData : Array < Incident > ;
45+ chartDays : number ;
46+ theme : 'light' | 'dark' ;
47+ } ) => {
3248 const dispatch = useDispatch ( ) ;
3349 const [ isLoading , setIsLoading ] = React . useState ( true ) ;
34- const [ chartContainerHeight , setChartContainerHeight ] = React . useState ( ) ;
35- const [ chartHeight , setChartHeight ] = React . useState ( ) ;
50+ const [ chartContainerHeight , setChartContainerHeight ] = React . useState < number > ( ) ;
51+ const [ chartHeight , setChartHeight ] = React . useState < number > ( ) ;
3652 const dateValues = React . useMemo ( ( ) => generateDateArray ( chartDays ) , [ chartDays ] ) ;
3753
3854 const chartData = React . useMemo ( ( ) => {
3955 if ( ! Array . isArray ( incidentsData ) || incidentsData . length === 0 ) return [ ] ;
40- return incidentsData . map ( ( incident ) => createIncidentsChartBars ( incident , theme , dateValues ) ) ;
41- } , [ incidentsData , theme , dateValues ] ) ;
56+ return incidentsData . map ( ( incident ) => createIncidentsChartBars ( incident , dateValues ) ) ;
57+ } , [ incidentsData , dateValues ] ) ;
4258
4359 React . useEffect ( ( ) => {
4460 setIsLoading ( false ) ;
@@ -63,8 +79,10 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
6379 return ( ) => observer ( ) ;
6480 } , [ ] ) ;
6581
66- const selectedId = useSelector ( ( state ) => state . plugins . mcp . getIn ( [ 'incidentsData' , 'groupId' ] ) ) ;
67- const incidentsActiveFilters = useSelector ( ( state ) =>
82+ const selectedId = useSelector ( ( state : MonitoringState ) =>
83+ state . plugins . mcp . getIn ( [ 'incidentsData' , 'groupId' ] ) ,
84+ ) ;
85+ const incidentsActiveFilters = useSelector ( ( state : MonitoringState ) =>
6886 state . plugins . mcp . getIn ( [ 'incidentsData' , 'incidentsActiveFilters' ] ) ,
6987 ) ;
7088
@@ -97,8 +115,8 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
97115 ) ;
98116
99117 return (
100- < Card className = "incidents-chart-card" >
101- < div ref = { containerRef } >
118+ < Card className = "incidents-chart-card" style = { { overflow : 'visible' } } >
119+ < div ref = { containerRef } style = { { position : 'relative' } } >
102120 < CardTitle > Incidents Timeline</ CardTitle >
103121 { isLoading ? (
104122 < Bullseye >
@@ -107,29 +125,33 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
107125 ) : (
108126 < CardBody
109127 style = { {
110- height : { chartContainerHeight } ,
128+ height : chartContainerHeight ,
111129 width : '100%' ,
112130 } }
113131 >
114132 < Chart
115133 containerComponent = {
116134 < ChartVoronoiContainer
117135 labelComponent = {
118- < ChartTooltip
119- orientation = "top"
120- dx = { ( { x, x0 } ) => - ( x - x0 ) / 2 }
121- dy = { - 5 } // Position tooltip so pointer appears above bar
122- constrainToVisibleArea
123- labelComponent = { < ChartLabel /> }
124- />
136+ < VictoryPortal >
137+ < ChartTooltip
138+ activateData = { false }
139+ orientation = "top"
140+ dx = { ( { x, x0 } : any ) => - ( x - x0 ) / 2 }
141+ dy = { - 5 } // Position tooltip so pointer appears above bar
142+ labelComponent = { < ChartLabel /> }
143+ />
144+ </ VictoryPortal >
125145 }
146+ voronoiPadding = { 0 }
126147 labels = { ( { datum } ) => {
127148 if ( datum . nodata ) {
128149 return null ;
129150 }
130151 return `Severity: ${ datum . name }
131152 Component: ${ datum . componentList ?. join ( ', ' ) }
132- Incident ID: ${ datum . group_id }
153+ Incident ID:
154+ ${ datum . group_id }
133155 Start: ${ formatDate ( new Date ( datum . y0 ) , true ) }
134156 End: ${ datum . firing ? '---' : formatDate ( new Date ( datum . y ) , true ) } ` ;
135157 } }
@@ -181,7 +203,7 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
181203 tickFormat = { ( t ) =>
182204 new Date ( t ) . toLocaleDateString ( 'en-US' , { month : 'short' , day : 'numeric' } )
183205 }
184- tickValues = { dateValues }
206+ tickValues = { dateValues . map ( ( ts ) => new Date ( ts * 1000 ) ) }
185207 tickLabelComponent = {
186208 < ChartLabel style = { { fill : theme === 'light' ? '#1b1d21' : '#e0e0e0' } } />
187209 }
@@ -192,7 +214,7 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
192214 //we have several arrays and for each array we make a ChartBar
193215 < ChartBar
194216 data = { bar }
195- key = { bar . group_id }
217+ key = { bar [ 0 ] . group_id }
196218 style = { {
197219 data : {
198220 fill : ( { datum } ) => datum . fill ,
@@ -203,6 +225,7 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
203225 } }
204226 events = { [
205227 {
228+ target : 'data' ,
206229 eventHandlers : {
207230 onClick : ( props , datum ) => clickHandler ( props , datum ) ,
208231 } ,
0 commit comments