Skip to content

Commit

Permalink
Merge pull request #1940 from lukasolson/issue-1933
Browse files Browse the repository at this point in the history
Don't allow sorting on unsortable field types
  • Loading branch information
lukasolson committed Nov 19, 2014
2 parents b8a068a + 1baa52c commit bb906f0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
11 changes: 8 additions & 3 deletions src/kibana/plugins/discover/directives/table_header.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ define(function (require) {
},
template: headerHtml,
controller: function ($scope) {
var unsortableFields = ['geo_point', 'geo_shape', 'attachment'];
var sortableField = function (field) {
var mapping = $scope.mapping[field];
return mapping && mapping.indexed && !_.contains(unsortableFields, mapping.type);
};

$scope.headerClass = function (column) {
if (!$scope.mapping) return;
if ($scope.mapping[column] && !$scope.mapping[column].indexed) return;
if (!sortableField(column)) return;

var sorting = $scope.sorting;
var defaultClass = ['fa', 'fa-sort', 'table-header-sortchange'];
Expand Down Expand Up @@ -45,7 +50,7 @@ define(function (require) {
};

$scope.sort = function (column) {
if ($scope.mapping[column] && !$scope.mapping[column].indexed) return;
if (!sortableField(column)) return;
var sorting = $scope.sorting || [];
$scope.sorting = [column, sorting[1] === 'asc' ? 'desc' : 'asc'];
};
Expand Down
27 changes: 15 additions & 12 deletions test/unit/specs/apps/discover/directives/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define(function (require) {

var $parentScope, $scope, config;

// Stub out a minimal mapping of 3 fields
// Stub out a minimal mapping of 4 fields
var mapping = {
bytes: {
indexed: true,
Expand All @@ -26,6 +26,10 @@ define(function (require) {
timestamp: {
indexed: true,
type: 'date'
},
geo: {
indexed: true,
type: 'geo_point'
}
};

Expand Down Expand Up @@ -156,6 +160,11 @@ define(function (require) {
done();
});

it('should NOT sort geo_point fields', function (done) {
$scope.sort('geo');
expect($scope.sorting).to.be(undefined);
done();
});
});

describe('moving columns', function () {
Expand All @@ -174,10 +183,10 @@ define(function (require) {
});

it('shouldnt move the last column to the right', function () {
expect($scope.columns[2]).to.be('timestamp');
expect($scope.columns[3]).to.be('geo');

$scope.moveRight('timestamp');
expect($scope.columns[2]).to.be('timestamp');
$scope.moveRight('geo');
expect($scope.columns[3]).to.be('geo');
});

it('should move columns to the left', function () {
Expand Down Expand Up @@ -334,13 +343,7 @@ define(function (require) {
it('should have a row for each field', function () {
var rows = $details.find('tr');
var row = $scope.row;
expect($details.find('tr').length).to.be(3);
});

it('should have a row for each field', function () {
var rows = $details.find('tr');
var row = $scope.row;
expect($details.find('tr').length).to.be(3);
expect($details.find('tr').length).to.be(_.keys(mapping).length);
});

describe('filtering', function () {
Expand Down Expand Up @@ -397,7 +400,7 @@ define(function (require) {
});

it('should render even when the row source contains a field with the same name as a meta field', function () {
expect($details.find('tr').length).to.be(4);
expect($details.find('tr').length).to.be(_.keys(mapping).length);
});
});

Expand Down

0 comments on commit bb906f0

Please sign in to comment.