@@ -7,84 +7,84 @@ import PropTypes from "prop-types";
7
7
const PieChartLegend = ( { audits } ) => {
8
8
const theme = useTheme ( ) ;
9
9
10
- if ( typeof audits === "undefined" ) return null ;
11
10
return (
12
11
< LegendBox
13
12
icon = { < SpeedometerIcon /> }
14
13
header = "Performance metrics"
15
14
sx = { { flex : 1 } }
16
15
>
17
- { Object . keys ( audits ) . map ( ( key ) => {
18
- if ( key === "_id" ) return ;
16
+ { typeof audits !== "undefined" &&
17
+ Object . keys ( audits ) . map ( ( key ) => {
18
+ if ( key === "_id" ) return ;
19
19
20
- let audit = audits [ key ] ;
21
- let score = audit . score * 100 ;
22
- let bg =
23
- score >= 90
24
- ? theme . palette . success . main
25
- : score >= 50
26
- ? theme . palette . warning . main
27
- : score >= 0
28
- ? theme . palette . error . main
29
- : theme . palette . tertiary . main ;
20
+ let audit = audits [ key ] ;
21
+ let score = audit . score * 100 ;
22
+ let bg =
23
+ score >= 90
24
+ ? theme . palette . success . main
25
+ : score >= 50
26
+ ? theme . palette . warning . main
27
+ : score >= 0
28
+ ? theme . palette . error . main
29
+ : theme . palette . tertiary . main ;
30
30
31
- // Find the position where the number ends and the unit begins
32
- const match = audit . displayValue . match ( / ( \d + \. ? \d * ) \s * ( [ a - z A - Z ] + ) / ) ;
33
- let value ;
34
- let unit ;
35
- if ( match ) {
36
- value = match [ 1 ] ;
37
- match [ 2 ] === "s" ? ( unit = "seconds" ) : ( unit = match [ 2 ] ) ;
38
- } else {
39
- value = audit . displayValue ;
40
- }
31
+ // Find the position where the number ends and the unit begins
32
+ const match = audit . displayValue . match ( / ( \d + \. ? \d * ) \s * ( [ a - z A - Z ] + ) / ) ;
33
+ let value ;
34
+ let unit ;
35
+ if ( match ) {
36
+ value = match [ 1 ] ;
37
+ match [ 2 ] === "s" ? ( unit = "seconds" ) : ( unit = match [ 2 ] ) ;
38
+ } else {
39
+ value = audit . displayValue ;
40
+ }
41
41
42
- return (
43
- < Stack
44
- flex = { 1 }
45
- key = { `${ key } -box` }
46
- justifyContent = "space-between"
47
- direction = "row"
48
- gap = { theme . spacing ( 4 ) }
49
- p = { theme . spacing ( 3 ) }
50
- border = { 1 }
51
- borderColor = { theme . palette . primary . lowContrast }
52
- borderRadius = { 4 }
53
- >
54
- < Box >
55
- < Typography
56
- fontSize = { 12 }
57
- fontWeight = { 500 }
58
- lineHeight = { 1 }
59
- mb = { 1 }
60
- textTransform = "uppercase"
61
- >
62
- { audit . title }
63
- </ Typography >
64
- < Typography
65
- component = "span"
66
- fontSize = { 14 }
67
- fontWeight = { 500 }
68
- color = { theme . palette . primary . contrastText }
69
- >
70
- { value }
42
+ return (
43
+ < Stack
44
+ flex = { 1 }
45
+ key = { `${ key } -box` }
46
+ justifyContent = "space-between"
47
+ direction = "row"
48
+ gap = { theme . spacing ( 4 ) }
49
+ p = { theme . spacing ( 3 ) }
50
+ border = { 1 }
51
+ borderColor = { theme . palette . primary . lowContrast }
52
+ borderRadius = { 4 }
53
+ >
54
+ < Box >
55
+ < Typography
56
+ fontSize = { 12 }
57
+ fontWeight = { 500 }
58
+ lineHeight = { 1 }
59
+ mb = { 1 }
60
+ textTransform = "uppercase"
61
+ >
62
+ { audit . title }
63
+ </ Typography >
71
64
< Typography
72
65
component = "span"
73
- variant = "body2"
74
- ml = { 2 }
66
+ fontSize = { 14 }
67
+ fontWeight = { 500 }
68
+ color = { theme . palette . primary . contrastText }
75
69
>
76
- { unit }
70
+ { value }
71
+ < Typography
72
+ component = "span"
73
+ variant = "body2"
74
+ ml = { 2 }
75
+ >
76
+ { unit }
77
+ </ Typography >
77
78
</ Typography >
78
- </ Typography >
79
- </ Box >
80
- < Box
81
- width = { 4 }
82
- backgroundColor = { bg }
83
- borderRadius = { 4 }
84
- />
85
- </ Stack >
86
- ) ;
87
- } ) }
79
+ </ Box >
80
+ < Box
81
+ width = { 4 }
82
+ backgroundColor = { bg }
83
+ borderRadius = { 4 }
84
+ />
85
+ </ Stack >
86
+ ) ;
87
+ } ) }
88
88
</ LegendBox >
89
89
) ;
90
90
} ;
0 commit comments