Skip to content

Commit 29554c3

Browse files
committed
refactor: applied changes made in dashboard side
1 parent bcfc1a2 commit 29554c3

File tree

1 file changed

+29
-33
lines changed

1 file changed

+29
-33
lines changed

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiff.utils.tsx

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ const getConfigData = (
8383
cmSecretData: ConfigMapSecretDataConfigDatumDTO,
8484
type: ConfigResourceType,
8585
): Record<string, string> => {
86+
if (!cmSecretData) {
87+
// Return undefined intentionally, as JSON.stringify converts null to "null" but keeps undefined as undefined.
88+
return undefined
89+
}
90+
8691
const secretKeys = ['secretData', 'esoSecretData', 'defaultSecretData', 'defaultESOSecretData']
8792

8893
if (type === ConfigResourceType.Secret) {
@@ -94,12 +99,7 @@ const getConfigData = (
9499

95100
const configmapKeys = ['data', 'defaultData']
96101
const data = configmapKeys.find((key) => Object.keys(cmSecretData?.[key] ?? {}).length > 0)
97-
if (data) {
98-
return cmSecretData[data]
99-
}
100-
101-
// Return undefined intentionally, as JSON.stringify converts null to "null" but keeps undefined as undefined.
102-
return undefined
102+
return cmSecretData[data]
103103
}
104104

105105
/**
@@ -302,32 +302,20 @@ const getDiffHeading = <DeploymentTemplate extends boolean>(
302302

303303
if (deploymentTemplate) {
304304
const _data = data as DeploymentTemplateDTO
305-
if (!_data?.deploymentDraftData && !_data?.data) {
305+
if (!_data) {
306306
doesNotExist = true
307-
} else if (
308-
_data?.deploymentDraftData?.configData[0].draftMetadata.draftState === DraftState.Init ||
309-
_data?.data?.configData?.[0].draftMetadata.draftState === DraftState.Init
310-
) {
307+
} else if (_data?.deploymentDraftData?.configData[0].draftMetadata.draftState === DraftState.Init) {
311308
isDraft = true
312-
} else if (
313-
_data?.deploymentDraftData?.configData[0].draftMetadata.draftState === DraftState.AwaitApproval ||
314-
_data?.data?.configData?.[0].draftMetadata.draftState === DraftState.AwaitApproval
315-
) {
309+
} else if (_data?.deploymentDraftData?.configData[0].draftMetadata.draftState === DraftState.AwaitApproval) {
316310
isApprovalPending = true
317311
}
318312
} else {
319313
const _data = data as ConfigMapSecretDataConfigDatumDTO
320-
if (!_data?.draftMetadata && !_data?.data && !_data?.defaultData) {
314+
if (!_data) {
321315
doesNotExist = true
322-
} else if (
323-
_data?.draftMetadata?.draftState === DraftState.Init ||
324-
_data?.draftMetadata?.draftState === DraftState.Init
325-
) {
316+
} else if (_data?.draftMetadata?.draftState === DraftState.Init) {
326317
isDraft = true
327-
} else if (
328-
_data?.draftMetadata?.draftState === DraftState.AwaitApproval ||
329-
_data?.draftMetadata?.draftState === DraftState.AwaitApproval
330-
) {
318+
} else if (_data?.draftMetadata?.draftState === DraftState.AwaitApproval) {
331319
isApprovalPending = true
332320
}
333321
}
@@ -385,7 +373,8 @@ const getConfigMapSecretData = (
385373

386374
return {
387375
id: `${resourceType === ConfigResourceType.ConfigMap ? EnvResourceType.ConfigMap : EnvResourceType.Secret}-${currentItem?.name || compareItem?.name}`,
388-
title: currentItem?.name || compareItem?.name,
376+
title: `${resourceType === ConfigResourceType.ConfigMap ? 'ConfigMap' : 'Secret'} / ${currentItem?.name || compareItem?.name}`,
377+
name: currentItem?.name || compareItem?.name,
389378
primaryConfig: {
390379
heading: getDiffHeading(compareItem),
391380
list: compareWithDiff,
@@ -406,14 +395,21 @@ const getConfigMapSecretData = (
406395
*
407396
* @param currentList - The current deployment configuration list.
408397
* @param compareList - The deployment configuration list to compare against.
409-
* @returns The combined deployment configuration list and an object indicating which configurations have changed.
398+
* @param getNavItemHref - A function to generate navigation item URLs based on the resource type and resource name.
399+
* @param sortOrder - (Optional) The order in which to sort the deployment templates.
400+
*
401+
* @returns An object containing the combined deployment configuration list, a collapsible navigation list, and a navigation list.
410402
*/
411403
export const getAppEnvDeploymentConfigList = (
412404
currentList: AppEnvDeploymentConfigDTO,
413405
compareList: AppEnvDeploymentConfigDTO,
414406
getNavItemHref: (resourceType: EnvResourceType, resourceName: string) => string,
415407
sortOrder?: SortingOrder,
416-
): Pick<DeploymentConfigDiffProps, 'configList' | 'collapsibleNavList' | 'navList'> => {
408+
): {
409+
configList: DeploymentConfigDiffProps['configList']
410+
navList: DeploymentConfigDiffProps['navList']
411+
collapsibleNavList: DeploymentConfigDiffProps['collapsibleNavList']
412+
} => {
417413
const currentDeploymentData = getDeploymentTemplateDiffViewData(currentList.deploymentTemplate, sortOrder)
418414
const compareDeploymentData = getDeploymentTemplateDiffViewData(compareList.deploymentTemplate, sortOrder)
419415

@@ -466,10 +462,10 @@ export const getAppEnvDeploymentConfigList = (
466462
{
467463
header: 'ConfigMaps',
468464
id: EnvResourceType.ConfigMap,
469-
items: cmData.map(({ title, hasDiff, id }) => ({
470-
title,
465+
items: cmData.map(({ name, hasDiff, id }) => ({
466+
title: name,
471467
hasDiff,
472-
href: getNavItemHref(EnvResourceType.ConfigMap, title),
468+
href: getNavItemHref(EnvResourceType.ConfigMap, name),
473469
onClick: () => {
474470
const element = document.querySelector(`#${id}`)
475471
element?.scrollIntoView({ block: 'start' })
@@ -480,10 +476,10 @@ export const getAppEnvDeploymentConfigList = (
480476
{
481477
header: 'Secrets',
482478
id: EnvResourceType.Secret,
483-
items: secretData.map(({ title, hasDiff, id }) => ({
484-
title,
479+
items: secretData.map(({ name, hasDiff, id }) => ({
480+
title: name,
485481
hasDiff,
486-
href: getNavItemHref(EnvResourceType.Secret, title),
482+
href: getNavItemHref(EnvResourceType.Secret, name),
487483
onClick: () => {
488484
const element = document.querySelector(`#${id}`)
489485
element?.scrollIntoView({ block: 'start' })

0 commit comments

Comments
 (0)