From b4d509eb5d7b756470bda90dd68cbd45fa178341 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 17 Nov 2021 13:13:12 +0100 Subject: [PATCH] fix bug and another consumer --- .../indexpattern_datasource/to_expression.ts | 44 +++++++++---------- .../packs/pack_queries_status_table.tsx | 3 +- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/to_expression.ts b/x-pack/plugins/lens/public/indexpattern_datasource/to_expression.ts index 3470adaa8eb91..432c932b85da8 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/to_expression.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/to_expression.ts @@ -24,7 +24,8 @@ import { GenericIndexPatternColumn } from './indexpattern'; import { operationDefinitionMap } from './operations'; import { IndexPattern, IndexPatternPrivateState, IndexPatternLayer } from './types'; import { DateHistogramIndexPatternColumn, RangeIndexPatternColumn } from './operations/definitions'; -import { isColumnOfType } from './operations/definitions/helpers'; +import { FormattedIndexPatternColumn } from './operations/definitions/column_types'; +import { isColumnFormatted, isColumnOfType } from './operations/definitions/helpers'; type OriginalColumn = { id: string } & GenericIndexPatternColumn; @@ -148,32 +149,29 @@ function getExpressionForLayer( }, }; }, {} as Record); - const columnsWithFormatters = columnEntries.filter( ([, col]) => - isColumnOfType('range', col) && - (col.params?.format || col.params?.parentFormat) - ) as Array<[string, RangeIndexPatternColumn]>; - const formatterOverrides: ExpressionAstFunction[] = columnsWithFormatters.map( - ([id, col]: [string, RangeIndexPatternColumn]) => { - // TODO: improve the type handling here - const parentFormat = 'parentFormat' in col.params ? col.params!.parentFormat! : undefined; - const format = col.params!.format; + (isColumnOfType('range', col) && col.params?.parentFormat) || + (isColumnFormatted(col) && col.params?.format) + ) as Array<[string, RangeIndexPatternColumn | FormattedIndexPatternColumn]>; + const formatterOverrides: ExpressionAstFunction[] = columnsWithFormatters.map(([id, col]) => { + // TODO: improve the type handling here + const parentFormat = 'parentFormat' in col.params! ? col.params!.parentFormat! : undefined; + const format = col.params!.format; - const base: ExpressionAstFunction = { - type: 'function', - function: 'lens_format_column', - arguments: { - format: format ? [format.id] : [''], - columnId: [id], - decimals: typeof format?.params?.decimals === 'number' ? [format.params.decimals] : [], - parentFormat: parentFormat ? [JSON.stringify(parentFormat)] : [], - }, - }; + const base: ExpressionAstFunction = { + type: 'function', + function: 'lens_format_column', + arguments: { + format: format ? [format.id] : [''], + columnId: [id], + decimals: typeof format?.params?.decimals === 'number' ? [format.params.decimals] : [], + parentFormat: parentFormat ? [JSON.stringify(parentFormat)] : [], + }, + }; - return base; - } - ); + return base; + }); const firstDateHistogramColumn = columnEntries.find( ([, col]) => col.operationType === 'date_histogram' diff --git a/x-pack/plugins/osquery/public/packs/pack_queries_status_table.tsx b/x-pack/plugins/osquery/public/packs/pack_queries_status_table.tsx index 5aacffb52cb49..5567d4562b1d8 100644 --- a/x-pack/plugins/osquery/public/packs/pack_queries_status_table.tsx +++ b/x-pack/plugins/osquery/public/packs/pack_queries_status_table.tsx @@ -28,6 +28,7 @@ import { TypedLensByValueInput, PersistedIndexPatternLayer, PieVisualizationState, + TermsIndexPatternColumn, } from '../../../lens/public'; import { FilterStateStore, DataView } from '../../../../../src/plugins/data/common'; import { useKibana } from '../common/lib/kibana'; @@ -88,7 +89,7 @@ function getLensAttributes( }, orderDirection: 'desc', }, - }, + } as TermsIndexPatternColumn, 'ed999e9d-204c-465b-897f-fe1a125b39ed': { sourceField: 'Records', isBucketed: false,