@@ -23,44 +23,42 @@ export type Resource = {
2323 status ?: unknown ;
2424} ;
2525
26- export const removeManagedFieldsAndFilterData = ( resourceObject : Resource , showOnlyImportantData : boolean ) => {
27- if ( resourceObject ?. metadata ?. managedFields ) {
28- return {
29- ...resourceObject ,
30- metadata : {
31- ...resourceObject . metadata ,
32- managedFields : undefined ,
33- annotations : {
34- ...resourceObject . metadata . annotations ,
35- [ LAST_APPLIED_CONFIGURATION_ANNOTATION ] : showOnlyImportantData
36- ? undefined
37- : resourceObject ?. metadata ?. annotations ?. [ LAST_APPLIED_CONFIGURATION_ANNOTATION ] ,
38- } ,
39- generation : showOnlyImportantData ? undefined : resourceObject ?. metadata ?. generation ,
40- uid : showOnlyImportantData ? undefined : resourceObject ?. metadata ?. uid ,
41- } ,
42- } ;
26+ const cleanUpResource = (
27+ resource : Omit < Resource , 'items' > ,
28+ showOnlyImportantData : boolean ,
29+ ) : Omit < Resource , 'items' > => {
30+ const newResource = { ...resource } ;
31+
32+ if ( newResource . metadata ) {
33+ newResource . metadata = { ...newResource . metadata } ;
34+ delete newResource . metadata . managedFields ;
35+
36+ if ( showOnlyImportantData ) {
37+ if ( newResource . metadata . annotations ) {
38+ newResource . metadata . annotations = { ...newResource . metadata . annotations } ;
39+ delete newResource . metadata . annotations [ LAST_APPLIED_CONFIGURATION_ANNOTATION ] ;
40+ }
41+ delete newResource . metadata . generation ;
42+ delete newResource . metadata . uid ;
43+ }
44+ }
45+
46+ return newResource ;
47+ } ;
48+
49+ export const removeManagedFieldsAndFilterData = (
50+ resourceObject : Resource ,
51+ showOnlyImportantData : boolean ,
52+ ) : Resource => {
53+ if ( ! resourceObject ) {
54+ return { } as Resource ;
4355 }
44- if ( resourceObject ? .items ) {
56+ if ( resourceObject . items ) {
4557 return {
46- ...resourceObject ,
47- items : resourceObject . items . map ( ( item ) => ( {
48- ...item ,
49- metadata : {
50- ...item . metadata ,
51- managedFields : undefined ,
52- annotations : {
53- ...item . metadata . annotations ,
54- [ LAST_APPLIED_CONFIGURATION_ANNOTATION ] : showOnlyImportantData
55- ? undefined
56- : resourceObject ?. metadata ?. annotations ?. [ LAST_APPLIED_CONFIGURATION_ANNOTATION ] ,
57- } ,
58- generation : showOnlyImportantData ? undefined : resourceObject ?. metadata ?. generation ,
59- uid : showOnlyImportantData ? undefined : resourceObject ?. metadata ?. uid ,
60- } ,
61- } ) ) ,
58+ ...cleanUpResource ( resourceObject , showOnlyImportantData ) ,
59+ items : resourceObject . items . map ( ( item ) => cleanUpResource ( item , showOnlyImportantData ) ) ,
6260 } ;
6361 }
6462
65- return resourceObject ;
63+ return cleanUpResource ( resourceObject , showOnlyImportantData ) ;
6664} ;
0 commit comments