File tree Expand file tree Collapse file tree 1 file changed +4
-8
lines changed
src/components/StatsBoxGrid Expand file tree Collapse file tree 1 file changed +4
-8
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { Line } from "react-chartjs-2"
11
11
import { MdInfoOutline } from "react-icons/md"
12
12
import { Box , Flex , Icon , Text } from "@chakra-ui/react"
13
13
14
- import type { StatsBoxMetric } from "@/lib/types"
14
+ import type { StatsBoxMetric , TimestampedData } from "@/lib/types"
15
15
16
16
import { RANGES } from "@/lib/constants"
17
17
@@ -69,8 +69,7 @@ export const GridItem = ({ metric }: GridItemProps) => {
69
69
)
70
70
71
71
// Returns either 90 or 30-day data range depending on `range` selection
72
- const filteredData = ( data : Array < { timestamp : number } > ) => {
73
- if ( ! data ) return
72
+ const filteredData = ( data : TimestampedData < number > [ ] ) => {
74
73
if ( range === RANGES [ 1 ] ) return [ ...data ]
75
74
76
75
return data . filter ( ( { timestamp } ) => {
@@ -138,16 +137,13 @@ export const GridItem = ({ metric }: GridItemProps) => {
138
137
} ,
139
138
}
140
139
141
- const filteredRange = hasData ? filteredData ( state . data ) : [ ] // timestamp values
142
- const dataValues = hasData ? state . data . map ( ( item ) => item . value ) : [ ] // data values
140
+ const filteredRange = filteredData ( hasData ? state . data : [ ] )
143
141
144
142
const chartData = {
145
143
labels : filteredRange ,
146
144
datasets : [
147
145
{
148
- data : hasData
149
- ? dataValues . slice ( dataValues . length - filteredRange ! . length )
150
- : [ ] ,
146
+ data : filteredRange . map ( ( item ) => item . value ) ,
151
147
} ,
152
148
] ,
153
149
}
You can’t perform that action at this time.
0 commit comments