mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Lens] Add advanced params to formula API (#143876)
* ✨ Add supported global params to formula api * ✅ Add tests
This commit is contained in:
parent
6c9e9ac392
commit
30f585be41
2 changed files with 61 additions and 1 deletions
|
@ -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: {} }
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue