Skip to content

Commit 5c94c29

Browse files
committed
fixed issue in case of data not found
1 parent f47c1cd commit 5c94c29

File tree

2 files changed

+72
-31
lines changed

2 files changed

+72
-31
lines changed

src/components/v2/appDetails/k8Resource/nodeDetail/NodeDetailTabs/Manifest.component.tsx

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,27 @@ import MessageUI, { MsgUIType } from '../../../../common/message.ui'
1717
import { AppType, ManifestActionPropsType, NodeType } from '../../../appDetails.type'
1818
import YAML from 'yaml'
1919
import { toast } from 'react-toastify'
20-
import { Checkbox, CHECKBOX_VALUE, DeploymentAppTypes, showError, ToastBody } from '@devtron-labs/devtron-fe-common-lib'
20+
import {
21+
Checkbox,
22+
CHECKBOX_VALUE,
23+
ConditionalWrap,
24+
DeploymentAppTypes,
25+
noop,
26+
showError,
27+
ToastBody,
28+
} from '@devtron-labs/devtron-fe-common-lib'
2129
import { appendRefetchDataToUrl } from '../../../../../util/URLUtil'
2230
import {
2331
EA_MANIFEST_SECRET_EDIT_MODE_INFO_TEXT,
2432
EA_MANIFEST_SECRET_INFO_TEXT,
2533
} from '../../../../../../config/constantMessaging'
2634
import { MODES } from '../../../../../../config'
27-
import { EMPTY_YAML_ERROR, SAVE_DATA_VALIDATION_ERROR_MSG } from '../../../../values/chartValuesDiff/ChartValuesView.constants'
35+
import {
36+
EMPTY_YAML_ERROR,
37+
SAVE_DATA_VALIDATION_ERROR_MSG,
38+
} from '../../../../values/chartValuesDiff/ChartValuesView.constants'
2839
import { getDecodedEncodedSecretManifestData, getTrimmedManifestData } from '../nodeDetail.util'
40+
import Tippy from '@tippyjs/react'
2941

3042
function ManifestComponent({
3143
selectedTab,
@@ -39,7 +51,14 @@ function ManifestComponent({
3951
const history = useHistory()
4052
const [{ tabs, activeTab }, dispatch] = useTab(ManifestTabJSON)
4153
const { url } = useRouteMatch()
42-
const params = useParams<{ actionName: string; podName: string; nodeType: string; node: string; group: string, namespace: string }>()
54+
const params = useParams<{
55+
actionName: string
56+
podName: string
57+
nodeType: string
58+
node: string
59+
group: string
60+
namespace: string
61+
}>()
4362
const [manifest, setManifest] = useState('')
4463
const [modifiedManifest, setModifiedManifest] = useState('')
4564
const [activeManifestEditorData, setActiveManifestEditorData] = useState('')
@@ -86,8 +105,7 @@ function ManifestComponent({
86105
if (
87106
isResourceBrowserView ||
88107
appDetails.appType === AppType.EXTERNAL_HELM_CHART ||
89-
(appDetails.deploymentAppType === DeploymentAppTypes.GITOPS &&
90-
appDetails.deploymentAppDeleteRequest)
108+
(appDetails.deploymentAppType === DeploymentAppTypes.GITOPS && appDetails.deploymentAppDeleteRequest)
91109
) {
92110
markActiveTab('Live manifest')
93111
}
@@ -166,7 +184,7 @@ function ManifestComponent({
166184

167185
const handleEditorValueChange = (codeEditorData: string) => {
168186
if (activeTab === 'Live manifest' && isEditmode) {
169-
setModifiedManifest(codeEditorData)
187+
setModifiedManifest(codeEditorData)
170188
}
171189
}
172190

@@ -186,7 +204,7 @@ function ManifestComponent({
186204
if (!modifiedManifest) {
187205
setErrorText(`${SAVE_DATA_VALIDATION_ERROR_MSG} "${EMPTY_YAML_ERROR}"`)
188206
// Handled for blocking API call
189-
manifestString = ""
207+
manifestString = ''
190208
} else {
191209
manifestString = JSON.stringify(YAML.parse(modifiedManifest))
192210
}
@@ -227,7 +245,7 @@ function ManifestComponent({
227245
className: 'devtron-toast unauthorized',
228246
},
229247
)
230-
} else if (err.code === 400 || err.code === 409 || err.code === 422 ) {
248+
} else if (err.code === 400 || err.code === 409 || err.code === 422) {
231249
const error = err['errors'] && err['errors'][0]
232250
if (error && error.code && error.userMessage) {
233251
setErrorText(`ERROR ${err.code} > Message: “${error.userMessage}”`)
@@ -303,29 +321,54 @@ function ManifestComponent({
303321
updateEditor(_tab.name)
304322
}
305323

306-
const onChangeToggleShowDecodedValue = () => {
324+
const onChangeToggleShowDecodedValue = (jsonManifestData) => {
325+
if (!jsonManifestData?.data) return
307326
setShowDecodedData(!showDecodedData)
308-
const jsonManifestData = YAML.parse(trimedManifestEditorData)
309-
if(!showDecodedData){
310-
setTrimedManifestEditorData(getDecodedEncodedSecretManifestData(jsonManifestData, true , showDecodedData) as string)
327+
if (!showDecodedData) {
328+
setTrimedManifestEditorData(
329+
getDecodedEncodedSecretManifestData(jsonManifestData, true, showDecodedData) as string,
330+
)
311331
} else {
312332
setTrimedManifestEditorData(getDecodedEncodedSecretManifestData(jsonManifestData, true, true) as string)
313333
}
314334
}
315335

316336
const renderShowDecodedValueCheckbox = () => {
317-
return (
318-
<div className="flex left ml-8">
319-
<Checkbox
320-
rootClassName="mb-0-imp h-18"
321-
id="showDecodedValue"
322-
isChecked={showDecodedData}
323-
onChange={onChangeToggleShowDecodedValue}
324-
value={CHECKBOX_VALUE.CHECKED}
325-
/>
326-
Show decoded Value
327-
</div>
328-
)
337+
const jsonManifestData = YAML.parse(trimedManifestEditorData)
338+
if (jsonManifestData?.kind === 'Secret' && !isEditmode && secretViewAccess) {
339+
return (
340+
<ConditionalWrap
341+
condition={!jsonManifestData?.data}
342+
wrap={(children) => (
343+
<Tippy
344+
className="default-tt w-200"
345+
arrow={false}
346+
placement="top-start"
347+
content="Nothing to decode, data field not found."
348+
>
349+
{children}
350+
</Tippy>
351+
)}
352+
>
353+
<div
354+
className={`${
355+
!jsonManifestData?.data ? 'dc__opacity-0_5 cursor-not-allowed' : ''
356+
} flex left ml-8`}
357+
>
358+
<Checkbox
359+
rootClassName={`${
360+
!jsonManifestData?.data ? 'dc__opacity-0_5 cursor-not-allowed' : 'cursor'
361+
} mb-0-imp h-18`}
362+
id="showDecodedValue"
363+
isChecked={showDecodedData}
364+
onChange={() => onChangeToggleShowDecodedValue(jsonManifestData)}
365+
value={CHECKBOX_VALUE.CHECKED}
366+
/>
367+
Show decoded Value
368+
</div>
369+
</ConditionalWrap>
370+
)
371+
}
329372
}
330373

331374
return isDeleted ? (
@@ -446,7 +489,7 @@ function ManifestComponent({
446489
}
447490
className="flex left"
448491
>
449-
{!isEditmode && secretViewAccess && renderShowDecodedValueCheckbox()}
492+
{renderShowDecodedValueCheckbox()}
450493
</CodeEditor.Information>
451494
)}
452495
{activeTab === 'Compare' && (

src/components/v2/appDetails/k8Resource/nodeDetail/nodeDetail.util.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,9 @@ export const getDecodedEncodedSecretManifestData = (
412412
returnAsString: boolean = false,
413413
isEncoded?: boolean,
414414
): ManifestData | string => {
415-
if (manifestData && manifestData?.MANIFEST_KEY_FIELDS.DATA) {
416-
const encodedData = {
417-
...manifestData,
418-
[MANIFEST_KEY_FIELDS.DATA]: decode(manifestData[MANIFEST_KEY_FIELDS.DATA], isEncoded),
419-
}
420-
return returnAsString ? JSON.stringify(encodedData) : manifestData
415+
const encodedData = {
416+
...manifestData,
417+
[MANIFEST_KEY_FIELDS.DATA]: decode(manifestData[MANIFEST_KEY_FIELDS.DATA], isEncoded),
421418
}
419+
return returnAsString ? JSON.stringify(encodedData) : manifestData
422420
}

0 commit comments

Comments
 (0)