@@ -8,30 +8,28 @@ import RedisBaseNode from "./redisBaseNode";
8
8
export class FolderNode extends RedisBaseNode {
9
9
contextValue = ModelType . REDIS_FOLDER ;
10
10
readonly iconPath = path . join ( Constants . RES_PATH , `image/folder.svg` ) ;
11
- constructor ( readonly label : string , readonly prefix : string , readonly childens : string [ ] , readonly parent : Node ) {
11
+ constructor ( readonly label : string , readonly childens : string [ ] , readonly parent : Node ) {
12
12
super ( label )
13
13
this . init ( parent )
14
14
this . pattern = label
15
+ this . level = parent . hasOwnProperty ( 'level' ) ? parent . level + 1 : 0
15
16
}
16
17
17
18
public async getChildren ( ) {
18
- return FolderNode . buildChilds ( this , ` ${ this . prefix } ${ this . label } ` , this . childens )
19
+ return FolderNode . buildChilds ( this , this . childens )
19
20
}
20
21
21
- public static buildChilds ( parent : RedisBaseNode , parentPrefix : string , keys : string [ ] ) {
22
- if ( parentPrefix ) {
23
- parentPrefix = parentPrefix + ":"
24
- }
22
+ public static buildChilds ( parent : RedisBaseNode , keys : string [ ] ) {
25
23
const prefixMap : { [ key : string ] : string [ ] } = { }
26
24
for ( const key of keys . sort ( ) ) {
27
- let prefix = key . replace ( parentPrefix , "" ) . split ( ":" ) [ 0 ] ;
25
+ let prefix = key . split ( ":" ) [ parent . level ] ;
28
26
if ( ! prefixMap [ prefix ] ) prefixMap [ prefix ] = [ ]
29
27
prefixMap [ prefix ] . push ( key )
30
28
}
31
29
32
30
return Object . keys ( prefixMap ) . map ( ( prefix : string ) => {
33
31
if ( prefixMap [ prefix ] . length > 1 ) {
34
- return new FolderNode ( prefix , parentPrefix , prefixMap [ prefix ] , parent )
32
+ return new FolderNode ( prefix , prefixMap [ prefix ] , parent )
35
33
} else {
36
34
return new KeyNode ( prefixMap [ prefix ] [ 0 ] , prefix , parent )
37
35
}
0 commit comments