1
- import React , { useEffect , useRef } from "react" ;
1
+ import React , { useEffect , useState } from "react" ;
2
2
import {
3
3
ApolloClient ,
4
4
InMemoryCache ,
@@ -17,7 +17,7 @@ const client = new ApolloClient({
17
17
18
18
export const MetricCard = ( { type, index } ) => {
19
19
20
- const data = useRef ( [ ] ) ;
20
+ const [ data , setData ] = useState ( null ) ;
21
21
22
22
const metricType = [ "Liveness Indicator" , "Error Rate" , "Error Queries" , "Bytes Consumed" ] ;
23
23
const iconColor = [ "rgb(6, 27, 100)" , "rgb(4, 41, 122)" , "rgb(122, 79, 1)" , "rgb(122, 12, 46)" ] ;
@@ -27,7 +27,7 @@ export const MetricCard = ({ type, index }) => {
27
27
`linear-gradient(135deg, rgba(12, 83, 183, 0) 0%, rgba(12, 83, 183, 0.24) 100%)` ,
28
28
`linear-gradient(135deg, rgba(183, 129, 3, 0) 0%, rgba(183, 129, 3, 0.24) 100%)` ,
29
29
`linear-gradient(135deg, rgba(183, 33, 54, 0) 0%, rgba(183, 33, 54, 0.24) 100%)` ] ;
30
- const dataToShow = [ ] ;
30
+
31
31
32
32
const flipCard = ( ) => {
33
33
// supposed to flip liveness card here
@@ -40,26 +40,30 @@ export const MetricCard = ({ type, index }) => {
40
40
client . query ( {
41
41
query : gql `
42
42
query testQuery {
43
- ksqlDBMetrics(metric: "${ metric } ", resolution: 2, start: ${ Math . round ( new Date ( ) . getTime ( ) / 1000 ) - 3000 } , end: ${ Math . round ( new Date ( ) . getTime ( ) / 1000 ) } ) {
43
+ ksqlDBMetrics(metric: "${ metric } ", resolution: 2, start: ${ Math . round ( new Date ( ) . getTime ( ) / 1000 ) - 5 } , end: ${ Math . round ( new Date ( ) . getTime ( ) / 1000 ) } ) {
44
44
x,
45
45
y
46
46
}
47
47
}
48
48
`
49
49
} )
50
50
. then ( res => {
51
+ console . log ( res ) ;
51
52
// chart.data.datasets[0].data.push(...[{x: new Date(), y: 1}]);
52
- data . current = res . data . ksqlDBMetrics . map ( ( queryObj ) => {
53
- return {
54
- x : new Date ( queryObj . x * 1000 ) ,
55
- y : queryObj . y
56
- }
57
- } ) ;
53
+ // setData( res.data.ksqlDBMetrics.map((queryObj) => {
54
+ // return {
55
+ // x: new Date(queryObj.x * 1000),
56
+ // y: queryObj.y
57
+ // }
58
+ // }) );
58
59
// chart.data.datasets[0].data = data;
60
+ setData ( res ) ;
59
61
} )
60
62
. catch ( error => console . log ( error ) ) ;
61
63
} , [ ] ) //useEffect dependency here
62
64
65
+
66
+
63
67
return (
64
68
< CardContent
65
69
sx = { { display : 'flex' , justifyContent : "center" , alignItems : "center" , flexDirection : "column" , bgcolor : bgColor [ index ] , boxShadow : 0 , borderRadius : '16px' } } >
@@ -70,16 +74,16 @@ export const MetricCard = ({ type, index }) => {
70
74
onClick = { ( ) => console . log ( '' ) } // placeholder for flipping card
71
75
>
72
76
{ index === 0 && < MonitorHeartIcon /> }
73
- { index === 1 && < ErrorIcon /> }
77
+ { /* { index === 1 && <ErrorIcon />}
74
78
{index === 2 && <BugReportIcon />}
75
- { index === 3 && < DataThresholdingIcon /> }
79
+ {index === 3 && <DataThresholdingIcon />} */ }
76
80
</ IconButton >
77
81
78
82
< Typography variant = 'h3' sx = { { textAlign : 'center' , pt : '1.2rem' , fontWeight : 700 , lineHeight : 1.5 , fontSize : '1.8rem' , fontFamily : 'Public Sans' , color : textColor [ index ] } } >
79
- { index === 0 && ( data [ data . length - 1 ] ? 'Running' : 'Down' ) }
80
- { index === 1 && ( data [ data . length - 1 ] ? data [ data . length - 1 ] : 0 ) }
83
+ { index === 0 && ( data ?. data ?. ksqlDBMetrics [ 0 ] . y ? 'Running' : 'Down' ) }
84
+ { /* { index === 1 && (data[data.length - 1] ? data[data.length - 1] : 0)}
81
85
{index === 2 && (data[data.length - 1] ? data[data.length - 1] : 0)}
82
- { index === 3 && ( data [ data . length - 1 ] ? data [ data . length - 1 ] : 0 ) }
86
+ {index === 3 && (data[data.length - 1] ? data[data.length - 1] : 0)} */ }
83
87
</ Typography >
84
88
85
89
< Typography variant = 'h6' sx = { { fontWeight : 600 , lineHeight : 1.5 , fontSize : '0.96rem' , fontFamily : 'Public Sans' , opacity : 0.72 , color : textColor [ index ] } } >
0 commit comments