-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathOrgLimits.tsx
More file actions
127 lines (111 loc) · 3.62 KB
/
OrgLimits.tsx
File metadata and controls
127 lines (111 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Libraries
import React, {FC} from 'react'
import {useSelector} from 'react-redux'
import {Columns, Grid} from '@influxdata/clockface'
// Components
import OrgLimitStat from 'src/billing/components/Free/OrgLimitStat'
// Selectors
import {isOrgIOx} from 'src/organizations/selectors'
// Types
import {AppState} from 'src/types'
import {Limit} from 'src/cloud/actions/limits'
import {LimitsState} from 'src/cloud/reducers/limits'
enum LimitNames {
Buckets = 'buckets',
Endpoints = 'endpoints',
MaxRetentionSeconds = 'maxRetentionSeconds',
OrgID = 'orgID',
Rate = 'rate',
Status = 'status',
}
interface LimitCardProps {
limitName: string
limitValue: Limit
}
const removeUnrenderedProps = (orgLimits: LimitsState | {}) =>
Object.entries(orgLimits).filter(
([limitName]) =>
limitName !== LimitNames.OrgID &&
limitName !== LimitNames.Status &&
limitName !== LimitNames.Endpoints
)
const LimitCard: FC<LimitCardProps> = ({limitName, limitValue}) => {
return (
<Grid.Column
key={limitName}
widthXS={Columns.Twelve}
widthSM={Columns.Six}
widthMD={Columns.Four}
widthLG={Columns.Three}
>
<OrgLimitStat name={limitName} value={limitValue.maxAllowed} />
</Grid.Column>
)
}
export const OrgLimits: FC = () => {
const orgLimits = useSelector((state: AppState) => state.cloud?.limits ?? {})
const orgUsesIOx = useSelector(isOrgIOx)
return (
<Grid>
{removeUnrenderedProps(orgLimits).map(limit => {
const [limitName, limitValue] = limit
// The "Rate" category includes multiple object literal 'limits', each with its own 'limitStatus.'
if (limitName === LimitNames.Rate) {
const hiddenLimits = ['queryTime']
// IOx orgs have no cardinality limit.
if (orgUsesIOx) {
hiddenLimits.push('cardinality')
}
return Object.keys(limitValue)
.filter(sublimitName => !hiddenLimits.includes(sublimitName))
.map(sublimitName => {
return (
<LimitCard
key={sublimitName}
limitName={sublimitName}
limitValue={limitValue[sublimitName]}
/>
)
})
}
// The "Buckets" category is one object literal with two sublimits and a shared 'limitStatus.'
if (limitName === LimitNames.Buckets) {
const maxBucketsLimit = limitValue
const maxRetentionLimit = {
maxAllowed: limitValue.maxRetentionSeconds,
limitStatus: limitValue.limitStatus,
}
return (
<div key={`${LimitNames.Buckets}-limits`}>
<LimitCard
key={LimitNames.Buckets}
limitName={LimitNames.Buckets}
limitValue={maxBucketsLimit}
/>
<LimitCard
key={LimitNames.MaxRetentionSeconds}
limitName={LimitNames.MaxRetentionSeconds}
limitValue={maxRetentionLimit}
/>
</div>
)
}
// The 'dashboards', 'tasks', 'checks', and 'rules' limits are not applicable to orgs using IOx.
if (orgUsesIOx) {
const hiddenLimits = ['dashboards', 'tasks', 'checks', 'rules']
if (hiddenLimits.includes(limitName)) {
return null
}
}
// By default, any 'limit' is a single object literal containing one limitStatus.
return (
<LimitCard
key={limitName}
limitName={limitName}
limitValue={limitValue}
/>
)
})}
</Grid>
)
}