1
- import { PrivateCloudProject } from '@prisma/client' ;
1
+ import { PrivateCloudProject , Quota } from '@prisma/client' ;
2
+ import classNames from 'classnames' ;
3
+ import _startCase from 'lodash-es/startCase' ;
4
+ import { useFormContext } from 'react-hook-form' ;
2
5
import QuotasChangeInfo from '@/components/form/QuotasChangeInfo' ;
3
6
import ExternalLink from '@/components/generic/button/ExternalLink' ;
4
- import { defaultCpuOptionsLookup , defaultMemoryOptionsLookup , defaultStorageOptionsLookup } from '../.. /constants' ;
7
+ import { defaultCpuOptionsLookup , defaultMemoryOptionsLookup , defaultStorageOptionsLookup } from '@ /constants' ;
5
8
import QuotaInput from './QuotaInput' ;
6
9
7
10
const quotaOptionsLookup = {
@@ -10,6 +13,17 @@ const quotaOptionsLookup = {
10
13
storage : defaultStorageOptionsLookup ,
11
14
} ;
12
15
16
+ const namespaceSuffixes = {
17
+ production : '-prod' ,
18
+ tools : '-tools' ,
19
+ test : '-test' ,
20
+ development : '-dev' ,
21
+ } ;
22
+
23
+ type namespaceKeyType = keyof typeof namespaceSuffixes ;
24
+
25
+ const namespaceKeys = Object . keys ( namespaceSuffixes ) as namespaceKeyType [ ] ;
26
+
13
27
export default function Quotas ( {
14
28
licencePlate,
15
29
disabled,
@@ -19,50 +33,64 @@ export default function Quotas({
19
33
disabled : boolean ;
20
34
currentProject ?: PrivateCloudProject | null | undefined ;
21
35
} ) {
22
- const namespaceSuffixes = {
23
- production : '-prod' ,
24
- tools : '-tools' ,
25
- test : '-test' ,
26
- development : '-dev' ,
27
- } ;
36
+ const formData = useFormContext ( ) ;
37
+ const newValues = formData . getValues ( ) ;
38
+
39
+ if ( ! currentProject ) return null ;
40
+
28
41
return (
29
42
< >
30
43
< p className = "text-base leading-6 mt-5" >
31
- All quota increase requests require < b > Platform Services Team’s </ b >
32
- approval, and must have supporting information as per the{ ' ' }
44
+ All quota increase requests require < span className = "font-bold" > Platform Services Team’s </ span >
45
+ approval, and must have supporting information as per the
33
46
< ExternalLink href = "https://docs.developer.gov.bc.ca/request-quota-increase-for-openshift-project-set/" >
34
47
Quota Increase Request Process
35
48
</ ExternalLink >
36
- . Any Quota Requests without supporting information
37
- < b > will not </ b > be processed.
49
+ . Any Quota Requests without supporting information
50
+ < span className = "font-bold text-red-600 uppercase" > will not</ span > be processed.
38
51
</ p >
39
- < div className = "mt-10 grid grid-cols-1 gap-x-8 xl:gap-x-16 gap-y-8 sm:grid-cols-8 " >
40
- { ( [ 'production' , 'test' , 'tools' , 'development' ] as const ) . map ( ( nameSpace ) => (
41
- < div className = "sm:col-span-2" key = { nameSpace } >
42
- < h3 className = "text-base 2xl:text-lg font-semibold leading-7 text-gray-900" >
43
- { nameSpace . charAt ( 0 ) . toUpperCase ( ) + nameSpace . slice ( 1 ) } Namespace
44
- </ h3 >
45
- < ExternalLink
46
- href = { `https://console.apps.${ currentProject ?. cluster } .devops.gov.bc.ca/k8s/cluster/projects/${ licencePlate } ${ namespaceSuffixes [ nameSpace ] } ` }
52
+ < div className = "mt-10 mb-5 grid grid-cols-1 gap-x-4 xl:gap-x-4 gap-y-8 sm:grid-cols-8 " >
53
+ { namespaceKeys . map ( ( namespace ) => {
54
+ const quotaField = ( namespace + 'Quota' ) as keyof PrivateCloudProject ;
55
+ const originalEnvQuota = currentProject [ quotaField ] as Quota ;
56
+ const newEnvQuota = newValues [ quotaField ] ;
57
+ const hasResourceChange =
58
+ newEnvQuota ?. cpu !== originalEnvQuota ?. cpu ||
59
+ newEnvQuota ?. memory !== originalEnvQuota ?. memory ||
60
+ newEnvQuota ?. storage !== originalEnvQuota ?. storage ;
61
+
62
+ return (
63
+ < div
64
+ key = { namespace }
65
+ className = { classNames ( 'sm:col-span-2 py-3 px-5 rounded-lg border-2' , {
66
+ 'border-purple-800 shadow-[0_0_15px_2px_rgba(59,130,246,0.2)]' : hasResourceChange ,
67
+ 'border-transparent' : ! hasResourceChange ,
68
+ } ) }
47
69
>
48
- { licencePlate }
49
- { namespaceSuffixes [ nameSpace ] || '' }
50
- </ ExternalLink >
51
- { ( [ 'cpu' , 'memory' , 'storage' ] as const ) . map ( ( quotaName ) => (
52
- < QuotaInput
53
- key = { quotaName }
54
- quotaName = { quotaName }
55
- selectOptions = { quotaOptionsLookup [ quotaName ] }
56
- licencePlate = { licencePlate }
57
- nameSpace = { nameSpace }
58
- disabled = { disabled }
59
- quota = { ( currentProject as { [ key : string ] : any } ) ?. [ nameSpace + 'Quota' ] [ quotaName ] }
60
- />
61
- ) ) }
62
- </ div >
63
- ) ) }
70
+ < h3 className = "text-base 2xl:text-lg font-semibold leading-7 text-gray-900" >
71
+ { _startCase ( namespace ) } Namespace
72
+ </ h3 >
73
+ < ExternalLink
74
+ href = { `https://console.apps.${ currentProject . cluster } .devops.gov.bc.ca/k8s/cluster/projects/${ licencePlate } ${ namespaceSuffixes [ namespace ] } ` }
75
+ >
76
+ { licencePlate }
77
+ { namespaceSuffixes [ namespace ] || '' }
78
+ </ ExternalLink >
79
+ { ( [ 'cpu' , 'memory' , 'storage' ] as const ) . map ( ( quotaName ) => (
80
+ < QuotaInput
81
+ key = { quotaName }
82
+ quotaName = { quotaName }
83
+ selectOptions = { quotaOptionsLookup [ quotaName ] }
84
+ licencePlate = { licencePlate }
85
+ nameSpace = { namespace }
86
+ disabled = { disabled }
87
+ quota = { ( currentProject as { [ key : string ] : any } ) ?. [ namespace + 'Quota' ] [ quotaName ] }
88
+ />
89
+ ) ) }
90
+ </ div >
91
+ ) ;
92
+ } ) }
64
93
</ div >
65
-
66
94
< QuotasChangeInfo disabled = { disabled } />
67
95
</ >
68
96
) ;
0 commit comments