Skip to content

Commit

Permalink
move conversion to handleRequest based on discussion with @ppisljar
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Jan 6, 2021
1 parent 543203e commit d001f1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
15 changes: 6 additions & 9 deletions src/plugins/data/common/search/expressions/esaggs/esaggs_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { FormatFactory } from '../../../field_formats/utils';
import { IndexPatternExpressionType } from '../../../index_patterns/expressions';
import { IndexPatternsContract } from '../../../index_patterns/index_patterns';
import { getAbsoluteTimeRange } from '../../../query';
import { calculateBounds } from '../../../query';

import { AggsStart, AggExpressionType } from '../../aggs';
import { ISearchStartSearchSource } from '../../search_source';
Expand Down Expand Up @@ -120,12 +120,9 @@ export async function handleEsaggsRequest(
params: RequestHandlerParams
): Promise<Datatable> {
const resolvedTimeRange =
params.timeRange && getAbsoluteTimeRange(params.timeRange, { forceNow: params.getNow?.() });
input?.timeRange && calculateBounds(input.timeRange, { forceNow: params.getNow?.() });

const response = await handleRequest({
...params,
timeRange: resolvedTimeRange,
});
const response = await handleRequest(params);

const table: Datatable = {
type: 'datatable',
Expand All @@ -144,12 +141,12 @@ export async function handleEsaggsRequest(
indexPatternId: params.indexPattern?.id,
appliedTimeRange:
column.aggConfig.params.field?.name &&
resolvedTimeRange &&
input?.timeRange &&
args.timeFields &&
args.timeFields.includes(column.aggConfig.params.field?.name)
? {
from: resolvedTimeRange?.from,
to: resolvedTimeRange?.to,
from: resolvedTimeRange?.min?.toISOString(),
to: resolvedTimeRange?.max?.toISOString(),
}
: undefined,
...column.aggConfig.serialize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ export const handleRequest = async ({
searchSourceService,
timeFields,
timeRange,
getNow,
}: RequestHandlerParams) => {
const forceNow = getNow?.();
const searchSource = await searchSourceService.create();

searchSource.setField('index', indexPattern);
Expand Down Expand Up @@ -116,7 +118,7 @@ export const handleRequest = async ({
if (timeRange && allTimeFields.length > 0) {
timeFilterSearchSource.setField('filter', () => {
return allTimeFields
.map((fieldName) => getTime(indexPattern, timeRange, { fieldName }))
.map((fieldName) => getTime(indexPattern, timeRange, { fieldName, forceNow }))
.filter(isRangeFilter);
});
}
Expand Down Expand Up @@ -184,7 +186,7 @@ export const handleRequest = async ({
}
}

const parsedTimeRange = timeRange ? calculateBounds(timeRange) : null;
const parsedTimeRange = timeRange ? calculateBounds(timeRange, { forceNow }) : null;
const tabifyParams = {
metricsAtAllLevels,
partialRows,
Expand Down

0 comments on commit d001f1b

Please sign in to comment.