1
1
import React from 'react'
2
2
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
3
- import { CCard , CCardBody , CCardFooter , CCardHeader , CCardTitle } from '@coreui/react'
4
- import Skeleton from 'react-loading-skeleton'
3
+ import { CButton , CCard , CCardBody , CCardHeader , CCardTitle } from '@coreui/react'
5
4
import { CChart } from '@coreui/react-chartjs'
6
5
import { getStyle } from '@coreui/utils'
6
+ import PropTypes from 'prop-types'
7
7
8
8
export default function CippChartCard ( {
9
9
title,
@@ -13,23 +13,38 @@ export default function CippChartCard({
13
13
ChartType = 'pie' ,
14
14
LegendLocation = 'bottom' ,
15
15
isFetching,
16
+ refreshFunction,
16
17
} ) {
17
18
return (
18
19
< CCard className = "h-100 mb-3" >
19
20
< CCardHeader >
20
21
< CCardTitle >
21
22
{ titleType === 'big' ? < h3 className = "underline mb-3" > { title } </ h3 > : title }
23
+ { refreshFunction ? (
24
+ < CButton
25
+ className = "position-absolute top-0 end-0 mt-2 me-2"
26
+ variant = "ghost"
27
+ onClick = { refreshFunction }
28
+ disabled = { isFetching }
29
+ >
30
+ < FontAwesomeIcon icon = "sync" spin = { isFetching } />
31
+ </ CButton >
32
+ ) : (
33
+ < CButton className = "position-absolute top-0 end-0 mt-2 me-2" variant = "ghost" disabled >
34
+ < FontAwesomeIcon icon = "sync" spin = { isFetching } />
35
+ </ CButton >
36
+ ) }
22
37
</ CCardTitle >
23
38
</ CCardHeader >
24
39
< CCardBody >
25
- { isFetching && < Skeleton /> }
26
- { ! isFetching && (
40
+ { ChartData && (
27
41
< CChart
28
42
type = { ChartType }
29
43
data = { {
30
44
labels : ChartLabels ,
31
45
datasets : [
32
46
{
47
+ label : title ,
33
48
backgroundColor : [
34
49
getStyle ( '--cyberdrain-warning' ) ,
35
50
getStyle ( '--cyberdrain-info' ) ,
@@ -59,3 +74,13 @@ export default function CippChartCard({
59
74
</ CCard >
60
75
)
61
76
}
77
+ CippChartCard . propTypes = {
78
+ title : PropTypes . string . isRequired ,
79
+ titleType : PropTypes . oneOf ( [ 'normal' , 'big' ] ) ,
80
+ ChartData : PropTypes . array . isRequired ,
81
+ ChartLabels : PropTypes . array . isRequired ,
82
+ ChartType : PropTypes . oneOf ( [ 'pie' , 'bar' , 'line' ] ) ,
83
+ LegendLocation : PropTypes . oneOf ( [ 'top' , 'bottom' , 'left' , 'right' ] ) ,
84
+ isFetching : PropTypes . bool ,
85
+ refreshFunction : PropTypes . func ,
86
+ }
0 commit comments