From b352b31a4bd8ecafaf7f7b9757cd64f24274a556 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 12 Jul 2022 14:01:04 -0500 Subject: [PATCH 1/7] [ML] Add filter to boolean content --- .../expanded_row/index_based_expanded_row.tsx | 2 +- .../boolean_content.tsx | 93 ++++++------------- 2 files changed, 30 insertions(+), 65 deletions(-) diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx index c108ca238de8a..79acba2b9bf7a 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx @@ -55,7 +55,7 @@ export const IndexBasedDataVisualizerExpandedRow = ({ return ; case JOB_FIELD_TYPES.BOOLEAN: - return ; + return ; case JOB_FIELD_TYPES.DATE: return ; diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/components/field_data_expanded_row/boolean_content.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/components/field_data_expanded_row/boolean_content.tsx index 907bc6166afff..210f69c435a45 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/components/field_data_expanded_row/boolean_content.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/components/field_data_expanded_row/boolean_content.tsx @@ -5,18 +5,13 @@ * 2.0. */ -import React, { FC, ReactNode, useMemo } from 'react'; -import { - EuiBasicTable, - EuiSpacer, - RIGHT_ALIGNMENT, - LEFT_ALIGNMENT, - HorizontalAlignment, -} from '@elastic/eui'; +import React, { FC, useMemo } from 'react'; +import { EuiSpacer } from '@elastic/eui'; import { Axis, BarSeries, Chart, Settings, ScaleType } from '@elastic/charts'; import { FormattedMessage } from '@kbn/i18n-react'; import { i18n } from '@kbn/i18n'; +import { TopValues } from '../../../top_values'; import type { FieldDataRowProps } from '../../types/field_data_row'; import { ExpandedRowFieldHeader } from '../expanded_row_field_header'; import { getTFPercentage } from '../../utils'; @@ -44,72 +39,42 @@ function getFormattedValue(value: number, totalCount: number): string { const BOOLEAN_DISTRIBUTION_CHART_HEIGHT = 70; -export const BooleanContent: FC = ({ config }) => { +export const BooleanContent: FC = ({ config, onAddFilter }) => { const fieldFormat = 'fieldFormat' in config ? config.fieldFormat : undefined; const formattedPercentages = useMemo(() => getTFPercentage(config), [config]); const theme = useDataVizChartTheme(); if (!formattedPercentages) return null; const { trueCount, falseCount, count } = formattedPercentages; - const summaryTableItems = [ - { - function: 'true', - display: ( - - ), - value: getFormattedValue(trueCount, count), - }, - { - function: 'false', - display: ( - - ), - value: getFormattedValue(falseCount, count), - }, - ]; - const summaryTableColumns = [ - { - field: 'function', - name: '', - render: (_: string, summaryItem: { display: ReactNode }) => summaryItem.display, - width: '25px', - align: LEFT_ALIGNMENT as HorizontalAlignment, - }, - { - field: 'value', - name: '', - render: (v: string) => {v}, - align: RIGHT_ALIGNMENT as HorizontalAlignment, - }, - ]; - - const summaryTableTitle = i18n.translate( - 'xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.summaryTableTitle', - { - defaultMessage: 'Summary', - } - ); - + const stats = { + ...config.stats, + topValues: [ + { + key: i18n.translate( + 'xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.trueCountLabel', + { defaultMessage: 'true' } + ), + doc_count: trueCount ?? 0, + }, + { + key: i18n.translate( + 'xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.falseCountLabel', + { defaultMessage: 'false' } + ), + doc_count: falseCount ?? 0, + }, + ], + }; return ( - - {summaryTableTitle} - - + From da837f277e2406f29933e38ee375da68e542c112 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 12 Jul 2022 14:31:58 -0500 Subject: [PATCH 2/7] [ML] Change to version type if detected from estypes --- x-pack/plugins/data_visualizer/common/constants.ts | 1 + .../components/expanded_row/file_based_expanded_row.tsx | 1 + .../components/expanded_row/index_based_expanded_row.tsx | 1 + .../components/field_data_row/action_menu/lens_utils.ts | 7 ++++++- .../public/application/common/util/field_types_utils.ts | 8 ++++++++ .../hooks/use_data_visualizer_grid_data.ts | 1 - .../search_strategy/requests/get_fields_stats.ts | 1 + 7 files changed, 18 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/data_visualizer/common/constants.ts b/x-pack/plugins/data_visualizer/common/constants.ts index f31a42cc7784c..0d0b0552cee24 100644 --- a/x-pack/plugins/data_visualizer/common/constants.ts +++ b/x-pack/plugins/data_visualizer/common/constants.ts @@ -40,6 +40,7 @@ export const JOB_FIELD_TYPES = { TEXT: 'text', HISTOGRAM: 'histogram', UNKNOWN: 'unknown', + VERSION: 'version', } as const; export const OMIT_FIELDS: string[] = ['_source', '_type', '_index', '_id', '_version', '_score']; diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/file_based_expanded_row.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/file_based_expanded_row.tsx index 07e5d01e71d9b..1cf0f66596bd7 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/file_based_expanded_row.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/file_based_expanded_row.tsx @@ -41,6 +41,7 @@ export const FileBasedDataVisualizerExpandedRow = ({ item }: { item: FileBasedFi return ; case JOB_FIELD_TYPES.KEYWORD: + case JOB_FIELD_TYPES.VERSION: return ; case JOB_FIELD_TYPES.TEXT: diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx index 79acba2b9bf7a..e4c5cf460fd97 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx @@ -74,6 +74,7 @@ export const IndexBasedDataVisualizerExpandedRow = ({ return ; case JOB_FIELD_TYPES.KEYWORD: + case JOB_FIELD_TYPES.VERSION: return ; case JOB_FIELD_TYPES.TEXT: diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/lens_utils.ts b/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/lens_utils.ts index 731499cee2f89..b201baffa8f49 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/lens_utils.ts +++ b/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/lens_utils.ts @@ -201,6 +201,7 @@ export function getCompatibleLensDataType(type: FieldVisConfig['type']): string let lensType: string | undefined; switch (type) { case JOB_FIELD_TYPES.KEYWORD: + case JOB_FIELD_TYPES.VERSION: lensType = 'string'; break; case JOB_FIELD_TYPES.DATE: @@ -234,7 +235,11 @@ function getColumnsAndLayer( if (fieldType === JOB_FIELD_TYPES.NUMBER) { return getNumberSettings(item, defaultDataView); } - if (fieldType === JOB_FIELD_TYPES.IP || fieldType === JOB_FIELD_TYPES.KEYWORD) { + if ( + fieldType === JOB_FIELD_TYPES.IP || + fieldType === JOB_FIELD_TYPES.KEYWORD || + fieldType === JOB_FIELD_TYPES.VERSION + ) { return getKeywordSettings(item); } if (fieldType === JOB_FIELD_TYPES.BOOLEAN) { diff --git a/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.ts b/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.ts index d9617ae61e2ec..9e4a686d692d9 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.ts +++ b/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.ts @@ -54,6 +54,9 @@ export const jobTypeLabels = { [JOB_FIELD_TYPES.UNKNOWN]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.unknownTypeLabel', { defaultMessage: 'Unknown', }), + [JOB_FIELD_TYPES.VERSION]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.versionTypeLabel', { + defaultMessage: 'Version', + }), }; // convert kibana types to ML Job types @@ -62,9 +65,14 @@ export const jobTypeLabels = { export function kbnTypeToJobType(field: DataViewField) { // Return undefined if not one of the supported data visualizer field types. let type; + switch (field.type) { case KBN_FIELD_TYPES.STRING: type = field.aggregatable ? JOB_FIELD_TYPES.KEYWORD : JOB_FIELD_TYPES.TEXT; + + if (field.esTypes?.includes(JOB_FIELD_TYPES.VERSION)) { + type = JOB_FIELD_TYPES.VERSION; + } break; case KBN_FIELD_TYPES.NUMBER: type = JOB_FIELD_TYPES.NUMBER; diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/hooks/use_data_visualizer_grid_data.ts b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/hooks/use_data_visualizer_grid_data.ts index eecebf6b9f947..dd92b025d7112 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/hooks/use_data_visualizer_grid_data.ts +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/hooks/use_data_visualizer_grid_data.ts @@ -394,7 +394,6 @@ export const useDataVisualizerGridData = ( nonMetricFieldsToShow.forEach((field) => { const fieldData = nonMetricFieldData.find((f) => f.fieldName === field.spec.name); - const nonMetricConfig: Partial = { ...(fieldData ? fieldData : {}), fieldFormat: currentDataView.getFormatterForField(field), diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_fields_stats.ts b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_fields_stats.ts index 4dd0b3a7ba40a..e798b1138996e 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_fields_stats.ts +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_fields_stats.ts @@ -35,6 +35,7 @@ export const getFieldsStats = ( return fetchNumericFieldsStats(dataSearch, params, fields, options); case JOB_FIELD_TYPES.KEYWORD: case JOB_FIELD_TYPES.IP: + case JOB_FIELD_TYPES.VERSION: return fetchStringFieldsStats(dataSearch, params, fields, options); case JOB_FIELD_TYPES.DATE: return fetchDateFieldsStats(dataSearch, params, fields, options); From 4b64a604c7e1e13c7656d253893eb3932f055acd Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 12 Jul 2022 15:42:51 -0500 Subject: [PATCH 3/7] [ML] Remove duplicated geo examples --- .../common/types/field_request_config.ts | 12 +++- .../examples_list/examples_list.tsx | 3 +- .../geo_point_content_with_map.tsx | 8 ++- .../application/common/util/geo_utils.test.ts | 58 +++++++++++++++++++ .../application/common/util/geo_utils.ts | 34 +++++++++++ .../translations/translations/fr-FR.json | 1 - .../translations/translations/ja-JP.json | 1 - .../translations/translations/zh-CN.json | 1 - 8 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.test.ts create mode 100644 x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.ts diff --git a/x-pack/plugins/data_visualizer/common/types/field_request_config.ts b/x-pack/plugins/data_visualizer/common/types/field_request_config.ts index 5f21748575831..4db8cc8aa7996 100644 --- a/x-pack/plugins/data_visualizer/common/types/field_request_config.ts +++ b/x-pack/plugins/data_visualizer/common/types/field_request_config.ts @@ -29,6 +29,16 @@ export interface DocumentCounts { interval?: number; } +export interface LatLongExample { + lat: number; + lon: number; +} + +export interface GeoPointExample { + coordinates: number[]; + type?: string; +} + export interface FieldVisStats { error?: Error; cardinality?: number; @@ -56,7 +66,7 @@ export interface FieldVisStats { topValues?: Array<{ key: number | string; doc_count: number }>; topValuesSampleSize?: number; topValuesSamplerShardSize?: number; - examples?: Array; + examples?: Array; timeRangeEarliest?: number; timeRangeLatest?: number; } diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/examples_list/examples_list.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/examples_list/examples_list.tsx index c4792b314b6a6..211d9a84f9a68 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/examples_list/examples_list.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/examples_list/examples_list.tsx @@ -10,10 +10,11 @@ import React, { FC } from 'react'; import { EuiListGroup, EuiListGroupItem } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; +import { GeoPointExample } from '../../../../../common/types/field_request_config'; import { ExpandedRowFieldHeader } from '../stats_table/components/expanded_row_field_header'; import { ExpandedRowPanel } from '../stats_table/components/field_data_expanded_row/expanded_row_panel'; interface Props { - examples: Array; + examples: Array; } export const ExamplesList: FC = ({ examples }) => { diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx index 8a0b1d7a3dfe6..d8c4ba411ae42 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx @@ -4,10 +4,10 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - -import React, { FC, useEffect, useState } from 'react'; +import React, { FC, useEffect, useMemo, useState } from 'react'; import { DataView } from '@kbn/data-views-plugin/public'; import { ES_GEO_FIELD_TYPE, LayerDescriptor } from '@kbn/maps-plugin/common'; +import { getUniqCoordinates } from '../../../util/geo_utils'; import { CombinedQuery } from '../../../../index_data_visualizer/types/combined_query'; import { ExpandedRowContent } from '../../stats_table/components/field_data_expanded_row/expanded_row_content'; import { DocumentStatsTable } from '../../stats_table/components/field_data_expanded_row/document_stats'; @@ -29,6 +29,8 @@ export const GeoPointContentWithMap: FC<{ services: { maps: mapsPlugin, data }, } = useDataVisualizerKibana(); + const uniqueExamples = useMemo(() => getUniqCoordinates(stats?.examples), [stats?.examples]); + // Update the layer list with updated geo points upon refresh useEffect(() => { async function updateIndexPatternSearchLayer() { @@ -64,7 +66,7 @@ export const GeoPointContentWithMap: FC<{ return ( - + diff --git a/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.test.ts b/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.test.ts new file mode 100644 index 0000000000000..d57345375a203 --- /dev/null +++ b/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.test.ts @@ -0,0 +1,58 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { getUniqCoordinates } from './geo_utils'; + +describe('geo type utils', () => { + describe('getUniqCoordinates', () => { + test('should remove duplicated coordinates', () => { + expect( + getUniqCoordinates([ + { coordinates: [0.0001, 2343], type: 'Point' }, + { coordinates: [0.0001, 2343], type: 'Point' }, + { coordinates: [0.0001, 2343], type: 'Point' }, + { coordinates: [0.0001, 2343], type: 'Shape' }, + { coordinates: [0.0001, 2343] }, + { coordinates: [4321, 2343], type: 'Point' }, + { coordinates: [4321, 2343], type: 'Point' }, + ]) + ).toMatchObject([ + { + coordinates: [0.0001, 2343], + type: 'Point', + }, + { + coordinates: [0.0001, 2343], + type: 'Shape', + }, + { + coordinates: [0.0001, 2343], + }, + { + coordinates: [4321, 2343], + type: 'Point', + }, + ]); + expect( + getUniqCoordinates([ + { coordinates: [1000, 2000, 3000], type: 'Point' }, + { coordinates: [1000, 2000, 3000], type: 'Point' }, + { coordinates: [1000, 2000, 3000], type: 'Point' }, + { coordinates: [1000, 2000, 3000, 4000], type: 'Shape' }, + { coordinates: [1000, 2000, 3000, 4000] }, + ]) + ).toMatchObject([ + { + coordinates: [1000, 2000, 3000], + type: 'Point', + }, + { coordinates: [1000, 2000, 3000, 4000], type: 'Shape' }, + { coordinates: [1000, 2000, 3000, 4000] }, + ]); + }); + }); +}); diff --git a/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.ts b/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.ts new file mode 100644 index 0000000000000..6d40f567d8f88 --- /dev/null +++ b/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.ts @@ -0,0 +1,34 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { isPopulatedObject } from '@kbn/ml-is-populated-object'; +import { GeoPointExample } from '../../../../common/types/field_request_config'; +import { isDefined } from './is_defined'; + +export function isGeoPointExample(arg: unknown): arg is GeoPointExample { + return isPopulatedObject(arg, ['coordinates']); +} + +export function getUniqCoordinates( + coordinates: Array | undefined +): GeoPointExample[] { + const uniqueCoordinates: GeoPointExample[] = []; + if (!isDefined(coordinates)) return uniqueCoordinates; + + coordinates.forEach((ex) => { + if ( + isGeoPointExample(ex) && + uniqueCoordinates.findIndex( + (c) => + c.type === ex.type && ex.coordinates.every((coord, idx) => coord === c.coordinates[idx]) + ) === -1 + ) { + uniqueCoordinates.push(ex); + } + }); + return uniqueCoordinates; +} diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index 750bc121875b4..2a60c2e3ff87e 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -10528,7 +10528,6 @@ "xpack.dataVisualizer.dataGrid.field.topValues.calculatedFromSampleDescription": "Calculé à partir d'un échantillon de {topValuesSamplerShardSize} documents par partition", "xpack.dataVisualizer.dataGrid.field.topValuesLabel": "Valeurs les plus élevées", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.falseCountLabel": "faux", - "xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.summaryTableTitle": "Résumé", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.trueCountLabel": "vrai", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.choroplethMapTopValues.calculatedFromSampleDescription": "Calculé à partir d'un échantillon de {topValuesSamplerShardSize} documents par partition", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.documentStatsTable.countLabel": "compte", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 0ca4cbaa696b7..12e917dab041b 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -10520,7 +10520,6 @@ "xpack.dataVisualizer.dataGrid.field.topValues.calculatedFromSampleDescription": "1 つのシャードにつき {topValuesSamplerShardSize} のドキュメントのサンプルで計算されています", "xpack.dataVisualizer.dataGrid.field.topValuesLabel": "トップの値", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.falseCountLabel": "false", - "xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.summaryTableTitle": "まとめ", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.trueCountLabel": "true", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.choroplethMapTopValues.calculatedFromSampleDescription": "1 つのシャードにつき {topValuesSamplerShardSize} のドキュメントのサンプルで計算されています", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.documentStatsTable.countLabel": "カウント", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 9d3b92f48be3e..50aa804bd09db 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -10534,7 +10534,6 @@ "xpack.dataVisualizer.dataGrid.field.topValues.calculatedFromSampleDescription": "基于每个分片的 {topValuesSamplerShardSize} 文档样例计算", "xpack.dataVisualizer.dataGrid.field.topValuesLabel": "排名最前值", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.falseCountLabel": "false", - "xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.summaryTableTitle": "摘要", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.booleanContent.trueCountLabel": "true", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.choroplethMapTopValues.calculatedFromSampleDescription": "基于每个分片的 {topValuesSamplerShardSize} 文档样例计算", "xpack.dataVisualizer.dataGrid.fieldExpandedRow.documentStatsTable.countLabel": "计数", From 9c6ca41f28f44b08d0e2f5901009824352a952f2 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 13 Jul 2022 15:01:38 -0500 Subject: [PATCH 4/7] [ML] Change duplicated geo util to duplicated generic util --- .../examples_list/examples_list.tsx | 14 +- .../geo_point_content_with_map.tsx | 7 +- .../common/util/example_utils.test.ts | 153 ++++++++++++++++++ .../application/common/util/example_utils.ts | 58 +++++++ .../application/common/util/geo_utils.test.ts | 58 ------- .../application/common/util/geo_utils.ts | 34 ---- .../requests/get_field_examples.ts | 21 +-- 7 files changed, 233 insertions(+), 112 deletions(-) create mode 100644 x-pack/plugins/data_visualizer/public/application/common/util/example_utils.test.ts create mode 100644 x-pack/plugins/data_visualizer/public/application/common/util/example_utils.ts delete mode 100644 x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.test.ts delete mode 100644 x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.ts diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/examples_list/examples_list.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/examples_list/examples_list.tsx index 211d9a84f9a68..242823c2b6bc2 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/examples_list/examples_list.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/examples_list/examples_list.tsx @@ -10,13 +10,19 @@ import React, { FC } from 'react'; import { EuiListGroup, EuiListGroupItem } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; +import { i18n } from '@kbn/i18n'; import { GeoPointExample } from '../../../../../common/types/field_request_config'; import { ExpandedRowFieldHeader } from '../stats_table/components/expanded_row_field_header'; import { ExpandedRowPanel } from '../stats_table/components/field_data_expanded_row/expanded_row_panel'; + interface Props { examples: Array; } +const EMPTY_EXAMPLE = i18n.translate( + 'xpack.dataVisualizer.dataGrid.field.examplesList.noExamplesMessage', + { defaultMessage: '(empty)' } +); export const ExamplesList: FC = ({ examples }) => { if (examples === undefined || examples === null || !Array.isArray(examples)) { return null; @@ -35,7 +41,13 @@ export const ExamplesList: FC = ({ examples }) => { ); }); diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx index d8c4ba411ae42..b3d34ffb040bd 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx @@ -4,10 +4,9 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import React, { FC, useEffect, useMemo, useState } from 'react'; +import React, { FC, useEffect, useState } from 'react'; import { DataView } from '@kbn/data-views-plugin/public'; import { ES_GEO_FIELD_TYPE, LayerDescriptor } from '@kbn/maps-plugin/common'; -import { getUniqCoordinates } from '../../../util/geo_utils'; import { CombinedQuery } from '../../../../index_data_visualizer/types/combined_query'; import { ExpandedRowContent } from '../../stats_table/components/field_data_expanded_row/expanded_row_content'; import { DocumentStatsTable } from '../../stats_table/components/field_data_expanded_row/document_stats'; @@ -29,8 +28,6 @@ export const GeoPointContentWithMap: FC<{ services: { maps: mapsPlugin, data }, } = useDataVisualizerKibana(); - const uniqueExamples = useMemo(() => getUniqCoordinates(stats?.examples), [stats?.examples]); - // Update the layer list with updated geo points upon refresh useEffect(() => { async function updateIndexPatternSearchLayer() { @@ -66,7 +63,7 @@ export const GeoPointContentWithMap: FC<{ return ( - + diff --git a/x-pack/plugins/data_visualizer/public/application/common/util/example_utils.test.ts b/x-pack/plugins/data_visualizer/public/application/common/util/example_utils.test.ts new file mode 100644 index 0000000000000..c939ba8c03e86 --- /dev/null +++ b/x-pack/plugins/data_visualizer/public/application/common/util/example_utils.test.ts @@ -0,0 +1,153 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { getUniqGeoOrStrExamples } from './example_utils'; + +describe('geo type utils', () => { + describe('getUniqGeoOrStrExamples', () => { + test('should remove duplicated strings up to maxExamples', () => { + expect( + getUniqGeoOrStrExamples( + [ + 'deb', + '', + 'css', + 'deb', + '', + '', + 'deb', + 'gz', + '', + 'gz', + '', + 'deb', + 'gz', + 'deb', + '', + 'deb', + 'deb', + '', + 'gz', + 'gz', + ], + 20 + ) + ).toMatchObject(['deb', '', 'css', 'gz']); + expect( + getUniqGeoOrStrExamples( + [ + 'deb', + '', + 'css', + 'deb', + '', + '', + 'deb', + 'gz', + '', + 'gz', + '', + 'deb', + 'gz', + 'deb', + '', + 'deb', + 'deb', + '', + 'gz', + 'gz', + ], + 2 + ) + ).toMatchObject(['deb', '']); + }); + + test('should remove duplicated coordinates up to maxExamples', () => { + expect( + getUniqGeoOrStrExamples([ + { coordinates: [0.1, 2343], type: 'Point' }, + { coordinates: [0.1, 2343], type: 'Point' }, + { coordinates: [0.1, 2343], type: 'Point' }, + { coordinates: [0.1, 2343], type: 'Shape' }, + { coordinates: [0.1, 2343] }, + { coordinates: [4321, 2343], type: 'Point' }, + { coordinates: [4321, 2343], type: 'Point' }, + ]) + ).toMatchObject([ + { + coordinates: [0.1, 2343], + type: 'Point', + }, + { + coordinates: [0.1, 2343], + type: 'Shape', + }, + { + coordinates: [0.1, 2343], + }, + { + coordinates: [4321, 2343], + type: 'Point', + }, + ]); + expect( + getUniqGeoOrStrExamples([ + { coordinates: [1, 2, 3], type: 'Point' }, + { coordinates: [1, 2, 3], type: 'Point' }, + { coordinates: [1, 2, 3], type: 'Point' }, + { coordinates: [1, 2, 3, 4], type: 'Shape' }, + { coordinates: [1, 2, 3, 4] }, + ]) + ).toMatchObject([ + { + coordinates: [1, 2, 3], + type: 'Point', + }, + { coordinates: [1, 2, 3, 4], type: 'Shape' }, + { coordinates: [1, 2, 3, 4] }, + ]); + }); + + test('should remove duplicated lon/lat coordinates up to maxExamples', () => { + expect( + getUniqGeoOrStrExamples([ + { lon: 0.1, lat: 2343 }, + { lon: 0.1, lat: 2343 }, + { lon: 0.1, lat: 2343 }, + { lon: 0.1, lat: 2343 }, + { lon: 0.1, lat: 2343 }, + { lon: 4321, lat: 2343 }, + { lon: 4321, lat: 2343 }, + ]) + ).toMatchObject([ + { lon: 0.1, lat: 2343 }, + { lon: 4321, lat: 2343 }, + ]); + expect( + getUniqGeoOrStrExamples( + [ + { lon: 1, lat: 2 }, + { lon: 1, lat: 2 }, + { lon: 2, lat: 3 }, + { lon: 2, lat: 3 }, + { lon: 3, lat: 4 }, + { lon: 3, lat: 4 }, + { lon: 4, lat: 5 }, + { lon: 4, lat: 5 }, + { lon: 5, lat: 6 }, + { lon: 5, lat: 6 }, + ], + 3 + ) + ).toMatchObject([ + { lon: 1, lat: 2 }, + { lon: 2, lat: 3 }, + { lon: 3, lat: 4 }, + ]); + }); + }); +}); diff --git a/x-pack/plugins/data_visualizer/public/application/common/util/example_utils.ts b/x-pack/plugins/data_visualizer/public/application/common/util/example_utils.ts new file mode 100644 index 0000000000000..cc4a9a3ca9bfa --- /dev/null +++ b/x-pack/plugins/data_visualizer/public/application/common/util/example_utils.ts @@ -0,0 +1,58 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { isPopulatedObject } from '@kbn/ml-is-populated-object'; +import { isDefined } from './is_defined'; +import { GeoPointExample, LatLongExample } from '../../../../common/types/field_request_config'; + +export function isGeoPointExample(arg: unknown): arg is GeoPointExample { + return isPopulatedObject(arg, ['coordinates']) && Array.isArray(arg.coordinates); +} + +export function isLonLatExample(arg: unknown): arg is LatLongExample { + return isPopulatedObject(arg, ['lon', 'lat']); +} + +export function getUniqGeoOrStrExamples( + examples: Array | undefined, + maxExamples = 10 +): Array { + const uniqueCoordinates: Array = []; + if (!isDefined(examples)) return uniqueCoordinates; + for (let i = 0; i < examples.length; i++) { + const example = examples[i]; + if (typeof example === 'string' && uniqueCoordinates.indexOf(example) === -1) { + uniqueCoordinates.push(example); + } else { + if ( + isGeoPointExample(example) && + uniqueCoordinates.findIndex( + (c) => + isGeoPointExample(c) && + c.type === example.type && + example.coordinates.every((coord, idx) => coord === c.coordinates[idx]) + ) === -1 + ) { + uniqueCoordinates.push(example); + } + + if ( + isLonLatExample(example) && + uniqueCoordinates.findIndex( + (c) => isLonLatExample(c) && example.lon === c.lon && example.lat === c.lat + ) === -1 + ) { + uniqueCoordinates.push(example); + } + } + if (uniqueCoordinates.length === maxExamples) { + return uniqueCoordinates; + } + } + + return uniqueCoordinates; +} diff --git a/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.test.ts b/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.test.ts deleted file mode 100644 index d57345375a203..0000000000000 --- a/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { getUniqCoordinates } from './geo_utils'; - -describe('geo type utils', () => { - describe('getUniqCoordinates', () => { - test('should remove duplicated coordinates', () => { - expect( - getUniqCoordinates([ - { coordinates: [0.0001, 2343], type: 'Point' }, - { coordinates: [0.0001, 2343], type: 'Point' }, - { coordinates: [0.0001, 2343], type: 'Point' }, - { coordinates: [0.0001, 2343], type: 'Shape' }, - { coordinates: [0.0001, 2343] }, - { coordinates: [4321, 2343], type: 'Point' }, - { coordinates: [4321, 2343], type: 'Point' }, - ]) - ).toMatchObject([ - { - coordinates: [0.0001, 2343], - type: 'Point', - }, - { - coordinates: [0.0001, 2343], - type: 'Shape', - }, - { - coordinates: [0.0001, 2343], - }, - { - coordinates: [4321, 2343], - type: 'Point', - }, - ]); - expect( - getUniqCoordinates([ - { coordinates: [1000, 2000, 3000], type: 'Point' }, - { coordinates: [1000, 2000, 3000], type: 'Point' }, - { coordinates: [1000, 2000, 3000], type: 'Point' }, - { coordinates: [1000, 2000, 3000, 4000], type: 'Shape' }, - { coordinates: [1000, 2000, 3000, 4000] }, - ]) - ).toMatchObject([ - { - coordinates: [1000, 2000, 3000], - type: 'Point', - }, - { coordinates: [1000, 2000, 3000, 4000], type: 'Shape' }, - { coordinates: [1000, 2000, 3000, 4000] }, - ]); - }); - }); -}); diff --git a/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.ts b/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.ts deleted file mode 100644 index 6d40f567d8f88..0000000000000 --- a/x-pack/plugins/data_visualizer/public/application/common/util/geo_utils.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { isPopulatedObject } from '@kbn/ml-is-populated-object'; -import { GeoPointExample } from '../../../../common/types/field_request_config'; -import { isDefined } from './is_defined'; - -export function isGeoPointExample(arg: unknown): arg is GeoPointExample { - return isPopulatedObject(arg, ['coordinates']); -} - -export function getUniqCoordinates( - coordinates: Array | undefined -): GeoPointExample[] { - const uniqueCoordinates: GeoPointExample[] = []; - if (!isDefined(coordinates)) return uniqueCoordinates; - - coordinates.forEach((ex) => { - if ( - isGeoPointExample(ex) && - uniqueCoordinates.findIndex( - (c) => - c.type === ex.type && ex.coordinates.every((coord, idx) => coord === c.coordinates[idx]) - ) === -1 - ) { - uniqueCoordinates.push(ex); - } - }); - return uniqueCoordinates; -} diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_field_examples.ts b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_field_examples.ts index 0e04665256e20..dfc68e6dac9ae 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_field_examples.ts +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_field_examples.ts @@ -15,6 +15,8 @@ import type { ISearchStart, } from '@kbn/data-plugin/public'; import { isPopulatedObject } from '@kbn/ml-is-populated-object'; +import type { SearchHit } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import { getUniqGeoOrStrExamples } from '../../../common/util/example_utils'; import { buildBaseFilterCriteria } from '../../../../../common/utils/query_utils'; import type { Field, @@ -90,20 +92,11 @@ export const fetchFieldsExamples = ( if (body.hits.total > 0) { const hits = body.hits.hits; - for (let i = 0; i < hits.length; i++) { - // Use lodash get() to support field names containing dots. - const doc: object[] | undefined = get(hits[i].fields, field.fieldName); - // the results from fields query is always an array - if (Array.isArray(doc) && doc.length > 0) { - const example = doc[0]; - if (example !== undefined && stats.examples.indexOf(example) === -1) { - stats.examples.push(example); - if (stats.examples.length === maxExamples) { - break; - } - } - } - } + const processedDocs = hits.map((hit: SearchHit) => { + const doc: object[] | undefined = get(hit.fields, field.fieldName); + return Array.isArray(doc) && doc.length > 0 ? doc[0] : doc; + }); + stats.examples = getUniqGeoOrStrExamples(processedDocs, maxExamples); } return stats; From 9466d9b33661a84373f38a30ff6002f8d5c128d5 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 13 Jul 2022 15:03:46 -0500 Subject: [PATCH 5/7] [ML] Use name for data view instead of title --- .../index_data_visualizer_view/index_data_visualizer_view.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/components/index_data_visualizer_view/index_data_visualizer_view.tsx b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/components/index_data_visualizer_view/index_data_visualizer_view.tsx index 0b4103687bbde..079804a47cd7b 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/components/index_data_visualizer_view/index_data_visualizer_view.tsx +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/components/index_data_visualizer_view/index_data_visualizer_view.tsx @@ -399,7 +399,7 @@ export const IndexDataVisualizerView: FC = (dataVi
-

{currentDataView.title}

+

{currentDataView.getName()}

Date: Wed, 13 Jul 2022 16:09:56 -0500 Subject: [PATCH 6/7] [ML] Add sticky header for field stats table in Discover --- .../common/components/stats_table/_index.scss | 5 ++--- .../stats_table/data_visualizer_stats_table.tsx | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/_index.scss b/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/_index.scss index 7ac8aa4365732..5aaf24b82a1a6 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/_index.scss +++ b/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/_index.scss @@ -31,9 +31,8 @@ $panelWidthL: #{'max(40%, 450px)'}; } .euiTableRow > .euiTableRowCell { - border-bottom: 0; - border-top: $euiBorderThin; - + border-top: 0; + border-bottom: $euiBorderThin; } .euiTableCellContent { diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/data_visualizer_stats_table.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/data_visualizer_stats_table.tsx index a2d61d104d138..dcdefb9441ade 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/data_visualizer_stats_table.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/data_visualizer_stats_table.tsx @@ -20,10 +20,12 @@ import { RIGHT_ALIGNMENT, EuiResizeObserver, EuiLoadingSpinner, + useEuiTheme, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { EuiTableComputedColumnType } from '@elastic/eui/src/components/basic_table/table_types'; import { throttle } from 'lodash'; +import { css } from '@emotion/react'; import { JOB_FIELD_TYPES } from '../../../../../common/constants'; import type { JobFieldType, DataVisualizerTableState } from '../../../../../common/types'; import { DocumentStat } from './components/field_data_row/document_stats'; @@ -70,6 +72,8 @@ export const DataVisualizerTable = ({ onChange, loading, }: DataVisualizerTableProps) => { + const { euiTheme } = useEuiTheme(); + const [expandedRowItemIds, setExpandedRowItemIds] = useState([]); const [expandAll, setExpandAll] = useState(false); @@ -361,6 +365,18 @@ export const DataVisualizerTable = ({ rowProps={(item) => ({ 'data-test-subj': `dataVisualizerRow row-${item.fieldName}`, })} + css={css` + thead { + position: sticky; + inset-block-start: 0; + z-index: 1; + background-color: ${euiTheme.colors.emptyShade}; + box-shadow: inset 0 0px 0, inset 0 -1px 0 ${euiTheme.border.color}; + } + .euiTableRow > .euiTableRowCel { + border-top: 0px; + } + `} />
)} From cc5f0fd3ec2c3c73693f7c809509ae5d8fbf4459 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 14 Jul 2022 11:28:50 -0500 Subject: [PATCH 7/7] [ML] Move unknown to bottom, rename JOB_FIELD_TYPES --- .../data_visualizer/common/constants.ts | 6 +- .../common/types/job_field_type.ts | 4 +- .../expanded_row/file_based_expanded_row.tsx | 18 ++--- .../geo_point_content_with_map.tsx | 5 +- .../expanded_row/index_based_expanded_row.tsx | 20 ++--- .../field_data_row/action_menu/actions.ts | 7 +- .../field_data_row/action_menu/lens_utils.ts | 26 +++--- .../field_type_icon/field_type_icon.test.tsx | 6 +- .../fields_stats_grid/create_fields.ts | 20 ++--- .../fields_stats_grid/filter_fields.ts | 4 +- .../fields_stats_grid/get_field_names.ts | 6 +- .../data_visualizer_stats_table.tsx | 9 ++- .../common/util/field_types_utils.test.ts | 16 ++-- .../common/util/field_types_utils.ts | 79 +++++++++++-------- .../hooks/use_data_visualizer_grid_data.ts | 4 +- .../requests/get_fields_stats.ts | 16 ++-- 16 files changed, 134 insertions(+), 112 deletions(-) diff --git a/x-pack/plugins/data_visualizer/common/constants.ts b/x-pack/plugins/data_visualizer/common/constants.ts index 0d0b0552cee24..1923613d72c58 100644 --- a/x-pack/plugins/data_visualizer/common/constants.ts +++ b/x-pack/plugins/data_visualizer/common/constants.ts @@ -29,18 +29,18 @@ export const FILE_FORMATS = { // XML: 'xml', }; -export const JOB_FIELD_TYPES = { +export const SUPPORTED_FIELD_TYPES = { BOOLEAN: 'boolean', DATE: 'date', GEO_POINT: 'geo_point', GEO_SHAPE: 'geo_shape', + HISTOGRAM: 'histogram', IP: 'ip', KEYWORD: 'keyword', NUMBER: 'number', TEXT: 'text', - HISTOGRAM: 'histogram', - UNKNOWN: 'unknown', VERSION: 'version', + UNKNOWN: 'unknown', } as const; export const OMIT_FIELDS: string[] = ['_source', '_type', '_index', '_id', '_version', '_score']; diff --git a/x-pack/plugins/data_visualizer/common/types/job_field_type.ts b/x-pack/plugins/data_visualizer/common/types/job_field_type.ts index ecb6ade035695..bc44361a416c7 100644 --- a/x-pack/plugins/data_visualizer/common/types/job_field_type.ts +++ b/x-pack/plugins/data_visualizer/common/types/job_field_type.ts @@ -5,5 +5,5 @@ * 2.0. */ -import { JOB_FIELD_TYPES } from '../constants'; -export type JobFieldType = typeof JOB_FIELD_TYPES[keyof typeof JOB_FIELD_TYPES]; +import { SUPPORTED_FIELD_TYPES } from '../constants'; +export type JobFieldType = typeof SUPPORTED_FIELD_TYPES[keyof typeof SUPPORTED_FIELD_TYPES]; diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/file_based_expanded_row.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/file_based_expanded_row.tsx index 1cf0f66596bd7..ebe37dda153f4 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/file_based_expanded_row.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/file_based_expanded_row.tsx @@ -16,7 +16,7 @@ import { NumberContent, } from '../stats_table/components/field_data_expanded_row'; import { GeoPointContent } from './geo_point_content/geo_point_content'; -import { JOB_FIELD_TYPES } from '../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../common/constants'; import type { FileBasedFieldVisConfig } from '../../../../../common/types/field_vis_config'; export const FileBasedDataVisualizerExpandedRow = ({ item }: { item: FileBasedFieldVisConfig }) => { @@ -25,26 +25,26 @@ export const FileBasedDataVisualizerExpandedRow = ({ item }: { item: FileBasedFi function getCardContent() { switch (type) { - case JOB_FIELD_TYPES.NUMBER: + case SUPPORTED_FIELD_TYPES.NUMBER: return ; - case JOB_FIELD_TYPES.BOOLEAN: + case SUPPORTED_FIELD_TYPES.BOOLEAN: return ; - case JOB_FIELD_TYPES.DATE: + case SUPPORTED_FIELD_TYPES.DATE: return ; - case JOB_FIELD_TYPES.GEO_POINT: + case SUPPORTED_FIELD_TYPES.GEO_POINT: return ; - case JOB_FIELD_TYPES.IP: + case SUPPORTED_FIELD_TYPES.IP: return ; - case JOB_FIELD_TYPES.KEYWORD: - case JOB_FIELD_TYPES.VERSION: + case SUPPORTED_FIELD_TYPES.KEYWORD: + case SUPPORTED_FIELD_TYPES.VERSION: return ; - case JOB_FIELD_TYPES.TEXT: + case SUPPORTED_FIELD_TYPES.TEXT: return ; default: diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx index b3d34ffb040bd..f12b65569be1c 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/geo_point_content_with_map/geo_point_content_with_map.tsx @@ -13,7 +13,7 @@ import { DocumentStatsTable } from '../../stats_table/components/field_data_expa import { ExamplesList } from '../../examples_list'; import { FieldVisConfig } from '../../stats_table/types'; import { useDataVisualizerKibana } from '../../../../kibana_context'; -import { JOB_FIELD_TYPES } from '../../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../../common/constants'; import { EmbeddedMapComponent } from '../../embedded_map'; import { ExpandedRowPanel } from '../../stats_table/components/field_data_expanded_row/expanded_row_panel'; @@ -35,7 +35,8 @@ export const GeoPointContentWithMap: FC<{ dataView?.id !== undefined && config !== undefined && config.fieldName !== undefined && - (config.type === JOB_FIELD_TYPES.GEO_POINT || config.type === JOB_FIELD_TYPES.GEO_SHAPE) + (config.type === SUPPORTED_FIELD_TYPES.GEO_POINT || + config.type === SUPPORTED_FIELD_TYPES.GEO_SHAPE) ) { const params = { indexPatternId: dataView.id, diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx index e4c5cf460fd97..e770a4c6bba7a 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/expanded_row/index_based_expanded_row.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { DataView, DataViewField } from '@kbn/data-views-plugin/public'; import { GeoPointContentWithMap } from './geo_point_content_with_map'; -import { JOB_FIELD_TYPES } from '../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../common/constants'; import { BooleanContent, DateContent, @@ -51,17 +51,17 @@ export const IndexBasedDataVisualizerExpandedRow = ({ } switch (type) { - case JOB_FIELD_TYPES.NUMBER: + case SUPPORTED_FIELD_TYPES.NUMBER: return ; - case JOB_FIELD_TYPES.BOOLEAN: + case SUPPORTED_FIELD_TYPES.BOOLEAN: return ; - case JOB_FIELD_TYPES.DATE: + case SUPPORTED_FIELD_TYPES.DATE: return ; - case JOB_FIELD_TYPES.GEO_POINT: - case JOB_FIELD_TYPES.GEO_SHAPE: + case SUPPORTED_FIELD_TYPES.GEO_POINT: + case SUPPORTED_FIELD_TYPES.GEO_SHAPE: return ( ); - case JOB_FIELD_TYPES.IP: + case SUPPORTED_FIELD_TYPES.IP: return ; - case JOB_FIELD_TYPES.KEYWORD: - case JOB_FIELD_TYPES.VERSION: + case SUPPORTED_FIELD_TYPES.KEYWORD: + case SUPPORTED_FIELD_TYPES.VERSION: return ; - case JOB_FIELD_TYPES.TEXT: + case SUPPORTED_FIELD_TYPES.TEXT: return ; default: diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/actions.ts b/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/actions.ts index 73e69b00132d3..314856e07554f 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/actions.ts +++ b/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/actions.ts @@ -18,7 +18,7 @@ import { dataVisualizerRefresh$, Refresh, } from '../../../../index_data_visualizer/services/timefilter_refresh_service'; -import { JOB_FIELD_TYPES } from '../../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../../common/constants'; import { APP_ID } from '../../../../../../common/constants'; export function getActions( @@ -80,7 +80,10 @@ export function getActions( type: 'icon', icon: 'gisApp', available: (item: FieldVisConfig) => { - return item.type === JOB_FIELD_TYPES.GEO_POINT || item.type === JOB_FIELD_TYPES.GEO_SHAPE; + return ( + item.type === SUPPORTED_FIELD_TYPES.GEO_POINT || + item.type === SUPPORTED_FIELD_TYPES.GEO_SHAPE + ); }, onClick: async (item: FieldVisConfig) => { if (services?.uiActions && dataView) { diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/lens_utils.ts b/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/lens_utils.ts index b201baffa8f49..034f7037fc29a 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/lens_utils.ts +++ b/x-pack/plugins/data_visualizer/public/application/common/components/field_data_row/action_menu/lens_utils.ts @@ -19,7 +19,7 @@ import type { import { DOCUMENT_FIELD_NAME as RECORDS_FIELD } from '@kbn/lens-plugin/common/constants'; import type { CombinedQuery } from '../../../../index_data_visualizer/types/combined_query'; import { FieldVisConfig } from '../../stats_table/types'; -import { JOB_FIELD_TYPES } from '../../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../../common/constants'; interface ColumnsAndLayer { columns: Record; @@ -200,20 +200,20 @@ export function getBooleanSettings(item: FieldVisConfig) { export function getCompatibleLensDataType(type: FieldVisConfig['type']): string | undefined { let lensType: string | undefined; switch (type) { - case JOB_FIELD_TYPES.KEYWORD: - case JOB_FIELD_TYPES.VERSION: + case SUPPORTED_FIELD_TYPES.KEYWORD: + case SUPPORTED_FIELD_TYPES.VERSION: lensType = 'string'; break; - case JOB_FIELD_TYPES.DATE: + case SUPPORTED_FIELD_TYPES.DATE: lensType = 'date'; break; - case JOB_FIELD_TYPES.NUMBER: + case SUPPORTED_FIELD_TYPES.NUMBER: lensType = 'number'; break; - case JOB_FIELD_TYPES.IP: + case SUPPORTED_FIELD_TYPES.IP: lensType = 'ip'; break; - case JOB_FIELD_TYPES.BOOLEAN: + case SUPPORTED_FIELD_TYPES.BOOLEAN: lensType = 'string'; break; default: @@ -229,20 +229,20 @@ function getColumnsAndLayer( ): ColumnsAndLayer | undefined { if (item.fieldName === undefined) return; - if (fieldType === JOB_FIELD_TYPES.DATE) { + if (fieldType === SUPPORTED_FIELD_TYPES.DATE) { return getDateSettings(item); } - if (fieldType === JOB_FIELD_TYPES.NUMBER) { + if (fieldType === SUPPORTED_FIELD_TYPES.NUMBER) { return getNumberSettings(item, defaultDataView); } if ( - fieldType === JOB_FIELD_TYPES.IP || - fieldType === JOB_FIELD_TYPES.KEYWORD || - fieldType === JOB_FIELD_TYPES.VERSION + fieldType === SUPPORTED_FIELD_TYPES.IP || + fieldType === SUPPORTED_FIELD_TYPES.KEYWORD || + fieldType === SUPPORTED_FIELD_TYPES.VERSION ) { return getKeywordSettings(item); } - if (fieldType === JOB_FIELD_TYPES.BOOLEAN) { + if (fieldType === SUPPORTED_FIELD_TYPES.BOOLEAN) { return getBooleanSettings(item); } } diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/field_type_icon/field_type_icon.test.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/field_type_icon/field_type_icon.test.tsx index 874cdaa670c49..9962937fa80dc 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/field_type_icon/field_type_icon.test.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/field_type_icon/field_type_icon.test.tsx @@ -9,12 +9,12 @@ import React from 'react'; import { mount, shallow } from 'enzyme'; import { FieldTypeIcon } from './field_type_icon'; -import { JOB_FIELD_TYPES } from '../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../common/constants'; describe('FieldTypeIcon', () => { test(`render component when type matches a field type`, () => { const typeIconComponent = shallow( - + ); expect(typeIconComponent).toMatchSnapshot(); }); @@ -24,7 +24,7 @@ describe('FieldTypeIcon', () => { jest.useFakeTimers(); const typeIconComponent = mount( - + ); expect(typeIconComponent.find('EuiToolTip').children()).toHaveLength(1); diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/create_fields.ts b/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/create_fields.ts index 05d07111c80ac..2ac163104eea5 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/create_fields.ts +++ b/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/create_fields.ts @@ -8,7 +8,7 @@ import { FindFileStructureResponse } from '@kbn/file-upload-plugin/common'; import { getFieldNames, getSupportedFieldType } from './get_field_names'; import { FileBasedFieldVisConfig } from '../stats_table/types'; -import { JOB_FIELD_TYPES } from '../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../common/constants'; import { roundToDecimalPlace } from '../utils'; export function createFields(results: FindFileStructureResponse) { @@ -28,20 +28,20 @@ export function createFields(results: FindFileStructureResponse) { if (fieldStats[name] !== undefined) { const field: FileBasedFieldVisConfig = { fieldName: name, - type: JOB_FIELD_TYPES.UNKNOWN, + type: SUPPORTED_FIELD_TYPES.UNKNOWN, }; const f = fieldStats[name]; const m = mappings.properties[name]; // sometimes the timestamp field is not in the mappings, and so our // collection of fields will be missing a time field with a type of date - if (name === timestampField && field.type === JOB_FIELD_TYPES.UNKNOWN) { - field.type = JOB_FIELD_TYPES.DATE; + if (name === timestampField && field.type === SUPPORTED_FIELD_TYPES.UNKNOWN) { + field.type = SUPPORTED_FIELD_TYPES.DATE; } if (m !== undefined) { field.type = getSupportedFieldType(m.type); - if (field.type === JOB_FIELD_TYPES.NUMBER) { + if (field.type === SUPPORTED_FIELD_TYPES.NUMBER) { numericFieldsCount += 1; } if (m.format !== undefined) { @@ -71,7 +71,7 @@ export function createFields(results: FindFileStructureResponse) { } if (f.top_hits !== undefined) { - if (field.type === JOB_FIELD_TYPES.TEXT) { + if (field.type === SUPPORTED_FIELD_TYPES.TEXT) { _stats = { ..._stats, examples: f.top_hits.map((hit) => hit.value), @@ -84,7 +84,7 @@ export function createFields(results: FindFileStructureResponse) { } } - if (field.type === JOB_FIELD_TYPES.DATE) { + if (field.type === SUPPORTED_FIELD_TYPES.DATE) { _stats = { ..._stats, earliest: f.earliest, @@ -99,9 +99,9 @@ export function createFields(results: FindFileStructureResponse) { // this could be the message field for a semi-structured log file or a // field which the endpoint has not been able to work out any information for const type = - mappings.properties[name] && mappings.properties[name].type === JOB_FIELD_TYPES.TEXT - ? JOB_FIELD_TYPES.TEXT - : JOB_FIELD_TYPES.UNKNOWN; + mappings.properties[name] && mappings.properties[name].type === SUPPORTED_FIELD_TYPES.TEXT + ? SUPPORTED_FIELD_TYPES.TEXT + : SUPPORTED_FIELD_TYPES.UNKNOWN; return { fieldName: name, diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/filter_fields.ts b/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/filter_fields.ts index 145a8fa5f8867..4ca65eec6635b 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/filter_fields.ts +++ b/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/filter_fields.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { JOB_FIELD_TYPES } from '../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../common/constants'; interface CommonFieldConfig { type: string; @@ -32,6 +32,6 @@ export function filterFields( return { filteredFields: items, visibleFieldsCount: items.length, - visibleMetricsCount: items.filter((d) => d.type === JOB_FIELD_TYPES.NUMBER).length, + visibleMetricsCount: items.filter((d) => d.type === SUPPORTED_FIELD_TYPES.NUMBER).length, }; } diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/get_field_names.ts b/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/get_field_names.ts index b6868ced4de69..b0750278ab9e3 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/get_field_names.ts +++ b/x-pack/plugins/data_visualizer/public/application/common/components/fields_stats_grid/get_field_names.ts @@ -9,7 +9,7 @@ import { difference } from 'lodash'; import { ES_FIELD_TYPES } from '@kbn/data-plugin/common'; import type { FindFileStructureResponse } from '@kbn/file-upload-plugin/common'; import type { JobFieldType } from '../../../../../common/types'; -import { JOB_FIELD_TYPES } from '../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../common/constants'; export function getFieldNames(results: FindFileStructureResponse) { const { mappings, field_stats: fieldStats, column_names: columnNames } = results; @@ -44,11 +44,11 @@ export function getSupportedFieldType(type: string): JobFieldType { case ES_FIELD_TYPES.LONG: case ES_FIELD_TYPES.SHORT: case ES_FIELD_TYPES.UNSIGNED_LONG: - return JOB_FIELD_TYPES.NUMBER; + return SUPPORTED_FIELD_TYPES.NUMBER; case ES_FIELD_TYPES.DATE: case ES_FIELD_TYPES.DATE_NANOS: - return JOB_FIELD_TYPES.DATE; + return SUPPORTED_FIELD_TYPES.DATE; default: return type as JobFieldType; diff --git a/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/data_visualizer_stats_table.tsx b/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/data_visualizer_stats_table.tsx index dcdefb9441ade..8b38563591e3d 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/data_visualizer_stats_table.tsx +++ b/x-pack/plugins/data_visualizer/public/application/common/components/stats_table/data_visualizer_stats_table.tsx @@ -26,7 +26,7 @@ import { i18n } from '@kbn/i18n'; import { EuiTableComputedColumnType } from '@elastic/eui/src/components/basic_table/table_types'; import { throttle } from 'lodash'; import { css } from '@emotion/react'; -import { JOB_FIELD_TYPES } from '../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../common/constants'; import type { JobFieldType, DataVisualizerTableState } from '../../../../../common/types'; import { DocumentStat } from './components/field_data_row/document_stats'; import { IndexBasedNumberContentPreview } from './components/field_data_row/number_content_preview'; @@ -293,13 +293,14 @@ export const DataVisualizerTable = ({ } if ( - (item.type === JOB_FIELD_TYPES.KEYWORD || item.type === JOB_FIELD_TYPES.IP) && + (item.type === SUPPORTED_FIELD_TYPES.KEYWORD || + item.type === SUPPORTED_FIELD_TYPES.IP) && item.stats?.topValues !== undefined ) { return ; } - if (item.type === JOB_FIELD_TYPES.NUMBER) { + if (item.type === SUPPORTED_FIELD_TYPES.NUMBER) { if (isIndexBasedFieldVisConfig(item) && item.stats?.distribution !== undefined) { // If the cardinality is only low, show the top values instead of a distribution chart return item.stats?.distribution?.percentiles.length <= 2 ? ( @@ -312,7 +313,7 @@ export const DataVisualizerTable = ({ } } - if (item.type === JOB_FIELD_TYPES.BOOLEAN) { + if (item.type === SUPPORTED_FIELD_TYPES.BOOLEAN) { return ; } diff --git a/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.test.ts b/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.test.ts index 8f9e4ffd3b898..0f3ae62eae209 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.test.ts +++ b/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.test.ts @@ -5,24 +5,26 @@ * 2.0. */ -import { JOB_FIELD_TYPES } from '../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../common/constants'; import { getJobTypeLabel, jobTypeLabels } from './field_types_utils'; describe('field type utils', () => { describe('getJobTypeLabel: Getting a field type aria label by passing what it is stored in constants', () => { - test('should returns all JOB_FIELD_TYPES labels exactly as it is for each correct value', () => { - const keys = Object.keys(JOB_FIELD_TYPES); + test('should returns all SUPPORTED_FIELD_TYPES labels exactly as it is for each correct value', () => { + const keys = Object.keys(SUPPORTED_FIELD_TYPES); const receivedLabels: Record = {}; const testStorage = jobTypeLabels; keys.forEach((key) => { - const constant = key as keyof typeof JOB_FIELD_TYPES; - receivedLabels[JOB_FIELD_TYPES[constant]] = getJobTypeLabel(JOB_FIELD_TYPES[constant]); + const constant = key as keyof typeof SUPPORTED_FIELD_TYPES; + receivedLabels[SUPPORTED_FIELD_TYPES[constant]] = getJobTypeLabel( + SUPPORTED_FIELD_TYPES[constant] + ); }); expect(receivedLabels).toEqual(testStorage); }); - test('should returns NULL as JOB_FIELD_TYPES does not contain such a keyword', () => { - expect(getJobTypeLabel('JOB_FIELD_TYPES')).toBe(null); + test('should returns NULL as SUPPORTED_FIELD_TYPES does not contain such a keyword', () => { + expect(getJobTypeLabel('SUPPORTED_FIELD_TYPES')).toBe(null); }); }); }); diff --git a/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.ts b/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.ts index 9e4a686d692d9..5d1293f0a22b3 100644 --- a/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.ts +++ b/x-pack/plugins/data_visualizer/public/application/common/util/field_types_utils.ts @@ -8,55 +8,70 @@ import { i18n } from '@kbn/i18n'; import { DataViewField } from '@kbn/data-views-plugin/public'; import { KBN_FIELD_TYPES } from '@kbn/data-plugin/common'; -import { JOB_FIELD_TYPES } from '../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../common/constants'; export const getJobTypeLabel = (type: string) => { return type in jobTypeLabels ? jobTypeLabels[type as keyof typeof jobTypeLabels] : null; }; export const jobTypeLabels = { - [JOB_FIELD_TYPES.BOOLEAN]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.booleanTypeLabel', { - defaultMessage: 'Boolean', - }), - [JOB_FIELD_TYPES.DATE]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.dateTypeLabel', { + [SUPPORTED_FIELD_TYPES.BOOLEAN]: i18n.translate( + 'xpack.dataVisualizer.fieldTypeIcon.booleanTypeLabel', + { + defaultMessage: 'Boolean', + } + ), + [SUPPORTED_FIELD_TYPES.DATE]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.dateTypeLabel', { defaultMessage: 'Date', }), - [JOB_FIELD_TYPES.GEO_POINT]: i18n.translate( + [SUPPORTED_FIELD_TYPES.GEO_POINT]: i18n.translate( 'xpack.dataVisualizer.fieldTypeIcon.geoPointTypeLabel', { defaultMessage: 'Geo point', } ), - [JOB_FIELD_TYPES.GEO_SHAPE]: i18n.translate( + [SUPPORTED_FIELD_TYPES.GEO_SHAPE]: i18n.translate( 'xpack.dataVisualizer.fieldTypeIcon.geoShapeTypeLabel', { defaultMessage: 'Geo shape', } ), - [JOB_FIELD_TYPES.IP]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.ipTypeLabel', { + [SUPPORTED_FIELD_TYPES.IP]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.ipTypeLabel', { defaultMessage: 'IP', }), - [JOB_FIELD_TYPES.KEYWORD]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.keywordTypeLabel', { - defaultMessage: 'Keyword', - }), - [JOB_FIELD_TYPES.NUMBER]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.numberTypeLabel', { - defaultMessage: 'Number', - }), - [JOB_FIELD_TYPES.HISTOGRAM]: i18n.translate( + [SUPPORTED_FIELD_TYPES.KEYWORD]: i18n.translate( + 'xpack.dataVisualizer.fieldTypeIcon.keywordTypeLabel', + { + defaultMessage: 'Keyword', + } + ), + [SUPPORTED_FIELD_TYPES.NUMBER]: i18n.translate( + 'xpack.dataVisualizer.fieldTypeIcon.numberTypeLabel', + { + defaultMessage: 'Number', + } + ), + [SUPPORTED_FIELD_TYPES.HISTOGRAM]: i18n.translate( 'xpack.dataVisualizer.fieldTypeIcon.histogramTypeLabel', { defaultMessage: 'Histogram', } ), - [JOB_FIELD_TYPES.TEXT]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.textTypeLabel', { + [SUPPORTED_FIELD_TYPES.TEXT]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.textTypeLabel', { defaultMessage: 'Text', }), - [JOB_FIELD_TYPES.UNKNOWN]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.unknownTypeLabel', { - defaultMessage: 'Unknown', - }), - [JOB_FIELD_TYPES.VERSION]: i18n.translate('xpack.dataVisualizer.fieldTypeIcon.versionTypeLabel', { - defaultMessage: 'Version', - }), + [SUPPORTED_FIELD_TYPES.UNKNOWN]: i18n.translate( + 'xpack.dataVisualizer.fieldTypeIcon.unknownTypeLabel', + { + defaultMessage: 'Unknown', + } + ), + [SUPPORTED_FIELD_TYPES.VERSION]: i18n.translate( + 'xpack.dataVisualizer.fieldTypeIcon.versionTypeLabel', + { + defaultMessage: 'Version', + } + ), }; // convert kibana types to ML Job types @@ -68,32 +83,32 @@ export function kbnTypeToJobType(field: DataViewField) { switch (field.type) { case KBN_FIELD_TYPES.STRING: - type = field.aggregatable ? JOB_FIELD_TYPES.KEYWORD : JOB_FIELD_TYPES.TEXT; + type = field.aggregatable ? SUPPORTED_FIELD_TYPES.KEYWORD : SUPPORTED_FIELD_TYPES.TEXT; - if (field.esTypes?.includes(JOB_FIELD_TYPES.VERSION)) { - type = JOB_FIELD_TYPES.VERSION; + if (field.esTypes?.includes(SUPPORTED_FIELD_TYPES.VERSION)) { + type = SUPPORTED_FIELD_TYPES.VERSION; } break; case KBN_FIELD_TYPES.NUMBER: - type = JOB_FIELD_TYPES.NUMBER; + type = SUPPORTED_FIELD_TYPES.NUMBER; break; case KBN_FIELD_TYPES.DATE: - type = JOB_FIELD_TYPES.DATE; + type = SUPPORTED_FIELD_TYPES.DATE; break; case KBN_FIELD_TYPES.IP: - type = JOB_FIELD_TYPES.IP; + type = SUPPORTED_FIELD_TYPES.IP; break; case KBN_FIELD_TYPES.BOOLEAN: - type = JOB_FIELD_TYPES.BOOLEAN; + type = SUPPORTED_FIELD_TYPES.BOOLEAN; break; case KBN_FIELD_TYPES.GEO_POINT: - type = JOB_FIELD_TYPES.GEO_POINT; + type = SUPPORTED_FIELD_TYPES.GEO_POINT; break; case KBN_FIELD_TYPES.GEO_SHAPE: - type = JOB_FIELD_TYPES.GEO_SHAPE; + type = SUPPORTED_FIELD_TYPES.GEO_SHAPE; break; case KBN_FIELD_TYPES.HISTOGRAM: - type = JOB_FIELD_TYPES.HISTOGRAM; + type = SUPPORTED_FIELD_TYPES.HISTOGRAM; break; default: diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/hooks/use_data_visualizer_grid_data.ts b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/hooks/use_data_visualizer_grid_data.ts index dd92b025d7112..5fbf8c447c989 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/hooks/use_data_visualizer_grid_data.ts +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/hooks/use_data_visualizer_grid_data.ts @@ -20,7 +20,7 @@ import { dataVisualizerRefresh$ } from '../services/timefilter_refresh_service'; import { TimeBuckets } from '../../../../common/services/time_buckets'; import { FieldVisConfig } from '../../common/components/stats_table/types'; import { - JOB_FIELD_TYPES, + SUPPORTED_FIELD_TYPES, NON_AGGREGATABLE_FIELD_TYPES, OMIT_FIELDS, } from '../../../../common/constants'; @@ -319,7 +319,7 @@ export const useDataVisualizerGridData = ( const metricConfig: FieldVisConfig = { ...fieldData, fieldFormat: currentDataView.getFormatterForField(field), - type: JOB_FIELD_TYPES.NUMBER, + type: SUPPORTED_FIELD_TYPES.NUMBER, loading: fieldData?.existsInDocs ?? true, aggregatable: true, deletable: field.runtimeField !== undefined, diff --git a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_fields_stats.ts b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_fields_stats.ts index e798b1138996e..a549e40704c0f 100644 --- a/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_fields_stats.ts +++ b/x-pack/plugins/data_visualizer/public/application/index_data_visualizer/search_strategy/requests/get_fields_stats.ts @@ -11,7 +11,7 @@ import { ISearchStart } from '@kbn/data-plugin/public'; import type { FieldStatsCommonRequestParams } from '../../../../../common/types/field_stats'; import type { FieldStatsError } from '../../../../../common/types/field_stats'; import type { FieldStats } from '../../../../../common/types/field_stats'; -import { JOB_FIELD_TYPES } from '../../../../../common/constants'; +import { SUPPORTED_FIELD_TYPES } from '../../../../../common/constants'; import { fetchDateFieldsStats } from './get_date_field_stats'; import { fetchBooleanFieldsStats } from './get_boolean_field_stats'; import { fetchFieldsExamples } from './get_field_examples'; @@ -31,17 +31,17 @@ export const getFieldsStats = ( ): Observable | undefined => { const fieldType = fields[0].type; switch (fieldType) { - case JOB_FIELD_TYPES.NUMBER: + case SUPPORTED_FIELD_TYPES.NUMBER: return fetchNumericFieldsStats(dataSearch, params, fields, options); - case JOB_FIELD_TYPES.KEYWORD: - case JOB_FIELD_TYPES.IP: - case JOB_FIELD_TYPES.VERSION: + case SUPPORTED_FIELD_TYPES.KEYWORD: + case SUPPORTED_FIELD_TYPES.IP: + case SUPPORTED_FIELD_TYPES.VERSION: return fetchStringFieldsStats(dataSearch, params, fields, options); - case JOB_FIELD_TYPES.DATE: + case SUPPORTED_FIELD_TYPES.DATE: return fetchDateFieldsStats(dataSearch, params, fields, options); - case JOB_FIELD_TYPES.BOOLEAN: + case SUPPORTED_FIELD_TYPES.BOOLEAN: return fetchBooleanFieldsStats(dataSearch, params, fields, options); - case JOB_FIELD_TYPES.TEXT: + case SUPPORTED_FIELD_TYPES.TEXT: return fetchFieldsExamples(dataSearch, params, fields, options); default: // Use an exists filter on the the field name to get