Skip to content

Commit

Permalink
Migrate get_sort.js test from mocha to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
kertal committed Jan 27, 2020
1 parent 94297f3 commit 09c58c2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 115 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import '../components/field_chooser/field_chooser';

// doc table
import './doc_table';
import { getSort } from './doc_table/lib/get_sort';
import { getSortArray } from './doc_table/lib/get_sort';
import { getSortForSearchSource } from './doc_table/lib/get_sort_for_search_source';
import * as columnActions from './doc_table/actions/columns';

Expand Down Expand Up @@ -522,7 +522,7 @@ function discoverController(
language:
localStorage.get('kibana.userQueryLanguage') || config.get('search:queryLanguage'),
},
sort: getSort.array(savedSearch.sort, $scope.indexPattern),
sort: getSortArray(savedSearch.sort, $scope.indexPattern),
columns:
savedSearch.columns.length > 0 ? savedSearch.columns : config.get('defaultColumns').slice(),
index: $scope.indexPattern.id,
Expand All @@ -534,7 +534,7 @@ function discoverController(
}

$state.index = $scope.indexPattern.id;
$state.sort = getSort.array($state.sort, $scope.indexPattern);
$state.sort = getSortArray($state.sort, $scope.indexPattern);

$scope.getBucketIntervalToolTipText = () => {
return i18n.translate('kbn.discover.bucketIntervalTooltip', {
Expand Down Expand Up @@ -615,10 +615,7 @@ function discoverController(
if (!sort) return;

// get the current sort from searchSource as array of arrays
const currentSort = getSort.array(
$scope.searchSource.getField('sort'),
$scope.indexPattern
);
const currentSort = getSortArray($scope.searchSource.getField('sort'), $scope.indexPattern);

// if the searchSource doesn't know, tell it so
if (!angular.equals(sort, currentSort)) $scope.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@
import { IIndexPattern } from '../../../../../../../../../plugins/data/public';
import { SortOrder } from '../components/table_header/helpers';

export type SortInput =
| Record<string, string>
| SortOrder
| SortOrder[]
| Array<Record<string, string>>
| string[];

export function getSort(
sort?: SortOrder[],
sort?: SortInput,
indexPattern?: IIndexPattern,
defaultSortOrder?: SortOrder
defaultSortOrder?: string
): any;

export function getSortArray(sort: SortInput, indexPattern?: IIndexPattern): any;
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export function getSort(sort, indexPattern) {
return [];
}

getSort.array = function(sort, indexPattern) {
export function getSortArray(sort, indexPattern) {
return getSort(sort, indexPattern).map(sortPair =>
_(sortPair)
.pairs()
.pop()
);
};
}

0 comments on commit 09c58c2

Please sign in to comment.