@@ -16,7 +16,7 @@ import {Component, Injectable, OnDestroy, OnInit} from '@angular/core';
16
16
import { ActivatedRoute , ActivatedRouteSnapshot , Resolve , RouterStateSnapshot } from '@angular/router' ;
17
17
import { Config , ConfigParams , ConsoleService } from '../console.service' ;
18
18
import { Observable } from 'rxjs' ;
19
- import { safeDump } from 'js-yaml' ;
19
+ import { dump } from 'js-yaml' ;
20
20
import * as FileSaver from 'file-saver' ;
21
21
import { FileSystemFileEntry , NgxFileDropEntry } from 'ngx-file-drop' ;
22
22
import { HttpClient } from '@angular/common/http' ;
@@ -73,34 +73,26 @@ export class ConfigComponent implements OnInit, OnDestroy {
73
73
} ) ;
74
74
}
75
75
76
- private flattenConfig ( config : Config ) : any {
77
- const flatConfig = [ ] ;
78
- this . traverseConfig ( '' , config , flatConfig ) ;
79
- const sortedConfig = flatConfig . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ;
80
- return sortedConfig ;
81
- }
76
+ private flattenConfig ( data : any , currPath : string = '' ) : any [ ] {
77
+ let result : any [ ] = [ ]
82
78
83
- private traverseConfig ( prefix : string , config : any , flattened : any [ ] ) : void {
84
- for ( const key in config ) {
85
- if ( key === 'env' ) {
86
- // we'll separate out runtime environments into its own config handling
87
- continue ;
88
- }
79
+ Object . keys ( data ) . forEach ( ( key ) => {
80
+ const node = data [ key ]
81
+ const path = currPath ? `${ currPath } .${ key } ` : key
82
+
83
+ if ( ! key ) return
89
84
90
- if ( Array . isArray ( config [ key ] ) ) {
91
- flattened . push ( {
92
- name : prefix + key ,
93
- value : config [ key ] . join ( ', ' ) ,
94
- } ) ;
95
- } else if ( typeof config [ key ] === 'object' ) {
96
- this . traverseConfig ( key + '.' , config [ key ] , flattened ) ;
85
+ if ( node && typeof node === 'object' && ! Array . isArray ( node ) ) {
86
+ result = result . concat ( this . flattenConfig ( node , path ) )
97
87
} else {
98
- flattened . push ( {
99
- name : prefix + key ,
100
- value : config [ key ] ,
101
- } ) ;
88
+ result . push ( {
89
+ name : path ,
90
+ value : node ,
91
+ } )
102
92
}
103
- }
93
+ } )
94
+
95
+ return result
104
96
}
105
97
106
98
public isEmpty ( value : any ) : boolean {
@@ -114,7 +106,7 @@ export class ConfigComponent implements OnInit, OnDestroy {
114
106
}
115
107
116
108
public exportYaml ( ) : void {
117
- const blob = new Blob ( [ safeDump ( this . jsonConfig ) ] , { type : 'text/yaml;charset=utf-8' } ) ;
109
+ const blob = new Blob ( [ dump ( this . jsonConfig ) ] , { type : 'text/yaml;charset=utf-8' } ) ;
118
110
FileSaver . saveAs ( blob , 'config.yaml' ) ;
119
111
}
120
112
0 commit comments