@@ -73,8 +73,10 @@ import { getModuleInfo } from '../../../v2/devtronStackManager/DevtronStackManag
73
73
import { ModuleStatus } from '../../../v2/devtronStackManager/DevtronStackManager.type'
74
74
import { DropdownIndicator , Option } from '../../../v2/common/ReactSelect.utils'
75
75
import {
76
+ DEPLOYMENT_CONFIGURATION_NAV_MAP ,
76
77
LAST_SAVED_CONFIG_OPTION ,
77
78
SPECIFIC_TRIGGER_CONFIG_OPTION ,
79
+ LATEST_TRIGGER_CONFIG_OPTION ,
78
80
checkForDiff ,
79
81
getDeployConfigOptions ,
80
82
processResolvedPromise ,
@@ -87,6 +89,7 @@ import { EMPTY_STATE_STATUS, TOAST_BUTTON_TEXT_VIEW_DETAILS } from '../../../../
87
89
import { abortEarlierRequests , getInitialState } from './cdMaterials.utils'
88
90
import { getLastExecutionByArtifactAppEnv } from '../../../../services/service'
89
91
import AnnouncementBanner from '../../../common/AnnouncementBanner'
92
+ import { useRouteMatch } from 'react-router-dom'
90
93
91
94
const ApprovalInfoTippy = importComponentFromFELibrary ( 'ApprovalInfoTippy' )
92
95
const ExpireApproval = importComponentFromFELibrary ( 'ExpireApproval' )
@@ -183,6 +186,7 @@ export default function CDMaterial({
183
186
const userApprovalConfig = materialsResult ?. userApprovalConfig
184
187
const isApprovalConfigured = userApprovalConfig ?. requiredCount > 0
185
188
const canApproverDeploy = materialsResult ?. canApproverDeploy ?? false
189
+ const showConfigDiffView = searchParams . mode === "review-config" && searchParams . deploy && searchParams . config
186
190
/* ------------ Utils required in useEffect ------------*/
187
191
const getSecurityModuleStatus = async ( ) => {
188
192
try {
@@ -197,7 +201,7 @@ export default function CDMaterial({
197
201
}
198
202
199
203
const getWfrId = ( initSelectedMaterial ?: CDMaterialType ) => {
200
- if ( state . selectedConfigToDeploy . value === DeploymentWithConfigType . LATEST_TRIGGER_CONFIG ) {
204
+ if ( state . selectedConfigToDeploy ? .value === DeploymentWithConfigType . LATEST_TRIGGER_CONFIG && state . recentDeploymentConfig ) {
201
205
return state . recentDeploymentConfig . wfrId
202
206
}
203
207
@@ -241,7 +245,12 @@ export default function CDMaterial({
241
245
checkingDiff : false ,
242
246
} ) )
243
247
} ,
244
- )
248
+ ) . catch ( ( error ) => {
249
+ showError ( error )
250
+ } )
251
+ . finally ( ( ) => {
252
+ setState ( ( prevState ) => ( { ...prevState , checkingDiff : false } ) )
253
+ } )
245
254
}
246
255
247
256
const setSearchValue = ( searchValue : string ) => {
@@ -395,18 +404,37 @@ export default function CDMaterial({
395
404
// The above states are derived from material so no need to make a state for them and shift the config diff here
396
405
} , [ material ] )
397
406
407
+ const getInitialSelectedConfigToDeploy = ( ) => {
408
+ if (
409
+ ( materialType === MATERIAL_TYPE . rollbackMaterialList && ! searchParams . deploy ) ||
410
+ searchParams . deploy === DeploymentWithConfigType . SPECIFIC_TRIGGER_CONFIG
411
+ ) {
412
+ return SPECIFIC_TRIGGER_CONFIG_OPTION
413
+ }
414
+ if ( searchParams . deploy === DeploymentWithConfigType . LATEST_TRIGGER_CONFIG ) {
415
+ return LATEST_TRIGGER_CONFIG_OPTION
416
+ }
417
+ return LAST_SAVED_CONFIG_OPTION
418
+ }
398
419
useEffect ( ( ) => {
399
420
setState ( ( prevState ) => ( {
400
421
...prevState ,
401
422
isRollbackTrigger : materialType === MATERIAL_TYPE . rollbackMaterialList ,
402
423
isSelectImageTrigger : materialType === MATERIAL_TYPE . inputMaterialList ,
403
424
selectedConfigToDeploy :
404
- materialType === MATERIAL_TYPE . rollbackMaterialList
405
- ? SPECIFIC_TRIGGER_CONFIG_OPTION
406
- : LAST_SAVED_CONFIG_OPTION ,
425
+ getInitialSelectedConfigToDeploy ( ) ,
407
426
} ) )
408
427
} , [ materialType ] )
409
428
429
+ useEffect ( ( ) => {
430
+ if ( searchParams . deploy ) {
431
+ setState ( ( prevState ) => ( {
432
+ ...prevState ,
433
+ selectedConfigToDeploy : getInitialSelectedConfigToDeploy ( ) ,
434
+ } ) )
435
+ }
436
+ } , [ searchParams . deploy ] )
437
+
410
438
useEffect ( ( ) => {
411
439
setState ( ( prevState ) => ( {
412
440
...prevState ,
@@ -722,19 +750,37 @@ export default function CDMaterial({
722
750
state . latestDeploymentConfig ?. deploymentTemplate &&
723
751
state . latestDeploymentConfig . pipelineStrategy )
724
752
753
+ const getConfigToDeployValue = ( ) => {
754
+ if ( searchParams . deploy ) {
755
+ return searchParams . deploy
756
+ } else {
757
+ if ( materialType === MATERIAL_TYPE . rollbackMaterialList ) {
758
+ return DeploymentWithConfigType . SPECIFIC_TRIGGER_CONFIG
759
+ } else {
760
+ return DeploymentWithConfigType . LAST_SAVED_CONFIG
761
+ }
762
+ }
763
+ }
764
+
725
765
const canReviewConfig = ( ) =>
726
766
( state . recentDeploymentConfig ?. deploymentTemplate &&
727
767
state . recentDeploymentConfig . pipelineStrategy &&
728
768
( state . selectedConfigToDeploy . value === DeploymentWithConfigType . LATEST_TRIGGER_CONFIG ||
729
769
isConfigPresent ( ) ) ) ||
730
770
! state . recentDeploymentConfig
731
771
732
- const reviewConfig = ( ) => {
733
- if ( canReviewConfig ( ) ) {
734
- setState ( ( prevState ) => ( {
735
- ...prevState ,
736
- showConfigDiffView : ! prevState . showConfigDiffView ,
737
- } ) )
772
+ const onClickSetInitialParams = ( modeParamValue : string ) => {
773
+ if ( canReviewConfig ) {
774
+ const newParams = {
775
+ ...searchParams ,
776
+ mode : modeParamValue ,
777
+ config : DEPLOYMENT_CONFIGURATION_NAV_MAP . DEPLOYMENT_TEMPLATE . key ,
778
+ deploy : getConfigToDeployValue ( ) ,
779
+ }
780
+
781
+ history . push ( {
782
+ search : new URLSearchParams ( newParams ) . toString ( ) ,
783
+ } )
738
784
}
739
785
}
740
786
@@ -765,16 +811,26 @@ export default function CDMaterial({
765
811
: state . specificDeploymentConfig
766
812
}
767
813
814
+ const setConfigParams = ( deploy : string ) => {
815
+ const newParams = {
816
+ ...searchParams ,
817
+ deploy,
818
+ }
819
+ history . push ( {
820
+ search : new URLSearchParams ( newParams ) . toString ( ) ,
821
+ } )
822
+ }
823
+
768
824
const handleConfigSelection = ( selected ) => {
769
825
if ( selected . value !== state . selectedConfigToDeploy . value ) {
770
826
const _diffOptions = checkForDiff ( state . recentDeploymentConfig , getBaseTemplateConfiguration ( selected ) )
771
-
772
827
setState ( ( prevState ) => ( {
773
828
...prevState ,
774
- selectedConfigToDeploy : selected ,
829
+ selectedConfigToDeploy : selected ? selected : getInitialSelectedConfigToDeploy ( ) ,
775
830
diffFound : _diffOptions && Object . values ( _diffOptions ) . some ( ( d ) => d ) ,
776
831
diffOptions : _diffOptions ,
777
832
} ) )
833
+ setConfigParams ( selected . value )
778
834
}
779
835
}
780
836
@@ -898,7 +954,7 @@ export default function CDMaterial({
898
954
appId ,
899
955
Number ( getCDArtifactId ( ) ) ,
900
956
e ,
901
- state . selectedConfigToDeploy ? .value ,
957
+ state . selectedConfigToDeploy . value ,
902
958
getWfrId ( ) ,
903
959
)
904
960
return
@@ -1007,7 +1063,7 @@ export default function CDMaterial({
1007
1063
const getTriggerBodyHeight = ( isApprovalConfigured : boolean ) => {
1008
1064
const subHeight = window ?. _env_ ?. ANNOUNCEMENT_BANNER_MSG ? 37 : 0
1009
1065
1010
- if ( state . showConfigDiffView ) {
1066
+ if ( showConfigDiffView ) {
1011
1067
return `calc(100vh - 141px - ${ subHeight } px)`
1012
1068
}
1013
1069
if (
@@ -1896,7 +1952,7 @@ export default function CDMaterial({
1896
1952
} ${ isLastDeployedOption ? 'pt-10 pb-10' : 'pt-7 pb-7' } `}
1897
1953
disabled = { state . checkingDiff }
1898
1954
type = "button"
1899
- onClick = { reviewConfig }
1955
+ onClick = { ( ) => onClickSetInitialParams ( 'review-config' ) }
1900
1956
>
1901
1957
{ ! isLastDeployedOption && ( state . recentDeploymentConfig !== null || state . checkingDiff ) && (
1902
1958
< div
@@ -1965,7 +2021,7 @@ export default function CDMaterial({
1965
2021
< div
1966
2022
className = { `trigger-modal__trigger ${
1967
2023
( ! state . isRollbackTrigger && ! state . isSelectImageTrigger ) ||
1968
- state . showConfigDiffView ||
2024
+ showConfigDiffView ||
1969
2025
stageType === DeploymentNodeType . PRECD ||
1970
2026
stageType === DeploymentNodeType . POSTCD
1971
2027
? 'flex right'
@@ -1974,7 +2030,7 @@ export default function CDMaterial({
1974
2030
>
1975
2031
{ ! hideConfigDiffSelector &&
1976
2032
( state . isRollbackTrigger || state . isSelectImageTrigger ) &&
1977
- ! state . showConfigDiffView &&
2033
+ ! showConfigDiffView &&
1978
2034
stageType === DeploymentNodeType . CD && (
1979
2035
< div className = "flex left dc__border br-4 h-42" >
1980
2036
< div className = "flex" >
@@ -2058,36 +2114,49 @@ export default function CDMaterial({
2058
2114
)
2059
2115
}
2060
2116
2117
+ const renderTriggerViewConfigDiff = ( ) => {
2118
+ if ( state . checkingDiff ) {
2119
+ return < Progressing pageLoader />
2120
+ }
2121
+
2122
+ return (
2123
+ < TriggerViewConfigDiff
2124
+ currentConfiguration = { state . recentDeploymentConfig }
2125
+ baseTemplateConfiguration = { getBaseTemplateConfiguration ( ) }
2126
+ selectedConfigToDeploy = { state . selectedConfigToDeploy }
2127
+ handleConfigSelection = { handleConfigSelection }
2128
+ isConfigAvailable = { isConfigAvailable }
2129
+ diffOptions = { state . diffOptions }
2130
+ isRollbackTriggerSelected = { state . isRollbackTrigger }
2131
+ isRecentConfigAvailable = { state . recentDeploymentConfig !== null }
2132
+ canReviewConfig = { showConfigDiffView && canReviewConfig ( ) }
2133
+ />
2134
+ )
2135
+ }
2136
+
2061
2137
const renderTriggerBody = ( isApprovalConfigured : boolean ) => (
2062
2138
< div
2063
- className = { `trigger-modal__body ${ state . showConfigDiffView && canReviewConfig ( ) ? 'p-0' : '' } ` }
2139
+ className = { `trigger-modal__body ${ showConfigDiffView && canReviewConfig ( ) ? 'p-0' : '' } ` }
2064
2140
style = { {
2065
2141
height : getTriggerBodyHeight ( isApprovalConfigured ) ,
2066
2142
} }
2067
2143
>
2068
- { state . showConfigDiffView && canReviewConfig ( ) ? (
2069
- < TriggerViewConfigDiff
2070
- currentConfiguration = { state . recentDeploymentConfig }
2071
- baseTemplateConfiguration = { getBaseTemplateConfiguration ( ) }
2072
- selectedConfigToDeploy = { state . selectedConfigToDeploy }
2073
- handleConfigSelection = { handleConfigSelection }
2074
- isConfigAvailable = { isConfigAvailable }
2075
- diffOptions = { state . diffOptions }
2076
- isRollbackTriggerSelected = { state . isRollbackTrigger }
2077
- isRecentConfigAvailable = { state . recentDeploymentConfig !== null }
2078
- />
2079
- ) : (
2080
- renderMaterialList ( isApprovalConfigured )
2081
- ) }
2144
+ { showConfigDiffView && canReviewConfig ( )
2145
+ ? renderTriggerViewConfigDiff ( )
2146
+ : renderMaterialList ( isApprovalConfigured ) }
2082
2147
</ div >
2083
2148
)
2084
2149
2085
2150
const renderCDModal = ( isApprovalConfigured : boolean ) => (
2086
2151
< >
2087
2152
< div className = "trigger-modal__header" >
2088
- { state . showConfigDiffView ? (
2153
+ { showConfigDiffView ? (
2089
2154
< div className = "flex left" >
2090
- < button type = "button" className = "dc__transparent icon-dim-24" onClick = { reviewConfig } >
2155
+ < button
2156
+ type = "button"
2157
+ className = "dc__transparent icon-dim-24"
2158
+ onClick = { ( ) => onClickSetInitialParams ( 'list' ) }
2159
+ >
2091
2160
< BackIcon />
2092
2161
</ button >
2093
2162
< div className = "flex column left ml-16" >
@@ -2107,7 +2176,7 @@ export default function CDMaterial({
2107
2176
</ button >
2108
2177
</ div >
2109
2178
2110
- { ! state . showConfigDiffView && window ?. _env_ ?. ANNOUNCEMENT_BANNER_MSG && (
2179
+ { ! showConfigDiffView && window ?. _env_ ?. ANNOUNCEMENT_BANNER_MSG && (
2111
2180
< AnnouncementBanner parentClassName = "cd-trigger-announcement" isCDMaterial />
2112
2181
) }
2113
2182
@@ -2202,13 +2271,13 @@ export default function CDMaterial({
2202
2271
if ( material . length > 0 ) {
2203
2272
return isFromBulkCD ? (
2204
2273
< >
2205
- { ! state . showConfigDiffView && window ?. _env_ ?. ANNOUNCEMENT_BANNER_MSG && (
2274
+ { ! showConfigDiffView && window ?. _env_ ?. ANNOUNCEMENT_BANNER_MSG && (
2206
2275
< AnnouncementBanner parentClassName = "cd-trigger-announcement" isCDMaterial />
2207
2276
) }
2208
2277
{ renderTriggerBody ( isApprovalConfigured ) }
2209
2278
</ >
2210
2279
) : (
2211
- renderCDModal ( isApprovalConfigured )
2280
+ renderCDModal ( isApprovalConfigured )
2212
2281
)
2213
2282
}
2214
2283
0 commit comments