@@ -11,34 +11,50 @@ import {
11
11
ChartTooltip ,
12
12
ChartVoronoiContainer ,
13
13
} from '@patternfly/react-charts/victory' ;
14
- import { Bullseye , Card , CardBody , CardTitle , Spinner } from '@patternfly/react-core' ;
15
14
import {
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' ;
24
22
import {
25
23
t_global_color_status_danger_default ,
26
24
t_global_color_status_info_default ,
27
25
t_global_color_status_warning_default ,
28
26
} 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' ;
30
38
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
+ } ) => {
32
48
const dispatch = useDispatch ( ) ;
33
49
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 > ( ) ;
36
52
const dateValues = React . useMemo ( ( ) => generateDateArray ( chartDays ) , [ chartDays ] ) ;
37
53
38
54
const chartData = React . useMemo ( ( ) => {
39
55
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 ] ) ;
42
58
43
59
React . useEffect ( ( ) => {
44
60
setIsLoading ( false ) ;
@@ -63,8 +79,10 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
63
79
return ( ) => observer ( ) ;
64
80
} , [ ] ) ;
65
81
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 ) =>
68
86
state . plugins . mcp . getIn ( [ 'incidentsData' , 'incidentsActiveFilters' ] ) ,
69
87
) ;
70
88
@@ -97,8 +115,8 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
97
115
) ;
98
116
99
117
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' } } >
102
120
< CardTitle > Incidents Timeline</ CardTitle >
103
121
{ isLoading ? (
104
122
< Bullseye >
@@ -107,29 +125,33 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
107
125
) : (
108
126
< CardBody
109
127
style = { {
110
- height : { chartContainerHeight } ,
128
+ height : chartContainerHeight ,
111
129
width : '100%' ,
112
130
} }
113
131
>
114
132
< Chart
115
133
containerComponent = {
116
134
< ChartVoronoiContainer
117
135
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 >
125
145
}
146
+ voronoiPadding = { 0 }
126
147
labels = { ( { datum } ) => {
127
148
if ( datum . nodata ) {
128
149
return null ;
129
150
}
130
151
return `Severity: ${ datum . name }
131
152
Component: ${ datum . componentList ?. join ( ', ' ) }
132
- Incident ID: ${ datum . group_id }
153
+ Incident ID:
154
+ ${ datum . group_id }
133
155
Start: ${ formatDate ( new Date ( datum . y0 ) , true ) }
134
156
End: ${ datum . firing ? '---' : formatDate ( new Date ( datum . y ) , true ) } ` ;
135
157
} }
@@ -181,7 +203,7 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
181
203
tickFormat = { ( t ) =>
182
204
new Date ( t ) . toLocaleDateString ( 'en-US' , { month : 'short' , day : 'numeric' } )
183
205
}
184
- tickValues = { dateValues }
206
+ tickValues = { dateValues . map ( ( ts ) => new Date ( ts * 1000 ) ) }
185
207
tickLabelComponent = {
186
208
< ChartLabel style = { { fill : theme === 'light' ? '#1b1d21' : '#e0e0e0' } } />
187
209
}
@@ -192,7 +214,7 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
192
214
//we have several arrays and for each array we make a ChartBar
193
215
< ChartBar
194
216
data = { bar }
195
- key = { bar . group_id }
217
+ key = { bar [ 0 ] . group_id }
196
218
style = { {
197
219
data : {
198
220
fill : ( { datum } ) => datum . fill ,
@@ -203,6 +225,7 @@ const IncidentsChart = ({ incidentsData, chartDays, theme }) => {
203
225
} }
204
226
events = { [
205
227
{
228
+ target : 'data' ,
206
229
eventHandlers : {
207
230
onClick : ( props , datum ) => clickHandler ( props , datum ) ,
208
231
} ,
0 commit comments