@@ -83,6 +83,11 @@ const getConfigData = (
83
83
cmSecretData : ConfigMapSecretDataConfigDatumDTO ,
84
84
type : ConfigResourceType ,
85
85
) : 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
+
86
91
const secretKeys = [ 'secretData' , 'esoSecretData' , 'defaultSecretData' , 'defaultESOSecretData' ]
87
92
88
93
if ( type === ConfigResourceType . Secret ) {
@@ -94,12 +99,7 @@ const getConfigData = (
94
99
95
100
const configmapKeys = [ 'data' , 'defaultData' ]
96
101
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 ]
103
103
}
104
104
105
105
/**
@@ -302,32 +302,20 @@ const getDiffHeading = <DeploymentTemplate extends boolean>(
302
302
303
303
if ( deploymentTemplate ) {
304
304
const _data = data as DeploymentTemplateDTO
305
- if ( ! _data ?. deploymentDraftData && ! _data ?. data ) {
305
+ if ( ! _data ) {
306
306
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 ) {
311
308
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 ) {
316
310
isApprovalPending = true
317
311
}
318
312
} else {
319
313
const _data = data as ConfigMapSecretDataConfigDatumDTO
320
- if ( ! _data ?. draftMetadata && ! _data ?. data && ! _data ?. defaultData ) {
314
+ if ( ! _data ) {
321
315
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 ) {
326
317
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 ) {
331
319
isApprovalPending = true
332
320
}
333
321
}
@@ -385,7 +373,8 @@ const getConfigMapSecretData = (
385
373
386
374
return {
387
375
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 ,
389
378
primaryConfig : {
390
379
heading : getDiffHeading ( compareItem ) ,
391
380
list : compareWithDiff ,
@@ -406,14 +395,21 @@ const getConfigMapSecretData = (
406
395
*
407
396
* @param currentList - The current deployment configuration list.
408
397
* @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.
410
402
*/
411
403
export const getAppEnvDeploymentConfigList = (
412
404
currentList : AppEnvDeploymentConfigDTO ,
413
405
compareList : AppEnvDeploymentConfigDTO ,
414
406
getNavItemHref : ( resourceType : EnvResourceType , resourceName : string ) => string ,
415
407
sortOrder ?: SortingOrder ,
416
- ) : Pick < DeploymentConfigDiffProps , 'configList' | 'collapsibleNavList' | 'navList' > => {
408
+ ) : {
409
+ configList : DeploymentConfigDiffProps [ 'configList' ]
410
+ navList : DeploymentConfigDiffProps [ 'navList' ]
411
+ collapsibleNavList : DeploymentConfigDiffProps [ 'collapsibleNavList' ]
412
+ } => {
417
413
const currentDeploymentData = getDeploymentTemplateDiffViewData ( currentList . deploymentTemplate , sortOrder )
418
414
const compareDeploymentData = getDeploymentTemplateDiffViewData ( compareList . deploymentTemplate , sortOrder )
419
415
@@ -466,10 +462,10 @@ export const getAppEnvDeploymentConfigList = (
466
462
{
467
463
header : 'ConfigMaps' ,
468
464
id : EnvResourceType . ConfigMap ,
469
- items : cmData . map ( ( { title , hasDiff, id } ) => ( {
470
- title,
465
+ items : cmData . map ( ( { name , hasDiff, id } ) => ( {
466
+ title : name ,
471
467
hasDiff,
472
- href : getNavItemHref ( EnvResourceType . ConfigMap , title ) ,
468
+ href : getNavItemHref ( EnvResourceType . ConfigMap , name ) ,
473
469
onClick : ( ) => {
474
470
const element = document . querySelector ( `#${ id } ` )
475
471
element ?. scrollIntoView ( { block : 'start' } )
@@ -480,10 +476,10 @@ export const getAppEnvDeploymentConfigList = (
480
476
{
481
477
header : 'Secrets' ,
482
478
id : EnvResourceType . Secret ,
483
- items : secretData . map ( ( { title , hasDiff, id } ) => ( {
484
- title,
479
+ items : secretData . map ( ( { name , hasDiff, id } ) => ( {
480
+ title : name ,
485
481
hasDiff,
486
- href : getNavItemHref ( EnvResourceType . Secret , title ) ,
482
+ href : getNavItemHref ( EnvResourceType . Secret , name ) ,
487
483
onClick : ( ) => {
488
484
const element = document . querySelector ( `#${ id } ` )
489
485
element ?. scrollIntoView ( { block : 'start' } )
0 commit comments