Skip to content

Commit 6d8e23a

Browse files
committed
chore: updated value type in environment list of build cd
1 parent d54bdff commit 6d8e23a

File tree

6 files changed

+37
-32
lines changed

6 files changed

+37
-32
lines changed

src/components/CIPipelineN/EnvironmentList.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
SelectPickerVariantType,
2323
} from '@devtron-labs/devtron-fe-common-lib'
2424
import { createClusterEnvGroup } from '../common'
25-
import { EnvironmentListType } from './types'
25+
import { EnvironmentListType, EnvironmentWithSelectPickerType } from './types'
2626
import { GroupBase } from 'react-select'
2727

2828
export const EnvironmentList = ({
@@ -41,7 +41,7 @@ export const EnvironmentList = ({
4141

4242
const envList = createClusterEnvGroup(environments as Environment[], 'clusterName')
4343

44-
const getEnvListOptions = (): GroupBase<SelectPickerOptionType<Environment>>[] =>
44+
const getEnvListOptions = (): GroupBase<EnvironmentWithSelectPickerType>[] =>
4545
envList.reduce((acc, _elm) => {
4646
if (_elm.label) {
4747
return [
@@ -71,11 +71,11 @@ export const EnvironmentList = ({
7171
]
7272
}, [])
7373

74-
const getSelectedEnvironment = (): SelectPickerOptionType<Environment> => {
75-
let _selectedEnv: SelectPickerOptionType<Environment> = {
74+
const getSelectedEnvironment = (): EnvironmentWithSelectPickerType => {
75+
let _selectedEnv: EnvironmentWithSelectPickerType = {
7676
...selectedEnv,
7777
label: selectedEnv?.name,
78-
value: selectedEnv, // assuming the whole object is set as value
78+
value: selectedEnv?.id, // assuming the whole object is set as value
7979
startIcon: !isBuildStage ? <div className="dc__environment-icon" /> : null,
8080
}
8181

@@ -96,7 +96,7 @@ export const EnvironmentList = ({
9696
>
9797
<div className={`${!isBuildStage ? 'w-250 dc__align-items-center flex left' : ''}`}>
9898
{getEnvironmentSelectLabel()}
99-
<SelectPicker<Environment, false>
99+
<SelectPicker
100100
required
101101
inputId="job-pipeline-environment-dropdown"
102102
name="job-pipeline-environment-dropdown"

src/components/CIPipelineN/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
StepType,
2121
PipelineFormType,
2222
Environment,
23+
SelectPickerOptionType,
2324
} from '@devtron-labs/devtron-fe-common-lib'
2425
import { ExtendedOptionType } from '@Components/app/types'
2526

@@ -102,10 +103,11 @@ export interface InputPluginSelectionType {
102103
selectedVariableIndex: number
103104
}
104105

106+
export interface EnvironmentWithSelectPickerType extends Environment, SelectPickerOptionType {}
105107
export interface EnvironmentListType {
106108
isBuildStage?: boolean
107-
environments: Environment[]
108-
selectedEnv: Environment
109-
setSelectedEnv?: React.Dispatch<React.SetStateAction<Environment>>
109+
environments: EnvironmentWithSelectPickerType[]
110+
selectedEnv: EnvironmentWithSelectPickerType
111+
setSelectedEnv?: React.Dispatch<React.SetStateAction<EnvironmentWithSelectPickerType>>
110112
isBorderLess?: boolean
111113
}

src/components/app/details/triggerView/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
Environment,
4444
} from '@devtron-labs/devtron-fe-common-lib'
4545
import React from 'react'
46+
import { EnvironmentWithSelectPickerType } from '@Components/CIPipelineN/types'
4647
import { HostURLConfig } from '../../../../services/service.types'
4748
import { DeploymentHistoryDetail } from '../cdDetails/cd.type'
4849
import { WorkflowDimensions } from './config'
@@ -222,8 +223,8 @@ export interface CIMaterialProps extends RouteComponentProps<CIMaterialRouterPro
222223
action: any
223224
metadataField: string
224225
}
225-
selectedEnv?: Environment
226-
setSelectedEnv?: React.Dispatch<React.SetStateAction<Environment>>
226+
selectedEnv?: EnvironmentWithSelectPickerType
227+
setSelectedEnv?: React.Dispatch<React.SetStateAction<EnvironmentWithSelectPickerType>>
227228
environmentLists?: any[]
228229
isJobCI?: boolean
229230
handleRuntimeParamChange: HandleRuntimeParamChange

src/components/cdPipeline/BuildCD.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import { ReactComponent as ICInfo } from '../../assets/icons/ic-info-filled.svg'
6161

6262
import PullImageDigestToggle from './PullImageDigestToggle'
6363
import { PipelineFormDataErrorType } from '@Components/workflowEditor/types'
64-
import { GroupBase } from 'react-select'
64+
import { EnvironmentWithSelectPickerType } from '@Components/CIPipelineN/types'
6565

6666
const VirtualEnvSelectionInfoText = importComponentFromFELibrary('VirtualEnvSelectionInfoText')
6767
const HelmManifestPush = importComponentFromFELibrary('HelmManifestPush')
@@ -149,7 +149,7 @@ export default function BuildCD({
149149
setFormData(_form)
150150
}
151151

152-
const selectEnvironment = (selection: Environment): void => {
152+
const selectEnvironment = (selection: EnvironmentWithSelectPickerType): void => {
153153
const _form = { ...formData, deploymentAppName: '' }
154154
const _formDataErrorObj = { ...formDataErrorObj }
155155

@@ -378,9 +378,10 @@ export default function BuildCD({
378378
const renderEnvSelector = () => {
379379
const envId = formData.environmentId
380380
const _environment = formData.environments.find((env) => env.id == envId)
381-
const selectedEnv = {
382-
label: _environment?.name,
383-
value: _environment,
381+
const selectedEnv: EnvironmentWithSelectPickerType = _environment &&{
382+
..._environment,
383+
label: _environment.name,
384+
value: _environment.id.toString(),
384385
}
385386
const envList = createClusterEnvGroup(formData.environments as Environment[], 'clusterName')
386387

@@ -390,18 +391,19 @@ export default function BuildCD({
390391
}
391392
}
392393

393-
const getEnvListOptions = (): GroupBase<SelectPickerOptionType<Environment>>[] =>
394+
const getEnvListOptions = () =>
394395
envList.map((_elm) => ({
395396
label: `Cluster: ${_elm.label}`,
396397
options: _elm.options.map((_option) => ({
398+
..._option,
397399
label: _option?.name,
398-
value: _option,
400+
value: _option?.id.toString(),
399401
})),
400402
}))
401403

402404
return (
403405
<>
404-
<SelectPicker<Environment, false>
406+
<SelectPicker
405407
label="Environment"
406408
required
407409
inputId="environment"
@@ -413,13 +415,13 @@ export default function BuildCD({
413415
options={
414416
releaseMode === ReleaseMode.MIGRATE_HELM
415417
? getEnvListOptions().filter((env) =>
416-
env.options.filter(({ value }) => !value.isVirtualEnvironment),
418+
env.options.filter((_env) => !_env.isVirtualEnvironment),
417419
)
418420
: getEnvListOptions()
419421
}
420422
value={selectedEnv}
421-
getOptionValue={(option) => option.value?.id as unknown as string}
422-
onChange={(selected) => selectEnvironment(selected.value)}
423+
getOptionValue={(option) => option.value as unknown as string}
424+
onChange={selectEnvironment}
423425
size={ComponentSizeType.large}
424426
/>
425427
{isEnvUsedState && (

src/components/ciConfig/CIConfigForm.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ export default function CIConfigForm({
7474
)
7575
: sourceConfig.material[0]
7676

77-
const getCurrentMaterial = (): SelectedGitMaterialType => {
77+
const getParsedCurrentMaterial = (material?): SelectedGitMaterialType => {
7878
const _currentMaterial: SelectedGitMaterialType = {
79-
...currentMaterial,
79+
...(material ? material : currentMaterial),
8080
value: currentMaterial.checkoutPath,
8181
label: currentMaterial.name,
8282
startIcon: getGitProviderIcon(currentMaterial.url),
@@ -87,14 +87,14 @@ export default function CIConfigForm({
8787
const getParsedSourceConfig = (): SourceConfigType => {
8888
const _sourceConfig = { ...sourceConfig }
8989
_sourceConfig.material = _sourceConfig.material.map((_material) => {
90-
return { ..._material, value: _material.checkoutPath, label: _material.name, startIcon: getGitProviderIcon(_material.url) }
90+
return getParsedCurrentMaterial(_material)
9191
})
9292
return _sourceConfig
9393
}
9494

95-
const currentBuildContextGitMaterial = buildCtxGitMaterial || getCurrentMaterial()
95+
const currentBuildContextGitMaterial = buildCtxGitMaterial || getParsedCurrentMaterial()
9696

97-
const [selectedMaterial, setSelectedMaterial] = useState<SelectedGitMaterialType>(getCurrentMaterial)
97+
const [selectedMaterial, setSelectedMaterial] = useState<SelectedGitMaterialType>(getParsedCurrentMaterial)
9898
const [selectedBuildContextGitMaterial, setSelectedBuildContextGitMaterial] =
9999
useState(currentBuildContextGitMaterial)
100100
const currentRegistry =
@@ -360,7 +360,7 @@ export default function CIConfigForm({
360360
configOverrideView={configOverrideView}
361361
allowOverride={allowOverride}
362362
selectedCIPipeline={selectedCIPipeline}
363-
currentMaterial={getCurrentMaterial()}
363+
currentMaterial={getParsedCurrentMaterial()}
364364
currentBuildContextGitMaterial={currentBuildContextGitMaterial}
365365
selectedMaterial={selectedMaterial}
366366
selectedBuildContextGitMaterial={selectedBuildContextGitMaterial}

src/components/ciConfig/types.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ import {
2525
CommonNodeAttr,
2626
WorkflowType,
2727
Material,
28-
Environment,
2928
SelectPickerOptionType,
3029
} from '@devtron-labs/devtron-fe-common-lib'
3130
import { OptionTypeWithIcon } from '@Components/externalLinks/ExternalLinks.type'
31+
import { EnvironmentWithSelectPickerType } from '@Components/CIPipelineN/types'
3232
import { ConfigOverrideWorkflowDetails } from '../../services/service.types'
3333
import { CiPipeline, CiPipelineResult } from '../app/details/triggerView/types'
3434
import { OptionType } from '../app/types'
@@ -373,9 +373,9 @@ export interface CIPipelineSidebarType {
373373
postBuildStage: Map<string, VariableType>[]
374374
}>
375375
>
376-
environments?: Environment[]
377-
selectedEnv?: Environment
378-
setSelectedEnv?: React.Dispatch<React.SetStateAction<Environment>>
376+
environments?: EnvironmentWithSelectPickerType[]
377+
selectedEnv?: EnvironmentWithSelectPickerType
378+
setSelectedEnv?: React.Dispatch<React.SetStateAction<EnvironmentWithSelectPickerType>>
379379
}
380380

381381
export interface TaskListType {

0 commit comments

Comments
 (0)