@@ -17,56 +17,9 @@ interface ManagedAgentsConsumptionProps {
17
17
managedAgentFeature ?: Feature ;
18
18
}
19
19
20
- const validateFeature = ( feature ?: Feature ) : string | null => {
21
- if ( ! feature ) {
22
- return null ; // No feature is valid (will show disabled state)
23
- }
24
-
25
- // If enabled, we need valid numeric data
26
- if ( feature . enabled ) {
27
- if (
28
- feature . actual === undefined ||
29
- feature . soft_limit === undefined ||
30
- feature . limit === undefined
31
- ) {
32
- return "Managed agent feature is enabled but missing required usage data (actual, soft_limit, or limit)." ;
33
- }
34
-
35
- if ( feature . actual < 0 || feature . soft_limit < 0 || feature . limit < 0 ) {
36
- return "Managed agent feature contains invalid negative values for usage metrics." ;
37
- }
38
-
39
- if ( feature . soft_limit > feature . limit ) {
40
- return "Managed agent feature has invalid configuration: soft limit exceeds total limit." ;
41
- }
42
-
43
- // Validate usage period if present
44
- if ( feature . usage_period ) {
45
- const start = dayjs ( feature . usage_period . start ) ;
46
- const end = dayjs ( feature . usage_period . end ) ;
47
-
48
- if ( ! start . isValid ( ) || ! end . isValid ( ) ) {
49
- return "Managed agent feature has invalid usage period dates." ;
50
- }
51
-
52
- if ( end . isBefore ( start ) ) {
53
- return "Managed agent feature has invalid usage period: end date is before start date." ;
54
- }
55
- }
56
- }
57
-
58
- return null ; // Valid
59
- } ;
60
-
61
20
export const ManagedAgentsConsumption : FC < ManagedAgentsConsumptionProps > = ( {
62
21
managedAgentFeature,
63
22
} ) => {
64
- // Validate the feature data
65
- const validationError = validateFeature ( managedAgentFeature ) ;
66
- if ( validationError ) {
67
- return < ErrorAlert error = { new Error ( validationError ) } /> ;
68
- }
69
-
70
23
// If no feature is provided or it's disabled, show disabled state
71
24
if ( ! managedAgentFeature ?. enabled ) {
72
25
return (
@@ -85,11 +38,29 @@ export const ManagedAgentsConsumption: FC<ManagedAgentsConsumptionProps> = ({
85
38
) ;
86
39
}
87
40
88
- const usage = managedAgentFeature . actual || 0 ;
89
- const included = managedAgentFeature . soft_limit || 0 ;
90
- const limit = managedAgentFeature . limit || 0 ;
91
- const startDate = managedAgentFeature . usage_period ?. start || "" ;
92
- const endDate = managedAgentFeature . usage_period ?. end || "" ;
41
+ const usage = managedAgentFeature . actual ;
42
+ const included = managedAgentFeature . soft_limit ;
43
+ const limit = managedAgentFeature . limit ;
44
+ const startDate = managedAgentFeature . usage_period ?. start ;
45
+ const endDate = managedAgentFeature . usage_period ?. end ;
46
+
47
+ if ( ! usage || usage < 0 ) {
48
+ return < ErrorAlert error = "Invalid usage data" />
49
+ }
50
+
51
+ if ( ! included || included < 0 || ! limit || limit < 0 ) {
52
+ return < ErrorAlert error = "Invalid license usage limits" />
53
+ }
54
+
55
+ if ( ! startDate || ! endDate ) {
56
+ return < ErrorAlert error = "Missing license usage period" />
57
+ }
58
+
59
+ const start = dayjs ( startDate ) ;
60
+ const end = dayjs ( endDate ) ;
61
+ if ( ! start . isValid ( ) || ! end . isValid ( ) || ! start . isBefore ( end ) ) {
62
+ return < ErrorAlert error = "Invalid license usage period" />
63
+ }
93
64
94
65
const usagePercentage = Math . min ( ( usage / limit ) * 100 , 100 ) ;
95
66
const includedPercentage = Math . min ( ( included / limit ) * 100 , 100 ) ;
0 commit comments