Skip to content
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
11 changes: 11 additions & 0 deletions src/platform/plugins/shared/data_views/common/data_view.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { DataViewType } from './types';
import { stubFieldSpecMap, stubLogstashFieldSpecMap } from './field.stub';
import { createStubDataView } from './data_views/data_view.stub';
export {
Expand All @@ -23,6 +24,16 @@ export const stubDataView = createStubDataView({
},
});

export const stubRollupDataView = createStubDataView({
spec: {
id: 'logstash-*',
fields: stubFieldSpecMap,
title: 'logstash-*',
timeFieldName: '@timestamp',
type: DataViewType.ROLLUP,
},
});

export const stubIndexPattern = stubDataView;

export const stubDataViewWithoutTimeField = createStubDataView({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@

import type { SortOrder } from '@kbn/saved-search-plugin/public';
import { getSortForSearchSource } from './get_sort_for_search_source';
import { stubDataView, stubDataViewWithoutTimeField } from '@kbn/data-plugin/common/stubs';
import {
stubDataView,
stubDataViewWithoutTimeField,
stubRollupDataView,
} from '@kbn/data-plugin/common/stubs';

describe('getSortForSearchSource function', function () {
test('should be a function', function () {
Expand Down Expand Up @@ -94,4 +98,24 @@ describe('getSortForSearchSource function', function () {
})
).toEqual([{ _score: 'asc' }]);
});

test('should return an object including format when data view is not a rollup', function () {
expect(
getSortForSearchSource({
sort: [['@timestamp', 'desc']],
dataView: stubDataView,
defaultSortDir: 'desc',
})
).toEqual([{ '@timestamp': { format: 'strict_date_optional_time', order: 'desc' } }]);
});

test('should not return an object excluding format when data view is a rollup', function () {
expect(
getSortForSearchSource({
sort: [['@timestamp', 'desc']],
dataView: stubRollupDataView,
defaultSortDir: 'desc',
})
).toEqual([{ '@timestamp': 'desc' }]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import type { DataView } from '@kbn/data-views-plugin/common';
import { type DataView, DataViewType } from '@kbn/data-views-plugin/common';
import type { EsQuerySortValue, SortDirection } from '@kbn/data-plugin/common';
import type { SortOrder } from '@kbn/saved-search-plugin/public';
import { getSort } from './get_sort';
Expand Down Expand Up @@ -50,7 +50,7 @@ export function getSortForSearchSource({
const sortPairs = getSort(sort, dataView, false); // ES|QL request is not using search source

const sortForSearchSource = sortPairs.map((sortPair: Record<string, string>) => {
if (timeFieldName && sortPair[timeFieldName]) {
if (dataView.type !== DataViewType.ROLLUP && timeFieldName && sortPair[timeFieldName]) {
return getESQuerySortForTimeField({
sortDir: sortPair[timeFieldName] as SortDirection,
timeFieldName,
Expand Down