@@ -87,6 +87,7 @@ import { EMPTY_STATE_STATUS, TOAST_BUTTON_TEXT_VIEW_DETAILS } from '../../../../
87
87
import { abortEarlierRequests , getInitialState } from './cdMaterials.utils'
88
88
import { getLastExecutionByArtifactAppEnv } from '../../../../services/service'
89
89
import AnnouncementBanner from '../../../common/AnnouncementBanner'
90
+ import { useRouteMatch } from 'react-router-dom'
90
91
91
92
const ApprovalInfoTippy = importComponentFromFELibrary ( 'ApprovalInfoTippy' )
92
93
const ExpireApproval = importComponentFromFELibrary ( 'ExpireApproval' )
@@ -128,6 +129,7 @@ export default function CDMaterial({
128
129
const { searchParams } = useSearchString ( )
129
130
// Add dep here
130
131
const { isSuperAdmin } = useSuperAdmin ( )
132
+ const match = useRouteMatch ( )
131
133
132
134
const searchImageTag = searchParams . search
133
135
@@ -137,6 +139,7 @@ export default function CDMaterial({
137
139
const [ isConsumedImageAvailable , setIsConsumedImageAvailable ] = useState < boolean > ( false )
138
140
// Should be able to abort request using useAsync
139
141
const abortControllerRef = useRef ( new AbortController ( ) )
142
+ // const [mode, setMode] = useState<string>(searchParams.mode)
140
143
141
144
// TODO: Ask if pipelineId always changes on change of app else add appId as dependency
142
145
const [ loadingMaterials , materialsResult , materialsError , reloadMaterials ] = useAsync (
@@ -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"
186
190
/* ------------ Utils required in useEffect ------------*/
187
191
const getSecurityModuleStatus = async ( ) => {
188
192
try {
@@ -259,6 +263,18 @@ export default function CDMaterial({
259
263
} )
260
264
}
261
265
266
+ const setParamsValue = ( modeParamValue : string ) => {
267
+ const newParams = {
268
+ ...searchParams ,
269
+ mode : modeParamValue ,
270
+ config : 'deploymentTemplate' ,
271
+ deploy : 'LAST_SAVED_CONFIG' . toLocaleLowerCase ( ) //LATEST_TRIGGER_CONFIG
272
+ }
273
+ history . push ( {
274
+ search : new URLSearchParams ( newParams ) . toString ( ) ,
275
+ } )
276
+ }
277
+
262
278
/* ------------ UseEffects ------------*/
263
279
useEffect ( ( ) => {
264
280
if ( ! loadingMaterials && materialsResult ) {
@@ -729,12 +745,10 @@ export default function CDMaterial({
729
745
isConfigPresent ( ) ) ) ||
730
746
! state . recentDeploymentConfig
731
747
732
- const reviewConfig = ( ) => {
748
+ const reviewConfig = ( modeParamValue : string ) => {
749
+ // setMode(modeParamValue)
733
750
if ( canReviewConfig ( ) ) {
734
- setState ( ( prevState ) => ( {
735
- ...prevState ,
736
- showConfigDiffView : ! prevState . showConfigDiffView ,
737
- } ) )
751
+ setParamsValue ( modeParamValue )
738
752
}
739
753
}
740
754
@@ -765,10 +779,15 @@ export default function CDMaterial({
765
779
: state . specificDeploymentConfig
766
780
}
767
781
782
+ const redirectURLToInitial = ( urlTo : string = '' ) => {
783
+ const urlPrefix = match . url
784
+ history . push ( `${ urlPrefix } /${ urlTo } ` )
785
+ }
786
+
768
787
const handleConfigSelection = ( selected ) => {
769
788
if ( selected . value !== state . selectedConfigToDeploy . value ) {
770
789
const _diffOptions = checkForDiff ( state . recentDeploymentConfig , getBaseTemplateConfiguration ( selected ) )
771
-
790
+ redirectURLToInitial ( selected . value )
772
791
setState ( ( prevState ) => ( {
773
792
...prevState ,
774
793
selectedConfigToDeploy : selected ,
@@ -1007,7 +1026,7 @@ export default function CDMaterial({
1007
1026
const getTriggerBodyHeight = ( isApprovalConfigured : boolean ) => {
1008
1027
const subHeight = window ?. _env_ ?. ANNOUNCEMENT_BANNER_MSG ? 37 : 0
1009
1028
1010
- if ( state . showConfigDiffView ) {
1029
+ if ( showConfigDiffView ) {
1011
1030
return `calc(100vh - 141px - ${ subHeight } px)`
1012
1031
}
1013
1032
if (
@@ -1896,7 +1915,7 @@ export default function CDMaterial({
1896
1915
} ${ isLastDeployedOption ? 'pt-10 pb-10' : 'pt-7 pb-7' } `}
1897
1916
disabled = { state . checkingDiff }
1898
1917
type = "button"
1899
- onClick = { reviewConfig }
1918
+ onClick = { ( ) => reviewConfig ( 'review-config' ) }
1900
1919
>
1901
1920
{ ! isLastDeployedOption && ( state . recentDeploymentConfig !== null || state . checkingDiff ) && (
1902
1921
< div
@@ -1965,7 +1984,7 @@ export default function CDMaterial({
1965
1984
< div
1966
1985
className = { `trigger-modal__trigger ${
1967
1986
( ! state . isRollbackTrigger && ! state . isSelectImageTrigger ) ||
1968
- state . showConfigDiffView ||
1987
+ showConfigDiffView ||
1969
1988
stageType === DeploymentNodeType . PRECD ||
1970
1989
stageType === DeploymentNodeType . POSTCD
1971
1990
? 'flex right'
@@ -1974,7 +1993,7 @@ export default function CDMaterial({
1974
1993
>
1975
1994
{ ! hideConfigDiffSelector &&
1976
1995
( state . isRollbackTrigger || state . isSelectImageTrigger ) &&
1977
- ! state . showConfigDiffView &&
1996
+ ! showConfigDiffView &&
1978
1997
stageType === DeploymentNodeType . CD && (
1979
1998
< div className = "flex left dc__border br-4 h-42" >
1980
1999
< div className = "flex" >
@@ -2060,12 +2079,12 @@ export default function CDMaterial({
2060
2079
2061
2080
const renderTriggerBody = ( isApprovalConfigured : boolean ) => (
2062
2081
< div
2063
- className = { `trigger-modal__body ${ state . showConfigDiffView && canReviewConfig ( ) ? 'p-0' : '' } ` }
2082
+ className = { `trigger-modal__body ${ showConfigDiffView && canReviewConfig ( ) ? 'p-0' : '' } ` }
2064
2083
style = { {
2065
2084
height : getTriggerBodyHeight ( isApprovalConfigured ) ,
2066
2085
} }
2067
2086
>
2068
- { state . showConfigDiffView && canReviewConfig ( ) ? (
2087
+ { showConfigDiffView && canReviewConfig ( ) ? (
2069
2088
< TriggerViewConfigDiff
2070
2089
currentConfiguration = { state . recentDeploymentConfig }
2071
2090
baseTemplateConfiguration = { getBaseTemplateConfiguration ( ) }
@@ -2075,6 +2094,7 @@ export default function CDMaterial({
2075
2094
diffOptions = { state . diffOptions }
2076
2095
isRollbackTriggerSelected = { state . isRollbackTrigger }
2077
2096
isRecentConfigAvailable = { state . recentDeploymentConfig !== null }
2097
+ history = { history }
2078
2098
/>
2079
2099
) : (
2080
2100
renderMaterialList ( isApprovalConfigured )
@@ -2085,9 +2105,9 @@ export default function CDMaterial({
2085
2105
const renderCDModal = ( isApprovalConfigured : boolean ) => (
2086
2106
< >
2087
2107
< div className = "trigger-modal__header" >
2088
- { state . showConfigDiffView ? (
2108
+ { showConfigDiffView ? (
2089
2109
< div className = "flex left" >
2090
- < button type = "button" className = "dc__transparent icon-dim-24" onClick = { reviewConfig } >
2110
+ < button type = "button" className = "dc__transparent icon-dim-24" onClick = { ( ) => reviewConfig ( 'list' ) } >
2091
2111
< BackIcon />
2092
2112
</ button >
2093
2113
< div className = "flex column left ml-16" >
@@ -2107,7 +2127,7 @@ export default function CDMaterial({
2107
2127
</ button >
2108
2128
</ div >
2109
2129
2110
- { ! state . showConfigDiffView && window ?. _env_ ?. ANNOUNCEMENT_BANNER_MSG && (
2130
+ { ! showConfigDiffView && window ?. _env_ ?. ANNOUNCEMENT_BANNER_MSG && (
2111
2131
< AnnouncementBanner parentClassName = "cd-trigger-announcement" isCDMaterial />
2112
2132
) }
2113
2133
@@ -2202,7 +2222,7 @@ export default function CDMaterial({
2202
2222
if ( material . length > 0 ) {
2203
2223
return isFromBulkCD ? (
2204
2224
< >
2205
- { ! state . showConfigDiffView && window ?. _env_ ?. ANNOUNCEMENT_BANNER_MSG && (
2225
+ { ! showConfigDiffView && window ?. _env_ ?. ANNOUNCEMENT_BANNER_MSG && (
2206
2226
< AnnouncementBanner parentClassName = "cd-trigger-announcement" isCDMaterial />
2207
2227
) }
2208
2228
{ renderTriggerBody ( isApprovalConfigured ) }
0 commit comments