Filter unused categories from ratings browser
#CTCTOWALTZ-1028
@@ -85,8 +85,10 @@ function prepareTreeData(data = []) {
function prepareTabs(categories = [], measurables = [], ratingSchemesById = {}) {
const measurablesByCategory = _.groupBy(measurables, 'categoryId');
-
- const tabs = _.map(categories, category => {
+ return _
+ .chain(categories)
+ .filter(category => _.get(measurablesByCategory, category.id, []).length > 0)
+ .map(category => {
const measurablesForCategory = measurablesByCategory[category.id];
const treeData = prepareTreeData(measurablesForCategory);
const maxSize = _.chain(treeData)
@@ -101,9 +103,9 @@ function prepareTabs(categories = [], measurables = [], ratingSchemesById = {})
maxSize,
expandedNodes: []
};
- });
-
- return _.sortBy(tabs, 'category.name');
+ })
+ .sortBy('category.name')
+ .value();
}
@@ -128,8 +130,7 @@ function initialiseRatingTalliesMap(ratingTallies = [], measurables = []) {
};
return acc;
};
- const talliesMap = _.reduce(measurables, reducer, {});
- return talliesMap;
+ return _.reduce(measurables, reducer, {});
}
@@ -160,7 +161,6 @@ function controller(serviceBroker) {
_.isEmpty(vm.ratingTallies) ||
_.isEmpty(vm.categories) ||
_.isEmpty(vm.ratingSchemesById)) {
- return;
} else {
vm.tabs = prepareTabs(vm.categories, vm.measurables, vm.ratingSchemesById);
vm.ratingsMap = mkRatingTalliesMap(vm.ratingTallies, vm.measurables);
