Skip to content

Commit df1f799

Browse files
authored
Merge pull request #3783 from bcgov/feat/3364
Feat/3364
2 parents c1dbffc + d6a97f8 commit df1f799

File tree

2 files changed

+66
-37
lines changed

2 files changed

+66
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
22

33
# dependencies
4+
.vscode/settings.json
45
/node_modules
56
/.pnp
67
.pnp.js

app/components/form/Quotas.tsx

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
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';
25
import QuotasChangeInfo from '@/components/form/QuotasChangeInfo';
36
import ExternalLink from '@/components/generic/button/ExternalLink';
4-
import { defaultCpuOptionsLookup, defaultMemoryOptionsLookup, defaultStorageOptionsLookup } from '../../constants';
7+
import { defaultCpuOptionsLookup, defaultMemoryOptionsLookup, defaultStorageOptionsLookup } from '@/constants';
58
import QuotaInput from './QuotaInput';
69

710
const quotaOptionsLookup = {
@@ -10,6 +13,17 @@ const quotaOptionsLookup = {
1013
storage: defaultStorageOptionsLookup,
1114
};
1215

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+
1327
export default function Quotas({
1428
licencePlate,
1529
disabled,
@@ -19,50 +33,64 @@ export default function Quotas({
1933
disabled: boolean;
2034
currentProject?: PrivateCloudProject | null | undefined;
2135
}) {
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+
2841
return (
2942
<>
3043
<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&rsquo;s</span>
45+
&nbsp;approval, and must have supporting information as per the&nbsp;
3346
<ExternalLink href="https://docs.developer.gov.bc.ca/request-quota-increase-for-openshift-project-set/">
3447
Quota Increase Request Process
3548
</ExternalLink>
36-
. Any Quota Requests without supporting information
37-
<b> will not </b> be processed.
49+
. Any Quota Requests without supporting information&nbsp;
50+
<span className="font-bold text-red-600 uppercase">will not</span> be processed.
3851
</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+
})}
4769
>
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+
})}
6493
</div>
65-
6694
<QuotasChangeInfo disabled={disabled} />
6795
</>
6896
);

0 commit comments

Comments
 (0)