[Discover] Sort option: Introduce format parameter (#96774)
* [Discover] Updating a functional test * [Discover] Context view: add support for date nanos custom * Remove unnecessary change to a functional test * Fix failing unit tests * Remove unnecessary intialization * Add new type definition to data plugin * Update docs * Simplify return statement * Removing unnecessary type export Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
ce6d2f5a50
commit
5035230190
|
@ -7,5 +7,5 @@
|
|||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export declare type EsQuerySortValue = Record<string, SortDirection | SortDirectionNumeric>;
|
||||
export declare type EsQuerySortValue = Record<string, SortDirection | SortDirectionNumeric | SortDirectionFormat>;
|
||||
```
|
||||
|
|
|
@ -42,12 +42,20 @@ export enum SortDirection {
|
|||
desc = 'desc',
|
||||
}
|
||||
|
||||
export interface SortDirectionFormat {
|
||||
order: SortDirection;
|
||||
format?: string;
|
||||
}
|
||||
|
||||
export interface SortDirectionNumeric {
|
||||
order: SortDirection;
|
||||
numeric_type?: 'double' | 'long' | 'date' | 'date_nanos';
|
||||
}
|
||||
|
||||
export type EsQuerySortValue = Record<string, SortDirection | SortDirectionNumeric>;
|
||||
export type EsQuerySortValue = Record<
|
||||
string,
|
||||
SortDirection | SortDirectionNumeric | SortDirectionFormat
|
||||
>;
|
||||
|
||||
interface SearchField {
|
||||
[key: string]: SearchFieldValue;
|
||||
|
|
|
@ -832,10 +832,11 @@ export interface EsQueryConfig {
|
|||
}
|
||||
|
||||
// Warning: (ae-forgotten-export) The symbol "SortDirectionNumeric" needs to be exported by the entry point index.d.ts
|
||||
// Warning: (ae-forgotten-export) The symbol "SortDirectionFormat" needs to be exported by the entry point index.d.ts
|
||||
// Warning: (ae-missing-release-tag) "EsQuerySortValue" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
export type EsQuerySortValue = Record<string, SortDirection | SortDirectionNumeric>;
|
||||
export type EsQuerySortValue = Record<string, SortDirection | SortDirectionNumeric | SortDirectionFormat>;
|
||||
|
||||
// Warning: (ae-forgotten-export) The symbol "ExpressionTypeDefinition" needs to be exported by the entry point index.d.ts
|
||||
// Warning: (ae-forgotten-export) The symbol "name" needs to be exported by the entry point index.d.ts
|
||||
|
|
|
@ -66,7 +66,7 @@ export function createContextSearchSourceStub(hits, timeField = '@timestamp') {
|
|||
const lastQuery = searchSourceStub.setField.withArgs('query').lastCall.args[1];
|
||||
const timeRange = lastQuery.query.bool.must.constant_score.filter.range[timeField];
|
||||
const lastSort = searchSourceStub.setField.withArgs('sort').lastCall.args[1];
|
||||
const sortDirection = lastSort[0][timeField];
|
||||
const sortDirection = lastSort[0][timeField].order;
|
||||
const sortFunction =
|
||||
sortDirection === 'asc'
|
||||
? (first, second) => first[timeField] - second[timeField]
|
||||
|
|
|
@ -211,7 +211,10 @@ describe('context app', function () {
|
|||
[]
|
||||
).then(() => {
|
||||
expect(
|
||||
mockSearchSource.setField.calledWith('sort', [{ '@timestamp': 'asc' }, { _doc: 'asc' }])
|
||||
mockSearchSource.setField.calledWith('sort', [
|
||||
{ '@timestamp': { order: 'asc', format: 'strict_date_optional_time' } },
|
||||
{ _doc: 'asc' },
|
||||
])
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -215,7 +215,10 @@ describe('context app', function () {
|
|||
[]
|
||||
).then(() => {
|
||||
expect(
|
||||
mockSearchSource.setField.calledWith('sort', [{ '@timestamp': 'desc' }, { _doc: 'desc' }])
|
||||
mockSearchSource.setField.calledWith('sort', [
|
||||
{ '@timestamp': { order: 'desc', format: 'strict_date_optional_time' } },
|
||||
{ _doc: 'desc' },
|
||||
])
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -87,7 +87,7 @@ function fetchContextProvider(indexPatterns: IndexPatternsContract, useNewFields
|
|||
useNewFieldsApi
|
||||
);
|
||||
|
||||
const sort = getEsQuerySort(timeField, tieBreakerField, sortDirToApply);
|
||||
const sort = getEsQuerySort(timeField, tieBreakerField, sortDirToApply, nanos);
|
||||
|
||||
const hits = await fetchHitsInInterval(
|
||||
searchSource,
|
||||
|
|
|
@ -14,11 +14,21 @@ import { EsQuerySortValue, SortDirection } from '../../../../../kibana_services'
|
|||
* @param timeField
|
||||
* @param tieBreakerField
|
||||
* @param sortDir
|
||||
* @param nanos
|
||||
*/
|
||||
export function getEsQuerySort(
|
||||
timeField: string,
|
||||
tieBreakerField: string,
|
||||
sortDir: SortDirection
|
||||
sortDir: SortDirection,
|
||||
nanos?: string
|
||||
): [EsQuerySortValue, EsQuerySortValue] {
|
||||
return [{ [timeField]: sortDir }, { [tieBreakerField]: sortDir }];
|
||||
return [
|
||||
{
|
||||
[timeField]: {
|
||||
order: sortDir,
|
||||
format: nanos ? 'strict_date_optional_time_nanos' : 'strict_date_optional_time',
|
||||
},
|
||||
},
|
||||
{ [tieBreakerField]: sortDir },
|
||||
];
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ export default function ({ getService, getPageObjects }) {
|
|||
await kibanaServer.uiSettings.update({
|
||||
'context:defaultSize': `${TEST_DEFAULT_CONTEXT_SIZE}`,
|
||||
'context:step': `${TEST_STEP_SIZE}`,
|
||||
'discover:searchFieldsFromSource': true,
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -35,9 +34,9 @@ export default function ({ getService, getPageObjects }) {
|
|||
await PageObjects.context.navigateTo(TEST_INDEX_PATTERN, '1');
|
||||
const actualRowsText = await docTable.getRowsText();
|
||||
const expectedRowsText = [
|
||||
'Oct 21, 2019 @ 08:30:04.828733000 -',
|
||||
'Oct 21, 2019 @ 00:30:04.828740000 -',
|
||||
'Oct 21, 2019 @ 00:30:04.828723000 -',
|
||||
'Oct 21, 2019 @ 08:30:04.828733000',
|
||||
'Oct 21, 2019 @ 00:30:04.828740000',
|
||||
'Oct 21, 2019 @ 00:30:04.828723000',
|
||||
];
|
||||
expect(actualRowsText).to.eql(expectedRowsText);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue