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

Check sort:options for Discover default sort order #13708

Merged
merged 3 commits into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions docs/management/advanced-options.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ adapt to the interval between measurements. Keys are http://en.wikipedia.org/wik
document.
`discover:sampleSize`:: The number of rows to show in the Discover table.
`discover:aggs:terms:size`:: Determines how many terms will be visualized when clicking the "visualize" button, in the field drop downs, in the discover sidebar. The default value is `20`.
`discover:sort:defaultOrder`:: Controls the default sort direction for time based index patterns in the Discover app.
`doc_table:highlight`:: Highlight results in Discover and Saved Searches Dashboard. Highlighting makes request slow when
working on big documents. Set this property to `false` to disable highlighting.
`courier:maxSegmentCount`:: Kibana splits requests in the Discover app into segments to limit the size of requests sent to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ function discoverController(
function getStateDefaults() {
return {
query: $scope.searchSource.get('query') || { query: '', language: config.get('search:queryLanguage') },
sort: getSort.array(savedSearch.sort, $scope.indexPattern),
sort: getSort.array(savedSearch.sort, $scope.indexPattern, { order: config.get('discover:sort:defaultOrder') }),
columns: savedSearch.columns.length > 0 ? savedSearch.columns : config.get('defaultColumns').slice(),
index: $scope.indexPattern.id,
interval: 'auto',
Expand Down
6 changes: 6 additions & 0 deletions src/core_plugins/kibana/ui_setting_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ export function getUiSettingDefaults() {
description: 'Determines how many terms will be visualized when clicking the "visualize" ' +
'button, in the field drop downs, in the discover sidebar.'
},
'discover:sort:defaultOrder': {
value: 'desc',
options: ['desc', 'asc'],
type: 'select',
description: 'Controls the default sort direction for time based index patterns in the Discover app.',
},
'doc_table:highlight': {
value: true,
description: 'Highlight results in Discover and Saved Searches Dashboard.' +
Expand Down
8 changes: 4 additions & 4 deletions src/ui/public/doc_table/lib/get_sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import _ from 'lodash';
* @param {object} indexPattern used for determining default sort
* @returns {object} a sort object suitable for returning to elasticsearch
*/
export function getSort(sort, indexPattern) {
export function getSort(sort, indexPattern, sortOptions = {}) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just passing defaultOrder here, since that is the only property in use right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 faba375

const sortObj = {};
let field;
let direction;
Expand All @@ -21,7 +21,7 @@ export function getSort(sort, indexPattern) {
direction = sort[1];
} else if (indexPattern.timeFieldName && isSortable(indexPattern.timeFieldName)) {
field = indexPattern.timeFieldName;
direction = 'desc';
direction = sortOptions.order || 'desc';
}

if (field) {
Expand All @@ -35,7 +35,7 @@ export function getSort(sort, indexPattern) {
return sortObj;
}

getSort.array = function (sort, indexPattern) {
return _(getSort(sort, indexPattern)).pairs().pop();
getSort.array = function (sort, indexPattern, sortOptions) {
return _(getSort(sort, indexPattern, sortOptions)).pairs().pop();
};