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

Prevent Discover from fetching twice on initial load #57010

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,11 @@ function discoverController(
if (!sort) return;

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

// if the searchSource doesn't know, tell it so
if (!angular.equals(sort, currentSort)) $fetchObservable.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import _ from 'lodash';
import { IndexPattern } from '../../../../../../../../../plugins/data/public';
import { getDefaultSort } from './get_default_sort';

export type SortPairObj = Record<string, string>;
export type SortPairArr = [string, string];
Expand Down Expand Up @@ -53,8 +54,16 @@ function createSortObject(
* @param {object} indexPattern used for determining default sort
* @returns Array<{object}> an array of sort objects
*/
export function getSort(sort: SortPair[], indexPattern: IndexPattern): SortPairObj[] {
export function getSort(
sort: SortPair[],
indexPattern: IndexPattern,
defaultDirection?: string
): SortPairObj[] {
if (Array.isArray(sort)) {
if (sort.length === 0 && defaultDirection) {
sort = getDefaultSort(indexPattern, defaultDirection);
}

return sort
.map((sortPair: SortPair) => createSortObject(sortPair, indexPattern))
.filter(sortPairObj => typeof sortPairObj === 'object') as SortPairObj[];
Expand Down