Skip to content

Commit

Permalink
fix namespace picker so that it always expands into an object when co… (
Browse files Browse the repository at this point in the history
#7333)

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

* sort namespaces lexicographically

* fix linting
  • Loading branch information
meirish authored Aug 22, 2019
1 parent fdb788d commit b241b2d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ui/app/lib/path-to-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ 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
// to a nested object that we can then query with Ember.get
return deepmerge.all(
tree.map(p => {
p = p.replace(/\.+/g, DOT_REPLACEMENT);
return unflatten({ [p]: null }, { delimiter: '/' });
return unflatten({ [p]: null }, { delimiter: '/', object: true });
})
);
}
48 changes: 48 additions & 0 deletions ui/tests/unit/lib/path-to-tree-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down

0 comments on commit b241b2d

Please sign in to comment.