Skip to content

Commit 2d38182

Browse files
committed
fix for deploy dropdown lending issue
1 parent 588acf1 commit 2d38182

File tree

3 files changed

+71
-21
lines changed

3 files changed

+71
-21
lines changed

src/components/app/details/triggerView/TriggerView.utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const LAST_SAVED_CONFIG_OPTION = {
4040
infoText: 'Use last saved configuration to deploy',
4141
}
4242

43-
const LATEST_TRIGGER_CONFIG_OPTION = {
43+
export const LATEST_TRIGGER_CONFIG_OPTION = {
4444
label: 'Last deployed config',
4545
value: DeploymentWithConfigType.LATEST_TRIGGER_CONFIG,
4646
infoText: 'Retain currently deployed configuration',

src/components/app/details/triggerView/cdMaterial.tsx

Lines changed: 57 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ import { getModuleInfo } from '../../../v2/devtronStackManager/DevtronStackManag
7373
import { ModuleStatus } from '../../../v2/devtronStackManager/DevtronStackManager.type'
7474
import { DropdownIndicator, Option } from '../../../v2/common/ReactSelect.utils'
7575
import {
76+
DEPLOYMENT_CONFIGURATION_NAV_MAP,
7677
LAST_SAVED_CONFIG_OPTION,
7778
SPECIFIC_TRIGGER_CONFIG_OPTION,
79+
LATEST_TRIGGER_CONFIG_OPTION,
7880
checkForDiff,
7981
getDeployConfigOptions,
8082
processResolvedPromise,
@@ -88,6 +90,7 @@ import { abortEarlierRequests, getInitialState } from './cdMaterials.utils'
8890
import { getLastExecutionByArtifactAppEnv } from '../../../../services/service'
8991
import AnnouncementBanner from '../../../common/AnnouncementBanner'
9092
import { useRouteMatch } from 'react-router-dom'
93+
import { get } from 'http'
9194

9295
const ApprovalInfoTippy = importComponentFromFELibrary('ApprovalInfoTippy')
9396
const ExpireApproval = importComponentFromFELibrary('ExpireApproval')
@@ -139,7 +142,6 @@ export default function CDMaterial({
139142
const [isConsumedImageAvailable, setIsConsumedImageAvailable] = useState<boolean>(false)
140143
// Should be able to abort request using useAsync
141144
const abortControllerRef = useRef(new AbortController())
142-
// const [mode, setMode] = useState<string>(searchParams.mode)
143145

144146
// TODO: Ask if pipelineId always changes on change of app else add appId as dependency
145147
const [loadingMaterials, materialsResult, materialsError, reloadMaterials] = useAsync(
@@ -179,7 +181,7 @@ export default function CDMaterial({
179181
const [showAppliedFilters, setShowAppliedFilters] = useState<boolean>(false)
180182
const [deploymentLoading, setDeploymentLoading] = useState<boolean>(false)
181183
const [appliedFilterList, setAppliedFilterList] = useState<FilterConditionsListType[]>([])
182-
184+
183185
const resourceFilters = materialsResult?.resourceFilters ?? []
184186
const hideImageTaggingHardDelete = materialsResult?.hideImageTaggingHardDelete ?? false
185187
const requestedUserId = materialsResult?.requestedUserId ?? ''
@@ -245,7 +247,13 @@ export default function CDMaterial({
245247
checkingDiff: false,
246248
}))
247249
},
248-
)
250+
).catch(err => {
251+
showError(err)
252+
setState((prevState) => ({ ...prevState, checkingDiff: false }))
253+
254+
}).finally(() => {
255+
setState((prevState) => ({ ...prevState, checkingDiff: false }))
256+
})
249257
}
250258

251259
const setSearchValue = (searchValue: string) => {
@@ -263,12 +271,12 @@ export default function CDMaterial({
263271
})
264272
}
265273

266-
const setParamsValue = (modeParamValue: string) => {
274+
const setInitialModeParams = (modeParamValue: string) => {
267275
const newParams = {
268276
...searchParams,
269277
mode: modeParamValue,
270-
config: 'deploymentTemplate',
271-
deploy: 'LAST_SAVED_CONFIG'.toLocaleLowerCase() //LATEST_TRIGGER_CONFIG
278+
config: DEPLOYMENT_CONFIGURATION_NAV_MAP.DEPLOYMENT_TEMPLATE.key,
279+
deploy: searchParams.deploy ? searchParams.deploy : DeploymentWithConfigType.LAST_SAVED_CONFIG
272280
}
273281
history.push({
274282
search: new URLSearchParams(newParams).toString(),
@@ -411,15 +419,30 @@ export default function CDMaterial({
411419
// The above states are derived from material so no need to make a state for them and shift the config diff here
412420
}, [material])
413421

422+
const getInitialSelectedConfigToDeploy = () => {
423+
if (searchParams.deploy === DeploymentWithConfigType.LAST_SAVED_CONFIG) {
424+
return LAST_SAVED_CONFIG_OPTION
425+
}
426+
if (
427+
searchParams.deploy === DeploymentWithConfigType.SPECIFIC_TRIGGER_CONFIG ||
428+
(materialType === MATERIAL_TYPE.rollbackMaterialList && !searchParams.deploy)
429+
) {
430+
return SPECIFIC_TRIGGER_CONFIG_OPTION
431+
}
432+
if (
433+
searchParams.deploy === DeploymentWithConfigType.LATEST_TRIGGER_CONFIG ||
434+
(materialType === MATERIAL_TYPE.inputMaterialList && !searchParams.deploy)
435+
) {
436+
return LATEST_TRIGGER_CONFIG_OPTION
437+
}
438+
}
414439
useEffect(() => {
415440
setState((prevState) => ({
416441
...prevState,
417442
isRollbackTrigger: materialType === MATERIAL_TYPE.rollbackMaterialList,
418443
isSelectImageTrigger: materialType === MATERIAL_TYPE.inputMaterialList,
419444
selectedConfigToDeploy:
420-
materialType === MATERIAL_TYPE.rollbackMaterialList
421-
? SPECIFIC_TRIGGER_CONFIG_OPTION
422-
: LAST_SAVED_CONFIG_OPTION,
445+
getInitialSelectedConfigToDeploy(),
423446
}))
424447
}, [materialType])
425448

@@ -746,9 +769,8 @@ export default function CDMaterial({
746769
!state.recentDeploymentConfig
747770

748771
const reviewConfig = (modeParamValue: string) => {
749-
// setMode(modeParamValue)
750772
if (canReviewConfig()) {
751-
setParamsValue(modeParamValue)
773+
setInitialModeParams(modeParamValue)
752774
}
753775
}
754776

@@ -779,16 +801,39 @@ export default function CDMaterial({
779801
: state.specificDeploymentConfig
780802
}
781803

804+
const setConfigParams = (deploy: string) => {
805+
const newParams = {
806+
...searchParams,
807+
deploy,
808+
}
809+
history.push({
810+
search: new URLSearchParams(newParams).toString(),
811+
})
812+
}
813+
814+
const getDeploymentConfigSelectedValue = () => {
815+
if (searchParams.deploy === DeploymentWithConfigType.LAST_SAVED_CONFIG) {
816+
return getDeployConfigOptions(state.isRollbackTrigger, state.recentDeploymentConfig !== null)[0].options[0]
817+
}
818+
if (searchParams.deploy === DeploymentWithConfigType.LATEST_TRIGGER_CONFIG) {
819+
return getDeployConfigOptions(state.isRollbackTrigger, state.recentDeploymentConfig !== null)[0].options[1]
820+
}
821+
822+
if( searchParams.deploy === DeploymentWithConfigType.SPECIFIC_TRIGGER_CONFIG){
823+
return getDeployConfigOptions(state.isRollbackTrigger, state.recentDeploymentConfig !== null)[0].options[2]
824+
}
825+
}
782826

783827
const handleConfigSelection = (selected) => {
784828
if (selected?.value !== state.selectedConfigToDeploy.value) {
785829
const _diffOptions = checkForDiff(state.recentDeploymentConfig, getBaseTemplateConfiguration(selected))
786830
setState((prevState) => ({
787831
...prevState,
788-
selectedConfigToDeploy: selected,
832+
selectedConfigToDeploy: selected? selected : getInitialSelectedConfigToDeploy(),
789833
diffFound: _diffOptions && Object.values(_diffOptions).some((d) => d),
790834
diffOptions: _diffOptions,
791835
}))
836+
setConfigParams(selected.value)
792837
}
793838
}
794839

src/components/app/details/triggerView/triggerViewConfigDiff/TriggerViewConfigDiff.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,25 @@ export default function TriggerViewConfigDiff({
5454
const [secretOptionCollapsed, setSecretOptionCollapsed] = useState<boolean>(false)
5555
const [currentData, setCurrentData] = useState<any>({}) // store codeEditorValue of current(lhs) and base(rhs) config
5656

57-
5857
useEffect(() => {
59-
if(canReviewConfig() && baseTemplateConfiguration && currentConfiguration){
58+
const newSearchParams = {
59+
...searchParams,
60+
config: searchParams.config?.replace('-', '/'),
61+
deploy: searchParams.deploy,
62+
}
63+
if (canReviewConfig() && baseTemplateConfiguration && currentConfiguration) {
6064
const configParamValue = searchParams.config?.replace('-', '/')
61-
setParamsValue(configParamValue.replace('/', '-'))
65+
history.push({
66+
search: new URLSearchParams(newSearchParams).toString(),
67+
})
6268
//handling the case when the user directly lands on the deployment history page
63-
handleNavOptionSelection(null, configParamValue)
64-
handleConfigSelection({value: searchParams.deploy.toLocaleUpperCase()})
69+
handleNavOptionSelection(null, configParamValue)
6570
}
66-
}, [canReviewConfig(), baseTemplateConfiguration , currentConfiguration])
67-
71+
}, [canReviewConfig(), baseTemplateConfiguration, currentConfiguration])
72+
6873
useEffect(() => {
6974
handleConfigToDeploySelection()
70-
}, [selectedConfigToDeploy])
75+
}, [selectedConfigToDeploy, searchParams.deploy])
7176

7277
useEffect(() => {
7378
if (Object.keys(currentData).length === 0) {

0 commit comments

Comments
 (0)