diff --git a/src/plugins/visualizations/public/convert_to_lens/datasource.ts b/src/plugins/visualizations/public/convert_to_lens/datasource.ts new file mode 100644 index 000000000000..502632651170 --- /dev/null +++ b/src/plugins/visualizations/public/convert_to_lens/datasource.ts @@ -0,0 +1,20 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; + +export const getDataViewByIndexPatternId = async ( + indexPatternId: string | undefined, + dataViews: DataViewsPublicPluginStart +) => { + try { + return indexPatternId ? await dataViews.get(indexPatternId) : await dataViews.getDefault(); + } catch (err) { + return null; + } +}; diff --git a/src/plugins/visualizations/public/convert_to_lens/utils.ts b/src/plugins/visualizations/public/convert_to_lens/utils.ts index 66bc71d3d42b..a5337568b556 100644 --- a/src/plugins/visualizations/public/convert_to_lens/utils.ts +++ b/src/plugins/visualizations/public/convert_to_lens/utils.ts @@ -8,7 +8,6 @@ import type { DataView } from '@kbn/data-views-plugin/common'; import { METRIC_TYPES } from '@kbn/data-plugin/public'; -import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; import { AggBasedColumn, SchemaConfig, SupportedAggregation } from '../../common'; import { convertBucketToColumns } from '../../common/convert_to_lens/lib/buckets'; import { isSiblingPipeline } from '../../common/convert_to_lens/lib/utils'; @@ -122,14 +121,3 @@ export const sortColumns = ( }; export const getColumnIds = (columns: AggBasedColumn[]) => columns.map(({ columnId }) => columnId); - -export const getDataViewByIndexPatternId = async ( - indexPatternId: string | undefined, - dataViews: DataViewsPublicPluginStart -) => { - try { - return indexPatternId ? await dataViews.get(indexPatternId) : await dataViews.getDefault(); - } catch (err) { - return null; - } -}; diff --git a/src/plugins/visualizations/public/index.ts b/src/plugins/visualizations/public/index.ts index c704342f14ea..693bbd26a2e2 100644 --- a/src/plugins/visualizations/public/index.ts +++ b/src/plugins/visualizations/public/index.ts @@ -74,4 +74,4 @@ export { } from './triggers'; export const convertToLensModule = import('./convert_to_lens'); -export { getDataViewByIndexPatternId } from './convert_to_lens/utils'; +export { getDataViewByIndexPatternId } from './convert_to_lens/datasource';