Skip to content

Commit 47834cf

Browse files
author
Trent Willis
committed
Implement table sorting for time
1 parent e016eee commit 47834cf

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

app/components/slow-node-times.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function nodeTime(node) {
2727
export default Ember.Component.extend({
2828
graph: inject.service(),
2929

30+
sortDescending: true,
31+
3032
nodes: computed('data', 'filter', 'pluginNameFilter', 'groupByPluginName', function() {
3133
let data = this.get('data');
3234
if (!data) { return []; }
@@ -74,12 +76,17 @@ export default Ember.Component.extend({
7476
}
7577
}
7678

77-
let sortedNodes = nodes
78-
.sort((a, b) => {
79-
return b._stats.time.plugin - a._stats.time.plugin;
80-
});
79+
return nodes;
80+
}),
8181

82-
return sortedNodes;
82+
sortedNodes: computed('nodes', 'sortDescending', function() {
83+
return this.get('nodes').sort((a, b) => {
84+
if (this.get('sortDescending')) {
85+
return b._stats.time.plugin - a._stats.time.plugin;
86+
} else {
87+
return a._stats.time.plugin - b._stats.time.plugin;
88+
}
89+
});
8390
}),
8491

8592
totalTime: computed('nodes', function() {
@@ -103,6 +110,10 @@ export default Ember.Component.extend({
103110
let shown = get(node, 'showDetails');
104111
set(node, 'showDetails', !shown);
105112
}
113+
},
114+
115+
toggleTime() {
116+
this.toggleProperty('sortDescending');
106117
}
107118
}
108119
});

app/styles/app.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ body {
5050
left: 0;
5151
}
5252

53+
.nodes-table_header tr:hover {
54+
background-color: initial;
55+
}
56+
57+
.nodes-table_toggle {
58+
color: inherit;
59+
}
60+
5361
.table-row:hover {
5462
cursor: pointer;
5563
}

app/templates/components/slow-node-times.hbs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@
2121
</div>
2222
</div>
2323

24-
<table class="table is-striped">
25-
<thead>
24+
<table class="nodes-table table is-striped">
25+
<thead class="nodes-table_header">
2626
<tr>
2727
<td style="width: 65%">Description</td>
2828
<td>{{if groupByPluginName "Count" "Plugin Name"}}</td>
29-
<td>Time (ms)</td>
29+
<td>
30+
<a href="#" class="nodes-table_toggle" {{action "toggleTime"}}>Time (ms) <i class="fa fa-caret-{{if sortDescending 'down' 'up'}}"></i></a>
31+
</td>
3032
</tr>
3133
</thead>
34+
3235
<tbody>
33-
{{#each nodes as |node|}}
36+
{{#each sortedNodes as |node|}}
3437
<tr class="table-row" {{action 'toggleDetailsForNode' node}}>
3538
<td>{{node.label.name}}</td>
3639
<td>{{node.label.broccoliPluginName}}</td>

0 commit comments

Comments
 (0)