From b2610b209531c1102e65a4703c0b3f9dc4d2e3d2 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Fri, 7 Oct 2022 15:54:50 +0300 Subject: [PATCH 1/4] [Draft][Lens] Bundle Size Reduction --- .../expression_xy/common/index.ts | 2 + .../expression_xy/public/index.ts | 2 + x-pack/plugins/lens/common/constants.ts | 6 - x-pack/plugins/lens/common/types.ts | 15 +- x-pack/plugins/lens/kibana.json | 2 +- .../editor_frame/config_panel/add_layer.tsx | 8 +- .../config_panel/config_panel.test.tsx | 31 ++-- .../layer_actions/remove_layer_action.tsx | 13 +- .../editor_frame/suggestion_helpers.ts | 17 +- x-pack/plugins/lens/public/index.ts | 5 +- .../dimension_panel/dimension_panel.test.tsx | 4 +- .../dimension_panel/dimension_panel.tsx | 19 ++- .../definitions/calculations/utils.test.ts | 4 +- .../definitions/calculations/utils.ts | 5 +- .../lens/public/mocks/visualization_mock.ts | 6 +- x-pack/plugins/lens/public/plugin.ts | 6 +- .../shared_components/axis_extent/types.ts | 2 +- .../state_management/lens_slice.test.ts | 6 +- .../open_in_discover_action.ts | 10 +- .../open_in_discover_drilldown.tsx | 41 ++--- x-pack/plugins/lens/public/utils.ts | 4 +- .../components/dimension_editor.test.tsx | 4 +- ...mension_editor_additional_section.test.tsx | 4 +- .../datatable/visualization.test.tsx | 68 ++++---- .../datatable/visualization.tsx | 9 +- .../visualizations/gauge/suggestions.test.ts | 20 +-- .../visualizations/gauge/suggestions.ts | 6 +- .../lens/public/visualizations/gauge/utils.ts | 2 +- .../gauge/visualization.test.ts | 8 +- .../visualizations/gauge/visualization.tsx | 6 +- .../heatmap/suggestions.test.ts | 40 ++--- .../visualizations/heatmap/suggestions.ts | 4 +- .../heatmap/visualization.test.ts | 8 +- .../visualizations/heatmap/visualization.tsx | 6 +- .../legacy_metric/dimension_editor.test.tsx | 4 +- .../legacy_metric/metric_suggestions.ts | 4 +- .../legacy_metric/visualization.test.ts | 28 ++-- .../legacy_metric/visualization.tsx | 6 +- .../visualizations/metric/suggestions.test.ts | 30 ++-- .../visualizations/metric/suggestions.ts | 4 +- .../metric/visualization.test.ts | 4 +- .../visualizations/metric/visualization.tsx | 8 +- .../partition/suggestions.test.ts | 26 +-- .../visualizations/partition/suggestions.ts | 18 +- .../partition/visualization.test.ts | 8 +- .../partition/visualization.tsx | 17 +- .../visualizations/xy/annotations/helpers.tsx | 4 +- .../xy/axes_configuration.test.ts | 4 +- .../xy/color_assignment.test.ts | 6 +- .../xy/reference_line_helpers.tsx | 4 +- .../visualizations/xy/to_expression.test.ts | 38 ++--- .../public/visualizations/xy/to_expression.ts | 14 +- .../visualizations/xy/visualization.test.ts | 154 +++++++++--------- .../visualizations/xy/visualization.tsx | 12 +- .../xy/visualization_helpers.tsx | 40 ++--- .../annotations_config_panel/index.test.tsx | 4 +- .../axis_settings_popover.test.tsx | 4 +- .../visual_options_popover.test.tsx | 6 +- .../xy_config_panel/xy_config_panel.test.tsx | 10 +- .../visualizations/xy/xy_suggestions.test.ts | 42 ++--- .../visualizations/xy/xy_suggestions.ts | 8 +- .../server/migrations/common_migrations.ts | 7 +- .../saved_object_migrations.test.ts | 13 +- 63 files changed, 466 insertions(+), 454 deletions(-) diff --git a/src/plugins/chart_expressions/expression_xy/common/index.ts b/src/plugins/chart_expressions/expression_xy/common/index.ts index b39002c8549c..9b404de95872 100755 --- a/src/plugins/chart_expressions/expression_xy/common/index.ts +++ b/src/plugins/chart_expressions/expression_xy/common/index.ts @@ -9,6 +9,8 @@ export const PLUGIN_ID = 'expressionXy'; export const PLUGIN_NAME = 'expressionXy'; +export { LayerTypes } from './constants'; + export type { XYArgs, EndValue, diff --git a/src/plugins/chart_expressions/expression_xy/public/index.ts b/src/plugins/chart_expressions/expression_xy/public/index.ts index d9447400aa26..7578c4ad89f9 100755 --- a/src/plugins/chart_expressions/expression_xy/public/index.ts +++ b/src/plugins/chart_expressions/expression_xy/public/index.ts @@ -14,4 +14,6 @@ export function plugin() { return new ExpressionXyPlugin(); } +export { LayerTypes } from '../common'; + export type { ExpressionXyPluginSetup, ExpressionXyPluginStart } from './types'; diff --git a/x-pack/plugins/lens/common/constants.ts b/x-pack/plugins/lens/common/constants.ts index 95cba8b75c4b..1e3d51a6941c 100644 --- a/x-pack/plugins/lens/common/constants.ts +++ b/x-pack/plugins/lens/common/constants.ts @@ -44,12 +44,6 @@ export const LegendDisplay = { HIDE: 'hide', } as const; -export const layerTypes = { - DATA: 'data', - REFERENCELINE: 'referenceLine', - ANNOTATIONS: 'annotations', -} as const; - // might collide with user-supplied field names, try to make as unique as possible export const DOCUMENT_FIELD_NAME = '___records___'; diff --git a/x-pack/plugins/lens/common/types.ts b/x-pack/plugins/lens/common/types.ts index d70ee4b7025a..c3410f986017 100644 --- a/x-pack/plugins/lens/common/types.ts +++ b/x-pack/plugins/lens/common/types.ts @@ -11,14 +11,9 @@ import type { $Values } from '@kbn/utility-types'; import type { CustomPaletteParams, PaletteOutput } from '@kbn/coloring'; import type { IFieldFormat, SerializedFieldFormat } from '@kbn/field-formats-plugin/common'; import type { ColorMode } from '@kbn/charts-plugin/common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/common'; import type { LegendSize } from '@kbn/visualizations-plugin/common'; -import { - CategoryDisplay, - layerTypes, - LegendDisplay, - NumberDisplay, - PieChartTypes, -} from './constants'; +import { CategoryDisplay, LegendDisplay, NumberDisplay, PieChartTypes } from './constants'; export type { OriginalColumn } from './expressions/map_to_columns'; @@ -44,11 +39,7 @@ export interface PersistableFilter extends Filter { export type SortingHint = 'version'; -export type CustomPaletteParamsConfig = CustomPaletteParams & { - maxSteps?: number; -}; - -export type LayerType = typeof layerTypes[keyof typeof layerTypes]; +export type LayerType = typeof LayerTypes[keyof typeof LayerTypes]; export type ValueLabelConfig = 'hide' | 'show'; diff --git a/x-pack/plugins/lens/kibana.json b/x-pack/plugins/lens/kibana.json index b84353e116f7..5f0b48608dab 100644 --- a/x-pack/plugins/lens/kibana.json +++ b/x-pack/plugins/lens/kibana.json @@ -25,12 +25,12 @@ "expressionGauge", "expressionMetricVis", "expressionHeatmap", + "expressionXY", "eventAnnotation", "unifiedSearch", "unifiedFieldList" ], "optionalPlugins": [ - "expressionXY", "usageCollection", "taskManager", "globalSearch", diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/add_layer.tsx b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/add_layer.tsx index c38a9a349370..dee24edcad17 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/add_layer.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/add_layer.tsx @@ -17,8 +17,8 @@ import { EuiFlexGroup, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; - -import { LayerType, layerTypes } from '../../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; +import type { LayerType } from '../../../../common'; import type { FramePublicAPI, Visualization } from '../../../types'; interface AddLayerButtonProps { @@ -29,7 +29,7 @@ interface AddLayerButtonProps { } export function getLayerType(visualization: Visualization, state: unknown, layerId: string) { - return visualization.getLayerType(layerId, state) || layerTypes.DATA; + return visualization.getLayerType(layerId, state) || LayerTypes.DATA; } export function AddLayerButton({ @@ -120,7 +120,7 @@ export function AddLayerButton({ toolTipContent, disabled, name: - type === layerTypes.ANNOTATIONS ? ( + type === LayerTypes.ANNOTATIONS ? ( {label} diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx index 102b1e3f2dd2..5fbfb0b86e11 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/config_panel.test.tsx @@ -24,7 +24,8 @@ import { UiActionsStart } from '@kbn/ui-actions-plugin/public'; import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks'; import { generateId } from '../../../id_generator'; import { mountWithProvider } from '../../../mocks'; -import { LayerType, layerTypes } from '../../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; +import type { LayerType } from '../../../../common'; import { ReactWrapper } from 'enzyme'; import { addLayer } from '../../../state_management'; import { AddLayerButton } from './add_layer'; @@ -266,7 +267,7 @@ describe('ConfigPanel', () => { describe('initial default value', () => { function clickToAddLayer( instance: ReactWrapper, - layerType: LayerType = layerTypes.REFERENCELINE + layerType: LayerType = LayerTypes.REFERENCELINE ) { act(() => { instance.find('[data-test-subj="lnsLayerAddButton"]').first().simulate('click'); @@ -295,9 +296,9 @@ describe('ConfigPanel', () => { const visualizationMap = mockVisualizationMap(); visualizationMap.testVis.getSupportedLayers = jest.fn(() => [ - { type: layerTypes.DATA, label: 'Data Layer' }, + { type: LayerTypes.DATA, label: 'Data Layer' }, { - type: layerTypes.REFERENCELINE, + type: LayerTypes.REFERENCELINE, label: 'Reference layer', }, ]); @@ -318,7 +319,7 @@ describe('ConfigPanel', () => { visualizationMap.testVis.getSupportedLayers = jest.fn(() => [ { - type: layerTypes.DATA, + type: LayerTypes.DATA, label: 'Data Layer', initialDimensions: [ { @@ -329,7 +330,7 @@ describe('ConfigPanel', () => { ], }, { - type: layerTypes.REFERENCELINE, + type: LayerTypes.REFERENCELINE, label: 'Reference layer', }, ]); @@ -345,9 +346,9 @@ describe('ConfigPanel', () => { const datasourceMap = mockDatasourceMap(); const visualizationMap = mockVisualizationMap(); visualizationMap.testVis.getSupportedLayers = jest.fn(() => [ - { type: layerTypes.DATA, label: 'Data Layer' }, + { type: LayerTypes.DATA, label: 'Data Layer' }, { - type: layerTypes.REFERENCELINE, + type: LayerTypes.REFERENCELINE, label: 'Reference layer', initialDimensions: [ { @@ -383,7 +384,7 @@ describe('ConfigPanel', () => { const visualizationMap = mockVisualizationMap(); visualizationMap.testVis.getSupportedLayers = jest.fn(() => [ { - type: layerTypes.DATA, + type: LayerTypes.DATA, label: 'Data Layer', initialDimensions: [ { @@ -420,7 +421,7 @@ describe('ConfigPanel', () => { visualizationMap.testVis.setDimension = jest.fn(); visualizationMap.testVis.getSupportedLayers = jest.fn(() => [ { - type: layerTypes.DATA, + type: LayerTypes.DATA, label: 'Data Layer', initialDimensions: [ { @@ -431,11 +432,11 @@ describe('ConfigPanel', () => { ], }, { - type: layerTypes.REFERENCELINE, + type: LayerTypes.REFERENCELINE, label: 'Reference layer', }, { - type: layerTypes.ANNOTATIONS, + type: LayerTypes.ANNOTATIONS, label: 'Annotations Layer', noDatasource: true, initialDimensions: [ @@ -451,7 +452,7 @@ describe('ConfigPanel', () => { datasourceMap.testDatasource.initializeDimension = jest.fn(); const props = getDefaultProps({ visualizationMap, datasourceMap }); const { instance, lensStore } = await prepareAndMountComponent(props); - await clickToAddLayer(instance, layerTypes.ANNOTATIONS); + await clickToAddLayer(instance, LayerTypes.ANNOTATIONS); expect(lensStore.dispatch).toHaveBeenCalledTimes(1); expect(visualizationMap.testVis.setDimension).toHaveBeenCalledWith({ @@ -478,9 +479,9 @@ describe('ConfigPanel', () => { const visualizationMap = mockVisualizationMap(); visualizationMap.testVis.getSupportedLayers = jest.fn(() => [ - { type: layerTypes.DATA, label: 'Data Layer' }, + { type: LayerTypes.DATA, label: 'Data Layer' }, { - type: layerTypes.REFERENCELINE, + type: LayerTypes.REFERENCELINE, label: 'Reference layer', }, ]); diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_actions/remove_layer_action.tsx b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_actions/remove_layer_action.tsx index 58a4248b5185..5156fd7efd75 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_actions/remove_layer_action.tsx +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/config_panel/layer_actions/remove_layer_action.tsx @@ -22,9 +22,10 @@ import { import { i18n } from '@kbn/i18n'; import { toMountPoint } from '@kbn/kibana-react-plugin/public'; import { Storage } from '@kbn/kibana-utils-plugin/public'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { LayerAction, Visualization } from '../../../../types'; import { LOCAL_STORAGE_LENS_KEY } from '../../../../settings_storage'; -import { type LayerType, layerTypes } from '../../../..'; +import type { LayerType } from '../../../../../common/types'; interface RemoveLayerAction { execute: () => void; @@ -54,11 +55,11 @@ const getButtonCopy = (layerType: LayerType, canBeRemoved?: boolean, isOnlyLayer let ariaLabel; const layerTypeCopy = - layerType === layerTypes.DATA + layerType === LayerTypes.DATA ? i18n.translate('xpack.lens.modalTitle.layerType.data', { defaultMessage: 'visualization', }) - : layerType === layerTypes.ANNOTATIONS + : layerType === LayerTypes.ANNOTATIONS ? i18n.translate('xpack.lens.modalTitle.layerType.annotation', { defaultMessage: 'annotations', }) @@ -80,9 +81,9 @@ const getButtonCopy = (layerType: LayerType, canBeRemoved?: boolean, isOnlyLayer modalDesc = modalDescClear; } - if (layerType === layerTypes.ANNOTATIONS) { + if (layerType === LayerTypes.ANNOTATIONS) { modalDesc = modalDescAnnotation; - } else if (layerType === layerTypes.REFERENCELINE) { + } else if (layerType === LayerTypes.REFERENCELINE) { modalDesc = modalDescRefLine; } @@ -200,7 +201,7 @@ const RemoveConfirmModal = ({ export const getRemoveLayerAction = (props: RemoveLayerAction): LayerAction => { const { ariaLabel, modalTitle, modalDesc } = getButtonCopy( - props.layerType || layerTypes.DATA, + props.layerType || LayerTypes.DATA, !!props.activeVisualization.removeLayer, props.isOnlyLayer ); diff --git a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.ts b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.ts index 21cab9188999..c96a022f4aed 100644 --- a/x-pack/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.ts +++ b/x-pack/plugins/lens/public/editor_frame_service/editor_frame/suggestion_helpers.ts @@ -5,11 +5,12 @@ * 2.0. */ -import { Datatable } from '@kbn/expressions-plugin/common'; +import type { Datatable } from '@kbn/expressions-plugin/common'; import type { PaletteOutput } from '@kbn/coloring'; -import { VisualizeFieldContext } from '@kbn/ui-actions-plugin/public'; +import type { VisualizeFieldContext } from '@kbn/ui-actions-plugin/public'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { showMemoizedErrorNotification } from '../../lens_ui_errors'; -import { +import type { Visualization, Datasource, TableSuggestion, @@ -20,8 +21,8 @@ import { Suggestion, DatasourceLayers, } from '../../types'; -import { DragDropIdentifier } from '../../drag_drop'; -import { LayerType, layerTypes } from '../../../common'; +import type { DragDropIdentifier } from '../../drag_drop'; +import type { LayerType } from '../../../common'; import { getLayerType } from './config_panel/add_layer'; import { LensDispatch, @@ -83,7 +84,7 @@ export function getSuggestions({ }, {} as Record); const isLayerSupportedByVisualization = (layerId: string, supportedTypes: LayerType[]) => - supportedTypes.includes(layerTypesMap[layerId] ?? layerTypes.DATA); + supportedTypes.includes(layerTypesMap[layerId] ?? LayerTypes.DATA); // Collect all table suggestions from available datasources const datasourceTableSuggestions = datasources.flatMap(([datasourceId, datasource]) => { @@ -112,14 +113,14 @@ export function getSuggestions({ dataSourceSuggestions = datasource.getDatasourceSuggestionsForField( datasourceState, field, - (layerId) => isLayerSupportedByVisualization(layerId, [layerTypes.DATA]), // a field dragged to workspace should added to data layer + (layerId) => isLayerSupportedByVisualization(layerId, [LayerTypes.DATA]), // a field dragged to workspace should added to data layer dataViews.indexPatterns ); } else { dataSourceSuggestions = datasource.getDatasourceSuggestionsFromCurrentState( datasourceState, dataViews.indexPatterns, - (layerId) => isLayerSupportedByVisualization(layerId, [layerTypes.DATA]), + (layerId) => isLayerSupportedByVisualization(layerId, [LayerTypes.DATA]), activeData ); } diff --git a/x-pack/plugins/lens/public/index.ts b/x-pack/plugins/lens/public/index.ts index 776d8731d7ea..9efe67c4283e 100644 --- a/x-pack/plugins/lens/public/index.ts +++ b/x-pack/plugins/lens/public/index.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { LensPlugin } from './plugin'; export type { @@ -101,9 +102,11 @@ export type { ReferenceLineLayerArgs, ReferenceLineLayerConfig, } from '@kbn/expression-xy-plugin/common'; + export type { LensEmbeddableInput, LensSavedObjectAttributes, Embeddable } from './embeddable'; -export { layerTypes } from '../common'; +/** @deprecated Please use LayerTypes from @kbn/expression-xy-plugin **/ +export const layerTypes = LayerTypes; export type { LensPublicStart, LensPublicSetup } from './plugin'; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx index c7c0ff5d205c..41dd1df5bcd9 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.test.tsx @@ -32,6 +32,7 @@ import { CoreStart, } from '@kbn/core/public'; import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { generateId } from '../../id_generator'; import { IndexPatternPrivateState } from '../types'; import { @@ -49,7 +50,6 @@ import { TimeShift } from './time_shift'; import { ReducedTimeRange } from './reduced_time_range'; import { DimensionEditor } from './dimension_editor'; import { AdvancedOptions } from './advanced_options'; -import { layerTypes } from '../../../common'; jest.mock('./reference_editor', () => ({ ReferenceEditor: () => null, @@ -210,7 +210,7 @@ describe('IndexPatternDimensionEditorPanel', () => { dateRange: { fromDate: 'now-1d', toDate: 'now' }, columnId: 'col1', layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, uniqueLabel: 'stuff', filterOperations: () => true, storage: {} as IStorageWrapper, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.tsx index e38d48034622..e31c5abffc98 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/dimension_panel.tsx @@ -7,17 +7,18 @@ import React, { memo, useMemo } from 'react'; import { IUiSettingsClient, SavedObjectsClientContract, HttpSetup } from '@kbn/core/public'; -import { IStorageWrapper } from '@kbn/kibana-utils-plugin/public'; -import { DataPublicPluginStart } from '@kbn/data-plugin/public'; -import { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public'; -import { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; +import type { IStorageWrapper } from '@kbn/kibana-utils-plugin/public'; +import type { DataPublicPluginStart } from '@kbn/data-plugin/public'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; +import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public'; +import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public'; -import { DatasourceDimensionTriggerProps, DatasourceDimensionEditorProps } from '../../types'; -import { GenericIndexPatternColumn } from '../indexpattern'; +import type { DatasourceDimensionTriggerProps, DatasourceDimensionEditorProps } from '../../types'; +import type { GenericIndexPatternColumn } from '../indexpattern'; import { isColumnInvalid } from '../utils'; -import { IndexPatternPrivateState } from '../types'; +import type { IndexPatternPrivateState } from '../types'; import { DimensionEditor } from './dimension_editor'; -import { DateRange, layerTypes } from '../../../common'; +import type { DateRange } from '../../../common'; import { getOperationSupportMatrix } from './operation_support'; import { DimensionTrigger } from '../../shared_components/dimension_trigger'; @@ -94,7 +95,7 @@ export const IndexPatternDimensionEditorComponent = function IndexPatternDimensi return ( { describe('checkForDataLayerType', () => { it('should return an error if the layer is of the wrong type', () => { - expect(checkForDataLayerType(layerTypes.REFERENCELINE, 'Operation')).toEqual([ + expect(checkForDataLayerType(LayerTypes.REFERENCELINE, 'Operation')).toEqual([ 'Operation is disabled for this type of layer.', ]); }); diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/calculations/utils.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/calculations/utils.ts index 04a8f554be7d..5b33fb071753 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/calculations/utils.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/calculations/utils.ts @@ -8,8 +8,9 @@ import { i18n } from '@kbn/i18n'; import type { AstFunction } from '@kbn/interpreter'; import memoizeOne from 'memoize-one'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { IndexPattern } from '../../../../types'; -import { LayerType, layerTypes } from '../../../../../common'; +import type { LayerType } from '../../../../../common'; import type { TimeScaleUnit } from '../../../../../common/expressions'; import type { IndexPatternLayer } from '../../../types'; import { adjustTimeScaleLabelSuffix } from '../../time_scale_utils'; @@ -33,7 +34,7 @@ export const buildLabelFunction = }; export function checkForDataLayerType(layerType: LayerType, name: string) { - if (layerType === layerTypes.REFERENCELINE) { + if (layerType === LayerTypes.REFERENCELINE) { return [ i18n.translate('xpack.lens.indexPattern.calculations.layerDataType', { defaultMessage: '{name} is disabled for this type of layer.', diff --git a/x-pack/plugins/lens/public/mocks/visualization_mock.ts b/x-pack/plugins/lens/public/mocks/visualization_mock.ts index 23700094dc7c..27a6826e3d08 100644 --- a/x-pack/plugins/lens/public/mocks/visualization_mock.ts +++ b/x-pack/plugins/lens/public/mocks/visualization_mock.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { layerTypes } from '../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { Visualization, VisualizationMap } from '../types'; export function createMockVisualization(id = 'testVis'): jest.Mocked { @@ -14,8 +14,8 @@ export function createMockVisualization(id = 'testVis'): jest.Mocked state), removeLayer: jest.fn(), getLayerIds: jest.fn((_state) => ['layer1']), - getSupportedLayers: jest.fn(() => [{ type: layerTypes.DATA, label: 'Data Layer' }]), - getLayerType: jest.fn((_state, _layerId) => layerTypes.DATA), + getSupportedLayers: jest.fn(() => [{ type: LayerTypes.DATA, label: 'Data Layer' }]), + getLayerType: jest.fn((_state, _layerId) => LayerTypes.DATA), visualizationTypes: [ { icon: 'empty', diff --git a/x-pack/plugins/lens/public/plugin.ts b/x-pack/plugins/lens/public/plugin.ts index 10465a88f162..6b06978befea 100644 --- a/x-pack/plugins/lens/public/plugin.ts +++ b/x-pack/plugins/lens/public/plugin.ts @@ -32,8 +32,8 @@ import type { ChartsPluginSetup, ChartsPluginStart } from '@kbn/charts-plugin/pu import type { EventAnnotationPluginSetup } from '@kbn/event-annotation-plugin/public'; import type { PresentationUtilPluginStart } from '@kbn/presentation-util-plugin/public'; import { EmbeddableStateTransfer } from '@kbn/embeddable-plugin/public'; -import { IndexPatternFieldEditorStart } from '@kbn/data-view-field-editor-plugin/public'; -import { DataViewEditorStart } from '@kbn/data-view-editor-plugin/public'; +import type { IndexPatternFieldEditorStart } from '@kbn/data-view-field-editor-plugin/public'; +import type { DataViewEditorStart } from '@kbn/data-view-editor-plugin/public'; import type { SavedObjectTaggingPluginStart } from '@kbn/saved-objects-tagging-plugin/public'; import { AppNavLinkStatus } from '@kbn/core/public'; import { @@ -48,7 +48,7 @@ import { import { createStartServicesGetter } from '@kbn/kibana-utils-plugin/public'; import type { DiscoverSetup, DiscoverStart } from '@kbn/discover-plugin/public'; import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public'; -import { AdvancedUiActionsSetup } from '@kbn/ui-actions-enhanced-plugin/public'; +import type { AdvancedUiActionsSetup } from '@kbn/ui-actions-enhanced-plugin/public'; import type { DocLinksStart } from '@kbn/core-doc-links-browser'; import type { EditorFrameService as EditorFrameServiceType } from './editor_frame_service'; import type { diff --git a/x-pack/plugins/lens/public/shared_components/axis_extent/types.ts b/x-pack/plugins/lens/public/shared_components/axis_extent/types.ts index 77b91be17360..aa67f0a01e99 100644 --- a/x-pack/plugins/lens/public/shared_components/axis_extent/types.ts +++ b/x-pack/plugins/lens/public/shared_components/axis_extent/types.ts @@ -5,6 +5,6 @@ * 2.0. */ -import { AxisExtentConfig } from '@kbn/expression-xy-plugin/common'; +import type { AxisExtentConfig } from '@kbn/expression-xy-plugin/common'; export type UnifiedAxisExtentConfig = AxisExtentConfig; diff --git a/x-pack/plugins/lens/public/state_management/lens_slice.test.ts b/x-pack/plugins/lens/public/state_management/lens_slice.test.ts index f83786238f62..559120139894 100644 --- a/x-pack/plugins/lens/public/state_management/lens_slice.test.ts +++ b/x-pack/plugins/lens/public/state_management/lens_slice.test.ts @@ -21,7 +21,7 @@ import { selectTriggerApplyChanges, selectChangesApplied, } from '.'; -import { layerTypes } from '../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { makeLensStore, defaultState, mockStoreDeps } from '../mocks'; import { DatasourceMap, VisualizationMap } from '../types'; import { applyChanges, disableAutoApply, enableAutoApply, setChangesApplied } from './lens_slice'; @@ -306,7 +306,7 @@ describe('lensSlice', () => { (layerIds as string[]).filter((id: string) => id !== layerId), getLayerIds: (layerIds: unknown) => layerIds as string[], appendLayer: (layerIds: unknown, layerId: string) => [...(layerIds as string[]), layerId], - getSupportedLayers: jest.fn(() => [{ type: layerTypes.DATA, label: 'Data Layer' }]), + getSupportedLayers: jest.fn(() => [{ type: LayerTypes.DATA, label: 'Data Layer' }]), }, }; @@ -339,7 +339,7 @@ describe('lensSlice', () => { customStore.dispatch( addLayer({ layerId: 'foo', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }) ); const state = customStore.getState().lens; diff --git a/x-pack/plugins/lens/public/trigger_actions/open_in_discover_action.ts b/x-pack/plugins/lens/public/trigger_actions/open_in_discover_action.ts index b04f7115d3d1..18782d618a24 100644 --- a/x-pack/plugins/lens/public/trigger_actions/open_in_discover_action.ts +++ b/x-pack/plugins/lens/public/trigger_actions/open_in_discover_action.ts @@ -8,9 +8,8 @@ import { i18n } from '@kbn/i18n'; import { createAction } from '@kbn/ui-actions-plugin/public'; import type { DiscoverStart } from '@kbn/discover-plugin/public'; -import { IEmbeddable } from '@kbn/embeddable-plugin/public'; -import { DataViewsService } from '@kbn/data-views-plugin/public'; -import { execute, isCompatible, getHref } from './open_in_discover_helpers'; +import type { IEmbeddable } from '@kbn/embeddable-plugin/public'; +import type { DataViewsService } from '@kbn/data-views-plugin/public'; const ACTION_OPEN_IN_DISCOVER = 'ACTION_OPEN_IN_DISCOVER'; @@ -18,6 +17,8 @@ interface Context { embeddable: IEmbeddable; } +export const getDiscoverHelpersAsync = async () => await import('./open_in_discover_helpers'); + export const createOpenInDiscoverAction = ( discover: Pick, dataViews: Pick, @@ -33,6 +34,7 @@ export const createOpenInDiscoverAction = ( defaultMessage: 'Explore data in Discover', }), getHref: async (context: Context) => { + const { getHref } = await getDiscoverHelpersAsync(); return getHref({ discover, dataViews, @@ -41,6 +43,7 @@ export const createOpenInDiscoverAction = ( }); }, isCompatible: async (context: Context) => { + const { isCompatible } = await getDiscoverHelpersAsync(); return isCompatible({ hasDiscoverAccess, discover, @@ -49,6 +52,7 @@ export const createOpenInDiscoverAction = ( }); }, execute: async (context: Context) => { + const { execute } = await getDiscoverHelpersAsync(); return execute({ ...context, discover, dataViews, hasDiscoverAccess }); }, }); diff --git a/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.tsx b/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.tsx index 5518f0f99ff5..37e897625536 100644 --- a/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.tsx +++ b/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.tsx @@ -6,22 +6,23 @@ */ import React from 'react'; -import { IEmbeddable, EmbeddableInput } from '@kbn/embeddable-plugin/public'; +import type { IEmbeddable, EmbeddableInput } from '@kbn/embeddable-plugin/public'; import type { Query, Filter, TimeRange } from '@kbn/es-query'; import { APPLY_FILTER_TRIGGER } from '@kbn/data-plugin/public'; import type { ApplicationStart } from '@kbn/core/public'; -import { CollectConfigProps as CollectConfigPropsBase } from '@kbn/kibana-utils-plugin/public'; +import type { SerializableRecord } from '@kbn/utility-types'; +import type { CollectConfigProps as CollectConfigPropsBase } from '@kbn/kibana-utils-plugin/public'; import { reactToUiComponent } from '@kbn/kibana-react-plugin/public'; import { UiActionsEnhancedDrilldownDefinition as Drilldown, UiActionsEnhancedBaseActionFactoryContext as BaseActionFactoryContext, } from '@kbn/ui-actions-enhanced-plugin/public'; import { EuiFormRow, EuiSwitch } from '@elastic/eui'; -import { DiscoverSetup } from '@kbn/discover-plugin/public'; -import { ApplyGlobalFilterActionContext } from '@kbn/unified-search-plugin/public'; +import type { DiscoverSetup } from '@kbn/discover-plugin/public'; +import type { ApplyGlobalFilterActionContext } from '@kbn/unified-search-plugin/public'; import { i18n } from '@kbn/i18n'; -import { DataViewsService } from '@kbn/data-views-plugin/public'; -import { isCompatible, isLensEmbeddable, getHref, getLocation } from './open_in_discover_helpers'; +import type { DataViewsService } from '@kbn/data-views-plugin/public'; +import { DOC_TYPE } from '../../common/constants'; interface EmbeddableQueryInput extends EmbeddableInput { query?: Query; @@ -29,6 +30,8 @@ interface EmbeddableQueryInput extends EmbeddableInput { timeRange?: TimeRange; } +export const getDiscoverHelpersAsync = async () => await import('./open_in_discover_helpers'); + /** @internal */ export type EmbeddableWithQueryInput = IEmbeddable; @@ -41,10 +44,9 @@ interface UrlDrilldownDeps { export type ActionContext = ApplyGlobalFilterActionContext; -// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -export type Config = { +export interface Config extends SerializableRecord { openInNewTab: boolean; -}; +} export type OpenInDiscoverTrigger = typeof APPLY_FILTER_TRIGGER; @@ -53,12 +55,10 @@ export interface ActionFactoryContext extends BaseActionFactoryContext { } export type CollectConfigProps = CollectConfigPropsBase; -const OPEN_IN_DISCOVER_DRILLDOWN = 'OPEN_IN_DISCOVER_DRILLDOWN'; - export class OpenInDiscoverDrilldown implements Drilldown { - public readonly id = OPEN_IN_DISCOVER_DRILLDOWN; + public readonly id = 'OPEN_IN_DISCOVER_DRILLDOWN'; constructor(private readonly deps: UrlDrilldownDeps) {} @@ -75,11 +75,7 @@ export class OpenInDiscoverDrilldown return [APPLY_FILTER_TRIGGER]; } - private readonly ReactCollectConfig: React.FC = ({ - config, - onConfig, - context, - }) => { + private readonly ReactCollectConfig: React.FC = ({ config, onConfig }) => { return ( { + const { isCompatible } = await getDiscoverHelpersAsync(); + return isCompatible({ discover: this.deps.discover, dataViews: this.deps.dataViews(), @@ -117,11 +115,12 @@ export class OpenInDiscoverDrilldown }); }; - public readonly isConfigurable = (context: ActionFactoryContext) => { - return this.deps.hasDiscoverAccess() && isLensEmbeddable(context.embeddable as IEmbeddable); - }; + public readonly isConfigurable = (context: ActionFactoryContext) => + this.deps.hasDiscoverAccess() && context.embeddable?.type === DOC_TYPE; public readonly getHref = async (config: Config, context: ActionContext) => { + const { getHref } = await getDiscoverHelpersAsync(); + return getHref({ discover: this.deps.discover, dataViews: this.deps.dataViews(), @@ -132,6 +131,8 @@ export class OpenInDiscoverDrilldown }; public readonly execute = async (config: Config, context: ActionContext) => { + const { getLocation } = await getDiscoverHelpersAsync(); + if (config.openInNewTab) { window.open(await this.getHref(config, context), '_blank'); } else { diff --git a/x-pack/plugins/lens/public/utils.ts b/x-pack/plugins/lens/public/utils.ts index c40403cfd092..5b55dfe2054a 100644 --- a/x-pack/plugins/lens/public/utils.ts +++ b/x-pack/plugins/lens/public/utils.ts @@ -26,8 +26,8 @@ import { isOperation, } from './types'; import type { DatasourceStates, VisualizationState } from './state_management'; -import { IndexPatternServiceAPI } from './data_views_service/service'; -import { DraggingIdentifier } from './drag_drop'; +import type { IndexPatternServiceAPI } from './data_views_service/service'; +import type { DraggingIdentifier } from './drag_drop'; export function getVisualizeGeoFieldMessage(fieldType: string) { return i18n.translate('xpack.lens.visualizeGeoFieldMessage', { diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor.test.tsx b/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor.test.tsx index e3b2675e2bd0..a1c6dc550d7a 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor.test.tsx @@ -21,7 +21,7 @@ import { TableDimensionEditor } from './dimension_editor'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; import { act } from 'react-dom/test-utils'; import { PalettePanelContainer } from '../../../shared_components'; -import { layerTypes } from '../../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; describe('data table dimension editor', () => { let frame: FramePublicAPI; @@ -34,7 +34,7 @@ describe('data table dimension editor', () => { function testState(): DatatableVisualizationState { return { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [ { columnId: 'foo', diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor_additional_section.test.tsx b/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor_additional_section.test.tsx index 859c3867b0ce..3262a786c72f 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor_additional_section.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor_additional_section.test.tsx @@ -14,7 +14,7 @@ import { createMockDatasource, createMockFramePublicAPI } from '../../../mocks'; import { mountWithIntl } from '@kbn/test-jest-helpers'; import { TableDimensionEditorAdditionalSection } from './dimension_editor_addtional_section'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; -import { layerTypes } from '../../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; describe('data table dimension editor additional section', () => { let frame: FramePublicAPI; @@ -27,7 +27,7 @@ describe('data table dimension editor additional section', () => { function testState(): DatatableVisualizationState { return { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [ { columnId: 'foo', diff --git a/x-pack/plugins/lens/public/visualizations/datatable/visualization.test.tsx b/x-pack/plugins/lens/public/visualizations/datatable/visualization.test.tsx index 85d1bc3f1a57..cc4b108a23bd 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/visualization.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/visualization.test.tsx @@ -17,7 +17,7 @@ import { VisualizationDimensionGroupConfig, } from '../../types'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { themeServiceMock } from '@kbn/core/public/mocks'; function mockFrame(): FramePublicAPI { @@ -37,7 +37,7 @@ describe('Datatable Visualization', () => { it('should initialize from the empty state', () => { expect(datatableVisualization.initialize(() => 'aaa', undefined)).toEqual({ layerId: 'aaa', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [], }); }); @@ -45,7 +45,7 @@ describe('Datatable Visualization', () => { it('should initialize from a persisted state', () => { const expectedState: DatatableVisualizationState = { layerId: 'foo', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'saved' }], }; expect(datatableVisualization.initialize(() => 'foo', expectedState)).toEqual(expectedState); @@ -56,7 +56,7 @@ describe('Datatable Visualization', () => { it('return the layer ids', () => { const state: DatatableVisualizationState = { layerId: 'baz', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'a' }, { columnId: 'b' }, { columnId: 'c' }], }; expect(datatableVisualization.getLayerIds(state)).toEqual(['baz']); @@ -67,12 +67,12 @@ describe('Datatable Visualization', () => { it('should reset the layer', () => { const state: DatatableVisualizationState = { layerId: 'baz', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'a' }, { columnId: 'b' }, { columnId: 'c' }], }; expect(datatableVisualization.clearLayer(state, 'baz', 'indexPattern1')).toMatchObject({ layerId: 'baz', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [], }); }); @@ -88,10 +88,10 @@ describe('Datatable Visualization', () => { it('should return the type only if the layer is in the state', () => { const state: DatatableVisualizationState = { layerId: 'baz', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'a' }, { columnId: 'b' }, { columnId: 'c' }], }; - expect(datatableVisualization.getLayerType('baz', state)).toEqual(layerTypes.DATA); + expect(datatableVisualization.getLayerType('baz', state)).toEqual(LayerTypes.DATA); expect(datatableVisualization.getLayerType('foo', state)).toBeUndefined(); }); }); @@ -123,7 +123,7 @@ describe('Datatable Visualization', () => { const suggestions = datatableVisualization.getSuggestions({ state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'col1' }], }, table: { @@ -153,7 +153,7 @@ describe('Datatable Visualization', () => { const suggestions = datatableVisualization.getSuggestions({ state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'col1' }], }, table: { @@ -172,7 +172,7 @@ describe('Datatable Visualization', () => { const suggestions = datatableVisualization.getSuggestions({ state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [ { columnId: 'col1', width: 123 }, { columnId: 'col2', hidden: true }, @@ -207,7 +207,7 @@ describe('Datatable Visualization', () => { const suggestions = datatableVisualization.getSuggestions({ state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'col1' }], }, table: { @@ -226,7 +226,7 @@ describe('Datatable Visualization', () => { const suggestions = datatableVisualization.getSuggestions({ state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'col1' }], }, table: { @@ -245,7 +245,7 @@ describe('Datatable Visualization', () => { const suggestions = datatableVisualization.getSuggestions({ state: { layerId: 'older', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'col1' }], }, table: { @@ -286,7 +286,7 @@ describe('Datatable Visualization', () => { layerId: 'first', state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [], }, frame, @@ -302,7 +302,7 @@ describe('Datatable Visualization', () => { layerId: 'first', state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [], }, frame, @@ -342,7 +342,7 @@ describe('Datatable Visualization', () => { layerId: 'first', state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [], }, frame, @@ -380,7 +380,7 @@ describe('Datatable Visualization', () => { layerId: 'a', state: { layerId: 'a', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'b' }, { columnId: 'c' }], }, frame, @@ -395,7 +395,7 @@ describe('Datatable Visualization', () => { datatableVisualization.removeDimension({ prevState: { layerId: 'layer1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'b' }, { columnId: 'c' }], }, layerId: 'layer1', @@ -404,7 +404,7 @@ describe('Datatable Visualization', () => { }) ).toEqual({ layerId: 'layer1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'c' }], }); }); @@ -412,7 +412,7 @@ describe('Datatable Visualization', () => { it('should handle correctly the sorting state on removing dimension', () => { const state = { layerId: 'layer1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'b' }, { columnId: 'c' }], }; expect( @@ -425,7 +425,7 @@ describe('Datatable Visualization', () => { ).toEqual({ sorting: undefined, layerId: 'layer1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'c' }], }); @@ -439,7 +439,7 @@ describe('Datatable Visualization', () => { ).toEqual({ sorting: { columnId: 'c', direction: 'asc' }, layerId: 'layer1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'c' }], }); }); @@ -451,7 +451,7 @@ describe('Datatable Visualization', () => { datatableVisualization.setDimension({ prevState: { layerId: 'layer1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'b' }, { columnId: 'c' }], }, layerId: 'layer1', @@ -461,7 +461,7 @@ describe('Datatable Visualization', () => { }) ).toEqual({ layerId: 'layer1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'b' }, { columnId: 'c' }, { columnId: 'd', isTransposed: false }], }); }); @@ -471,7 +471,7 @@ describe('Datatable Visualization', () => { datatableVisualization.setDimension({ prevState: { layerId: 'layer1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'b' }, { columnId: 'c' }], }, layerId: 'layer1', @@ -481,7 +481,7 @@ describe('Datatable Visualization', () => { }) ).toEqual({ layerId: 'layer1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'b', isTransposed: false }, { columnId: 'c' }], }); }); @@ -501,7 +501,7 @@ describe('Datatable Visualization', () => { const defaultExpressionTableState = { layerId: 'a', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'b' }, { columnId: 'c' }], }; @@ -716,7 +716,7 @@ describe('Datatable Visualization', () => { const error = datatableVisualization.getErrorMessages({ layerId: 'a', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'b' }, { columnId: 'c' }], }); @@ -741,7 +741,7 @@ describe('Datatable Visualization', () => { const error = datatableVisualization.getErrorMessages({ layerId: 'a', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'b' }, { columnId: 'c' }], }); @@ -753,7 +753,7 @@ describe('Datatable Visualization', () => { it('should add a sort column to the state', () => { const currentState: DatatableVisualizationState = { layerId: 'foo', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'saved' }], }; expect( @@ -773,7 +773,7 @@ describe('Datatable Visualization', () => { it('should add a custom width to a column in the state', () => { const currentState: DatatableVisualizationState = { layerId: 'foo', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'saved' }], }; expect( @@ -790,7 +790,7 @@ describe('Datatable Visualization', () => { it('should clear custom width value for the column from the state', () => { const currentState: DatatableVisualizationState = { layerId: 'foo', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'saved', width: 5000 }], }; expect( @@ -807,7 +807,7 @@ describe('Datatable Visualization', () => { it('should update page size', () => { const currentState: DatatableVisualizationState = { layerId: 'foo', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: [{ columnId: 'saved', width: 5000 }], paging: { enabled: true, size: 10 }, }; diff --git a/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx b/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx index ca6f6775f893..c5206e7b82a6 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx @@ -15,6 +15,7 @@ import { ThemeServiceStart } from '@kbn/core/public'; import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; import { VIS_EVENT_TO_TRIGGER } from '@kbn/visualizations-plugin/public'; import { IconChartDatatable } from '@kbn/chart-icons'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { SuggestionRequest, Visualization, @@ -24,7 +25,7 @@ import type { } from '../../types'; import { TableDimensionEditor } from './components/dimension_editor'; import { TableDimensionEditorAdditionalSection } from './components/dimension_editor_addtional_section'; -import { LayerType, layerTypes } from '../../../common'; +import type { LayerType } from '../../../common'; import { getDefaultSummaryLabel, PagingState } from '../../../common/expressions'; import type { ColumnState, SortingState } from '../../../common/expressions'; import { DataTableToolbar } from './components/toolbar'; @@ -108,7 +109,7 @@ export const getDatatableVisualization = ({ state || { columns: [], layerId: addNewLayer(), - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } ); }, @@ -177,7 +178,7 @@ export const getDatatableVisualization = ({ state: { ...(state || {}), layerId: table.layerId, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, columns: table.columns.map((col, columnIndex) => ({ ...(oldColumnSettings[col.columnId] || {}), isTransposed: usesTransposing && columnIndex < lastTransposedColumnIndex, @@ -362,7 +363,7 @@ export const getDatatableVisualization = ({ getSupportedLayers() { return [ { - type: layerTypes.DATA, + type: LayerTypes.DATA, label: i18n.translate('xpack.lens.datatable.addLayer', { defaultMessage: 'Visualization', }), diff --git a/x-pack/plugins/lens/public/visualizations/gauge/suggestions.test.ts b/x-pack/plugins/lens/public/visualizations/gauge/suggestions.test.ts index 0b974cd3de8f..5b3eb512426b 100644 --- a/x-pack/plugins/lens/public/visualizations/gauge/suggestions.test.ts +++ b/x-pack/plugins/lens/public/visualizations/gauge/suggestions.test.ts @@ -6,7 +6,7 @@ */ import { getSuggestions } from './suggestions'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { GaugeShapes } from '@kbn/expression-gauge-plugin/common'; import { GaugeVisualizationState } from './constants'; @@ -43,7 +43,7 @@ describe('gauge suggestions', () => { state: { shape: GaugeShapes.HORIZONTAL_BULLET, layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as GaugeVisualizationState, keptLayerIds: ['first'], }; @@ -59,7 +59,7 @@ describe('gauge suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as GaugeVisualizationState, keptLayerIds: ['first'], }; @@ -77,7 +77,7 @@ describe('gauge suggestions', () => { state: { shape: GaugeShapes.HORIZONTAL_BULLET, layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, minAccessor: 'some-field', labelMajorMode: 'auto', ticksPosition: 'auto', @@ -97,7 +97,7 @@ describe('gauge suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as GaugeVisualizationState, keptLayerIds: ['first'], }) @@ -120,7 +120,7 @@ describe('gauge suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as GaugeVisualizationState, keptLayerIds: ['first'], }) @@ -141,7 +141,7 @@ describe('shows suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as GaugeVisualizationState, keptLayerIds: ['first'], }) @@ -149,7 +149,7 @@ describe('shows suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: GaugeShapes.HORIZONTAL_BULLET, metricAccessor: 'metric-column', labelMajorMode: 'auto', @@ -187,7 +187,7 @@ describe('shows suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: GaugeShapes.HORIZONTAL_BULLET, metricAccessor: 'metric-column', } as GaugeVisualizationState, @@ -197,7 +197,7 @@ describe('shows suggestions', () => { ).toEqual([ { state: { - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: GaugeShapes.VERTICAL_BULLET, metricAccessor: 'metric-column', labelMajorMode: 'auto', diff --git a/x-pack/plugins/lens/public/visualizations/gauge/suggestions.ts b/x-pack/plugins/lens/public/visualizations/gauge/suggestions.ts index 46688d3021fe..e90aa5e7d089 100644 --- a/x-pack/plugins/lens/public/visualizations/gauge/suggestions.ts +++ b/x-pack/plugins/lens/public/visualizations/gauge/suggestions.ts @@ -12,9 +12,9 @@ import { GaugeTicksPositions, GaugeLabelMajorModes, } from '@kbn/expression-gauge-plugin/common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { TableSuggestion, Visualization } from '../../types'; -import { layerTypes } from '../../../common'; -import { GaugeVisualizationState } from './constants'; +import type { GaugeVisualizationState } from './constants'; const isNotNumericMetric = (table: TableSuggestion) => table.columns?.[0]?.operation.dataType !== 'number' || @@ -57,7 +57,7 @@ export const getSuggestions: Visualization['getSuggesti ...state, shape, layerId: table.layerId, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, ticksPosition: GaugeTicksPositions.AUTO, labelMajorMode: GaugeLabelMajorModes.AUTO, }, diff --git a/x-pack/plugins/lens/public/visualizations/gauge/utils.ts b/x-pack/plugins/lens/public/visualizations/gauge/utils.ts index 5c95e1205568..bbd8190c213c 100644 --- a/x-pack/plugins/lens/public/visualizations/gauge/utils.ts +++ b/x-pack/plugins/lens/public/visualizations/gauge/utils.ts @@ -5,7 +5,7 @@ * 2.0. */ import type { Accessors } from '@kbn/expression-gauge-plugin/common'; -import { GaugeVisualizationState } from './constants'; +import type { GaugeVisualizationState } from './constants'; export const getAccessorsFromState = (state?: GaugeVisualizationState): Accessors | undefined => { const { minAccessor, maxAccessor, goalAccessor, metricAccessor } = state ?? {}; diff --git a/x-pack/plugins/lens/public/visualizations/gauge/visualization.test.ts b/x-pack/plugins/lens/public/visualizations/gauge/visualization.test.ts index e999cac9dd0e..1ecedc1a63c4 100644 --- a/x-pack/plugins/lens/public/visualizations/gauge/visualization.test.ts +++ b/x-pack/plugins/lens/public/visualizations/gauge/visualization.test.ts @@ -11,14 +11,14 @@ import { createMockDatasource, createMockFramePublicAPI } from '../../mocks'; import { GROUP_ID } from './constants'; import type { DatasourceLayers, OperationDescriptor } from '../../types'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { GaugeVisualizationState } from './constants'; import { themeServiceMock } from '@kbn/core/public/mocks'; function exampleState(): GaugeVisualizationState { return { layerId: 'test-layer', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, labelMajorMode: 'auto', ticksPosition: 'auto', shape: 'horizontalBullet', @@ -39,7 +39,7 @@ describe('gauge', () => { test('returns a default state', () => { expect(getGaugeVisualization({ paletteService, theme }).initialize(() => 'l1')).toEqual({ layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: 'horizontalBullet', labelMajorMode: 'auto', ticksPosition: 'auto', @@ -523,7 +523,7 @@ describe('gauge', () => { paletteService, theme, }); - expect(instance.getLayerType('test-layer', state)).toEqual(layerTypes.DATA); + expect(instance.getLayerType('test-layer', state)).toEqual(LayerTypes.DATA); expect(instance.getLayerType('foo', state)).toBeUndefined(); }); }); diff --git a/x-pack/plugins/lens/public/visualizations/gauge/visualization.tsx b/x-pack/plugins/lens/public/visualizations/gauge/visualization.tsx index 19fd46459b2b..4ea17a2136aa 100644 --- a/x-pack/plugins/lens/public/visualizations/gauge/visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/gauge/visualization.tsx @@ -23,6 +23,7 @@ import { getValueFromAccessor, } from '@kbn/expression-gauge-plugin/public'; import { IconChartHorizontalBullet, IconChartVerticalBullet } from '@kbn/chart-icons'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { DatasourceLayers, OperationMetadata, Visualization } from '../../types'; import { getSuggestions } from './suggestions'; import { @@ -34,7 +35,6 @@ import { import { GaugeToolbar } from './toolbar_component'; import { applyPaletteParams } from '../../shared_components'; import { GaugeDimensionEditor } from './dimension_editor'; -import { layerTypes } from '../../../common'; import { generateId } from '../../id_generator'; import { getAccessorsFromState } from './utils'; @@ -215,7 +215,7 @@ export const getGaugeVisualization = ({ return ( state || { layerId: addNewLayer(), - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: GaugeShapes.HORIZONTAL_BULLET, palette: mainPalette, ticksPosition: 'auto', @@ -432,7 +432,7 @@ export const getGaugeVisualization = ({ return [ { - type: layerTypes.DATA, + type: LayerTypes.DATA, label: i18n.translate('xpack.lens.gauge.addLayer', { defaultMessage: 'Visualization', }), diff --git a/x-pack/plugins/lens/public/visualizations/heatmap/suggestions.test.ts b/x-pack/plugins/lens/public/visualizations/heatmap/suggestions.test.ts index 70db8e0d4165..0fc9c6fc3067 100644 --- a/x-pack/plugins/lens/public/visualizations/heatmap/suggestions.test.ts +++ b/x-pack/plugins/lens/public/visualizations/heatmap/suggestions.test.ts @@ -6,10 +6,10 @@ */ import { Position } from '@elastic/charts'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { getSuggestions } from './suggestions'; import type { HeatmapVisualizationState } from './types'; import { HEATMAP_GRID_FUNCTION, LEGEND_FUNCTION } from './constants'; -import { layerTypes } from '../../../common'; describe('heatmap suggestions', () => { describe('rejects suggestions', () => { @@ -25,7 +25,7 @@ describe('heatmap suggestions', () => { state: { shape: 'heatmap', layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -72,7 +72,7 @@ describe('heatmap suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -118,7 +118,7 @@ describe('heatmap suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -173,7 +173,7 @@ describe('heatmap suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -220,7 +220,7 @@ describe('heatmap suggestions', () => { state: { shape: 'heatmap', layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, xAccessor: 'some-field', } as HeatmapVisualizationState, keptLayerIds: ['first'], @@ -269,7 +269,7 @@ describe('heatmap suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -277,7 +277,7 @@ describe('heatmap suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: 'heatmap', valueAccessor: 'metric-column', xAccessor: 'date-column-01', @@ -324,7 +324,7 @@ describe('heatmap suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -332,7 +332,7 @@ describe('heatmap suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: 'heatmap', xAccessor: 'test-column', gridConfig: { @@ -377,7 +377,7 @@ describe('heatmap suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -385,7 +385,7 @@ describe('heatmap suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: 'heatmap', valueAccessor: 'test-column', gridConfig: { @@ -440,7 +440,7 @@ describe('heatmap suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -448,7 +448,7 @@ describe('heatmap suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: 'heatmap', xAccessor: 'date-column', valueAccessor: 'metric-column', @@ -506,7 +506,7 @@ describe('heatmap suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -514,7 +514,7 @@ describe('heatmap suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: 'heatmap', xAccessor: 'number-column', valueAccessor: 'metric-column', @@ -579,7 +579,7 @@ describe('heatmap suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -587,7 +587,7 @@ describe('heatmap suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: 'heatmap', yAccessor: 'date-column', xAccessor: 'number-column', @@ -653,7 +653,7 @@ describe('heatmap suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as HeatmapVisualizationState, keptLayerIds: ['first'], }) @@ -661,7 +661,7 @@ describe('heatmap suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, shape: 'heatmap', xAccessor: 'number-column', yAccessor: 'group-column', diff --git a/x-pack/plugins/lens/public/visualizations/heatmap/suggestions.ts b/x-pack/plugins/lens/public/visualizations/heatmap/suggestions.ts index a302be4cfceb..aca5f4dfe689 100644 --- a/x-pack/plugins/lens/public/visualizations/heatmap/suggestions.ts +++ b/x-pack/plugins/lens/public/visualizations/heatmap/suggestions.ts @@ -8,10 +8,10 @@ import { partition } from 'lodash'; import { Position } from '@elastic/charts'; import { i18n } from '@kbn/i18n'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { Visualization } from '../../types'; import type { HeatmapVisualizationState } from './types'; import { CHART_SHAPES, HEATMAP_GRID_FUNCTION, LEGEND_FUNCTION } from './constants'; -import { layerTypes } from '../../../common'; export const getSuggestions: Visualization['getSuggestions'] = ({ table, @@ -81,7 +81,7 @@ export const getSuggestions: Visualization['getSugges const newState: HeatmapVisualizationState = { shape: CHART_SHAPES.HEATMAP, layerId: table.layerId, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, legend: { isVisible: state?.legend?.isVisible ?? true, position: state?.legend?.position ?? Position.Right, diff --git a/x-pack/plugins/lens/public/visualizations/heatmap/visualization.test.ts b/x-pack/plugins/lens/public/visualizations/heatmap/visualization.test.ts index 38cfa9bf10b5..8f958b8fa75c 100644 --- a/x-pack/plugins/lens/public/visualizations/heatmap/visualization.test.ts +++ b/x-pack/plugins/lens/public/visualizations/heatmap/visualization.test.ts @@ -18,17 +18,17 @@ import { HEATMAP_GRID_FUNCTION, LEGEND_FUNCTION, } from './constants'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { Position } from '@elastic/charts'; import type { HeatmapVisualizationState } from './types'; import type { DatasourceLayers, OperationDescriptor } from '../../types'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; -import { layerTypes } from '../../../common'; import { themeServiceMock } from '@kbn/core/public/mocks'; function exampleState(): HeatmapVisualizationState { return { layerId: 'test-layer', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, legend: { isVisible: true, position: Position.Right, @@ -62,7 +62,7 @@ describe('heatmap', () => { test('returns a default state', () => { expect(getHeatmapVisualization({ paletteService, theme }).initialize(() => 'l1')).toEqual({ layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, title: 'Empty Heatmap chart', shape: CHART_SHAPES.HEATMAP, legend: { @@ -358,7 +358,7 @@ describe('heatmap', () => { paletteService, theme, }); - expect(instance.getLayerType('test-layer', state)).toEqual(layerTypes.DATA); + expect(instance.getLayerType('test-layer', state)).toEqual(LayerTypes.DATA); expect(instance.getLayerType('foo', state)).toBeUndefined(); }); }); diff --git a/x-pack/plugins/lens/public/visualizations/heatmap/visualization.tsx b/x-pack/plugins/lens/public/visualizations/heatmap/visualization.tsx index 1fc48b4d71c3..b8e98d03843a 100644 --- a/x-pack/plugins/lens/public/visualizations/heatmap/visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/heatmap/visualization.tsx @@ -16,6 +16,7 @@ import { CUSTOM_PALETTE, PaletteRegistry, CustomPaletteParams } from '@kbn/color import { ThemeServiceStart } from '@kbn/core/public'; import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; import { VIS_EVENT_TO_TRIGGER } from '@kbn/visualizations-plugin/public'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { OperationMetadata, Visualization } from '../../types'; import type { HeatmapVisualizationState } from './types'; import { getSuggestions } from './suggestions'; @@ -32,7 +33,6 @@ import { import { HeatmapToolbar } from './toolbar_component'; import { HeatmapDimensionEditor } from './dimension_editor'; import { getSafePaletteParams } from './utils'; -import { layerTypes } from '../../../common'; const groupLabelForHeatmap = i18n.translate('xpack.lens.heatmapVisualization.heatmapGroupLabel', { defaultMessage: 'Magnitude', @@ -146,7 +146,7 @@ export const getHeatmapVisualization = ({ return ( state || { layerId: addNewLayer(), - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, title: 'Empty Heatmap chart', ...getInitialState(), } @@ -289,7 +289,7 @@ export const getHeatmapVisualization = ({ getSupportedLayers() { return [ { - type: layerTypes.DATA, + type: LayerTypes.DATA, label: i18n.translate('xpack.lens.heatmap.addLayer', { defaultMessage: 'Visualization', }), diff --git a/x-pack/plugins/lens/public/visualizations/legacy_metric/dimension_editor.test.tsx b/x-pack/plugins/lens/public/visualizations/legacy_metric/dimension_editor.test.tsx index 560e4ed67b54..824f70dd6834 100644 --- a/x-pack/plugins/lens/public/visualizations/legacy_metric/dimension_editor.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/legacy_metric/dimension_editor.test.tsx @@ -22,7 +22,7 @@ import { import { act } from 'react-dom/test-utils'; import { PalettePanelContainer } from '../../shared_components'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { LegacyMetricState } from '../../../common/types'; // mocking random id generator function @@ -57,7 +57,7 @@ describe('metric dimension editor', () => { function testState(): LegacyMetricState { return { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, accessor: 'foo', }; } diff --git a/x-pack/plugins/lens/public/visualizations/legacy_metric/metric_suggestions.ts b/x-pack/plugins/lens/public/visualizations/legacy_metric/metric_suggestions.ts index 16f4d4890f47..c48e463ec83d 100644 --- a/x-pack/plugins/lens/public/visualizations/legacy_metric/metric_suggestions.ts +++ b/x-pack/plugins/lens/public/visualizations/legacy_metric/metric_suggestions.ts @@ -6,9 +6,9 @@ */ import { IconChartMetric } from '@kbn/chart-icons'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { SuggestionRequest, VisualizationSuggestion, TableSuggestion } from '../../types'; import type { LegacyMetricState } from '../../../common/types'; -import { layerTypes } from '../../../common'; import { legacyMetricSupportedTypes } from './visualization'; /** @@ -53,7 +53,7 @@ function getSuggestion(table: TableSuggestion): VisualizationSuggestion { expect(metricVisualization.clearLayer(exampleState(), 'l1', 'indexPattern1')).toEqual({ accessor: undefined, layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }); }); }); @@ -85,7 +85,7 @@ describe('metric_visualization', () => { state: { accessor: undefined, layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, layerId: 'l1', frame: mockFrame(), @@ -105,7 +105,7 @@ describe('metric_visualization', () => { state: { accessor: 'a', layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, layerId: 'l1', frame: mockFrame(), @@ -125,7 +125,7 @@ describe('metric_visualization', () => { state: { accessor: 'a', layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, palette: { type: 'palette', name: 'status', @@ -151,7 +151,7 @@ describe('metric_visualization', () => { state: { accessor: 'a', layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, layerId: 'l1', frame: mockFrame(), @@ -175,7 +175,7 @@ describe('metric_visualization', () => { prevState: { accessor: undefined, layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, layerId: 'l1', groupId: '', @@ -185,7 +185,7 @@ describe('metric_visualization', () => { ).toEqual({ accessor: 'newDimension', layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }); }); }); @@ -197,7 +197,7 @@ describe('metric_visualization', () => { prevState: { accessor: 'a', layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, layerId: 'l1', columnId: 'a', @@ -206,7 +206,7 @@ describe('metric_visualization', () => { ).toEqual({ accessor: undefined, layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, colorMode: ColorMode.None, palette: undefined, }); @@ -218,7 +218,7 @@ describe('metric_visualization', () => { prevState: { accessor: 'a', layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, colorMode: ColorMode.Background, palette: { type: 'palette', @@ -239,7 +239,7 @@ describe('metric_visualization', () => { ).toEqual({ accessor: undefined, layerId: 'l1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, colorMode: ColorMode.None, palette: undefined, }); @@ -254,7 +254,7 @@ describe('metric_visualization', () => { describe('#getLayerType', () => { it('should return the type only if the layer is in the state', () => { - expect(metricVisualization.getLayerType('l1', exampleState())).toEqual(layerTypes.DATA); + expect(metricVisualization.getLayerType('l1', exampleState())).toEqual(LayerTypes.DATA); expect(metricVisualization.getLayerType('foo', exampleState())).toBeUndefined(); }); }); diff --git a/x-pack/plugins/lens/public/visualizations/legacy_metric/visualization.tsx b/x-pack/plugins/lens/public/visualizations/legacy_metric/visualization.tsx index 02a4cd23ad4f..37304e09523a 100644 --- a/x-pack/plugins/lens/public/visualizations/legacy_metric/visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/legacy_metric/visualization.tsx @@ -15,10 +15,10 @@ import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; import { ColorMode, CustomPaletteState } from '@kbn/charts-plugin/common'; import { VIS_EVENT_TO_TRIGGER } from '@kbn/visualizations-plugin/public'; import { IconChartMetric } from '@kbn/chart-icons'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { getSuggestions } from './metric_suggestions'; import { Visualization, OperationMetadata, DatasourceLayers } from '../../types'; import type { LegacyMetricState } from '../../../common/types'; -import { layerTypes } from '../../../common'; import { MetricDimensionEditor } from './dimension_editor'; import { MetricToolbar } from './metric_config_panel'; import { DEFAULT_TITLE_POSITION } from './metric_config_panel/title_position_option'; @@ -222,7 +222,7 @@ export const getLegacyMetricVisualization = ({ state || { layerId: addNewLayer(), accessor: undefined, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } ); }, @@ -267,7 +267,7 @@ export const getLegacyMetricVisualization = ({ getSupportedLayers() { return [ { - type: layerTypes.DATA, + type: LayerTypes.DATA, label: i18n.translate('xpack.lens.legacyMetric.addLayer', { defaultMessage: 'Visualization', }), diff --git a/x-pack/plugins/lens/public/visualizations/metric/suggestions.test.ts b/x-pack/plugins/lens/public/visualizations/metric/suggestions.test.ts index 45f332776a4d..22d701cee570 100644 --- a/x-pack/plugins/lens/public/visualizations/metric/suggestions.test.ts +++ b/x-pack/plugins/lens/public/visualizations/metric/suggestions.test.ts @@ -6,7 +6,7 @@ */ import { getSuggestions } from './suggestions'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { MetricVisualizationState } from './visualization'; import { IconChartMetric } from '@kbn/chart-icons'; @@ -125,7 +125,7 @@ describe('metric suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as MetricVisualizationState, keptLayerIds: ['first'], }; @@ -146,7 +146,7 @@ describe('metric suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as MetricVisualizationState, keptLayerIds: ['first'], }) @@ -154,7 +154,7 @@ describe('metric suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, metricAccessor: metricColumn.columnId, // should ignore bucketed column for initial drag }, @@ -177,7 +177,7 @@ describe('metric suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as MetricVisualizationState, keptLayerIds: ['first'], }) @@ -185,7 +185,7 @@ describe('metric suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, breakdownByAccessor: bucketColumn.columnId, }, title: 'Metric', @@ -207,7 +207,7 @@ describe('metric suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, metricAccessor: 'non_existent', } as MetricVisualizationState, keptLayerIds: ['first'], @@ -216,7 +216,7 @@ describe('metric suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, metricAccessor: undefined, breakdownByAccessor: bucketColumn.columnId, }, @@ -238,7 +238,7 @@ describe('metric suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, secondaryMetricAccessor: 'some-accessor', maxAccessor: 'some-accessor', } as MetricVisualizationState, @@ -260,7 +260,7 @@ describe('metric suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } as MetricVisualizationState, keptLayerIds: ['first'], }) @@ -280,7 +280,7 @@ describe('metric suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, breakdownByAccessor: bucketColumn.columnId, } as MetricVisualizationState, keptLayerIds: ['first'], @@ -289,7 +289,7 @@ describe('metric suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, metricAccessor: metricColumn.columnId, breakdownByAccessor: bucketColumn.columnId, }, @@ -312,7 +312,7 @@ describe('metric suggestions', () => { }, state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, metricAccessor: metricColumn.columnId, } as MetricVisualizationState, keptLayerIds: ['first'], @@ -321,7 +321,7 @@ describe('metric suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, metricAccessor: metricColumn.columnId, breakdownByAccessor: bucketColumn.columnId, }, @@ -352,7 +352,7 @@ describe('metric suggestions', () => { { state: { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, metricAccessor: metricColumn.columnId, breakdownByAccessor: bucketColumn.columnId, }, diff --git a/x-pack/plugins/lens/public/visualizations/metric/suggestions.ts b/x-pack/plugins/lens/public/visualizations/metric/suggestions.ts index c0354d4db65e..a4077b4aca45 100644 --- a/x-pack/plugins/lens/public/visualizations/metric/suggestions.ts +++ b/x-pack/plugins/lens/public/visualizations/metric/suggestions.ts @@ -6,8 +6,8 @@ */ import { IconChartMetric } from '@kbn/chart-icons'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { TableSuggestion, Visualization } from '../../types'; -import { layerTypes } from '../../../common'; import { metricLabel, MetricVisualizationState, supportedDataTypes } from './visualization'; const MAX_BUCKETED_COLUMNS = 1; @@ -56,7 +56,7 @@ export const getSuggestions: Visualization['getSuggest state: { ...state, layerId: table.layerId, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, title: metricLabel, previewIcon: IconChartMetric, diff --git a/x-pack/plugins/lens/public/visualizations/metric/visualization.test.ts b/x-pack/plugins/lens/public/visualizations/metric/visualization.test.ts index 8171bd379237..87b4835187d3 100644 --- a/x-pack/plugins/lens/public/visualizations/metric/visualization.test.ts +++ b/x-pack/plugins/lens/public/visualizations/metric/visualization.test.ts @@ -9,7 +9,7 @@ import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; import { CustomPaletteParams, PaletteOutput } from '@kbn/coloring'; import { ExpressionAstExpression, ExpressionAstFunction } from '@kbn/expressions-plugin/common'; import { euiLightVars, euiThemeVars } from '@kbn/ui-theme'; -import { layerTypes } from '../..'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { createMockDatasource, createMockFramePublicAPI } from '../../mocks'; import { DatasourceLayers, @@ -61,7 +61,7 @@ describe('metric visualization', () => { test('returns a default state', () => { expect(visualization.initialize(() => 'some-id')).toEqual({ layerId: 'some-id', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }); }); diff --git a/x-pack/plugins/lens/public/visualizations/metric/visualization.tsx b/x-pack/plugins/lens/public/visualizations/metric/visualization.tsx index 81f7f08fe322..e3b42fedc45e 100644 --- a/x-pack/plugins/lens/public/visualizations/metric/visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/metric/visualization.tsx @@ -17,7 +17,8 @@ import { LayoutDirection } from '@elastic/charts'; import { euiLightVars, euiThemeVars } from '@kbn/ui-theme'; import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; import { IconChartMetric } from '@kbn/chart-icons'; -import { LayerType } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; +import type { LayerType } from '../../../common'; import { getSuggestions } from './suggestions'; import { Visualization, @@ -26,7 +27,6 @@ import { AccessorConfig, Suggestion, } from '../../types'; -import { layerTypes } from '../../../common'; import { GROUP_ID, LENS_METRIC_ID } from './constants'; import { DimensionEditor } from './dimension_editor'; import { Toolbar } from './toolbar'; @@ -248,7 +248,7 @@ export const getMetricVisualization = ({ return ( state ?? { layerId: addNewLayer(), - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, palette: mainPalette, } ); @@ -402,7 +402,7 @@ export const getMetricVisualization = ({ getSupportedLayers(state) { return [ { - type: layerTypes.DATA, + type: LayerTypes.DATA, label: i18n.translate('xpack.lens.metric.addLayer', { defaultMessage: 'Visualization', }), diff --git a/x-pack/plugins/lens/public/visualizations/partition/suggestions.test.ts b/x-pack/plugins/lens/public/visualizations/partition/suggestions.test.ts index dc0ce54b5bc0..c7285fb8771a 100644 --- a/x-pack/plugins/lens/public/visualizations/partition/suggestions.test.ts +++ b/x-pack/plugins/lens/public/visualizations/partition/suggestions.test.ts @@ -16,7 +16,7 @@ import { PieLayerState, PieVisualizationState, } from '../../../common'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; describe('suggestions', () => { describe('pie', () => { @@ -64,7 +64,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: [], metric: 'a', numberDisplay: NumberDisplay.HIDDEN, @@ -566,7 +566,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: ['a'], metric: 'b', @@ -590,7 +590,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: ['a'], metric: 'b', numberDisplay: NumberDisplay.HIDDEN, @@ -623,7 +623,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: [], metric: 'a', @@ -673,7 +673,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: ['a', 'b'], metric: 'e', numberDisplay: NumberDisplay.VALUE, @@ -722,7 +722,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: ['a', 'b'], metric: 'e', numberDisplay: NumberDisplay.PERCENT, @@ -759,7 +759,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: ['a'], metric: 'b', @@ -782,7 +782,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: ['a'], metric: 'b', @@ -816,7 +816,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: [], metric: 'a', @@ -858,7 +858,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: ['a', 'b'], metric: 'c', @@ -893,7 +893,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: [], metric: 'a', @@ -931,7 +931,7 @@ describe('suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: ['a', 'b'], metric: 'c', numberDisplay: NumberDisplay.HIDDEN, diff --git a/x-pack/plugins/lens/public/visualizations/partition/suggestions.ts b/x-pack/plugins/lens/public/visualizations/partition/suggestions.ts index 7a0c94d5d1b3..25742f7cab03 100644 --- a/x-pack/plugins/lens/public/visualizations/partition/suggestions.ts +++ b/x-pack/plugins/lens/public/visualizations/partition/suggestions.ts @@ -7,6 +7,7 @@ import { partition } from 'lodash'; import { i18n } from '@kbn/i18n'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { SuggestionRequest, TableSuggestionColumn, @@ -14,7 +15,6 @@ import type { } from '../../types'; import { CategoryDisplay, - layerTypes, LegendDisplay, NumberDisplay, PieChartTypes, @@ -132,7 +132,7 @@ export function suggestions({ layerId: table.layerId, primaryGroups: groups.map((col) => col.columnId), metric: metricColumnId, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } : { layerId: table.layerId, @@ -142,7 +142,7 @@ export function suggestions({ categoryDisplay: CategoryDisplay.DEFAULT, legendDisplay: LegendDisplay.DEFAULT, nestedLegend: false, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, ], }, @@ -201,7 +201,7 @@ export function suggestions({ state.layers[0].categoryDisplay === CategoryDisplay.INSIDE ? CategoryDisplay.DEFAULT : state.layers[0].categoryDisplay, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } : { layerId: table.layerId, @@ -211,7 +211,7 @@ export function suggestions({ categoryDisplay: CategoryDisplay.DEFAULT, legendDisplay: LegendDisplay.DEFAULT, nestedLegend: false, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, ], }, @@ -246,7 +246,7 @@ export function suggestions({ secondaryGroups: groups[1] ? [groups[1].columnId] : [], metric: metricColumnId, categoryDisplay: CategoryDisplay.DEFAULT, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } : { layerId: table.layerId, @@ -257,7 +257,7 @@ export function suggestions({ categoryDisplay: CategoryDisplay.DEFAULT, legendDisplay: LegendDisplay.DEFAULT, nestedLegend: false, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, ], }, @@ -286,7 +286,7 @@ export function suggestions({ primaryGroups: groups.map((col) => col.columnId), metric: metricColumnId, categoryDisplay: CategoryDisplay.DEFAULT, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, } : { layerId: table.layerId, @@ -296,7 +296,7 @@ export function suggestions({ categoryDisplay: CategoryDisplay.DEFAULT, legendDisplay: LegendDisplay.DEFAULT, nestedLegend: false, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, ], }, diff --git a/x-pack/plugins/lens/public/visualizations/partition/visualization.test.ts b/x-pack/plugins/lens/public/visualizations/partition/visualization.test.ts index 82073f1d5d60..25975ffb6ec7 100644 --- a/x-pack/plugins/lens/public/visualizations/partition/visualization.test.ts +++ b/x-pack/plugins/lens/public/visualizations/partition/visualization.test.ts @@ -13,7 +13,7 @@ import { NumberDisplay, LegendDisplay, } from '../../../common'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; import { createMockDatasource, createMockFramePublicAPI } from '../../mocks'; import { FramePublicAPI } from '../../types'; @@ -36,7 +36,7 @@ function getExampleState(): PieVisualizationState { layers: [ { layerId: LAYER_ID, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, primaryGroups: [], metric: undefined, numberDisplay: NumberDisplay.PERCENT, @@ -92,7 +92,7 @@ describe('pie_visualization', () => { describe('#getLayerType', () => { it('should return the type only if the layer is in the state', () => { - expect(pieVisualization.getLayerType(LAYER_ID, getExampleState())).toEqual(layerTypes.DATA); + expect(pieVisualization.getLayerType(LAYER_ID, getExampleState())).toEqual(LayerTypes.DATA); expect(pieVisualization.getLayerType('foo', getExampleState())).toBeUndefined(); }); }); @@ -104,7 +104,7 @@ describe('pie_visualization', () => { { primaryGroups: ['a'], layerId: LAYER_ID, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, numberDisplay: NumberDisplay.PERCENT, categoryDisplay: CategoryDisplay.DEFAULT, legendDisplay: LegendDisplay.DEFAULT, diff --git a/x-pack/plugins/lens/public/visualizations/partition/visualization.tsx b/x-pack/plugins/lens/public/visualizations/partition/visualization.tsx index 2a8bdc2dd4ab..49a485debcf2 100644 --- a/x-pack/plugins/lens/public/visualizations/partition/visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/partition/visualization.tsx @@ -15,6 +15,7 @@ import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; import { VIS_EVENT_TO_TRIGGER } from '@kbn/visualizations-plugin/public'; import { EuiSpacer } from '@elastic/eui'; import { PartitionVisConfiguration } from '@kbn/visualizations-plugin/common/convert_to_lens'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { Visualization, OperationMetadata, @@ -24,13 +25,19 @@ import type { VisualizeEditorContext, } from '../../types'; import { getSortedGroups, toExpression, toPreviewExpression } from './to_expression'; -import { CategoryDisplay, layerTypes, LegendDisplay, NumberDisplay } from '../../../common'; +import { + CategoryDisplay, + LegendDisplay, + NumberDisplay, + PieChartTypes, + PieLayerState, + PieVisualizationState, +} from '../../../common'; import { suggestions } from './suggestions'; import { PartitionChartsMeta } from './partition_charts_meta'; import { DimensionEditor, PieToolbar } from './toolbar'; import { checkTableForContainsSmallValues } from './render_helpers'; -import { PieChartTypes, PieLayerState, PieVisualizationState } from '../../../common'; -import { IndexPatternLayer } from '../..'; +import type { IndexPatternLayer } from '../..'; interface DatatableDatasourceState { [prop: string]: unknown; @@ -52,7 +59,7 @@ function newLayerState(layerId: string): PieLayerState { categoryDisplay: CategoryDisplay.DEFAULT, legendDisplay: LegendDisplay.DEFAULT, nestedLegend: false, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }; } @@ -362,7 +369,7 @@ export const getPieVisualization = ({ getSupportedLayers() { return [ { - type: layerTypes.DATA, + type: LayerTypes.DATA, label: i18n.translate('xpack.lens.pie.addLayer', { defaultMessage: 'Visualization', }), diff --git a/x-pack/plugins/lens/public/visualizations/xy/annotations/helpers.tsx b/x-pack/plugins/lens/public/visualizations/xy/annotations/helpers.tsx index 990d0dd8f94d..7d2940f5b0df 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/annotations/helpers.tsx +++ b/x-pack/plugins/lens/public/visualizations/xy/annotations/helpers.tsx @@ -15,8 +15,8 @@ import { } from '@kbn/event-annotation-plugin/public'; import { EventAnnotationConfig } from '@kbn/event-annotation-plugin/common'; import { IconChartBarAnnotations } from '@kbn/chart-icons'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { isDraggedDataViewField } from '../../../utils'; -import { layerTypes } from '../../../../common'; import type { FramePublicAPI, Visualization } from '../../../types'; import { isHorizontalChart } from '../state_helpers'; import type { XYState, XYDataLayerConfig, XYAnnotationLayerConfig, XYLayerConfig } from '../types'; @@ -111,7 +111,7 @@ export const getAnnotationsSupportedLayer = ( : undefined; return { - type: layerTypes.ANNOTATIONS, + type: LayerTypes.ANNOTATIONS, label: i18n.translate('xpack.lens.xyChart.addAnnotationsLayerLabel', { defaultMessage: 'Annotations', }), diff --git a/x-pack/plugins/lens/public/visualizations/xy/axes_configuration.test.ts b/x-pack/plugins/lens/public/visualizations/xy/axes_configuration.test.ts index 568cd38635ac..a351b9eb9e90 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/axes_configuration.test.ts +++ b/x-pack/plugins/lens/public/visualizations/xy/axes_configuration.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { Datatable } from '@kbn/expressions-plugin/public'; import { getAxesConfiguration } from './axes_configuration'; import { XYDataLayerConfig } from './types'; @@ -221,7 +221,7 @@ describe('axes_configuration', () => { const sampleLayer: XYDataLayerConfig = { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'line', xAccessor: 'c', accessors: ['yAccessorId'], diff --git a/x-pack/plugins/lens/public/visualizations/xy/color_assignment.test.ts b/x-pack/plugins/lens/public/visualizations/xy/color_assignment.test.ts index b59aadda1fdf..e359b85d1339 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/color_assignment.test.ts +++ b/x-pack/plugins/lens/public/visualizations/xy/color_assignment.test.ts @@ -7,7 +7,7 @@ import { getColorAssignments } from './color_assignment'; import type { FormatFactory } from '../../../common'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { XYDataLayerConfig } from './types'; import { Datatable } from '@kbn/expressions-plugin/common'; @@ -17,7 +17,7 @@ describe('color_assignment', () => { seriesType: 'bar', palette: { type: 'palette', name: 'palette1' }, layerId: '1', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, splitAccessor: 'split1', accessors: ['y1', 'y2'], }, @@ -25,7 +25,7 @@ describe('color_assignment', () => { seriesType: 'bar', palette: { type: 'palette', name: 'palette2' }, layerId: '2', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, splitAccessor: 'split2', accessors: ['y3', 'y4'], }, diff --git a/x-pack/plugins/lens/public/visualizations/xy/reference_line_helpers.tsx b/x-pack/plugins/lens/public/visualizations/xy/reference_line_helpers.tsx index 84f0a35d3b95..6e1763841e70 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/reference_line_helpers.tsx +++ b/x-pack/plugins/lens/public/visualizations/xy/reference_line_helpers.tsx @@ -9,7 +9,7 @@ import { groupBy, partition } from 'lodash'; import { i18n } from '@kbn/i18n'; import { Datatable } from '@kbn/expressions-plugin/public'; import { IconChartBarReferenceLine } from '@kbn/chart-icons'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import type { DatasourceLayers, FramePublicAPI, Visualization } from '../../types'; import { groupAxesByType } from './axes_configuration'; import { isHorizontalChart, isPercentageSeries, isStackedChart } from './state_helpers'; @@ -314,7 +314,7 @@ export const getReferenceSupportedLayer = ( : undefined; return { - type: layerTypes.REFERENCELINE, + type: LayerTypes.REFERENCELINE, label: i18n.translate('xpack.lens.xyChart.addReferenceLineLayerLabel', { defaultMessage: 'Reference lines', }), diff --git a/x-pack/plugins/lens/public/visualizations/xy/to_expression.test.ts b/x-pack/plugins/lens/public/visualizations/xy/to_expression.test.ts index d66d49e1ba9b..79821d2fc423 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/to_expression.test.ts +++ b/x-pack/plugins/lens/public/visualizations/xy/to_expression.test.ts @@ -11,7 +11,7 @@ import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; import { getXyVisualization, XYState } from './xy_visualization'; import { OperationDescriptor } from '../../types'; import { createMockDatasource, createMockFramePublicAPI } from '../../mocks'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks'; import { eventAnnotationServiceMock } from '@kbn/event-annotation-plugin/public/mocks'; import { defaultReferenceLineColor } from './color_assignment'; @@ -102,7 +102,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -128,7 +128,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -153,7 +153,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -193,7 +193,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: undefined, xAccessor: undefined, @@ -220,7 +220,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: undefined, xAccessor: 'a', @@ -244,7 +244,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -280,7 +280,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -320,7 +320,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -360,7 +360,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -400,7 +400,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -424,7 +424,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -455,7 +455,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -486,7 +486,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -512,7 +512,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -521,7 +521,7 @@ describe('#toExpression', () => { }, { layerId: 'referenceLine', - layerType: layerTypes.REFERENCELINE, + layerType: LayerTypes.REFERENCELINE, accessors: ['b', 'c'], yConfig: [{ forAccessor: 'a' }], }, @@ -550,7 +550,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -559,7 +559,7 @@ describe('#toExpression', () => { }, { layerId: 'first', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, annotations: [], indexPatternId: 'my-indexPattern', ignoreGlobalFilters: true, @@ -582,7 +582,7 @@ describe('#toExpression', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', diff --git a/x-pack/plugins/lens/public/visualizations/xy/to_expression.ts b/x-pack/plugins/lens/public/visualizations/xy/to_expression.ts index bf75018f111e..b57e866088e2 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/to_expression.ts +++ b/x-pack/plugins/lens/public/visualizations/xy/to_expression.ts @@ -16,16 +16,17 @@ import { import { LegendSize } from '@kbn/visualizations-plugin/public'; import { XYCurveType } from '@kbn/expression-xy-plugin/common'; import { EventAnnotationConfig } from '@kbn/event-annotation-plugin/common'; -import { +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; +import type { State, YConfig, XYDataLayerConfig, XYReferenceLineLayerConfig, XYAnnotationLayerConfig, AxisConfig, + ValidXYDataLayerConfig, } from './types'; -import type { ValidXYDataLayerConfig } from './types'; -import { OperationMetadata, DatasourcePublicAPI, DatasourceLayers } from '../../types'; +import type { OperationMetadata, DatasourcePublicAPI, DatasourceLayers } from '../../types'; import { getColumnToLabelMap } from './state_helpers'; import { hasIcon } from './xy_config_panel/shared/icon_select'; import { defaultReferenceLineColor } from './color_assignment'; @@ -37,7 +38,6 @@ import { getAnnotationsLayers, } from './visualization_helpers'; import { getUniqueLabels } from './annotations/helpers'; -import { layerTypes } from '../../../common'; import { axisExtentConfigToExpression } from '../../shared_components'; export const getSortedAccessors = ( @@ -90,8 +90,8 @@ export const toExpression = ( }; const simplifiedLayerExpression = { - [layerTypes.DATA]: (layer: XYDataLayerConfig) => ({ ...layer, simpleView: true }), - [layerTypes.REFERENCELINE]: (layer: XYReferenceLineLayerConfig) => ({ + [LayerTypes.DATA]: (layer: XYDataLayerConfig) => ({ ...layer, simpleView: true }), + [LayerTypes.REFERENCELINE]: (layer: XYReferenceLineLayerConfig) => ({ ...layer, simpleView: true, yConfig: layer.yConfig?.map(({ ...rest }) => ({ @@ -101,7 +101,7 @@ const simplifiedLayerExpression = { textVisibility: false, })), }), - [layerTypes.ANNOTATIONS]: (layer: XYAnnotationLayerConfig) => ({ + [LayerTypes.ANNOTATIONS]: (layer: XYAnnotationLayerConfig) => ({ ...layer, simpleView: true, }), diff --git a/x-pack/plugins/lens/public/visualizations/xy/visualization.test.ts b/x-pack/plugins/lens/public/visualizations/xy/visualization.test.ts index e76633b34992..eb23efcfa7c5 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/visualization.test.ts +++ b/x-pack/plugins/lens/public/visualizations/xy/visualization.test.ts @@ -16,7 +16,7 @@ import type { XYReferenceLineLayerConfig, SeriesType, } from './types'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { createMockDatasource, createMockFramePublicAPI } from '../../mocks'; import { IconChartBar } from '@kbn/chart-icons'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; @@ -61,7 +61,7 @@ function exampleState(): XYState { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -221,7 +221,7 @@ describe('xy_visualization', () => { ...exampleState().layers, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'e', xAccessor: 'f', @@ -239,7 +239,7 @@ describe('xy_visualization', () => { const layers = xyVisualization.appendLayer!( exampleState(), 'foo', - layerTypes.DATA, + LayerTypes.DATA, 'indexPattern1' ).layers; expect(layers.length).toEqual(exampleState().layers.length + 1); @@ -328,7 +328,7 @@ describe('xy_visualization', () => { describe('#getLayerType', () => { it('should return the type only if the layer is in the state', () => { - expect(xyVisualization.getLayerType('first', exampleState())).toEqual(layerTypes.DATA); + expect(xyVisualization.getLayerType('first', exampleState())).toEqual(LayerTypes.DATA); expect(xyVisualization.getLayerType('foo', exampleState())).toBeUndefined(); }); }); @@ -377,7 +377,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: undefined, accessors: [], @@ -390,7 +390,7 @@ describe('xy_visualization', () => { }).layers[0] ).toEqual({ layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'newCol', accessors: [], @@ -406,7 +406,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: [], @@ -419,7 +419,7 @@ describe('xy_visualization', () => { }).layers[0] ).toEqual({ layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'newCol', accessors: [], @@ -435,7 +435,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'referenceLine', - layerType: layerTypes.REFERENCELINE, + layerType: LayerTypes.REFERENCELINE, accessors: [], }, ], @@ -446,7 +446,7 @@ describe('xy_visualization', () => { }).layers[0] ).toEqual({ layerId: 'referenceLine', - layerType: layerTypes.REFERENCELINE, + layerType: LayerTypes.REFERENCELINE, accessors: ['newCol'], yConfig: [ { @@ -467,7 +467,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, @@ -480,7 +480,7 @@ describe('xy_visualization', () => { }).layers[0] ).toEqual({ layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', ignoreGlobalFilters: true, annotations: [ @@ -716,7 +716,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation2], ignoreGlobalFilters: true, @@ -745,7 +745,7 @@ describe('xy_visualization', () => { }).layers[0] ).toEqual({ layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [ exampleAnnotation2, @@ -776,7 +776,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, @@ -805,7 +805,7 @@ describe('xy_visualization', () => { }).layers[0] ).toEqual({ layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [ { @@ -836,7 +836,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation2], ignoreGlobalFilters: true, @@ -862,7 +862,7 @@ describe('xy_visualization', () => { }).layers[0] ).toEqual({ layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation2, { ...exampleAnnotation2, id: 'newColId' }], ignoreGlobalFilters: true, @@ -877,7 +877,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation, exampleAnnotation2], ignoreGlobalFilters: true, @@ -904,7 +904,7 @@ describe('xy_visualization', () => { }).layers[0] ).toEqual({ layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation2, exampleAnnotation], ignoreGlobalFilters: true, @@ -920,14 +920,14 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, }, { layerId: 'second', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation2], ignoreGlobalFilters: true, @@ -955,14 +955,14 @@ describe('xy_visualization', () => { ).toEqual([ { layerId: 'first', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, }, { layerId: 'second', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [{ ...exampleAnnotation, id: 'an2' }], ignoreGlobalFilters: true, @@ -978,14 +978,14 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, }, { layerId: 'second', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation2], ignoreGlobalFilters: true, @@ -1013,14 +1013,14 @@ describe('xy_visualization', () => { ).toEqual([ { layerId: 'first', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation2], ignoreGlobalFilters: true, }, { layerId: 'second', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, @@ -1036,14 +1036,14 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, }, { layerId: 'second', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation2], ignoreGlobalFilters: true, @@ -1070,14 +1070,14 @@ describe('xy_visualization', () => { ).toEqual([ { layerId: 'first', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [], ignoreGlobalFilters: true, }, { layerId: 'second', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, @@ -1093,14 +1093,14 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, }, { layerId: 'second', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [], ignoreGlobalFilters: true, @@ -1128,14 +1128,14 @@ describe('xy_visualization', () => { ).toEqual([ { layerId: 'first', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [], ignoreGlobalFilters: true, }, { layerId: 'second', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, @@ -1183,7 +1183,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: [], @@ -1195,7 +1195,7 @@ describe('xy_visualization', () => { }).layers[0] ).toEqual({ layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: undefined, accessors: [], @@ -1210,14 +1210,14 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: [], }, { layerId: 'ann', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation, { ...exampleAnnotation, id: 'an2' }], ignoreGlobalFilters: true, @@ -1230,14 +1230,14 @@ describe('xy_visualization', () => { ).toEqual([ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: [], }, { layerId: 'ann', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, @@ -1533,7 +1533,7 @@ describe('xy_visualization', () => { ...baseState.layers[0], accessors: ['e'], seriesType: 'bar_percentage_stacked', - layerType: layerTypes.REFERENCELINE, + layerType: LayerTypes.REFERENCELINE, }, ], ], @@ -1600,7 +1600,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: undefined, xAccessor: undefined, @@ -1608,7 +1608,7 @@ describe('xy_visualization', () => { }, { layerId: 'referenceLine', - layerType: layerTypes.REFERENCELINE, + layerType: LayerTypes.REFERENCELINE, accessors: [], yConfig: [{ axisMode: 'left', forAccessor: 'a' }], }, @@ -1950,7 +1950,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: undefined, xAccessor: 'a', @@ -1958,7 +1958,7 @@ describe('xy_visualization', () => { }, { layerId: 'annotations', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation], ignoreGlobalFilters: true, @@ -2182,7 +2182,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: [], @@ -2198,14 +2198,14 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: [], }, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: [], @@ -2221,14 +2221,14 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: ['a'], }, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: undefined, accessors: ['a'], @@ -2245,7 +2245,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: undefined, accessors: [], @@ -2261,7 +2261,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: undefined, accessors: [], @@ -2269,7 +2269,7 @@ describe('xy_visualization', () => { }, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: undefined, accessors: [], @@ -2286,14 +2286,14 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: [], }, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: undefined, accessors: ['a'], @@ -2314,14 +2314,14 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: ['a'], }, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: undefined, accessors: [], @@ -2329,7 +2329,7 @@ describe('xy_visualization', () => { }, { layerId: 'third', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: undefined, accessors: [], @@ -2351,21 +2351,21 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: [], }, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: ['a'], }, { layerId: 'third', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: ['a'], @@ -2388,7 +2388,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -2436,7 +2436,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -2444,7 +2444,7 @@ describe('xy_visualization', () => { }, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'e', @@ -2492,7 +2492,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'a', @@ -2500,7 +2500,7 @@ describe('xy_visualization', () => { }, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', splitAccessor: 'd', xAccessor: 'e', @@ -2669,7 +2669,7 @@ describe('xy_visualization', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'area', xAccessor: 'a', accessors: ['b'], @@ -2789,7 +2789,7 @@ describe('xy_visualization', () => { ...baseState.layers, { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, annotations: [exampleAnnotation2], ignoreGlobalFilters: true, }, @@ -2809,7 +2809,7 @@ describe('xy_visualization', () => { ...baseState.layers, { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation2], ignoreGlobalFilters: true, @@ -2828,7 +2828,7 @@ describe('xy_visualization', () => { ...baseState.layers, { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, annotations: [exampleAnnotation2], ignoreGlobalFilters: true, }, @@ -2848,7 +2848,7 @@ describe('xy_visualization', () => { ...baseState.layers, { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', annotations: [exampleAnnotation2], ignoreGlobalFilters: true, @@ -2876,7 +2876,7 @@ describe('xy_visualization', () => { ...baseState.layers, { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, annotations: [exampleAnnotation2], ignoreGlobalFilters: true, indexPatternId: 'myIndexPattern', @@ -2908,7 +2908,7 @@ describe('xy_visualization', () => { ...baseState.layers, { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, annotations: [exampleAnnotation2], ignoreGlobalFilters: true, indexPatternId: 'myIndexPattern', @@ -2924,7 +2924,7 @@ describe('xy_visualization', () => { layers: expect.arrayContaining([ { layerId: 'annotation', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, annotations: [exampleAnnotation2], ignoreGlobalFilters: false, indexPatternId: 'myIndexPattern', diff --git a/x-pack/plugins/lens/public/visualizations/xy/visualization.tsx b/x-pack/plugins/lens/public/visualizations/xy/visualization.tsx index c013f0cd1d07..583f0f431610 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/xy/visualization.tsx @@ -13,12 +13,13 @@ import { i18n } from '@kbn/i18n'; import type { PaletteRegistry } from '@kbn/coloring'; import { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; import { CoreStart, ThemeServiceStart } from '@kbn/core/public'; -import { EventAnnotationServiceType } from '@kbn/event-annotation-plugin/public'; +import type { EventAnnotationServiceType } from '@kbn/event-annotation-plugin/public'; import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; import { VIS_EVENT_TO_TRIGGER } from '@kbn/visualizations-plugin/public'; import type { DataPublicPluginStart } from '@kbn/data-plugin/public'; import type { IStorageWrapper } from '@kbn/kibana-utils-plugin/public'; -import { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public'; +import type { UnifiedSearchPublicPluginStart } from '@kbn/unified-search-plugin/public'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { generateId } from '../../id_generator'; import { isDraggedDataViewField, @@ -30,7 +31,7 @@ import { getSuggestions } from './xy_suggestions'; import { XyToolbar } from './xy_config_panel'; import { DimensionEditor } from './xy_config_panel/dimension_editor'; import { LayerHeader, LayerHeaderContent } from './xy_config_panel/layer_header'; -import { Visualization, AccessorConfig, FramePublicAPI } from '../../types'; +import type { Visualization, AccessorConfig, FramePublicAPI } from '../../types'; import { type State, type XYLayerConfig, @@ -40,7 +41,6 @@ import { type PersistedState, visualizationTypes, } from './types'; -import { layerTypes } from '../../../common'; import { extractReferences, injectReferences, @@ -126,7 +126,7 @@ export const getXyVisualization = ({ }, getRemoveOperation(state, layerId) { - const dataLayers = getLayersByType(state, layerTypes.DATA).map((l) => l.layerId); + const dataLayers = getLayersByType(state, LayerTypes.DATA).map((l) => l.layerId); return dataLayers.includes(layerId) && dataLayers.length === 1 ? 'clear' : 'remove'; }, @@ -222,7 +222,7 @@ export const getXyVisualization = ({ position: Position.Top, seriesType: defaultSeriesType, showGridlines: false, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }, ], } diff --git a/x-pack/plugins/lens/public/visualizations/xy/visualization_helpers.tsx b/x-pack/plugins/lens/public/visualizations/xy/visualization_helpers.tsx index 7aaa1c93f8fd..43d8353627d8 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/visualization_helpers.tsx +++ b/x-pack/plugins/lens/public/visualizations/xy/visualization_helpers.tsx @@ -8,6 +8,7 @@ import { i18n } from '@kbn/i18n'; import { uniq } from 'lodash'; import { IconChartBarHorizontal, IconChartBarStacked, IconChartMixedXy } from '@kbn/chart-icons'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { DatasourceLayers, OperationMetadata, VisualizationType } from '../../types'; import { State, @@ -20,8 +21,7 @@ import { SeriesType, } from './types'; import { isHorizontalChart } from './state_helpers'; -import { layerTypes } from '../..'; -import { LayerType } from '../../../common'; +import type { LayerType } from '../../../common'; export function getAxisName( axis: 'x' | 'y' | 'yLeft' | 'yRight', @@ -126,7 +126,7 @@ export function checkScaleOperation( } export const isDataLayer = (layer: XYLayerConfig): layer is XYDataLayerConfig => - layer.layerType === layerTypes.DATA || !layer.layerType; + layer.layerType === LayerTypes.DATA || !layer.layerType; export const getDataLayers = (layers: XYLayerConfig[]) => (layers || []).filter((layer): layer is XYDataLayerConfig => isDataLayer(layer)); @@ -136,31 +136,31 @@ export const getFirstDataLayer = (layers: XYLayerConfig[]) => export const isReferenceLayer = ( layer: Pick -): layer is XYReferenceLineLayerConfig => layer.layerType === layerTypes.REFERENCELINE; +): layer is XYReferenceLineLayerConfig => layer.layerType === LayerTypes.REFERENCELINE; export const getReferenceLayers = (layers: Array>) => (layers || []).filter((layer): layer is XYReferenceLineLayerConfig => isReferenceLayer(layer)); export const isAnnotationsLayer = ( layer: Pick -): layer is XYAnnotationLayerConfig => layer.layerType === layerTypes.ANNOTATIONS; +): layer is XYAnnotationLayerConfig => layer.layerType === LayerTypes.ANNOTATIONS; export const getAnnotationsLayers = (layers: Array>) => (layers || []).filter((layer): layer is XYAnnotationLayerConfig => isAnnotationsLayer(layer)); export interface LayerTypeToLayer { - [layerTypes.DATA]: (layer: XYDataLayerConfig) => XYDataLayerConfig; - [layerTypes.REFERENCELINE]: (layer: XYReferenceLineLayerConfig) => XYReferenceLineLayerConfig; - [layerTypes.ANNOTATIONS]: (layer: XYAnnotationLayerConfig) => XYAnnotationLayerConfig; + [LayerTypes.DATA]: (layer: XYDataLayerConfig) => XYDataLayerConfig; + [LayerTypes.REFERENCELINE]: (layer: XYReferenceLineLayerConfig) => XYReferenceLineLayerConfig; + [LayerTypes.ANNOTATIONS]: (layer: XYAnnotationLayerConfig) => XYAnnotationLayerConfig; } export const getLayerTypeOptions = (layer: XYLayerConfig, options: LayerTypeToLayer) => { if (isDataLayer(layer)) { - return options[layerTypes.DATA](layer); + return options[LayerTypes.DATA](layer); } else if (isReferenceLayer(layer)) { - return options[layerTypes.REFERENCELINE](layer); + return options[LayerTypes.REFERENCELINE](layer); } - return options[layerTypes.ANNOTATIONS](layer); + return options[LayerTypes.ANNOTATIONS](layer); }; export function getVisualizationType(state: State): VisualizationType | 'mixed' { @@ -216,7 +216,7 @@ export const defaultIcon = IconChartBarStacked; export const defaultSeriesType = 'bar_stacked'; export const supportedDataLayer = { - type: layerTypes.DATA, + type: LayerTypes.DATA, label: i18n.translate('xpack.lens.xyChart.addDataLayerLabel', { defaultMessage: 'Visualization', }), @@ -258,7 +258,7 @@ export function getMessageIdsForDimension( } const newLayerFn = { - [layerTypes.DATA]: ({ + [LayerTypes.DATA]: ({ layerId, seriesType, }: { @@ -266,16 +266,16 @@ const newLayerFn = { seriesType: SeriesType; }): XYDataLayerConfig => ({ layerId, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, accessors: [], seriesType, }), - [layerTypes.REFERENCELINE]: ({ layerId }: { layerId: string }): XYReferenceLineLayerConfig => ({ + [LayerTypes.REFERENCELINE]: ({ layerId }: { layerId: string }): XYReferenceLineLayerConfig => ({ layerId, - layerType: layerTypes.REFERENCELINE, + layerType: LayerTypes.REFERENCELINE, accessors: [], }), - [layerTypes.ANNOTATIONS]: ({ + [LayerTypes.ANNOTATIONS]: ({ layerId, indexPatternId, }: { @@ -283,7 +283,7 @@ const newLayerFn = { indexPatternId: string; }): XYAnnotationLayerConfig => ({ layerId, - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, annotations: [], indexPatternId, ignoreGlobalFilters: true, @@ -292,7 +292,7 @@ const newLayerFn = { export function newLayerState({ layerId, - layerType = layerTypes.DATA, + layerType = LayerTypes.DATA, seriesType, indexPatternId, }: { @@ -305,7 +305,7 @@ export function newLayerState({ } export function getLayersByType(state: State, byType?: string) { - return state.layers.filter(({ layerType = layerTypes.DATA }) => + return state.layers.filter(({ layerType = LayerTypes.DATA }) => byType ? layerType === byType : true ); } diff --git a/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/annotations_config_panel/index.test.tsx b/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/annotations_config_panel/index.test.tsx index c852759a97aa..7d581d50d085 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/annotations_config_panel/index.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/annotations_config_panel/index.test.tsx @@ -8,9 +8,9 @@ import React from 'react'; import { mountWithIntl as mount } from '@kbn/test-jest-helpers'; import { createDatatableUtilitiesMock } from '@kbn/data-plugin/common/mocks'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { AnnotationsPanel } from '.'; import { FramePublicAPI } from '../../../../types'; -import { layerTypes } from '../../../..'; import { createMockFramePublicAPI } from '../../../../mocks'; import { State } from '../../types'; import { Position } from '@elastic/charts'; @@ -59,7 +59,7 @@ describe('AnnotationsPanel', () => { preferredSeriesType: 'bar', layers: [ { - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, layerId: 'annotation', indexPatternId: 'indexPattern1', annotations: [customLineStaticAnnotation], diff --git a/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/axis_settings_popover.test.tsx b/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/axis_settings_popover.test.tsx index 481987520ea2..3cbfbf3b84c8 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/axis_settings_popover.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/axis_settings_popover.test.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { shallowWithIntl as shallow } from '@kbn/test-jest-helpers'; import { AxisSettingsPopover, AxisSettingsPopoverProps } from './axis_settings_popover'; import { ToolbarPopover } from '../../../shared_components'; -import { layerTypes } from '../../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { ShallowWrapper } from 'enzyme'; function getRangeInputComponent(component: ShallowWrapper) { @@ -29,7 +29,7 @@ describe('Axes Settings', () => { layers: [ { seriesType: 'bar', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, layerId: 'first', splitAccessor: 'baz', xAccessor: 'foo', diff --git a/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/visual_options_popover/visual_options_popover.test.tsx b/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/visual_options_popover/visual_options_popover.test.tsx index 8fd65fcd60f8..0e29a5fa6634 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/visual_options_popover/visual_options_popover.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/visual_options_popover/visual_options_popover.test.tsx @@ -15,7 +15,7 @@ import { VisualOptionsPopover } from '.'; import { ToolbarPopover, ValueLabelsSettings } from '../../../../shared_components'; import { MissingValuesOptions } from './missing_values_option'; import { FillOpacityOption } from './fill_opacity_option'; -import { layerTypes } from '../../../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; describe('Visual options popover', () => { let frame: FramePublicAPI; @@ -28,7 +28,7 @@ describe('Visual options popover', () => { layers: [ { seriesType: 'bar', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, layerId: 'first', splitAccessor: 'baz', xAccessor: 'foo', @@ -234,7 +234,7 @@ describe('Visual options popover', () => { { ...state.layers[0], seriesType: 'bar' } as XYLayerConfig, { seriesType: 'bar', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, layerId: 'second', splitAccessor: 'baz', xAccessor: 'foo', diff --git a/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/xy_config_panel.test.tsx b/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/xy_config_panel.test.tsx index 82e979c245df..088ba4537393 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/xy_config_panel.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/xy/xy_config_panel/xy_config_panel.test.tsx @@ -18,7 +18,7 @@ import { Position } from '@elastic/charts'; import { createMockFramePublicAPI, createMockDatasource } from '../../../mocks'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; import { EuiColorPicker } from '@elastic/eui'; -import { layerTypes } from '../../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { act } from 'react-dom/test-utils'; jest.mock('lodash', () => { @@ -41,7 +41,7 @@ describe('XY Config panels', () => { layers: [ { seriesType: 'bar', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, layerId: 'first', splitAccessor: 'baz', xAccessor: 'foo', @@ -315,7 +315,7 @@ describe('XY Config panels', () => { layers: [ { seriesType: 'bar', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, layerId: 'first', splitAccessor: undefined, xAccessor: 'foo', @@ -356,7 +356,7 @@ describe('XY Config panels', () => { layers: [ { seriesType: 'bar', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, layerId: 'first', splitAccessor: undefined, xAccessor: 'foo', @@ -399,7 +399,7 @@ describe('XY Config panels', () => { layers: [ { seriesType: 'bar', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, layerId: 'first', splitAccessor: undefined, xAccessor: 'foo', diff --git a/x-pack/plugins/lens/public/visualizations/xy/xy_suggestions.test.ts b/x-pack/plugins/lens/public/visualizations/xy/xy_suggestions.test.ts index ff04ff46ce0f..399368ffb417 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/xy_suggestions.test.ts +++ b/x-pack/plugins/lens/public/visualizations/xy/xy_suggestions.test.ts @@ -19,7 +19,7 @@ import { getXyVisualization } from './xy_visualization'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; import { eventAnnotationServiceMock } from '@kbn/event-annotation-plugin/public/mocks'; import type { PaletteOutput } from '@kbn/coloring'; -import { layerTypes } from '../../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks'; import { coreMock, themeServiceMock } from '@kbn/core/public/mocks'; import { dataPluginMock } from '@kbn/data-plugin/public/mocks'; @@ -209,14 +209,14 @@ describe('xy_suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', accessors: ['bytes'], splitAccessor: undefined, }, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', accessors: ['bytes'], splitAccessor: undefined, @@ -315,7 +315,7 @@ describe('xy_suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', xAccessor: 'date', accessors: ['bytes'], @@ -357,7 +357,7 @@ describe('xy_suggestions', () => { layers: [ { layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', xAccessor: 'date', accessors: ['bytes'], @@ -365,7 +365,7 @@ describe('xy_suggestions', () => { }, { layerId: 'second', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', xAccessor: undefined, accessors: [], @@ -550,7 +550,7 @@ describe('xy_suggestions', () => { test('passes annotation layer for date histogram data layer', () => { const annotationLayer: XYAnnotationLayerConfig = { layerId: 'second', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', ignoreGlobalFilters: true, annotations: [ @@ -574,7 +574,7 @@ describe('xy_suggestions', () => { { accessors: ['price'], layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', splitAccessor: 'product', xAccessor: 'date', @@ -597,7 +597,7 @@ describe('xy_suggestions', () => { expect(suggestion.state.layers).toEqual( expect.arrayContaining([ expect.objectContaining({ - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, }), ]) ) @@ -607,7 +607,7 @@ describe('xy_suggestions', () => { test('does not pass annotation layer if x-axis is not date histogram', () => { const annotationLayer: XYAnnotationLayerConfig = { layerId: 'second', - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, indexPatternId: 'indexPattern1', ignoreGlobalFilters: true, annotations: [ @@ -633,7 +633,7 @@ describe('xy_suggestions', () => { layerId: 'first', accessors: ['price'], seriesType: 'bar', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, xAccessor: 'date', splitAccessor: 'price2', }, @@ -655,7 +655,7 @@ describe('xy_suggestions', () => { expect(suggestion.state.layers).toEqual( expect.arrayContaining([ expect.not.objectContaining({ - layerType: layerTypes.ANNOTATIONS, + layerType: LayerTypes.ANNOTATIONS, }), ]) ) @@ -710,7 +710,7 @@ describe('xy_suggestions', () => { { accessors: ['price', 'quantity'], layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', splitAccessor: 'product', xAccessor: 'date', @@ -765,7 +765,7 @@ describe('xy_suggestions', () => { { accessors: [], layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'line', splitAccessor: undefined, xAccessor: '', @@ -804,7 +804,7 @@ describe('xy_suggestions', () => { { accessors: ['price'], layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', splitAccessor: undefined, xAccessor: 'date', @@ -847,7 +847,7 @@ describe('xy_suggestions', () => { { accessors: ['price', 'quantity'], layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', splitAccessor: 'product', xAccessor: 'date', @@ -891,7 +891,7 @@ describe('xy_suggestions', () => { { accessors: ['price', 'quantity'], layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', splitAccessor: 'dummyCol', xAccessor: 'product', @@ -929,7 +929,7 @@ describe('xy_suggestions', () => { { accessors: ['price'], layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', splitAccessor: 'date', xAccessor: 'product', @@ -970,7 +970,7 @@ describe('xy_suggestions', () => { { accessors: ['price', 'quantity'], layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', splitAccessor: 'dummyCol', xAccessor: 'product', @@ -1015,7 +1015,7 @@ describe('xy_suggestions', () => { { accessors: ['price'], layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', splitAccessor: 'category', xAccessor: 'product', @@ -1061,7 +1061,7 @@ describe('xy_suggestions', () => { { accessors: ['price', 'quantity'], layerId: 'first', - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, seriesType: 'bar', splitAccessor: 'dummyCol', xAccessor: 'product', diff --git a/x-pack/plugins/lens/public/visualizations/xy/xy_suggestions.ts b/x-pack/plugins/lens/public/visualizations/xy/xy_suggestions.ts index b63bfeb5fbd9..3e6904ecb5ba 100644 --- a/x-pack/plugins/lens/public/visualizations/xy/xy_suggestions.ts +++ b/x-pack/plugins/lens/public/visualizations/xy/xy_suggestions.ts @@ -9,7 +9,8 @@ import { i18n } from '@kbn/i18n'; import { partition } from 'lodash'; import { Position } from '@elastic/charts'; import type { PaletteOutput } from '@kbn/coloring'; -import { +import { LayerTypes } from '@kbn/expression-xy-plugin/public'; +import type { SuggestionRequest, VisualizationSuggestion, TableSuggestionColumn, @@ -24,7 +25,6 @@ import { XYDataLayerConfig, SeriesType, } from './types'; -import { layerTypes } from '../../../common'; import { getIconForSeries } from './state_helpers'; import { getDataLayers, isDataLayer } from './visualization_helpers'; @@ -526,7 +526,7 @@ function buildSuggestion({ existingLayer && 'yConfig' in existingLayer && existingLayer.yConfig ? existingLayer.yConfig.filter(({ forAccessor }) => accessors.indexOf(forAccessor) !== -1) : undefined, - layerType: layerTypes.DATA, + layerType: LayerTypes.DATA, }; const hasDateHistogramDomain = @@ -539,7 +539,7 @@ function buildSuggestion({ .filter( (layer) => keptLayerIds.includes(layer.layerId) || - (hasDateHistogramDomain && layer.layerType === layerTypes.ANNOTATIONS) + (hasDateHistogramDomain && layer.layerType === LayerTypes.ANNOTATIONS) ) // Update in place .map((layer) => (layer.layerId === layerId ? newLayer : layer)) diff --git a/x-pack/plugins/lens/server/migrations/common_migrations.ts b/x-pack/plugins/lens/server/migrations/common_migrations.ts index 282308753698..4afe60729920 100644 --- a/x-pack/plugins/lens/server/migrations/common_migrations.ts +++ b/x-pack/plugins/lens/server/migrations/common_migrations.ts @@ -7,6 +7,7 @@ import { cloneDeep, mapValues } from 'lodash'; import type { PaletteOutput, CustomPaletteParams } from '@kbn/coloring'; +import { LayerTypes } from '@kbn/expression-xy-plugin/common'; import { SerializableRecord } from '@kbn/utility-types'; import { mergeMigrationFunctionMaps, @@ -34,7 +35,7 @@ import { VisState850, LensDocShape850, } from './types'; -import { DOCUMENT_FIELD_NAME, layerTypes, LegacyMetricState } from '../../common'; +import { DOCUMENT_FIELD_NAME, LegacyMetricState } from '../../common'; import { isPartitionShape } from '../../common/visualizations'; import { LensDocShape } from './saved_object_migrations'; @@ -111,11 +112,11 @@ export const commonUpdateVisLayerType = ( const newAttributes = cloneDeep(attributes); const visState = (newAttributes as LensDocShape715).state.visualization; if ('layerId' in visState) { - visState.layerType = layerTypes.DATA; + visState.layerType = LayerTypes.DATA; } if ('layers' in visState) { for (const layer of visState.layers) { - layer.layerType = layerTypes.DATA; + layer.layerType = LayerTypes.DATA; } } return newAttributes as LensDocShape715; diff --git a/x-pack/plugins/lens/server/migrations/saved_object_migrations.test.ts b/x-pack/plugins/lens/server/migrations/saved_object_migrations.test.ts index 8264ed4853d3..fcb1e2a5722f 100644 --- a/x-pack/plugins/lens/server/migrations/saved_object_migrations.test.ts +++ b/x-pack/plugins/lens/server/migrations/saved_object_migrations.test.ts @@ -26,7 +26,8 @@ import { XYVisStatePre850, VisState850, } from './types'; -import { layerTypes, LegacyMetricState } from '../../common'; +import { LayerTypes } from '@kbn/expression-xy-plugin/common'; +import { LegacyMetricState } from '../../common'; import { Filter } from '@kbn/es-query'; import { DataViewSpec } from '@kbn/data-views-plugin/common'; @@ -1064,7 +1065,7 @@ describe('Lens migrations', () => { const state = (result.attributes as LensDocShape715).state.visualization; if ('layers' in state) { for (const layer of state.layers) { - expect(layer.layerType).toEqual(layerTypes.DATA); + expect(layer.layerType).toEqual(LayerTypes.DATA); } } }); @@ -1092,7 +1093,7 @@ describe('Lens migrations', () => { const state = (result.attributes as LensDocShape715).state.visualization; if ('layers' in state) { for (const layer of state.layers) { - expect(layer.layerType).toEqual(layerTypes.DATA); + expect(layer.layerType).toEqual(LayerTypes.DATA); } } }); @@ -1109,7 +1110,7 @@ describe('Lens migrations', () => { const state = (result.attributes as LensDocShape715).state.visualization; expect('layerType' in state).toEqual(true); if ('layerType' in state) { - expect(state.layerType).toEqual(layerTypes.DATA); + expect(state.layerType).toEqual(LayerTypes.DATA); } }); it('should add layer info to a datatable visualization', () => { @@ -1125,7 +1126,7 @@ describe('Lens migrations', () => { const state = (result.attributes as LensDocShape715).state.visualization; expect('layerType' in state).toEqual(true); if ('layerType' in state) { - expect(state.layerType).toEqual(layerTypes.DATA); + expect(state.layerType).toEqual(LayerTypes.DATA); } }); it('should add layer info to a heatmap visualization', () => { @@ -1141,7 +1142,7 @@ describe('Lens migrations', () => { const state = (result.attributes as LensDocShape715).state.visualization; expect('layerType' in state).toEqual(true); if ('layerType' in state) { - expect(state.layerType).toEqual(layerTypes.DATA); + expect(state.layerType).toEqual(LayerTypes.DATA); } }); }); From 1f1e14591038c2a421ff6c01c3756aa0a6cf7727 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Fri, 7 Oct 2022 17:51:41 +0300 Subject: [PATCH 2/4] fix JEST --- .../trigger_actions/open_in_discover_drilldown.test.tsx | 6 ++++-- .../public/trigger_actions/open_in_discover_drilldown.tsx | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.test.tsx b/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.test.tsx index 26332f0cf005..84ae2a21a9a9 100644 --- a/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.test.tsx +++ b/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.test.tsx @@ -48,14 +48,16 @@ describe('open in discover drilldown', () => { instance.find('EuiSwitch').prop('onChange')!({} as unknown as FormEvent<{}>); expect(setConfig).toHaveBeenCalledWith({ openInNewTab: true }); }); - it('calls through to isCompatible helper', () => { + + it('calls through to isCompatible helper', async () => { const filters: Filter[] = [{ meta: { disabled: false } }]; - drilldown.isCompatible( + await drilldown.isCompatible( { openInNewTab: true }, { embeddable: { type: 'lens' } as IEmbeddable, filters } ); expect(isCompatible).toHaveBeenCalledWith(expect.objectContaining({ filters })); }); + it('calls through to getHref helper', async () => { const filters: Filter[] = [{ meta: { disabled: false } }]; await drilldown.execute( diff --git a/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.tsx b/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.tsx index 37e897625536..fa262c6b0d53 100644 --- a/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.tsx +++ b/x-pack/plugins/lens/public/trigger_actions/open_in_discover_drilldown.tsx @@ -131,11 +131,11 @@ export class OpenInDiscoverDrilldown }; public readonly execute = async (config: Config, context: ActionContext) => { - const { getLocation } = await getDiscoverHelpersAsync(); - if (config.openInNewTab) { window.open(await this.getHref(config, context), '_blank'); } else { + const { getLocation } = await getDiscoverHelpersAsync(); + const { app, path, state } = await getLocation({ discover: this.deps.discover, dataViews: this.deps.dataViews(), From 160fa8891841670e3450ccfa8272cfb45a21a12a Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Fri, 7 Oct 2022 22:47:26 +0300 Subject: [PATCH 3/4] update some imports --- .../common/expressions/datatable/datatable_column.ts | 2 +- .../plugins/lens/common/expressions/datatable/index.ts | 3 --- .../lens/common/expressions/datatable/sorting.tsx | 3 +-- .../lens/common/expressions/datatable/summary.ts | 1 + .../common/expressions/datatable/transpose_helpers.ts | 3 ++- x-pack/plugins/lens/public/expressions.ts | 2 +- .../dimension_panel/time_scaling.tsx | 1 - .../operations/definitions/count.tsx | 6 +++--- .../operations/layer_helpers.ts | 2 +- .../lens/public/indexpattern_datasource/utils.tsx | 2 +- .../visualizations/datatable/components/cell_value.tsx | 2 +- .../datatable/components/dimension_editor.tsx | 7 ++++--- .../components/dimension_editor_addtional_section.tsx | 10 ++++++---- .../datatable/components/table_actions.test.ts | 2 +- .../datatable/components/table_actions.ts | 2 +- .../datatable/components/table_basic.test.tsx | 2 +- .../datatable/components/table_basic.tsx | 3 ++- .../visualizations/datatable/expression.test.tsx | 2 +- .../public/visualizations/datatable/expression.tsx | 2 +- .../public/visualizations/datatable/visualization.tsx | 6 +++--- .../public/visualizations/gauge/dimension_editor.tsx | 7 ++++--- .../visualizations/legacy_metric/dimension_editor.tsx | 2 +- .../public/visualizations/metric/dimension_editor.tsx | 2 +- 23 files changed, 38 insertions(+), 36 deletions(-) diff --git a/x-pack/plugins/lens/common/expressions/datatable/datatable_column.ts b/x-pack/plugins/lens/common/expressions/datatable/datatable_column.ts index ae155fe560e8..a7592f3f179b 100644 --- a/x-pack/plugins/lens/common/expressions/datatable/datatable_column.ts +++ b/x-pack/plugins/lens/common/expressions/datatable/datatable_column.ts @@ -9,7 +9,7 @@ import type { Direction } from '@elastic/eui'; import type { PaletteOutput, CustomPaletteParams } from '@kbn/coloring'; import type { CustomPaletteState } from '@kbn/charts-plugin/common'; import type { ExpressionFunctionDefinition, DatatableColumn } from '@kbn/expressions-plugin/common'; -import { SortingHint } from '../..'; +import type { SortingHint } from '../..'; export type LensGridDirection = 'none' | Direction; diff --git a/x-pack/plugins/lens/common/expressions/datatable/index.ts b/x-pack/plugins/lens/common/expressions/datatable/index.ts index cf9fb1d0b479..2fa031236029 100644 --- a/x-pack/plugins/lens/common/expressions/datatable/index.ts +++ b/x-pack/plugins/lens/common/expressions/datatable/index.ts @@ -7,8 +7,5 @@ export * from './datatable_column'; export * from './datatable'; -export * from './summary'; -export * from './transpose_helpers'; -export * from './utils'; export type { DatatableProps } from './types'; diff --git a/x-pack/plugins/lens/common/expressions/datatable/sorting.tsx b/x-pack/plugins/lens/common/expressions/datatable/sorting.tsx index bfae4544c597..8985aaefa792 100644 --- a/x-pack/plugins/lens/common/expressions/datatable/sorting.tsx +++ b/x-pack/plugins/lens/common/expressions/datatable/sorting.tsx @@ -7,8 +7,7 @@ import versionCompare from 'compare-versions'; import valid from 'semver/functions/valid'; -import ipaddr from 'ipaddr.js'; -import type { IPv4, IPv6 } from 'ipaddr.js'; +import ipaddr, { IPv4, IPv6 } from 'ipaddr.js'; import type { FieldFormat } from '@kbn/field-formats-plugin/common'; function isIPv6Address(ip: IPv4 | IPv6): ip is IPv6 { diff --git a/x-pack/plugins/lens/common/expressions/datatable/summary.ts b/x-pack/plugins/lens/common/expressions/datatable/summary.ts index fe45a91b9a86..4516abfabb06 100644 --- a/x-pack/plugins/lens/common/expressions/datatable/summary.ts +++ b/x-pack/plugins/lens/common/expressions/datatable/summary.ts @@ -85,6 +85,7 @@ export function getSummaryRowOptions(): Array<{ ]; } +/** @internal **/ export function computeSummaryRowForColumn( columnArgs: ColumnConfigArg, table: Datatable, diff --git a/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.ts b/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.ts index f99977f74701..00e0de71395d 100644 --- a/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.ts +++ b/x-pack/plugins/lens/common/expressions/datatable/transpose_helpers.ts @@ -14,7 +14,7 @@ const TRANSPOSE_SEPARATOR = '---'; const TRANSPOSE_VISUAL_SEPARATOR = '›'; -export function getTransposeId(value: string, columnId: string) { +function getTransposeId(value: string, columnId: string) { return `${value}${TRANSPOSE_SEPARATOR}${columnId}`; } @@ -36,6 +36,7 @@ export function getOriginalId(id: string) { * * If the table is tranposed by multiple columns, this process is repeated on top of the previous transformation. * + * @internal * @param args Arguments for the table visualization * @param firstTable datatable object containing the actual data * @param formatters Formatters for all columns to transpose columns by actual display values diff --git a/x-pack/plugins/lens/public/expressions.ts b/x-pack/plugins/lens/public/expressions.ts index bfad4e70cf1c..ef12b43bec71 100644 --- a/x-pack/plugins/lens/public/expressions.ts +++ b/x-pack/plugins/lens/public/expressions.ts @@ -13,7 +13,7 @@ import { mapToColumns } from '../common/expressions/map_to_columns/map_to_column import { formatColumn } from '../common/expressions/format_column'; import { counterRate } from '../common/expressions/counter_rate'; import { getTimeScale } from '../common/expressions/time_scale/time_scale'; -import { collapse } from '../common/expressions'; +import { collapse } from '../common/expressions/collapse'; type TimeScaleArguments = Parameters; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/time_scaling.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/time_scaling.tsx index 536123956ce8..791d3b5846f2 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/time_scaling.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/dimension_panel/time_scaling.tsx @@ -13,7 +13,6 @@ import { EuiFlexItem, EuiFlexGroup, } from '@elastic/eui'; - import { i18n } from '@kbn/i18n'; import React from 'react'; import { diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/count.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/count.tsx index b911ac5394a2..46fb594c74a6 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/count.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/definitions/count.tsx @@ -11,9 +11,9 @@ import { euiThemeVars } from '@kbn/ui-theme'; import { EuiSwitch, EuiText } from '@elastic/eui'; import { AggFunctionsMapping } from '@kbn/data-plugin/public'; import { buildExpressionFunction } from '@kbn/expressions-plugin/public'; -import { TimeScaleUnit } from '../../../../common/expressions'; -import { OperationDefinition, ParamEditorProps } from '.'; -import { FieldBasedIndexPatternColumn, ValueFormatConfig } from './column_types'; +import type { TimeScaleUnit } from '../../../../common/expressions'; +import type { OperationDefinition, ParamEditorProps } from '.'; +import type { FieldBasedIndexPatternColumn, ValueFormatConfig } from './column_types'; import type { IndexPatternField } from '../../../types'; import { getInvalidFieldMessage, diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts index b3f1b3bc7d5f..0430cefea732 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts +++ b/x-pack/plugins/lens/public/indexpattern_datasource/operations/layer_helpers.ts @@ -43,7 +43,7 @@ import { FormulaIndexPatternColumn, insertOrReplaceFormulaColumn } from './defin import type { TimeScaleUnit } from '../../../common/expressions'; import { documentField } from '../document_field'; import { isColumnOfType } from './definitions/helpers'; -import { DataType } from '../..'; +import type { DataType } from '../..'; export interface ColumnAdvancedParams { filter?: Query | undefined; diff --git a/x-pack/plugins/lens/public/indexpattern_datasource/utils.tsx b/x-pack/plugins/lens/public/indexpattern_datasource/utils.tsx index 77a359729a5e..612719967161 100644 --- a/x-pack/plugins/lens/public/indexpattern_datasource/utils.tsx +++ b/x-pack/plugins/lens/public/indexpattern_datasource/utils.tsx @@ -44,7 +44,7 @@ import { hasField } from './pure_utils'; import { mergeLayer } from './state_helpers'; import { supportsRarityRanking } from './operations/definitions/terms'; import { DEFAULT_MAX_DOC_COUNT } from './operations/definitions/terms/constants'; -import { getOriginalId } from '../../common/expressions'; +import { getOriginalId } from '../../common/expressions/datatable/transpose_helpers'; import { isQueryValid } from '../shared_components'; export function isColumnInvalid( diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/cell_value.tsx b/x-pack/plugins/lens/public/visualizations/datatable/components/cell_value.tsx index baad0419074d..3f0d377c7c97 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/cell_value.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/cell_value.tsx @@ -10,7 +10,7 @@ import { EuiDataGridCellValueElementProps, EuiLink } from '@elastic/eui'; import type { IUiSettingsClient } from '@kbn/core/public'; import classNames from 'classnames'; import type { FormatFactory } from '../../../../common'; -import { getOriginalId } from '../../../../common/expressions'; +import { getOriginalId } from '../../../../common/expressions/datatable/transpose_helpers'; import type { ColumnConfig } from '../../../../common/expressions'; import type { DataContextType } from './types'; import { getContrastColor, getNumericValue } from '../../../shared_components/coloring/utils'; diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor.tsx b/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor.tsx index 091cd4faadf3..ed0048ca0d40 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor.tsx @@ -18,8 +18,8 @@ import { EuiButtonEmpty, } from '@elastic/eui'; import { CustomizablePalette, PaletteRegistry, FIXED_PROGRESSION } from '@kbn/coloring'; -import { VisualizationDimensionEditorProps } from '../../../types'; -import { DatatableVisualizationState } from '../visualization'; +import type { VisualizationDimensionEditorProps } from '../../../types'; +import type { DatatableVisualizationState } from '../visualization'; import { applyPaletteParams, @@ -27,7 +27,8 @@ import { PalettePanelContainer, findMinMaxByColumnId, } from '../../../shared_components'; -import { isNumericFieldForDatatable, getOriginalId } from '../../../../common/expressions'; +import { isNumericFieldForDatatable } from '../../../../common/expressions/datatable/utils'; +import { getOriginalId } from '../../../../common/expressions/datatable/transpose_helpers'; import './dimension_editor.scss'; import { CollapseSetting } from '../../../shared_components/collapse_setting'; diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor_addtional_section.tsx b/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor_addtional_section.tsx index c61a512991b6..19bcfcbabd53 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor_addtional_section.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/dimension_editor_addtional_section.tsx @@ -10,17 +10,19 @@ import { i18n } from '@kbn/i18n'; import { css } from '@emotion/react'; import { EuiFormRow, EuiFieldText, EuiText, useEuiTheme, EuiComboBox } from '@elastic/eui'; import { PaletteRegistry } from '@kbn/coloring'; -import { VisualizationDimensionEditorProps } from '../../../types'; -import { DatatableVisualizationState } from '../visualization'; +import type { VisualizationDimensionEditorProps } from '../../../types'; +import type { DatatableVisualizationState } from '../visualization'; import { useDebouncedValue } from '../../../shared_components'; import type { ColumnState } from '../../../../common/expressions'; + import { - isNumericFieldForDatatable, getDefaultSummaryLabel, getFinalSummaryConfiguration, getSummaryRowOptions, -} from '../../../../common/expressions'; +} from '../../../../common/expressions/datatable/summary'; + +import { isNumericFieldForDatatable } from '../../../../common/expressions/datatable/utils'; import './dimension_editor.scss'; diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/table_actions.test.ts b/x-pack/plugins/lens/public/visualizations/datatable/components/table_actions.test.ts index 760145e06c33..2a517acc3308 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/table_actions.test.ts +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/table_actions.test.ts @@ -17,7 +17,7 @@ import { createGridHideHandler, createTransposeColumnFilterHandler, } from './table_actions'; -import { LensGridDirection, ColumnConfig } from '../../../../common/expressions'; +import type { LensGridDirection, ColumnConfig } from '../../../../common/expressions'; function getDefaultConfig(): ColumnConfig { return { diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/table_actions.ts b/x-pack/plugins/lens/public/visualizations/datatable/components/table_actions.ts index b4075ef84898..07aea191a365 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/table_actions.ts +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/table_actions.ts @@ -10,7 +10,7 @@ import type { Datatable, DatatableColumn } from '@kbn/expressions-plugin/common' import { ClickTriggerEvent } from '@kbn/charts-plugin/public'; import type { LensResizeAction, LensSortAction, LensToggleAction } from './types'; import type { ColumnConfig, LensGridDirection } from '../../../../common/expressions'; -import { getOriginalId } from '../../../../common/expressions'; +import { getOriginalId } from '../../../../common/expressions/datatable/transpose_helpers'; export const createGridResizeHandler = ( diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.test.tsx b/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.test.tsx index 4c45e139bcc2..3583225584ec 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.test.tsx @@ -16,7 +16,7 @@ import { VisualizationContainer } from '../../../visualization_container'; import { EmptyPlaceholder } from '@kbn/charts-plugin/public'; import { IconChartDatatable } from '@kbn/chart-icons'; import { DataContext, DatatableComponent } from './table_basic'; -import { DatatableProps } from '../../../../common/expressions'; +import type { DatatableProps } from '../../../../common/expressions'; import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; import { IUiSettingsClient } from '@kbn/core/public'; import { Datatable, RenderMode } from '@kbn/expressions-plugin/common'; diff --git a/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx b/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx index c3ef4d1c1ea0..bbf5eddef879 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/components/table_basic.tsx @@ -52,7 +52,8 @@ import { createGridSortingConfig, createTransposeColumnFilterHandler, } from './table_actions'; -import { getOriginalId, getFinalSummaryConfiguration } from '../../../../common/expressions'; +import { getFinalSummaryConfiguration } from '../../../../common/expressions/datatable/summary'; +import { getOriginalId } from '../../../../common/expressions/datatable/transpose_helpers'; export const DataContext = React.createContext({}); diff --git a/x-pack/plugins/lens/public/visualizations/datatable/expression.test.tsx b/x-pack/plugins/lens/public/visualizations/datatable/expression.test.tsx index 7bd3bac4e950..eb3835f95b6a 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/expression.test.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/expression.test.tsx @@ -9,7 +9,7 @@ import type { DatatableProps } from '../../../common/expressions'; import { createMockExecutionContext } from '@kbn/expressions-plugin/common/mocks'; import type { FormatFactory } from '../../../common'; import { getDatatable } from '../../../common/expressions'; -import { Datatable } from '@kbn/expressions-plugin/common'; +import type { Datatable } from '@kbn/expressions-plugin/common'; function sampleArgs() { const indexPatternId = 'indexPatternId'; diff --git a/x-pack/plugins/lens/public/visualizations/datatable/expression.tsx b/x-pack/plugins/lens/public/visualizations/datatable/expression.tsx index 93a41f9baf53..da7fbceee5b2 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/expression.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/expression.tsx @@ -12,7 +12,7 @@ import { I18nProvider } from '@kbn/i18n-react'; import type { PaletteRegistry } from '@kbn/coloring'; import type { IAggType } from '@kbn/data-plugin/public'; import { IUiSettingsClient, ThemeServiceStart } from '@kbn/core/public'; -import { ExpressionRenderDefinition } from '@kbn/expressions-plugin/common'; +import type { ExpressionRenderDefinition } from '@kbn/expressions-plugin/common'; import { KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; import { trackUiCounterEvents } from '../../lens_ui_telemetry'; import { DatatableComponent } from './components/table_basic'; diff --git a/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx b/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx index c5206e7b82a6..ad5e8118c522 100644 --- a/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx +++ b/x-pack/plugins/lens/public/visualizations/datatable/visualization.tsx @@ -26,10 +26,10 @@ import type { import { TableDimensionEditor } from './components/dimension_editor'; import { TableDimensionEditorAdditionalSection } from './components/dimension_editor_addtional_section'; import type { LayerType } from '../../../common'; -import { getDefaultSummaryLabel, PagingState } from '../../../common/expressions'; -import type { ColumnState, SortingState } from '../../../common/expressions'; +import { getDefaultSummaryLabel } from '../../../common/expressions/datatable/summary'; +import type { ColumnState, SortingState, PagingState } from '../../../common/expressions'; import { DataTableToolbar } from './components/toolbar'; -import { IndexPatternLayer } from '../../indexpattern_datasource/types'; +import type { IndexPatternLayer } from '../../indexpattern_datasource/types'; export interface DatatableVisualizationState { columns: ColumnState[]; diff --git a/x-pack/plugins/lens/public/visualizations/gauge/dimension_editor.tsx b/x-pack/plugins/lens/public/visualizations/gauge/dimension_editor.tsx index 056b96619949..c886eaa360ec 100644 --- a/x-pack/plugins/lens/public/visualizations/gauge/dimension_editor.tsx +++ b/x-pack/plugins/lens/public/visualizations/gauge/dimension_editor.tsx @@ -25,14 +25,15 @@ import { } from '@kbn/coloring'; import { GaugeTicksPositions, GaugeColorModes } from '@kbn/expression-gauge-plugin/common'; import { getMaxValue, getMinValue } from '@kbn/expression-gauge-plugin/public'; -import { isNumericFieldForDatatable } from '../../../common/expressions'; +import { isNumericFieldForDatatable } from '../../../common/expressions/datatable/utils'; import { applyPaletteParams, PalettePanelContainer, TooltipWrapper } from '../../shared_components'; import type { VisualizationDimensionEditorProps } from '../../types'; -import './dimension_editor.scss'; -import { GaugeVisualizationState } from './constants'; +import type { GaugeVisualizationState } from './constants'; import { defaultPaletteParams } from './palette_config'; import { getAccessorsFromState } from './utils'; +import './dimension_editor.scss'; + export function GaugeDimensionEditor( props: VisualizationDimensionEditorProps & { paletteService: PaletteRegistry; diff --git a/x-pack/plugins/lens/public/visualizations/legacy_metric/dimension_editor.tsx b/x-pack/plugins/lens/public/visualizations/legacy_metric/dimension_editor.tsx index 5c2239a81c3e..84e0dc6f675b 100644 --- a/x-pack/plugins/lens/public/visualizations/legacy_metric/dimension_editor.tsx +++ b/x-pack/plugins/lens/public/visualizations/legacy_metric/dimension_editor.tsx @@ -23,7 +23,7 @@ import { i18n } from '@kbn/i18n'; import React, { useCallback, useState } from 'react'; import { ColorMode } from '@kbn/charts-plugin/common'; import type { LegacyMetricState } from '../../../common/types'; -import { isNumericFieldForDatatable } from '../../../common/expressions'; +import { isNumericFieldForDatatable } from '../../../common/expressions/datatable/utils'; import { applyPaletteParams, PalettePanelContainer } from '../../shared_components'; import type { VisualizationDimensionEditorProps } from '../../types'; import { defaultPaletteParams } from './palette_config'; diff --git a/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx b/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx index f2188f2a356a..2f1ea5dc1350 100644 --- a/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx +++ b/x-pack/plugins/lens/public/visualizations/metric/dimension_editor.tsx @@ -31,7 +31,7 @@ import { import { getDataBoundsForPalette } from '@kbn/expression-metric-vis-plugin/public'; import { css } from '@emotion/react'; import { getColumnByAccessor } from '@kbn/visualizations-plugin/common/utils'; -import { isNumericFieldForDatatable } from '../../../common/expressions'; +import { isNumericFieldForDatatable } from '../../../common/expressions/datatable/utils'; import { applyPaletteParams, PalettePanelContainer, From 7c5d0f55c483a491873d238de8c9fd0701a6ae29 Mon Sep 17 00:00:00 2001 From: Alexey Antonov Date: Mon, 10 Oct 2022 12:01:28 +0300 Subject: [PATCH 4/4] Update x-pack/plugins/lens/common/expressions/datatable/sorting.tsx Co-authored-by: Marco Liberati --- x-pack/plugins/lens/common/expressions/datatable/sorting.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/lens/common/expressions/datatable/sorting.tsx b/x-pack/plugins/lens/common/expressions/datatable/sorting.tsx index 8985aaefa792..e3db99d69dc7 100644 --- a/x-pack/plugins/lens/common/expressions/datatable/sorting.tsx +++ b/x-pack/plugins/lens/common/expressions/datatable/sorting.tsx @@ -7,7 +7,7 @@ import versionCompare from 'compare-versions'; import valid from 'semver/functions/valid'; -import ipaddr, { IPv4, IPv6 } from 'ipaddr.js'; +import ipaddr, { type IPv4, type IPv6 } from 'ipaddr.js'; import type { FieldFormat } from '@kbn/field-formats-plugin/common'; function isIPv6Address(ip: IPv4 | IPv6): ip is IPv6 {