Skip to content

Commit d00e1bb

Browse files
fixing the issue with generating the list of plugin names for the dropdown menu. Hopefully this will also pass the tests (it does locally)
1 parent 2d1ae35 commit d00e1bb

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

app/components/slow-node-times.js

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,25 @@ export default Ember.Component.extend({
5151
if (pluginNameFilter) {
5252
nodes = nodes.filter((node) => {
5353
return (node.label.broccoliNode &&
54-
node.label.broccoliPluginName &&
55-
pluginNameFilter === node.label.broccoliPluginName);
54+
(pluginNameFilter === node.label.broccoliPluginName ||
55+
pluginNameFilter === 'undefined' && node.label.broccoliPluginName === undefined));
5656
});
5757
}
5858

59+
// Note: the following is also gathering stats for the items that
60+
// have no broccoliPluginName (the 'name' is undefined).
5961
let groupByPluginName = this.get('groupByPluginName');
6062
if (groupByPluginName) {
63+
let pluginNameMap = nodes.reduce((memo, node) => {
64+
let pluginName = node.label.broccoliPluginName;
65+
memo[pluginName] = memo[pluginName] || { count: 0, time: 0 };
66+
memo[pluginName].time += node._stats.time.plugin;
67+
memo[pluginName].count++;
68+
return memo;
69+
}, {});
6170

6271
nodes = [];
72+
6373
for (let pluginName in pluginNameMap) {
6474
nodes.push({
6575
groupedByPluginName: true,
@@ -74,25 +84,33 @@ export default Ember.Component.extend({
7484
return nodes;
7585
}).readOnly(),
7686

77-
pluginNameMap: computed('nodes', function() {
87+
pluginNames: computed('nodes', function() {
7888
let nodes = this.get('nodes');
79-
return nodes.reduce((memo, node) => {
80-
let pluginName = node.label.broccoliPluginName;
81-
memo[pluginName] = memo[pluginName] || { count: 0, time: 0 };
82-
memo[pluginName].time += node._stats.time.plugin;
83-
memo[pluginName].count++;
84-
return memo;
85-
}, {});
86-
}).readOnly(),
89+
if (!nodes || nodes.length === 0) {
90+
return [];
91+
}
8792

88-
pluginNames: computed('pluginNameMap', function() {
89-
var keys = Object.keys(this.get('pluginNameMap'));
90-
var undefIndex = keys.indexOf('undefined');
91-
if (undefIndex >= 0) {
92-
keys.splice(undefIndex, 1);
93+
// If the first item in the list is an object with
94+
// 'groupedByPluginName' = true, we just need to pull
95+
// off the label as the plugin name. If not, we need
96+
// to create a map of the plugin names and return that.
97+
let pluginNames = [];
98+
99+
if (nodes[0].groupedByPluginName === true) {
100+
pluginNames = nodes.map(node => node.label.name);
101+
} else {
102+
let pluginNameMap = nodes.reduce((memo, node) => {
103+
let pluginName = node.label.broccoliPluginName;
104+
memo[pluginName] = pluginName;
105+
return memo;
106+
}, {});
107+
108+
pluginNames = Object.keys(pluginNameMap);
93109
}
94-
keys.sort();
95-
return keys;
110+
111+
pluginNames.sort();
112+
113+
return pluginNames;
96114
}).readOnly(),
97115

98116
sortedNodes: computed('nodes', 'sortDescending', function() {

0 commit comments

Comments
 (0)