Skip to content

Commit 6b8221c

Browse files
committed
feat: revert optional namespace for virtual env
1 parent 6a78a10 commit 6b8221c

File tree

4 files changed

+19
-33
lines changed

4 files changed

+19
-33
lines changed

src/Pages/GlobalConfigurations/ClustersAndEnvironments/ClusterEnvironmentDrawer/ClusterEnvironmentDrawer.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ export const ClusterEnvironmentDrawer = ({
105105
error: ServerErrors
106106
}>(INITIAL_NAMESPACES)
107107

108-
// Need different state since validations change on basis of this state
109-
const [isSelectedClusterVirtual, setIsSelectedClusterVirtual] = useState(isVirtualCluster ?? false)
110-
111108
const [clusterListLoading, clusterListResult, clusterListError, reloadClusterList] = useAsync(
112109
() => getClusterListing(true),
113110
[],
@@ -123,8 +120,9 @@ export const ClusterEnvironmentDrawer = ({
123120
isProduction: !!isProduction,
124121
category: category ?? null,
125122
description: description ?? '',
123+
isVirtualCluster,
126124
},
127-
validations: clusterEnvironmentDrawerFormValidationSchema({ isNamespaceMandatory: !isSelectedClusterVirtual }),
125+
validations: clusterEnvironmentDrawerFormValidationSchema(),
128126
})
129127

130128
const [, clusterDetails] = useAsync(
@@ -135,10 +133,10 @@ export const ClusterEnvironmentDrawer = ({
135133

136134
useEffect(() => {
137135
if (clusterDetails) {
138-
setIsSelectedClusterVirtual(clusterDetails[0].isVirtualCluster)
139136
setClusterNamespaces(INITIAL_NAMESPACES)
140137
setNamespaceLabels(INITIAL_NAMESPACE_LABELS)
141-
reset(data, { keepErrors: false })
138+
const updatedData = { ...data, isVirtualCluster: clusterDetails[0]?.isVirtualCluster ?? false }
139+
reset(updatedData, { keepErrors: false })
142140
}
143141
}, [clusterDetails])
144142

@@ -209,11 +207,10 @@ export const ClusterEnvironmentDrawer = ({
209207
envId,
210208
namespaceLabels: namespaceLabels.labels,
211209
resourceVersion: namespaceLabels.resourceVersion,
212-
isVirtualCluster: isSelectedClusterVirtual,
213210
})
214211

215212
let api
216-
if (isSelectedClusterVirtual) {
213+
if (data.isVirtualCluster) {
217214
api = getVirtualClusterSaveUpdate(envId)
218215
} else {
219216
api = envId ? updateEnvironment : saveEnvironment
@@ -284,7 +281,6 @@ export const ClusterEnvironmentDrawer = ({
284281
const onDelete = async () => {
285282
const payload = getClusterEnvironmentUpdatePayload({
286283
data,
287-
isVirtualCluster: isSelectedClusterVirtual,
288284
envId,
289285
})
290286
await deleteEnvironment(payload)
@@ -369,7 +365,7 @@ export const ClusterEnvironmentDrawer = ({
369365
{...register('namespace')}
370366
label="Namespace"
371367
shouldTrim={false}
372-
required={!isSelectedClusterVirtual}
368+
required
373369
/>
374370

375371
<CustomInput
@@ -423,7 +419,7 @@ export const ClusterEnvironmentDrawer = ({
423419
</div>
424420
)}
425421

426-
{EnvironmentLabels && !isSelectedClusterVirtual && (
422+
{EnvironmentLabels && !data.isVirtualCluster && (
427423
<div className="dc__border-top-n1 pt-16">
428424
<EnvironmentLabels
429425
tags={namespaceLabels.labels}

src/Pages/GlobalConfigurations/ClustersAndEnvironments/ClusterEnvironmentDrawer/schema.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ import { UseFormValidations } from '@devtron-labs/devtron-fe-common-lib'
1818

1919
import { EnvironmentFormType } from './types'
2020

21-
export const clusterEnvironmentDrawerFormValidationSchema = ({
22-
isNamespaceMandatory,
23-
}: {
24-
isNamespaceMandatory: boolean
25-
}): UseFormValidations<EnvironmentFormType> => ({
21+
export const clusterEnvironmentDrawerFormValidationSchema = (): UseFormValidations<EnvironmentFormType> => ({
2622
clusterId: {
2723
required: true,
2824
pattern: [{ message: 'Please select a cluster', value: /^(?!0$)\d+$/ }],
@@ -36,19 +32,15 @@ export const clusterEnvironmentDrawerFormValidationSchema = ({
3632
{ message: 'Minimum 1 and Maximum 16 characters required', value: /^.{1,16}$/ },
3733
],
3834
},
39-
...(isNamespaceMandatory
40-
? {
41-
namespace: {
42-
required: true,
43-
pattern: [
44-
{ message: 'Namespace is required', value: /^.*$/ },
45-
{ message: "Use only lowercase alphanumeric characters or '-'", value: /^[a-z0-9-]+$/ },
46-
{ message: "Cannot start/end with '-'", value: /^(?![-]).*[^-]$/ },
47-
{ message: 'Maximum 63 characters required', value: /^.{1,63}$/ },
48-
],
49-
},
50-
}
51-
: {}),
35+
namespace: {
36+
required: true,
37+
pattern: [
38+
{ message: 'Namespace is required', value: /^.*$/ },
39+
{ message: "Use only lowercase alphanumeric characters or '-'", value: /^[a-z0-9-]+$/ },
40+
{ message: "Cannot start/end with '-'", value: /^(?![-]).*[^-]$/ },
41+
{ message: 'Maximum 63 characters required', value: /^.{1,63}$/ },
42+
],
43+
},
5244
isProduction: {
5345
required: true,
5446
pattern: { message: 'token is required', value: /[^]+/ },

src/Pages/GlobalConfigurations/ClustersAndEnvironments/ClusterEnvironmentDrawer/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,14 @@ export type EnvDrawerProps = { reload: () => void; hideClusterDrawer: () => void
3636
| ({ drawerType: 'editEnv'; clusterId: number; clusterName: string } & EnvDetails)
3737
)
3838

39-
export type EnvironmentFormType = Omit<EnvDetails, 'isVirtualCluster' | 'envId'> & {
39+
export type EnvironmentFormType = Omit<EnvDetails, 'envId'> & {
4040
clusterId: number
4141
}
4242

4343
export type GetClusterEnvironmentUpdatePayloadType = Partial<Pick<ClusterNamespacesDTO, 'resourceVersion'>> & {
4444
data: EnvironmentFormType
4545
envId: number
4646
namespaceLabels?: TagType[]
47-
isVirtualCluster: boolean
4847
}
4948

5049
interface ClusterNamespacesLabel {

src/Pages/GlobalConfigurations/ClustersAndEnvironments/ClusterEnvironmentDrawer/utils.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ export const getClusterEnvironmentUpdatePayload = ({
2525
envId,
2626
namespaceLabels,
2727
resourceVersion,
28-
isVirtualCluster,
2928
}: GetClusterEnvironmentUpdatePayloadType) =>
30-
isVirtualCluster
29+
data.isVirtualCluster
3130
? {
3231
id: envId,
3332
environment_name: data.envName,

0 commit comments

Comments
 (0)