fix namespace picker so that it always expands into an object when co… (#7333)

* fix namespace picker so that it always expands into an object when constructing a tree

* sort namespaces lexicographically

* fix linting
This commit is contained in:
Matthew Irish 2019-08-22 14:00:53 -05:00 committed by GitHub
parent 9147ae64bc
commit ca80c9fa79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 1 deletions

View File

@ -38,6 +38,7 @@ export default function(paths) {
return accumulator;
}, []);
tree = tree.sort((a, b) => a.localeCompare(b));
// after the reduction we're left with an array that contains
// strings that represent the longest branches
// we'll replace the dots in the paths, then expand the path
@ -45,7 +46,7 @@ export default function(paths) {
return deepmerge.all(
tree.map(p => {
p = p.replace(/\.+/g, DOT_REPLACEMENT);
return unflatten({ [p]: null }, { delimiter: '/' });
return unflatten({ [p]: null }, { delimiter: '/', object: true });
})
);
}

View File

@ -49,6 +49,54 @@ module('Unit | Lib | path to tree', function() {
},
},
],
[
'leaves with nested number and shared prefix',
['ns1', 'ns1a', 'ns1a/99999/five9s', 'ns1a/999/ns3', 'ns1a/9999/ns3'],
{
ns1: null,
ns1a: {
999: {
ns3: null,
},
9999: {
ns3: null,
},
99999: {
five9s: null,
},
},
},
],
[
'sorting lexicographically',
[
'99',
'bat',
'bat/bird',
'animal/flying/birds',
'animal/walking/dogs',
'animal/walking/cats',
'1/thing',
],
{
1: {
thing: null,
},
99: null,
animal: {
flying: {
birds: null,
},
walking: {
cats: null,
dogs: null,
},
},
bat: {
bird: null,
},
},
],
];
tests.forEach(function([name, input, expected]) {