From b241b2d9156d270c8a1316557dc4061bd5068697 Mon Sep 17 00:00:00 2001 From: Matthew Irish Date: Thu, 22 Aug 2019 14:00:53 -0500 Subject: [PATCH] =?UTF-8?q?fix=20namespace=20picker=20so=20that=20it=20alw?= =?UTF-8?q?ays=20expands=20into=20an=20object=20when=20co=E2=80=A6=20(#733?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix namespace picker so that it always expands into an object when constructing a tree * sort namespaces lexicographically * fix linting --- ui/app/lib/path-to-tree.js | 3 +- ui/tests/unit/lib/path-to-tree-test.js | 48 ++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/ui/app/lib/path-to-tree.js b/ui/app/lib/path-to-tree.js index 254cd7fc2bc2..05423c4dfd36 100644 --- a/ui/app/lib/path-to-tree.js +++ b/ui/app/lib/path-to-tree.js @@ -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 }); }) ); } diff --git a/ui/tests/unit/lib/path-to-tree-test.js b/ui/tests/unit/lib/path-to-tree-test.js index 4c7788dabe83..6782f57f4cde 100644 --- a/ui/tests/unit/lib/path-to-tree-test.js +++ b/ui/tests/unit/lib/path-to-tree-test.js @@ -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]) {