4
4
*/
5
5
6
6
import Filter from 'gmp/models/filter' ;
7
- import FilterTerm from 'gmp/models/filter/filterterm' ;
8
7
import { isDefined } from 'gmp/utils/identity' ;
9
8
import React from 'react' ;
10
9
import DonutChart from 'web/components/chart/Donut' ;
11
10
import DataDisplay from 'web/components/dashboard/display/DataDisplay' ;
12
11
import { renderDonutChartIcons } from 'web/components/dashboard/display/DataDisplayIcons' ;
13
12
import transformSeverityData from 'web/components/dashboard/display/severity/SeverityClassTransform' ;
13
+ import { filterValueToFilterTerms } from 'web/components/dashboard/display/severity/utils' ;
14
14
import PropTypes from 'web/utils/PropTypes' ;
15
15
16
- class SeverityClassDisplay extends React . Component {
17
- constructor ( ...args ) {
18
- super ( ...args ) ;
19
-
20
- this . handleDataClick = this . handleDataClick . bind ( this ) ;
21
- }
22
-
23
- handleDataClick ( data ) {
24
- const { onFilterChanged, filter} = this . props ;
16
+ const SeverityClassDisplay = ( { onFilterChanged, filter, ...props } ) => {
17
+ const handleDataClick = data => {
25
18
const { filterValue} = data ;
26
19
27
20
let severityFilter ;
28
21
if ( ! isDefined ( onFilterChanged ) ) {
29
22
return ;
30
23
}
31
24
32
- const { start, end} = filterValue ;
33
- if ( start > 0 && end < 10 ) {
34
- const startTerm = FilterTerm . fromString ( `severity>${ start } ` ) ;
35
- const endTerm = FilterTerm . fromString ( `severity<${ end } ` ) ;
36
-
25
+ const [ startTerm , endTerm ] = filterValueToFilterTerms ( filterValue ) ;
26
+ if ( isDefined ( endTerm ) ) {
37
27
if (
38
28
isDefined ( filter ) &&
39
29
filter . hasTerm ( startTerm ) &&
@@ -44,58 +34,46 @@ class SeverityClassDisplay extends React.Component {
44
34
45
35
severityFilter = Filter . fromTerm ( startTerm ) . and ( Filter . fromTerm ( endTerm ) ) ;
46
36
} else {
47
- let severityTerm ;
48
- if ( start > 0 ) {
49
- severityTerm = FilterTerm . fromString ( `severity>${ start } ` ) ;
50
- } else {
51
- severityTerm = FilterTerm . fromString ( `severity=${ start } ` ) ;
52
- }
53
-
54
- if ( isDefined ( filter ) && filter . hasTerm ( severityTerm ) ) {
37
+ if ( isDefined ( filter ) && filter . hasTerm ( startTerm ) ) {
55
38
return ;
56
39
}
57
40
58
- severityFilter = Filter . fromTerm ( severityTerm ) ;
41
+ severityFilter = Filter . fromTerm ( startTerm ) ;
59
42
}
60
43
61
44
const newFilter = isDefined ( filter )
62
45
? filter . copy ( ) . and ( severityFilter )
63
46
: severityFilter ;
64
47
65
48
onFilterChanged ( newFilter ) ;
66
- }
67
-
68
- render ( ) {
69
- const { onFilterChanged, ...props } = this . props ;
70
- return (
71
- < DataDisplay
72
- { ...props }
73
- dataTransform = { transformSeverityData }
74
- icons = { renderDonutChartIcons }
75
- initialState = { {
76
- show3d : true ,
77
- } }
78
- >
79
- { ( { width, height, data, svgRef, state} ) => (
80
- < DonutChart
81
- data = { data }
82
- height = { height }
83
- show3d = { state . show3d }
84
- showLegend = { state . showLegend }
85
- svgRef = { svgRef }
86
- width = { width }
87
- onDataClick = {
88
- isDefined ( onFilterChanged ) ? this . handleDataClick : undefined
89
- }
90
- onLegendItemClick = {
91
- isDefined ( onFilterChanged ) ? this . handleDataClick : undefined
92
- }
93
- />
94
- ) }
95
- </ DataDisplay >
96
- ) ;
97
- }
98
- }
49
+ } ;
50
+ return (
51
+ < DataDisplay
52
+ { ...props }
53
+ dataTransform = { transformSeverityData }
54
+ filter = { filter }
55
+ icons = { renderDonutChartIcons }
56
+ initialState = { {
57
+ show3d : true ,
58
+ } }
59
+ >
60
+ { ( { width, height, data, svgRef, state} ) => (
61
+ < DonutChart
62
+ data = { data }
63
+ height = { height }
64
+ show3d = { state . show3d }
65
+ showLegend = { state . showLegend }
66
+ svgRef = { svgRef }
67
+ width = { width }
68
+ onDataClick = { isDefined ( onFilterChanged ) ? handleDataClick : undefined }
69
+ onLegendItemClick = {
70
+ isDefined ( onFilterChanged ) ? handleDataClick : undefined
71
+ }
72
+ />
73
+ ) }
74
+ </ DataDisplay >
75
+ ) ;
76
+ } ;
99
77
100
78
SeverityClassDisplay . propTypes = {
101
79
filter : PropTypes . filter ,
0 commit comments