[Lens] Bundle Size Reduction (#142938)

* [Draft][Lens] Bundle Size Reduction

* fix JEST

* update some imports

* Update x-pack/plugins/lens/common/expressions/datatable/sorting.tsx

Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
This commit is contained in:
Alexey Antonov 2022-10-10 13:12:10 +03:00 committed by GitHub
parent ee2b21f104
commit c38712a5be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 508 additions and 492 deletions

View file

@ -9,6 +9,8 @@
export const PLUGIN_ID = 'expressionXy';
export const PLUGIN_NAME = 'expressionXy';
export { LayerTypes } from './constants';
export type {
XYArgs,
EndValue,

View file

@ -14,4 +14,6 @@ export function plugin() {
return new ExpressionXyPlugin();
}
export { LayerTypes } from '../common';
export type { ExpressionXyPluginSetup, ExpressionXyPluginStart } from './types';

View file

@ -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___';

View file

@ -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;

View file

@ -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';

View file

@ -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, { type IPv4, type IPv6 } from 'ipaddr.js';
import type { FieldFormat } from '@kbn/field-formats-plugin/common';
function isIPv6Address(ip: IPv4 | IPv6): ip is IPv6 {

View file

@ -85,6 +85,7 @@ export function getSummaryRowOptions(): Array<{
];
}
/** @internal **/
export function computeSummaryRowForColumn(
columnArgs: ColumnConfigArg,
table: Datatable,

View file

@ -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

View file

@ -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';

View file

@ -25,12 +25,12 @@
"expressionGauge",
"expressionMetricVis",
"expressionHeatmap",
"expressionXY",
"eventAnnotation",
"unifiedSearch",
"unifiedFieldList"
],
"optionalPlugins": [
"expressionXY",
"usageCollection",
"taskManager",
"globalSearch",

View file

@ -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 ? (
<EuiFlexGroup gutterSize="m">
<EuiFlexItem>
<span className="lnsLayerAddButton__label">{label}</span>

View file

@ -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',
},
]);

View file

@ -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
);

View file

@ -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<string, LayerType>);
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
);
}

View file

@ -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<typeof getTimeScale>;

View file

@ -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';

View file

@ -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,

View file

@ -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 (
<DimensionEditor
{...props}
layerType={props.layerType || layerTypes.DATA}
layerType={props.layerType || LayerTypes.DATA}
currentIndexPattern={currentIndexPattern}
selectedColumn={selectedColumn}
operationSupportMatrix={operationSupportMatrix}

View file

@ -13,7 +13,6 @@ import {
EuiFlexItem,
EuiFlexGroup,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import {

View file

@ -8,7 +8,7 @@
import { checkReferences, checkForDataLayerType } from './utils';
import { operationDefinitionMap } from '..';
import { createMockedFullReference } from '../../mocks';
import { layerTypes } from '../../../../../common';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import { DateHistogramIndexPatternColumn } from '../date_histogram';
// Mock prevents issue with circular loading
@ -22,7 +22,7 @@ describe('utils', () => {
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.',
]);
});

View file

@ -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.',

View file

@ -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,

View file

@ -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;

View file

@ -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(

View file

@ -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<Visualization> {
@ -14,8 +14,8 @@ export function createMockVisualization(id = 'testVis'): jest.Mocked<Visualizati
clearLayer: jest.fn((state, _layerId, _indexPatternId) => 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',

View file

@ -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 {

View file

@ -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;

View file

@ -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;

View file

@ -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<DiscoverStart, 'locator'>,
dataViews: Pick<DataViewsService, 'get'>,
@ -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 });
},
});

View file

@ -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<EmbeddableInput>, filters }
);
expect(isCompatible).toHaveBeenCalledWith(expect.objectContaining({ filters }));
});
it('calls through to getHref helper', async () => {
const filters: Filter[] = [{ meta: { disabled: false } }];
await drilldown.execute(

View file

@ -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<EmbeddableQueryInput>;
@ -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<Config, ActionFactoryContext>;
const OPEN_IN_DISCOVER_DRILLDOWN = 'OPEN_IN_DISCOVER_DRILLDOWN';
export class OpenInDiscoverDrilldown
implements Drilldown<Config, ActionContext, ActionFactoryContext>
{
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<CollectConfigProps> = ({
config,
onConfig,
context,
}) => {
private readonly ReactCollectConfig: React.FC<CollectConfigProps> = ({ config, onConfig }) => {
return (
<EuiFormRow hasChildLabel={false}>
<EuiSwitch
@ -107,6 +103,8 @@ export class OpenInDiscoverDrilldown
};
public readonly isCompatible = async (config: Config, context: ActionContext) => {
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(),
@ -135,6 +134,8 @@ export class OpenInDiscoverDrilldown
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(),

View file

@ -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', {

View file

@ -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';

View file

@ -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',

View file

@ -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';

View file

@ -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',

View file

@ -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';

View file

@ -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 {

View file

@ -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 =
(

View file

@ -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';

View file

@ -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<DataContextType>({});

View file

@ -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';

View file

@ -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';

View file

@ -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 },
};

View file

@ -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,11 +25,11 @@ import type {
} from '../../types';
import { TableDimensionEditor } from './components/dimension_editor';
import { TableDimensionEditorAdditionalSection } from './components/dimension_editor_addtional_section';
import { LayerType, layerTypes } from '../../../common';
import { getDefaultSummaryLabel, PagingState } from '../../../common/expressions';
import type { ColumnState, SortingState } from '../../../common/expressions';
import type { LayerType } from '../../../common';
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[];
@ -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',
}),

View file

@ -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<GaugeVisualizationState> & {
paletteService: PaletteRegistry;

View file

@ -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',

View file

@ -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<GaugeVisualizationState>['getSuggesti
...state,
shape,
layerId: table.layerId,
layerType: layerTypes.DATA,
layerType: LayerTypes.DATA,
ticksPosition: GaugeTicksPositions.AUTO,
labelMajorMode: GaugeLabelMajorModes.AUTO,
},

View file

@ -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 ?? {};

View file

@ -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();
});
});

View file

@ -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',
}),

View file

@ -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',

View file

@ -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<HeatmapVisualizationState>['getSuggestions'] = ({
table,
@ -81,7 +81,7 @@ export const getSuggestions: Visualization<HeatmapVisualizationState>['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,

View file

@ -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();
});
});

View file

@ -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',
}),

View file

@ -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',
};
}

View file

@ -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';

View file

@ -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<LegacyMe
state: {
layerId: table.layerId,
accessor: col.columnId,
layerType: layerTypes.DATA,
layerType: LayerTypes.DATA,
},
};
}

View file

@ -6,8 +6,8 @@
*/
import { getLegacyMetricVisualization } from './visualization';
import { LayerTypes } from '@kbn/expression-xy-plugin/public';
import type { LegacyMetricState } from '../../../common/types';
import { layerTypes } from '../../../common';
import { createMockDatasource, createMockFramePublicAPI } from '../../mocks';
import { generateId } from '../../id_generator';
import { DatasourcePublicAPI, FramePublicAPI } from '../../types';
@ -21,7 +21,7 @@ function exampleState(): LegacyMetricState {
return {
accessor: 'a',
layerId: 'l1',
layerType: layerTypes.DATA,
layerType: LayerTypes.DATA,
};
}
@ -73,7 +73,7 @@ describe('metric_visualization', () => {
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();
});
});

View file

@ -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',
}),

View file

@ -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,

View file

@ -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,
},

View file

@ -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<MetricVisualizationState>['getSuggest
state: {
...state,
layerId: table.layerId,
layerType: layerTypes.DATA,
layerType: LayerTypes.DATA,
},
title: metricLabel,
previewIcon: IconChartMetric,

View file

@ -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,
});
});

View file

@ -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',
}),

View file

@ -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,

View file

@ -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,
},
],
},

View file

@ -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,

View file

@ -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',
}),

View file

@ -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',
}),

View file

@ -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'],

View file

@ -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'],
},

View file

@ -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',
}),

View file

@ -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',

View file

@ -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,
}),

View file

@ -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',

View file

@ -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,
},
],
}

View file

@ -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<XYLayerConfig, 'layerType'>
): layer is XYReferenceLineLayerConfig => layer.layerType === layerTypes.REFERENCELINE;
): layer is XYReferenceLineLayerConfig => layer.layerType === LayerTypes.REFERENCELINE;
export const getReferenceLayers = (layers: Array<Pick<XYLayerConfig, 'layerType'>>) =>
(layers || []).filter((layer): layer is XYReferenceLineLayerConfig => isReferenceLayer(layer));
export const isAnnotationsLayer = (
layer: Pick<XYLayerConfig, 'layerType'>
): layer is XYAnnotationLayerConfig => layer.layerType === layerTypes.ANNOTATIONS;
): layer is XYAnnotationLayerConfig => layer.layerType === LayerTypes.ANNOTATIONS;
export const getAnnotationsLayers = (layers: Array<Pick<XYLayerConfig, 'layerType'>>) =>
(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
);
}

View file

@ -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],

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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',

View file

@ -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))

View file

@ -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<VisStatePost715>).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<VisStatePost715>;

View file

@ -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<VisStatePost715>).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<VisStatePost715>).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<VisStatePost715>).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<VisStatePost715>).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<VisStatePost715>).state.visualization;
expect('layerType' in state).toEqual(true);
if ('layerType' in state) {
expect(state.layerType).toEqual(layerTypes.DATA);
expect(state.layerType).toEqual(LayerTypes.DATA);
}
});
});