Skip to content

Commit 4c628ff

Browse files
committed
Merge branch 'main' into vite_exploration
2 parents 773e422 + 448ec3a commit 4c628ff

File tree

9 files changed

+173
-31
lines changed

9 files changed

+173
-31
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"homepage": "/dashboard",
66
"dependencies": {
7-
"@devtron-labs/devtron-fe-common-lib": "0.0.59-beta-5",
7+
"@devtron-labs/devtron-fe-common-lib": "0.0.60-beta-1",
88
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
99
"@rjsf/core": "^5.13.3",
1010
"@rjsf/utils": "^5.13.3",

src/components/EnvironmentOverride/DeploymentTemplateOverrideForm.tsx

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useMemo, useState } from 'react'
1+
import React, { useEffect, useMemo, useRef, useState } from 'react'
22
import { useParams } from 'react-router-dom'
33
import { toast } from 'react-toastify'
44
import YAML from 'yaml'
@@ -27,11 +27,14 @@ import {
2727
validateBasicView,
2828
} from '../deploymentConfig/DeploymentConfig.utils'
2929
import CodeEditor from '../CodeEditor/CodeEditor'
30+
import * as jsonpatch from 'fast-json-patch'
3031

3132
const ConfigToolbar = importComponentFromFELibrary('ConfigToolbar', DeploymentConfigToolbar)
3233
const SaveChangesModal = importComponentFromFELibrary('SaveChangesModal')
3334
const DeleteOverrideDraftModal = importComponentFromFELibrary('DeleteOverrideDraftModal')
3435
const DeploymentTemplateLockedDiff = importComponentFromFELibrary('DeploymentTemplateLockedDiff')
36+
const applyPatches = importComponentFromFELibrary('applyPatches', null, 'function')
37+
3538
export default function DeploymentTemplateOverrideForm({
3639
state,
3740
isConfigProtectionEnabled,
@@ -66,6 +69,9 @@ export default function DeploymentTemplateOverrideForm({
6669
allowed: false,
6770
})
6871
const [disableSaveEligibleChanges, setDisableSaveEligibleChanges] = useState(false)
72+
const [hideLockedKeys, setHideLockedKeys] = useState(false)
73+
const hideLockKeysToggled = useRef(false)
74+
const removedPatches = useRef<Array<jsonpatch.Operation>>([])
6975

7076
useEffect(() => {
7177
// Reset editor value on delete override action
@@ -105,10 +111,15 @@ export default function DeploymentTemplateOverrideForm({
105111

106112
const prepareDataToSave = (envOverrideValuesWithBasic, includeInDraft?: boolean) => {
107113
let valuesOverride = envOverrideValuesWithBasic || obj || state.duplicate
114+
115+
if (applyPatches && hideLockedKeys) {
116+
valuesOverride = applyPatches(valuesOverride, removedPatches.current)
117+
}
118+
108119
if (state.showLockedTemplateDiff) {
109120
// if locked keys
110121
if (!lockedConfigKeysWithLockType.allowed) {
111-
valuesOverride = getUnlockedJSON(lockedOverride, lockedConfigKeysWithLockType.config)
122+
valuesOverride = getUnlockedJSON(lockedOverride, lockedConfigKeysWithLockType.config, true).newDocument
112123
} else {
113124
// if allowed keys
114125
valuesOverride = getLockedJSON(lockedOverride, lockedConfigKeysWithLockType.config)
@@ -213,9 +224,10 @@ export default function DeploymentTemplateOverrideForm({
213224
// loading state for checking locked changes
214225
dispatch({ type: DeploymentConfigStateActionTypes.lockChangesLoading, payload: true })
215226
}
227+
const payload = prepareDataToSave(envOverrideValuesWithBasic, false)
216228
const deploymentTemplateResp = isConfigProtectionEnabled
217229
? await checkForProtectedLockedChanges()
218-
: await api(+appId, +envId, prepareDataToSave(envOverrideValuesWithBasic, false))
230+
: await api(+appId, +envId, payload)
219231
if (deploymentTemplateResp.result.isLockConfigError && !saveEligibleChanges) {
220232
// checking if any locked changes and opening drawer to show eligible and locked ones
221233
setLockedOverride(deploymentTemplateResp.result?.lockedOverride)
@@ -230,6 +242,11 @@ export default function DeploymentTemplateOverrideForm({
230242

231243
if (envOverrideValuesWithBasic) {
232244
editorOnChange(YAML.stringify(envOverrideValuesWithBasic, { indent: 2 }), true)
245+
} else {
246+
dispatch({
247+
type: DeploymentConfigStateActionTypes.tempFormData,
248+
payload: YAML.stringify(deploymentTemplateResp.result.envOverrideValues),
249+
})
233250
}
234251
toast.success(
235252
<div className="toast">
@@ -360,6 +377,7 @@ export default function DeploymentTemplateOverrideForm({
360377
openComparison: state.showReadme && state.selectedTabIndex === 2,
361378
},
362379
})
380+
hideLockKeysToggled.current = true
363381
}
364382

365383
const handleComparisonClick = () => {
@@ -374,6 +392,9 @@ export default function DeploymentTemplateOverrideForm({
374392
return
375393
}
376394

395+
//setting true to update codeditor values with current locked keys checkbox value
396+
hideLockKeysToggled.current = true
397+
377398
dispatch({
378399
type: DeploymentConfigStateActionTypes.selectedTabIndex,
379400
payload:
@@ -518,6 +539,9 @@ export default function DeploymentTemplateOverrideForm({
518539
: YAML.stringify(state.data.globalConfig, { indent: 2 })
519540
} else if (state.tempFormData) {
520541
codeEditorValue = state.tempFormData
542+
if (applyPatches && hideLockedKeys) {
543+
codeEditorValue = YAML.stringify(applyPatches(YAML.parse(state.tempFormData), removedPatches.current))
544+
}
521545
} else {
522546
const isOverridden = state.latestDraft?.action === 3 ? state.isDraftOverriden : !!state.duplicate
523547
codeEditorValue = isOverridden
@@ -580,7 +604,10 @@ export default function DeploymentTemplateOverrideForm({
580604
return (
581605
<DeploymentTemplateReadOnlyEditorView
582606
value={isValuesOverride ? getCodeEditorValue(true) : manifestDataRHS}
583-
isEnvOverride
607+
isEnvOverride={true}
608+
lockedConfigKeysWithLockType={lockedConfigKeysWithLockType}
609+
hideLockedKeys={hideLockedKeys}
610+
removedPatches={removedPatches}
584611
/>
585612
)
586613
}
@@ -593,7 +620,7 @@ export default function DeploymentTemplateOverrideForm({
593620
}
594621
return (
595622
<DeploymentTemplateEditorView
596-
isEnvOverride
623+
isEnvOverride={true}
597624
value={isValuesOverride ? getCodeEditorValue(false) : manifestDataRHS}
598625
defaultValue={
599626
state.data && state.openComparison
@@ -617,6 +644,10 @@ export default function DeploymentTemplateOverrideForm({
617644
convertVariables={convertVariablesOverride}
618645
setConvertVariables={setConvertVariables}
619646
groupedData={groupedData}
647+
hideLockedKeys={hideLockedKeys}
648+
lockedConfigKeysWithLockType={lockedConfigKeysWithLockType}
649+
hideLockKeysToggled={hideLockKeysToggled}
650+
removedPatches={removedPatches}
620651
/>
621652
)
622653
}
@@ -713,6 +744,11 @@ export default function DeploymentTemplateOverrideForm({
713744
componentType={3}
714745
setShowLockedDiffForApproval={setShowLockedDiffForApproval}
715746
setLockedConfigKeysWithLockType={setLockedConfigKeysWithLockType}
747+
lockedConfigKeysWithLockType={lockedConfigKeysWithLockType}
748+
setHideLockedKeys={setHideLockedKeys}
749+
hideLockedKeys={hideLockedKeys}
750+
hideLockKeysToggled={hideLockKeysToggled}
751+
inValidYaml={state.unableToParseYaml}
716752
/>
717753
{state.selectedTabIndex !== 2 && !state.showReadme && renderOverrideInfoStrip()}
718754
{renderValuesView()}

src/components/ciPipeline/SourceMaterials.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export const SourceMaterials: React.FC<SourceMaterialsProps> = (props) => {
225225
}
226226
/>
227227
{/* Note: In case Error is not shown added height */}
228-
{errorObj?.isValid && <div className="h-24" />}
228+
{(errorObj?.isValid || islinkedCI) && <div className="h-24" />}
229229
</div>
230230
)}
231231

src/components/deploymentConfig/DeploymentConfig.tsx

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Reducer, createContext, useContext, useEffect, useReducer, useState } from 'react'
1+
import React, { Reducer, createContext, useContext, useEffect, useReducer, useRef, useState } from 'react'
22
import { useHistory, useParams } from 'react-router'
33
import { toast } from 'react-toastify'
44
import {
@@ -53,12 +53,13 @@ import { SaveConfirmationDialog, SuccessToastBody } from './DeploymentTemplateVi
5353
import { deploymentConfigReducer, initDeploymentConfigState } from './DeploymentConfigReducer'
5454
import DeploymentTemplateReadOnlyEditorView from './DeploymentTemplateView/DeploymentTemplateReadOnlyEditorView'
5555
import CodeEditor from '../CodeEditor/CodeEditor'
56-
56+
import * as jsonpatch from 'fast-json-patch'
5757
const DeploymentTemplateLockedDiff = importComponentFromFELibrary('DeploymentTemplateLockedDiff')
5858
const ConfigToolbar = importComponentFromFELibrary('ConfigToolbar', DeploymentConfigToolbar)
5959
const SaveChangesModal = importComponentFromFELibrary('SaveChangesModal')
6060
const DraftComments = importComponentFromFELibrary('DraftComments')
6161
const getDraftByResourceName = importComponentFromFELibrary('getDraftByResourceName', null, 'function')
62+
const applyPatches = importComponentFromFELibrary('applyPatches', null, 'function')
6263

6364
export const DeploymentConfigContext = createContext<DeploymentConfigContextType>(null)
6465

@@ -88,8 +89,12 @@ export default function DeploymentConfig({
8889
)
8990
const [obj, , , error] = useJsonYaml(state.tempFormData, 4, 'yaml', true)
9091
const [, grafanaModuleStatus] = useAsync(() => getModuleInfo(ModuleNameMap.GRAFANA), [appId])
92+
const [hideLockedKeys, setHideLockedKeys] = useState(false)
93+
const hideLockKeysToggled = useRef(false)
94+
9195
const readOnlyPublishedMode = state.selectedTabIndex === 1 && isProtected && !!state.latestDraft
9296
const baseDeploymentAbortController = new AbortController()
97+
const removedPatches = useRef<Array<jsonpatch.Operation>>([])
9398

9499
const setIsValues = (value: boolean) => {
95100
dispatch({
@@ -209,6 +214,12 @@ export default function DeploymentConfig({
209214
payload: false,
210215
})
211216
})
217+
.finally(() => {
218+
dispatch({
219+
type: DeploymentConfigStateActionTypes.loading,
220+
payload: false,
221+
})
222+
})
212223
}
213224

214225
const fetchAllDrafts = (chartRefsData) => {
@@ -360,6 +371,16 @@ export default function DeploymentConfig({
360371
})
361372
}
362373
}
374+
const reload = () => {
375+
dispatch({
376+
type: DeploymentConfigStateActionTypes.loading,
377+
payload: {
378+
loading: true,
379+
},
380+
})
381+
setHideLockedKeys(false)
382+
initialise()
383+
}
363384

364385
async function fetchDeploymentTemplate() {
365386
dispatch({
@@ -579,6 +600,7 @@ export default function DeploymentConfig({
579600
})
580601
saveEligibleChangesCb && closeLockedDiffDrawerWithChildModal()
581602
state.showConfirmation && handleConfirmationDialog(false)
603+
setHideLockedKeys(false)
582604
}
583605
}
584606

@@ -648,6 +670,7 @@ export default function DeploymentConfig({
648670
openComparison: state.showReadme && state.selectedTabIndex === 2,
649671
},
650672
})
673+
hideLockKeysToggled.current = true
651674
}
652675

653676
const handleComparisonClick = () => {
@@ -695,9 +718,9 @@ export default function DeploymentConfig({
695718
}
696719

697720
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
701724

702725
dispatch({
703726
type: DeploymentConfigStateActionTypes.selectedTabIndex,
@@ -772,16 +795,19 @@ export default function DeploymentConfig({
772795
const prepareDataToSave = (skipReadmeAndSchema?: boolean) => {
773796
let valuesOverride = obj
774797

798+
if (applyPatches && hideLockedKeys) {
799+
valuesOverride = applyPatches(valuesOverride, removedPatches.current)
800+
}
801+
775802
if (state.showLockedTemplateDiff) {
776803
// if locked keys
777804
if (!lockedConfigKeysWithLockType.allowed) {
778-
valuesOverride = getUnlockedJSON(lockedOverride, lockedConfigKeysWithLockType.config)
805+
valuesOverride = getUnlockedJSON(lockedOverride, lockedConfigKeysWithLockType.config, true).newDocument
779806
} else {
780807
// if allowed keys
781808
valuesOverride = getLockedJSON(lockedOverride, lockedConfigKeysWithLockType.config)
782809
}
783810
}
784-
785811
const requestData = {
786812
...(state.chartConfig.chartRefId === state.selectedChart.id ? state.chartConfig : {}),
787813
appId: +appId,
@@ -849,7 +875,11 @@ export default function DeploymentConfig({
849875
if (isCompareAndApprovalState) {
850876
result = await fetchManifestData(state.draftValues)
851877
} 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)
853883
}
854884
return result
855885
}
@@ -858,7 +888,14 @@ export default function DeploymentConfig({
858888

859889
const renderEditorComponent = () => {
860890
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+
)
862899
}
863900

864901
if (state.loadingManifest) {
@@ -882,6 +919,10 @@ export default function DeploymentConfig({
882919
convertVariables={state.convertVariables}
883920
setConvertVariables={setConvertVariables}
884921
groupedData={state.groupedOptionsData}
922+
hideLockedKeys={hideLockedKeys}
923+
lockedConfigKeysWithLockType={lockedConfigKeysWithLockType}
924+
hideLockKeysToggled={hideLockKeysToggled}
925+
removedPatches={removedPatches}
885926
/>
886927
)
887928
}
@@ -921,7 +962,7 @@ export default function DeploymentConfig({
921962
isCiPipeline={isCiPipeline}
922963
toggleAppMetrics={toggleAppMetrics}
923964
isPublishedMode={readOnlyPublishedMode}
924-
reload={initialise}
965+
reload={reload}
925966
isValues={state.isValues}
926967
convertVariables={state.convertVariables}
927968
isSuperAdmin={isSuperAdmin}
@@ -967,13 +1008,19 @@ export default function DeploymentConfig({
9671008
isApprovalPending={state.latestDraft?.draftState === 4}
9681009
approvalUsers={state.latestDraft?.approvers}
9691010
showValuesPostfix
970-
reload={initialise}
1011+
reload={reload}
9711012
isValues={state.isValues}
9721013
setIsValues={setIsValues}
9731014
convertVariables={state.convertVariables}
9741015
setConvertVariables={setConvertVariables}
9751016
componentType={3}
9761017
setShowLockedDiffForApproval={setShowLockedDiffForApproval}
1018+
setHideLockedKeys={setHideLockedKeys}
1019+
hideLockedKeys={hideLockedKeys}
1020+
setLockedConfigKeysWithLockType={setLockedConfigKeysWithLockType}
1021+
lockedConfigKeysWithLockType={lockedConfigKeysWithLockType}
1022+
hideLockKeysToggled={hideLockKeysToggled}
1023+
inValidYaml={state.unableToParseYaml}
9771024
/>
9781025
{renderValuesView()}
9791026
{state.showConfirmation && (
@@ -1006,7 +1053,7 @@ export default function DeploymentConfig({
10061053
prepareDataToSave={prepareDataToSave}
10071054
toggleModal={toggleSaveChangesModal}
10081055
latestDraft={state.latestDraft}
1009-
reload={initialise}
1056+
reload={reload}
10101057
closeLockedDiffDrawerWithChildModal={closeLockedDiffDrawerWithChildModal}
10111058
showAsModal={!state.showLockedTemplateDiff}
10121059
saveEligibleChangesCb={saveEligibleChangesCb}

0 commit comments

Comments
 (0)