Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/paginated table sort #2275

Merged
merged 4 commits into from
Dec 12, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/kibana/components/paginated_table/paginated_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,17 @@ define(function (require) {
};

// update the sordedRows result
$scope.$watchMulti([
'paginatedTable.sort.direction',
'rows'
], function () {
$scope.$watch('rows', rowSorter);
$scope.$watchCollection('paginatedTable.sort', rowSorter);

function rowSorter() {
if (self.sort.direction == null) {
$scope.sortedRows = $scope.rows.slice(0);
return;
}

$scope.sortedRows = orderBy($scope.rows, self.sort.getter, self.sort.direction === 'desc');
});
}
}
};
});
Expand Down
1 change: 0 additions & 1 deletion src/kibana/components/visualize/spy/_req_resp_stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<div ng-show="spyMode.name === 'request'">
<label>
Elasticsearch request body &nbsp;
<kbn-clipboard copy="history.req | json"></kbn-clipboard>
</label>
<pre>{{history.req | json}}</pre>
</div>
Expand Down
26 changes: 21 additions & 5 deletions test/unit/specs/components/paginated_table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ define(function (require) {

beforeEach(function () {
data = makeData(3, 0);
data.rows.push(['bbbb', 'bbbb', 'bbbb']);
data.rows.push(['cccc', 'cccc', 'cccc']);
data.rows.push(['zzzz', 'zzzz', 'zzzz']);
data.rows.push(['aaaa', 'aaaa', 'aaaa']);
data.rows.push(['bbbb', 'aaaa', 'zzzz']);
data.rows.push(['cccc', 'cccc', 'aaaa']);
data.rows.push(['zzzz', 'bbbb', 'bbbb']);
data.rows.push(['aaaa', 'zzzz', 'cccc']);

lastRowIndex = data.rows.length - 1;
renderTable(data.columns, data.rows);
Expand All @@ -131,16 +131,18 @@ define(function (require) {
// sortColumn
paginatedTable.sortColumn(data.columns[0]);
$scope.$digest();

var tableRows = $el.find('tbody tr');
expect(tableRows.eq(0).find('td').eq(0).text()).to.be('aaaa');
expect(tableRows.eq(lastRowIndex).find('td').eq(0).text()).to.be('zzzz');
});

it('should sort desciending on second invocation', function () {
it('should sort descending on second invocation', function () {
// sortColumn
paginatedTable.sortColumn(data.columns[0]);
paginatedTable.sortColumn(data.columns[0]);
$scope.$digest();

var tableRows = $el.find('tbody tr');
expect(tableRows.eq(0).find('td').eq(0).text()).to.be('zzzz');
expect(tableRows.eq(lastRowIndex).find('td').eq(0).text()).to.be('aaaa');
Expand All @@ -152,10 +154,24 @@ define(function (require) {
paginatedTable.sortColumn(data.columns[0]);
paginatedTable.sortColumn(data.columns[0]);
$scope.$digest();

var tableRows = $el.find('tbody tr');
expect(tableRows.eq(0).find('td').eq(0).text()).to.be(data.rows[0][0]);
expect(tableRows.eq(lastRowIndex).find('td').eq(0).text()).to.be('aaaa');
});

it('should sort new column ascending', function () {
// sort by first column
paginatedTable.sortColumn(data.columns[0]);
$scope.$digest();
// sort by second column
paginatedTable.sortColumn(data.columns[1]);
$scope.$digest();

var tableRows = $el.find('tbody tr');
expect(tableRows.eq(0).find('td').eq(1).text()).to.be('aaaa');
expect(tableRows.eq(lastRowIndex).find('td').eq(1).text()).to.be('zzzz');
});
});

describe('custom sorting', function () {
Expand Down