[Lens] Add advanced params to formula API (#143876)

*  Add supported global params to formula api

*  Add tests
This commit is contained in:
Marco Liberati 2022-10-27 10:28:22 +02:00 committed by GitHub
parent 6c9e9ac392
commit 30f585be41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 1 deletions

View file

@ -103,4 +103,54 @@ describe('createFormulaPublicApi', () => {
{ indexPattern: {} }
);
});
test('should pass over advanced parameters as global params for formula', () => {
const baseLayer = getBaseLayer();
publicApiHelper.insertOrReplaceFormulaColumn(
'col',
{
formula: 'count()',
timeScale: 'd',
filter: { query: 'myField: *', language: 'kuery' },
reducedTimeRange: '30s',
},
baseLayer,
dataView
);
expect(insertOrReplaceFormulaColumn).toHaveBeenCalledWith(
'col',
{
customLabel: false,
dataType: 'number',
isBucketed: false,
label: 'count()',
operationType: 'formula',
params: { formula: 'count()', format: undefined },
filter: {
language: 'kuery',
query: 'myField: *',
},
timeScale: 'd',
reducedTimeRange: '30s',
references: [],
},
{
columnOrder: ['col1'],
columns: {
col1: {
dataType: 'date',
isBucketed: true,
label: '@timestamp',
operationType: 'date_histogram',
params: { interval: 'auto' },
scale: 'interval',
},
},
indexPatternId: undefined,
},
{ indexPattern: {} }
);
});
});

View file

@ -10,6 +10,7 @@ import { Query } from '@kbn/es-query';
import { convertDataViewIntoLensIndexPattern } from '../../../../../data_views_service/loader';
import type { IndexPattern } from '../../../../../types';
import type { PersistedIndexPatternLayer } from '../../../types';
import type { TimeScaleUnit } from '../../../../../../common/expressions';
import { insertOrReplaceFormulaColumn } from './parse';
@ -33,6 +34,8 @@ export interface FormulaPublicApi {
formula: string;
label?: string;
filter?: Query;
reducedTimeRange?: string;
timeScale?: TimeScaleUnit;
format?: {
id: string;
params?: {
@ -60,7 +63,12 @@ export const createFormulaPublicApi = (): FormulaPublicApi => {
};
return {
insertOrReplaceFormulaColumn: (id, { formula, label, format, filter }, layer, dataView) => {
insertOrReplaceFormulaColumn: (
id,
{ formula, label, format, filter, reducedTimeRange, timeScale },
layer,
dataView
) => {
const indexPattern = getCachedLensIndexPattern(dataView);
return insertOrReplaceFormulaColumn(
@ -73,6 +81,8 @@ export const createFormulaPublicApi = (): FormulaPublicApi => {
references: [],
isBucketed: false,
filter,
reducedTimeRange,
timeScale,
params: {
formula,
format,