11import React , { FC } from 'react'
2- import Utils from 'common/utils/utils'
3- import { IonIcon } from '@ionic/react'
4- import { checkmarkSharp } from 'ionicons/icons'
52import { Res } from 'common/types/responses'
3+ import { IconName } from 'components/Icon'
4+ import StatItem from 'components/StatItem'
65
7- type LegendItemType = {
6+ type TotalItem = {
7+ colour : string | undefined
8+ icon : IconName
9+ limit : number | null | undefined
810 title : string
911 value : number
10- selection : string [ ]
11- onChange : ( v : string ) => void
12- colour ?: string
13- }
14-
15- const LegendItem : FC < LegendItemType > = ( {
16- colour,
17- onChange,
18- selection,
19- title,
20- value,
21- } ) => {
22- if ( ! value ) {
23- return null
24- }
25- return (
26- < div className = 'mb-4' >
27- < h3 className = 'mb-2' > { Utils . numberWithCommas ( value ) } </ h3 >
28- < div
29- className = 'cursor-pointer d-flex align-items-center gap-2'
30- onClick = { ( ) => onChange ( title ) }
31- >
32- { ! ! colour && (
33- < div
34- className = 'text-white d-flex align-items-center justify-content-center'
35- style = { {
36- backgroundColor : colour ,
37- borderRadius : 2 ,
38- flexShrink : 0 ,
39- height : 16 ,
40- width : 16 ,
41- } }
42- >
43- { selection . includes ( title ) && (
44- < IonIcon size = { '8px' } color = 'white' icon = { checkmarkSharp } />
45- ) }
46- </ div >
47- ) }
48- < span className = 'text-muted' > { title } </ span >
49- </ div >
50- </ div >
51- )
5212}
5313
5414export interface UsageChartTotalsProps {
@@ -57,11 +17,13 @@ export interface UsageChartTotalsProps {
5717 updateSelection : ( key : string ) => void
5818 colours : string [ ]
5919 withColor ?: boolean
20+ maxApiCalls ?: number | null
6021}
6122
6223const UsageChartTotals : FC < UsageChartTotalsProps > = ( {
6324 colours,
6425 data,
26+ maxApiCalls,
6527 selection,
6628 updateSelection,
6729 withColor = true ,
@@ -70,47 +32,67 @@ const UsageChartTotals: FC<UsageChartTotalsProps> = ({
7032 return null
7133 }
7234
73- const totalItems = [
35+ const totalItems : TotalItem [ ] = [
7436 {
7537 colour : colours [ 0 ] ,
38+ icon : 'features' ,
39+ limit : undefined ,
7640 title : 'Flags' ,
7741 value : data . totals . flags ,
7842 } ,
7943 {
8044 colour : colours [ 1 ] ,
45+ icon : 'person' ,
46+ limit : undefined ,
8147 title : 'Identities' ,
8248 value : data . totals . identities ,
8349 } ,
8450 {
8551 colour : colours [ 2 ] ,
52+ icon : 'file-text' ,
53+ limit : undefined ,
8654 title : 'Environment Document' ,
8755 value : data . totals . environmentDocument ,
8856 } ,
8957 {
9058 colour : colours [ 3 ] ,
59+ icon : 'layers' ,
60+ limit : undefined ,
9161 title : 'Traits' ,
9262 value : data . totals . traits ,
9363 } ,
9464 {
9565 colour : undefined ,
66+ icon : 'bar-chart' ,
67+ limit : maxApiCalls ,
9668 title : 'Total API Calls' ,
9769 value : data . totals . total ,
9870 } ,
9971 ]
10072
10173 return (
102- < div className = 'd-flex gap-5 align-items-start' >
103- { totalItems . map ( ( item ) => (
104- < LegendItem
105- key = { item . title }
106- selection = { selection }
107- onChange = { updateSelection }
108- colour = { ! withColor && item . colour ? '#6837fc' : item . colour }
109- value = { item . value }
110- title = { item . title }
111- />
112- ) ) }
113- </ div >
74+ < Row className = 'plan p-4 mb-4 flex-wrap gap-4' >
75+ { totalItems
76+ . filter ( ( item ) => item . value )
77+ . map ( ( item ) => (
78+ < StatItem
79+ key = { item . title }
80+ icon = { item . icon }
81+ label = { item . title }
82+ value = { item . value }
83+ limit = { item . limit }
84+ visibilityToggle = {
85+ withColor && item . colour
86+ ? {
87+ colour : item . colour ,
88+ isVisible : selection . includes ( item . title ) ,
89+ onToggle : ( ) => updateSelection ( item . title ) ,
90+ }
91+ : undefined
92+ }
93+ />
94+ ) ) }
95+ </ Row >
11496 )
11597}
11698
0 commit comments