File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,8 +31,10 @@ export function buildParameterTree(parameters) {
3131 ( cumulativePath in parameters && parameters [ cumulativePath ] . label ) ||
3232 key ;
3333 // Transform e.g. "0]" -> 1
34+ let bracketIndex = 0 ;
3435 if ( key . endsWith ( "]" ) ) {
35- label = `Bracket ${ parseInt ( key . slice ( 0 , - 1 ) ) + 1 } ` ;
36+ bracketIndex = parseInt ( key . slice ( 0 , - 1 ) ) ;
37+ label = `Bracket ${ bracketIndex + 1 } ` ;
3638 }
3739 label = label . replaceAll ( "_" , " " ) ;
3840 if ( ! currentNode . children ) {
@@ -46,7 +48,7 @@ export function buildParameterTree(parameters) {
4648 currentNode . children . push ( {
4749 label : label ,
4850 name : cumulativePath ,
49- index : 0 ,
51+ index : bracketIndex ,
5052 children : [ ] ,
5153 } ) ;
5254 }
Original file line number Diff line number Diff line change @@ -75,7 +75,14 @@ function PolicyLeftSidebar(props) {
7575 const sortTreeInPlace = ( tree ) => {
7676 if ( ! Array . isArray ( tree ) ) return [ ] ;
7777
78- tree . sort ( ( a , b ) => a . label . localeCompare ( b . label ) ) ;
78+ // Check if all nodes are bracket nodes
79+ const allBrackets = tree . every ( ( item ) => / ^ B r a c k e t \d + $ / . test ( item . label ) ) ;
80+ // If all nodes are bracket nodes, sort numerically by index else sort alphabetically by label
81+ if ( allBrackets ) {
82+ tree . sort ( ( a , b ) => a . index - b . index ) ;
83+ } else {
84+ tree . sort ( ( a , b ) => a . label . localeCompare ( b . label ) ) ;
85+ }
7986
8087 tree . forEach ( ( item ) => {
8188 if ( Array . isArray ( item . children ) ) {
You can’t perform that action at this time.
0 commit comments