diff --git a/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/formula/formula.test.tsx b/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/formula/formula.test.tsx index 06a118dc165c..26703a2eebbf 100644 --- a/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/formula/formula.test.tsx +++ b/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/formula/formula.test.tsx @@ -17,7 +17,7 @@ import { insertOrReplaceFormulaColumn } from './parse'; import type { FormBasedLayer } from '../../../types'; import { IndexPattern } from '../../../../../types'; import { TermsIndexPatternColumn } from '../terms'; -import { MovingAverageIndexPatternColumn } from '../calculations'; +import type { MovingAverageIndexPatternColumn } from '../calculations'; import { StaticValueIndexPatternColumn } from '../static_value'; import { getFilter } from '../helpers'; import { createOperationDefinitionMock } from './mocks/operation_mocks'; @@ -43,6 +43,7 @@ const operationDefinitionMap: Record = { terms: createOperationDefinitionMock('terms', {}, { scale: 'ordinal' }), sum: createOperationDefinitionMock('sum', { filterable: true }), last_value: createOperationDefinitionMock('last_value', { + input: 'field', getPossibleOperationForField: jest.fn(({ type }) => ({ scale: type === 'string' ? 'ordinal' : 'ratio', isBucketed: false, @@ -54,14 +55,14 @@ const operationDefinitionMap: Record = { filterable: true, canReduceTimeRange: true, }), - derivative: createOperationDefinitionMock('derivative', { input: 'fullReference' }), - moving_average: createOperationDefinitionMock('moving_average', { - // @ts-expect-error upgrade typescript v4.9.5 + derivative: createOperationDefinitionMock('derivative', { + input: 'fullReference', + }), + moving_average: createOperationDefinitionMock('moving_average', { input: 'fullReference', operationParams: [{ name: 'window', type: 'number', required: true }], filterable: true, getErrorMessage: jest.fn(() => ['mock error']), - // @ts-expect-error upgrade typescript v4.9.5 buildColumn: ({ referenceIds }, columnsParams) => ({ label: 'moving_average', dataType: 'number', @@ -74,7 +75,9 @@ const operationDefinitionMap: Record = { filter: getFilter(undefined, columnsParams), }), }), - cumulative_sum: createOperationDefinitionMock('cumulative_sum', { input: 'fullReference' }), + cumulative_sum: createOperationDefinitionMock('cumulative_sum', { + input: 'fullReference', + }), interval: createOperationDefinitionMock('interval', { input: 'managedReference', usedInMath: true, diff --git a/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/formula/mocks/operation_mocks.ts b/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/formula/mocks/operation_mocks.ts index 74d3236aa17c..2e9c0acd4148 100644 --- a/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/formula/mocks/operation_mocks.ts +++ b/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/formula/mocks/operation_mocks.ts @@ -21,14 +21,14 @@ type OperationByInputType = E { input: Input } >; -export function createOperationDefinitionMock( +export function createOperationDefinitionMock( operation: string, { input = 'field', getErrorMessage, buildColumn, ...params - }: Partial = {}, + }: Partial> = {}, { label = operation, dataType = 'number', @@ -81,13 +81,11 @@ export function createOperationDefinitionMock( return { buildColumn: buildColumn ?? - jest.fn(({ referenceIds }, columnParams: PartialColumnParams) => ({ + jest.fn(({ referenceIds }, columnParams: PartialColumnParams | undefined) => ({ references: referenceIds, filter: getFilter(undefined, columnParams), ...sharedColumnParams, })), - onFieldChange: jest.fn(), - toEsAggsFn: jest.fn(), getPossibleOperation: jest.fn(() => ({ scale: 'ratio', dataType: 'number', diff --git a/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/index.ts b/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/index.ts index fd6b68c2bf65..c7f8ed1e6923 100644 --- a/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/index.ts +++ b/x-pack/plugins/lens/public/datasources/form_based/operations/definitions/index.ts @@ -731,11 +731,13 @@ export type OperationType = string; * This is an operation definition of an unspecified column out of all possible * column types. */ -export type GenericOperationDefinition = - | OperationDefinition - | OperationDefinition - | OperationDefinition - | OperationDefinition; +export type GenericOperationDefinition< + ColumnType extends BaseIndexPatternColumn = BaseIndexPatternColumn +> = + | OperationDefinition + | OperationDefinition + | OperationDefinition + | OperationDefinition; /** * List of all available operation definitions