@@ -25,10 +25,13 @@ export default function TriggerViewConfigDiff({
25
25
diffOptions,
26
26
isRollbackTriggerSelected,
27
27
isRecentConfigAvailable,
28
- history
28
+ history,
29
+ canReviewConfig
29
30
} : TriggerViewConfigDiffProps ) {
31
+ const { searchParams } = useSearchString ( )
32
+
30
33
const [ activeSideNavOption , setActiveSideNavOption ] = useState (
31
- DEPLOYMENT_CONFIGURATION_NAV_MAP . DEPLOYMENT_TEMPLATE . key ,
34
+ searchParams . config ,
32
35
)
33
36
const [ convertVariables , setConvertVariables ] = useState < boolean > ( false ) // toggle to show/hide variable values
34
37
const [ isVariableAvailable , setIsVariableAvailable ] = useState < boolean > ( false ) // check if variable snapshot is {} or not
@@ -50,36 +53,17 @@ export default function TriggerViewConfigDiff({
50
53
const [ configMapOptionCollapsed , setConfigMapOptionCollapsed ] = useState < boolean > ( false )
51
54
const [ secretOptionCollapsed , setSecretOptionCollapsed ] = useState < boolean > ( false )
52
55
const [ currentData , setCurrentData ] = useState < any > ( { } ) // store codeEditorValue of current(lhs) and base(rhs) config
53
- const { searchParams } = useSearchString ( )
54
-
55
- useEffect ( ( ) => {
56
- const dataValue = searchParams . config ?. replace ( '-' , '/' )
57
- setParamsValue ( dataValue . replace ( '/' , '-' ) )
58
- if ( dataValue ) {
59
- setConvertVariables ( false )
60
- setActiveSideNavOption ( dataValue )
61
-
62
- const { rhsData, lhsData } = getCurrentConfiguration ( dataValue )
63
- setCurrentData ( {
64
- rhsData,
65
- lhsData,
66
- } )
67
56
68
- const _isVariableAvailable =
69
- Object . keys ( rhsData ?. variableSnapshot || { } ) . length !== 0 ||
70
- Object . keys ( lhsData ?. variableSnapshot || { } ) . length !== 0
71
- setIsVariableAvailable ( _isVariableAvailable )
72
57
73
- const editorValuesRHS = convertVariables ? rhsData ?. resolvedValue : rhsData ?. value
74
- const editorValuesLHS = convertVariables ? lhsData ?. resolvedValue : lhsData ?. value
75
- setEditorValues ( {
76
- displayName : rhsData ?. displayName || lhsData ?. displayName ,
77
- value : editorValuesRHS ? YAML . stringify ( JSON . parse ( editorValuesRHS ) ) : '' ,
78
- defaultValue : editorValuesLHS ? YAML . stringify ( JSON . parse ( editorValuesLHS ) ) : '' ,
79
- } )
58
+ useEffect ( ( ) => {
59
+ if ( canReviewConfig ( ) && baseTemplateConfiguration && currentConfiguration ) {
60
+ const dataValue = searchParams . config ?. replace ( '-' , '/' )
61
+ setParamsValue ( dataValue . replace ( '/' , '-' ) )
62
+ handleNavOptionSelection ( null , dataValue )
80
63
}
64
+
81
65
82
- } , [ ] )
66
+ } , [ canReviewConfig ( ) , baseTemplateConfiguration , currentConfiguration ] )
83
67
84
68
useEffect ( ( ) => {
85
69
handleConfigToDeploySelection ( )
@@ -105,8 +89,8 @@ export default function TriggerViewConfigDiff({
105
89
106
90
if ( ! getNavOptions ( navParentChildKeys [ 0 ] ) . includes ( navParentChildKeys [ 1 ] ) ) {
107
91
setConvertVariables ( false )
108
- setActiveSideNavOption ( DEPLOYMENT_CONFIGURATION_NAV_MAP . DEPLOYMENT_TEMPLATE . key )
109
- handleNavOptionSelection ( null , DEPLOYMENT_CONFIGURATION_NAV_MAP . DEPLOYMENT_TEMPLATE . key )
92
+ setActiveSideNavOption ( searchParams . config )
93
+ handleNavOptionSelection ( null , searchParams . config )
110
94
return
111
95
}
112
96
}
0 commit comments