@@ -51,15 +51,25 @@ export default Ember.Component.extend({
51
51
if ( pluginNameFilter ) {
52
52
nodes = nodes . filter ( ( node ) => {
53
53
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 ) ) ;
56
56
} ) ;
57
57
}
58
58
59
+ // Note: the following is also gathering stats for the items that
60
+ // have no broccoliPluginName (the 'name' is undefined).
59
61
let groupByPluginName = this . get ( 'groupByPluginName' ) ;
60
62
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
+ } , { } ) ;
61
70
62
71
nodes = [ ] ;
72
+
63
73
for ( let pluginName in pluginNameMap ) {
64
74
nodes . push ( {
65
75
groupedByPluginName : true ,
@@ -74,25 +84,33 @@ export default Ember.Component.extend({
74
84
return nodes ;
75
85
} ) . readOnly ( ) ,
76
86
77
- pluginNameMap : computed ( 'nodes' , function ( ) {
87
+ pluginNames : computed ( 'nodes' , function ( ) {
78
88
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
+ }
87
92
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 ) ;
93
109
}
94
- keys . sort ( ) ;
95
- return keys ;
110
+
111
+ pluginNames . sort ( ) ;
112
+
113
+ return pluginNames ;
96
114
} ) . readOnly ( ) ,
97
115
98
116
sortedNodes : computed ( 'nodes' , 'sortDescending' , function ( ) {
0 commit comments