1
- import React , { Reducer , createContext , useContext , useEffect , useReducer , useState } from 'react'
1
+ import React , { Reducer , createContext , useContext , useEffect , useReducer , useRef , useState } from 'react'
2
2
import { useHistory , useParams } from 'react-router'
3
3
import { toast } from 'react-toastify'
4
4
import {
@@ -53,12 +53,13 @@ import { SaveConfirmationDialog, SuccessToastBody } from './DeploymentTemplateVi
53
53
import { deploymentConfigReducer , initDeploymentConfigState } from './DeploymentConfigReducer'
54
54
import DeploymentTemplateReadOnlyEditorView from './DeploymentTemplateView/DeploymentTemplateReadOnlyEditorView'
55
55
import CodeEditor from '../CodeEditor/CodeEditor'
56
-
56
+ import * as jsonpatch from 'fast-json-patch'
57
57
const DeploymentTemplateLockedDiff = importComponentFromFELibrary ( 'DeploymentTemplateLockedDiff' )
58
58
const ConfigToolbar = importComponentFromFELibrary ( 'ConfigToolbar' , DeploymentConfigToolbar )
59
59
const SaveChangesModal = importComponentFromFELibrary ( 'SaveChangesModal' )
60
60
const DraftComments = importComponentFromFELibrary ( 'DraftComments' )
61
61
const getDraftByResourceName = importComponentFromFELibrary ( 'getDraftByResourceName' , null , 'function' )
62
+ const applyPatches = importComponentFromFELibrary ( 'applyPatches' , null , 'function' )
62
63
63
64
export const DeploymentConfigContext = createContext < DeploymentConfigContextType > ( null )
64
65
@@ -88,8 +89,12 @@ export default function DeploymentConfig({
88
89
)
89
90
const [ obj , , , error ] = useJsonYaml ( state . tempFormData , 4 , 'yaml' , true )
90
91
const [ , grafanaModuleStatus ] = useAsync ( ( ) => getModuleInfo ( ModuleNameMap . GRAFANA ) , [ appId ] )
92
+ const [ hideLockedKeys , setHideLockedKeys ] = useState ( false )
93
+ const hideLockKeysToggled = useRef ( false )
94
+
91
95
const readOnlyPublishedMode = state . selectedTabIndex === 1 && isProtected && ! ! state . latestDraft
92
96
const baseDeploymentAbortController = new AbortController ( )
97
+ const removedPatches = useRef < Array < jsonpatch . Operation > > ( [ ] )
93
98
94
99
const setIsValues = ( value : boolean ) => {
95
100
dispatch ( {
@@ -209,6 +214,12 @@ export default function DeploymentConfig({
209
214
payload : false ,
210
215
} )
211
216
} )
217
+ . finally ( ( ) => {
218
+ dispatch ( {
219
+ type : DeploymentConfigStateActionTypes . loading ,
220
+ payload : false ,
221
+ } )
222
+ } )
212
223
}
213
224
214
225
const fetchAllDrafts = ( chartRefsData ) => {
@@ -360,6 +371,16 @@ export default function DeploymentConfig({
360
371
} )
361
372
}
362
373
}
374
+ const reload = ( ) => {
375
+ dispatch ( {
376
+ type : DeploymentConfigStateActionTypes . loading ,
377
+ payload : {
378
+ loading : true ,
379
+ } ,
380
+ } )
381
+ setHideLockedKeys ( false )
382
+ initialise ( )
383
+ }
363
384
364
385
async function fetchDeploymentTemplate ( ) {
365
386
dispatch ( {
@@ -579,6 +600,7 @@ export default function DeploymentConfig({
579
600
} )
580
601
saveEligibleChangesCb && closeLockedDiffDrawerWithChildModal ( )
581
602
state . showConfirmation && handleConfirmationDialog ( false )
603
+ setHideLockedKeys ( false )
582
604
}
583
605
}
584
606
@@ -648,6 +670,7 @@ export default function DeploymentConfig({
648
670
openComparison : state . showReadme && state . selectedTabIndex === 2 ,
649
671
} ,
650
672
} )
673
+ hideLockKeysToggled . current = true
651
674
}
652
675
653
676
const handleComparisonClick = ( ) => {
@@ -695,9 +718,9 @@ export default function DeploymentConfig({
695
718
}
696
719
697
720
const handleTabSelection = ( index : number ) => {
698
- if ( state . unableToParseYaml ) {
699
- return
700
- }
721
+ if ( state . unableToParseYaml ) return
722
+ //setting true to update codeditor values with current locked keys checkbox value
723
+ hideLockKeysToggled . current = true
701
724
702
725
dispatch ( {
703
726
type : DeploymentConfigStateActionTypes . selectedTabIndex ,
@@ -772,16 +795,19 @@ export default function DeploymentConfig({
772
795
const prepareDataToSave = ( skipReadmeAndSchema ?: boolean ) => {
773
796
let valuesOverride = obj
774
797
798
+ if ( applyPatches && hideLockedKeys ) {
799
+ valuesOverride = applyPatches ( valuesOverride , removedPatches . current )
800
+ }
801
+
775
802
if ( state . showLockedTemplateDiff ) {
776
803
// if locked keys
777
804
if ( ! lockedConfigKeysWithLockType . allowed ) {
778
- valuesOverride = getUnlockedJSON ( lockedOverride , lockedConfigKeysWithLockType . config )
805
+ valuesOverride = getUnlockedJSON ( lockedOverride , lockedConfigKeysWithLockType . config , true ) . newDocument
779
806
} else {
780
807
// if allowed keys
781
808
valuesOverride = getLockedJSON ( lockedOverride , lockedConfigKeysWithLockType . config )
782
809
}
783
810
}
784
-
785
811
const requestData = {
786
812
...( state . chartConfig . chartRefId === state . selectedChart . id ? state . chartConfig : { } ) ,
787
813
appId : + appId ,
@@ -849,7 +875,11 @@ export default function DeploymentConfig({
849
875
if ( isCompareAndApprovalState ) {
850
876
result = await fetchManifestData ( state . draftValues )
851
877
} else {
852
- result = await fetchManifestData ( state . tempFormData )
878
+ if ( applyPatches && hideLockedKeys ) {
879
+ result = fetchManifestData (
880
+ YAML . stringify ( applyPatches ( YAML . parse ( state . tempFormData ) , removedPatches . current ) ) ,
881
+ )
882
+ } else result = await fetchManifestData ( state . tempFormData )
853
883
}
854
884
return result
855
885
}
@@ -858,7 +888,14 @@ export default function DeploymentConfig({
858
888
859
889
const renderEditorComponent = ( ) => {
860
890
if ( readOnlyPublishedMode && ! state . showReadme ) {
861
- return < DeploymentTemplateReadOnlyEditorView value = { state . publishedState ?. tempFormData } />
891
+ return (
892
+ < DeploymentTemplateReadOnlyEditorView
893
+ value = { state . publishedState ?. tempFormData }
894
+ lockedConfigKeysWithLockType = { lockedConfigKeysWithLockType }
895
+ hideLockedKeys = { hideLockedKeys }
896
+ removedPatches = { removedPatches }
897
+ />
898
+ )
862
899
}
863
900
864
901
if ( state . loadingManifest ) {
@@ -882,6 +919,10 @@ export default function DeploymentConfig({
882
919
convertVariables = { state . convertVariables }
883
920
setConvertVariables = { setConvertVariables }
884
921
groupedData = { state . groupedOptionsData }
922
+ hideLockedKeys = { hideLockedKeys }
923
+ lockedConfigKeysWithLockType = { lockedConfigKeysWithLockType }
924
+ hideLockKeysToggled = { hideLockKeysToggled }
925
+ removedPatches = { removedPatches }
885
926
/>
886
927
)
887
928
}
@@ -921,7 +962,7 @@ export default function DeploymentConfig({
921
962
isCiPipeline = { isCiPipeline }
922
963
toggleAppMetrics = { toggleAppMetrics }
923
964
isPublishedMode = { readOnlyPublishedMode }
924
- reload = { initialise }
965
+ reload = { reload }
925
966
isValues = { state . isValues }
926
967
convertVariables = { state . convertVariables }
927
968
isSuperAdmin = { isSuperAdmin }
@@ -967,13 +1008,19 @@ export default function DeploymentConfig({
967
1008
isApprovalPending = { state . latestDraft ?. draftState === 4 }
968
1009
approvalUsers = { state . latestDraft ?. approvers }
969
1010
showValuesPostfix
970
- reload = { initialise }
1011
+ reload = { reload }
971
1012
isValues = { state . isValues }
972
1013
setIsValues = { setIsValues }
973
1014
convertVariables = { state . convertVariables }
974
1015
setConvertVariables = { setConvertVariables }
975
1016
componentType = { 3 }
976
1017
setShowLockedDiffForApproval = { setShowLockedDiffForApproval }
1018
+ setHideLockedKeys = { setHideLockedKeys }
1019
+ hideLockedKeys = { hideLockedKeys }
1020
+ setLockedConfigKeysWithLockType = { setLockedConfigKeysWithLockType }
1021
+ lockedConfigKeysWithLockType = { lockedConfigKeysWithLockType }
1022
+ hideLockKeysToggled = { hideLockKeysToggled }
1023
+ inValidYaml = { state . unableToParseYaml }
977
1024
/>
978
1025
{ renderValuesView ( ) }
979
1026
{ state . showConfirmation && (
@@ -1006,7 +1053,7 @@ export default function DeploymentConfig({
1006
1053
prepareDataToSave = { prepareDataToSave }
1007
1054
toggleModal = { toggleSaveChangesModal }
1008
1055
latestDraft = { state . latestDraft }
1009
- reload = { initialise }
1056
+ reload = { reload }
1010
1057
closeLockedDiffDrawerWithChildModal = { closeLockedDiffDrawerWithChildModal }
1011
1058
showAsModal = { ! state . showLockedTemplateDiff }
1012
1059
saveEligibleChangesCb = { saveEligibleChangesCb }
0 commit comments