diff --git a/.eslintrc.js b/.eslintrc.js index 38c6fb34c4d8e..d97668b3545e2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -49,6 +49,11 @@ const ELASTIC_LICENSE_HEADER = ` */ `; +const allMochaRules = {}; +Object.keys(require('eslint-plugin-mocha').rules).forEach(k => { + allMochaRules['mocha/' + k] = 'off'; +}); + module.exports = { root: true, @@ -523,9 +528,7 @@ module.exports = { */ { files: ['test/harden/*.js'], - rules: { - 'mocha/handle-done-callback': 'off', // TODO: Find a way to disable all mocha rules - }, + rules: allMochaRules, }, /** diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/category_axis_panel.test.tsx.snap b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/category_axis_panel.test.tsx.snap index 037989a86af01..2b7c03084ec65 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/category_axis_panel.test.tsx.snap +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/category_axis_panel.test.tsx.snap @@ -52,59 +52,16 @@ exports[`CategoryAxisPanel component should init with the default set of props 1 value={true} /> `; diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/chart_options.test.tsx.snap b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/chart_options.test.tsx.snap index 56f35ae021173..e9cd2b737b879 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/chart_options.test.tsx.snap +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/chart_options.test.tsx.snap @@ -31,22 +31,6 @@ exports[`ChartOptions component should init with the default set of props 1`] = diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/value_axes_panel.test.tsx.snap b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/value_axes_panel.test.tsx.snap index f589a69eecbc3..0b673a819f666 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/value_axes_panel.test.tsx.snap +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/__snapshots__/value_axes_panel.test.tsx.snap @@ -89,7 +89,6 @@ exports[`ValueAxesPanel component should init with the default set of props 1`] size="m" /> diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/category_axis_panel.test.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/category_axis_panel.test.tsx index 69622bb3666a6..91cdcd0f456b1 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/category_axis_panel.test.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/category_axis_panel.test.tsx @@ -21,14 +21,12 @@ import React from 'react'; import { shallow } from 'enzyme'; import { CategoryAxisPanel, CategoryAxisPanelProps } from './category_axis_panel'; import { Axis } from '../../../types'; -import { Positions, getPositions } from '../../../utils/collections'; +import { Positions } from '../../../utils/collections'; import { LabelOptions } from './label_options'; -import { categoryAxis } from './mocks'; +import { categoryAxis, vis } from './mocks'; jest.mock('ui/new_platform'); -const positions = getPositions(); - describe('CategoryAxisPanel component', () => { let setCategoryAxis: jest.Mock; let onPositionChanged: jest.Mock; @@ -42,16 +40,10 @@ describe('CategoryAxisPanel component', () => { defaultProps = { axis, - vis: { - type: { - editorConfig: { - collections: { positions }, - }, - }, - }, + vis, onPositionChanged, setCategoryAxis, - } as any; + }; }); it('should init with the default set of props', () => { diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/category_axis_panel.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/category_axis_panel.tsx index c1da70f5c17c2..049df0cdd77be 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/category_axis_panel.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/category_axis_panel.tsx @@ -23,21 +23,25 @@ import { EuiPanel, EuiTitle, EuiSpacer } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { VisOptionsProps } from '../../../../../vis_default_editor/public'; -import { BasicVislibParams, Axis } from '../../../types'; +import { VisOptionsProps } from 'src/legacy/core_plugins/vis_default_editor/public'; +import { Axis } from '../../../types'; import { SelectOption, SwitchOption } from '../../common'; -import { LabelOptions } from './label_options'; +import { LabelOptions, SetAxisLabel } from './label_options'; import { Positions } from '../../../utils/collections'; -export interface CategoryAxisPanelProps extends VisOptionsProps { +export interface CategoryAxisPanelProps { axis: Axis; onPositionChanged: (position: Positions) => void; setCategoryAxis: (value: Axis) => void; + vis: VisOptionsProps['vis']; } -function CategoryAxisPanel(props: CategoryAxisPanelProps) { - const { axis, onPositionChanged, vis, setCategoryAxis } = props; - +function CategoryAxisPanel({ + axis, + onPositionChanged, + vis, + setCategoryAxis, +}: CategoryAxisPanelProps) { const setAxis = useCallback( (paramName: T, value: Axis[T]) => { const updatedAxis = { @@ -57,6 +61,17 @@ function CategoryAxisPanel(props: CategoryAxisPanelProps) { [setAxis, onPositionChanged] ); + const setAxisLabel: SetAxisLabel = useCallback( + (paramName, value) => { + const labels = { + ...axis.labels, + [paramName]: value, + }; + setAxis('labels', labels); + }, + [axis.labels, setAxis] + ); + return ( @@ -89,7 +104,13 @@ function CategoryAxisPanel(props: CategoryAxisPanelProps) { setValue={setAxis} /> - {axis.show && } + {axis.show && ( + + )} ); } diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/chart_options.test.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/chart_options.test.tsx index 9679728a2a3d1..c913fd4f35713 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/chart_options.test.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/chart_options.test.tsx @@ -22,21 +22,11 @@ import { shallow } from 'enzyme'; import { ChartOptions, ChartOptionsParams } from './chart_options'; import { SeriesParam } from '../../../types'; import { LineOptions } from './line_options'; -import { - ChartTypes, - ChartModes, - getInterpolationModes, - getChartTypes, - getChartModes, -} from '../../../utils/collections'; -import { valueAxis, seriesParam } from './mocks'; +import { ChartTypes, ChartModes } from '../../../utils/collections'; +import { valueAxis, seriesParam, vis } from './mocks'; jest.mock('ui/new_platform'); -const interpolationModes = getInterpolationModes(); -const chartTypes = getChartTypes(); -const chartModes = getChartModes(); - describe('ChartOptions component', () => { let setParamByIndex: jest.Mock; let changeValueAxis: jest.Mock; @@ -51,19 +41,11 @@ describe('ChartOptions component', () => { defaultProps = { index: 0, chart, - vis: { - type: { - editorConfig: { - collections: { interpolationModes, chartTypes, chartModes }, - }, - }, - }, - stateParams: { - valueAxes: [valueAxis], - }, + vis, + valueAxes: [valueAxis], setParamByIndex, changeValueAxis, - } as any; + }; }); it('should init with the default set of props', () => { diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/chart_options.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/chart_options.tsx index 399028a1128a9..bc12e04e29468 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/chart_options.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/chart_options.tsx @@ -22,8 +22,8 @@ import React, { useMemo, useCallback } from 'react'; import { i18n } from '@kbn/i18n'; import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui'; -import { VisOptionsProps } from '../../../../../vis_default_editor/public'; -import { BasicVislibParams, SeriesParam, ValueAxis } from '../../../types'; +import { Vis } from 'src/legacy/core_plugins/visualizations/public'; +import { SeriesParam, ValueAxis } from '../../../types'; import { ChartTypes } from '../../../utils/collections'; import { SelectOption } from '../../common'; import { LineOptions } from './line_options'; @@ -31,17 +31,19 @@ import { SetParamByIndex, ChangeValueAxis } from './'; export type SetChart = (paramName: T, value: SeriesParam[T]) => void; -export interface ChartOptionsParams extends VisOptionsProps { +export interface ChartOptionsParams { chart: SeriesParam; index: number; changeValueAxis: ChangeValueAxis; setParamByIndex: SetParamByIndex; + valueAxes: ValueAxis[]; + vis: Vis; } function ChartOptions({ chart, index, - stateParams, + valueAxes, vis, changeValueAxis, setParamByIndex, @@ -62,7 +64,7 @@ function ChartOptions({ const valueAxesOptions = useMemo( () => [ - ...stateParams.valueAxes.map(({ id, name }: ValueAxis) => ({ + ...valueAxes.map(({ id, name }: ValueAxis) => ({ text: name, value: id, })), @@ -73,7 +75,7 @@ function ChartOptions({ value: 'new', }, ], - [stateParams.valueAxes] + [valueAxes] ); return ( diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/custom_extents_options.test.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/custom_extents_options.test.tsx index a112b9a3db708..a93ee454a7afd 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/custom_extents_options.test.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/custom_extents_options.test.tsx @@ -42,7 +42,7 @@ describe('CustomExtentsOptions component', () => { setMultipleValidity = jest.fn(); defaultProps = { - axis: { ...valueAxis }, + axisScale: { ...valueAxis.scale }, setValueAxis, setValueAxisScale, setMultipleValidity, @@ -57,7 +57,7 @@ describe('CustomExtentsOptions component', () => { describe('boundsMargin', () => { it('should set validity as true when value is positive', () => { - defaultProps.axis.scale.boundsMargin = 5; + defaultProps.axisScale.boundsMargin = 5; mount(); expect(setMultipleValidity).toBeCalledWith(BOUNDS_MARGIN, true); @@ -66,17 +66,17 @@ describe('CustomExtentsOptions component', () => { it('should set validity as true when value is empty', () => { const comp = mount(); comp.setProps({ - axis: { ...valueAxis, scale: { ...valueAxis.scale, boundsMargin: undefined } }, + axisScale: { ...valueAxis.scale, boundsMargin: undefined }, }); expect(setMultipleValidity).toBeCalledWith(BOUNDS_MARGIN, true); }); it('should set validity as false when value is negative', () => { - defaultProps.axis.scale.defaultYExtents = true; + defaultProps.axisScale.defaultYExtents = true; const comp = mount(); comp.setProps({ - axis: { ...valueAxis, scale: { ...valueAxis.scale, boundsMargin: -1 } }, + axisScale: { ...valueAxis.scale, boundsMargin: -1 }, }); expect(setMultipleValidity).toBeCalledWith(BOUNDS_MARGIN, false); @@ -91,7 +91,7 @@ describe('CustomExtentsOptions component', () => { }); it('should hide bounds margin input when defaultYExtents is false', () => { - defaultProps.axis.scale = { ...defaultProps.axis.scale, defaultYExtents: false }; + defaultProps.axisScale = { ...defaultProps.axisScale, defaultYExtents: false }; const comp = shallow(); expect(comp.find({ paramName: BOUNDS_MARGIN }).exists()).toBeFalsy(); @@ -102,7 +102,7 @@ describe('CustomExtentsOptions component', () => { comp.find({ paramName: DEFAULT_Y_EXTENTS }).prop('setValue')(DEFAULT_Y_EXTENTS, true); expect(setMultipleValidity).not.toBeCalled(); - expect(setValueAxis).toBeCalledWith(SCALE, defaultProps.axis.scale); + expect(setValueAxis).toBeCalledWith(SCALE, defaultProps.axisScale); }); it('should reset boundsMargin when value is false', () => { @@ -110,7 +110,7 @@ describe('CustomExtentsOptions component', () => { comp.find({ paramName: DEFAULT_Y_EXTENTS }).prop('setValue')(DEFAULT_Y_EXTENTS, false); const newScale = { - ...defaultProps.axis.scale, + ...defaultProps.axisScale, boundsMargin: undefined, defaultYExtents: false, }; @@ -126,7 +126,7 @@ describe('CustomExtentsOptions component', () => { }); it('should hide YExtents when value is false', () => { - defaultProps.axis.scale = { ...defaultProps.axis.scale, setYExtents: false }; + defaultProps.axisScale = { ...defaultProps.axisScale, setYExtents: false }; const comp = shallow(); expect(comp.find(YExtents).exists()).toBeFalsy(); @@ -136,7 +136,7 @@ describe('CustomExtentsOptions component', () => { const comp = shallow(); comp.find({ paramName: SET_Y_EXTENTS }).prop('setValue')(SET_Y_EXTENTS, true); - expect(setValueAxis).toBeCalledWith(SCALE, defaultProps.axis.scale); + expect(setValueAxis).toBeCalledWith(SCALE, defaultProps.axisScale); }); it('should reset min and max when value is false', () => { @@ -144,7 +144,7 @@ describe('CustomExtentsOptions component', () => { comp.find({ paramName: SET_Y_EXTENTS }).prop('setValue')(SET_Y_EXTENTS, false); const newScale = { - ...defaultProps.axis.scale, + ...defaultProps.axisScale, min: undefined, max: undefined, setYExtents: false, diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/custom_extents_options.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/custom_extents_options.tsx index e322e2863a186..53b2ffa55a941 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/custom_extents_options.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/custom_extents_options.tsx @@ -26,14 +26,14 @@ import { YExtents } from './y_extents'; import { SetScale } from './value_axis_options'; export interface CustomExtentsOptionsProps { - axis: ValueAxis; + axisScale: ValueAxis['scale']; setMultipleValidity(paramName: string, isValid: boolean): void; setValueAxis(paramName: T, value: ValueAxis[T]): void; setValueAxisScale: SetScale; } function CustomExtentsOptions({ - axis, + axisScale, setMultipleValidity, setValueAxis, setValueAxisScale, @@ -44,7 +44,7 @@ function CustomExtentsOptions({ ); const isBoundsMarginValid = - !axis.scale.defaultYExtents || !axis.scale.boundsMargin || axis.scale.boundsMargin >= 0; + !axisScale.defaultYExtents || !axisScale.boundsMargin || axisScale.boundsMargin >= 0; const setBoundsMargin = useCallback( (paramName: 'boundsMargin', value: number | '') => @@ -54,25 +54,25 @@ function CustomExtentsOptions({ const onDefaultYExtentsChange = useCallback( (paramName: 'defaultYExtents', value: boolean) => { - const scale = { ...axis.scale, [paramName]: value }; + const scale = { ...axisScale, [paramName]: value }; if (!scale.defaultYExtents) { delete scale.boundsMargin; } setValueAxis('scale', scale); }, - [setValueAxis, axis.scale] + [axisScale, setValueAxis] ); const onSetYExtentsChange = useCallback( (paramName: 'setYExtents', value: boolean) => { - const scale = { ...axis.scale, [paramName]: value }; + const scale = { ...axisScale, [paramName]: value }; if (!scale.setYExtents) { delete scale.min; delete scale.max; } setValueAxis('scale', scale); }, - [setValueAxis, axis.scale] + [axisScale, setValueAxis] ); useEffect(() => { @@ -91,11 +91,11 @@ function CustomExtentsOptions({ } )} paramName="defaultYExtents" - value={axis.scale.defaultYExtents} + value={axisScale.defaultYExtents} setValue={onDefaultYExtentsChange} /> - {axis.scale.defaultYExtents && ( + {axisScale.defaultYExtents && ( <> @@ -121,13 +121,13 @@ function CustomExtentsOptions({ defaultMessage: 'Set axis extents', })} paramName="setYExtents" - value={axis.scale.setYExtents} + value={axisScale.setYExtents} setValue={onSetYExtentsChange} /> - {axis.scale.setYExtents && ( + {axisScale.setYExtents && ( diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/index.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/index.tsx index 32c21008c2a3a..82b64e4185ed2 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/index.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/index.tsx @@ -304,7 +304,13 @@ function MetricsAxisOptions(props: ValidationVisOptionsProps) return isTabSelected ? ( <> - + ) removeValueAxis={removeValueAxis} onValueAxisPositionChanged={onValueAxisPositionChanged} setParamByIndex={setParamByIndex} - {...props} + setMultipleValidity={props.setMultipleValidity} + seriesParams={stateParams.seriesParams} + valueAxes={stateParams.valueAxes} + vis={vis} /> ) : null; diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/label_options.test.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/label_options.test.tsx index 91d9987c77f3b..48fcbdf8f9082 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/label_options.test.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/label_options.test.tsx @@ -21,32 +21,26 @@ import React from 'react'; import { shallow } from 'enzyme'; import { LabelOptions, LabelOptionsProps } from './label_options'; import { TruncateLabelsOption } from '../../common'; -import { valueAxis, categoryAxis } from './mocks'; +import { valueAxis } from './mocks'; jest.mock('ui/new_platform'); const FILTER = 'filter'; const ROTATE = 'rotate'; const DISABLED = 'disabled'; -const CATEGORY_AXES = 'categoryAxes'; describe('LabelOptions component', () => { - let setValue: jest.Mock; + let setAxisLabel: jest.Mock; let defaultProps: LabelOptionsProps; beforeEach(() => { - setValue = jest.fn(); + setAxisLabel = jest.fn(); defaultProps = { - axis: { ...valueAxis }, - axesName: CATEGORY_AXES, - index: 0, - stateParams: { - categoryAxes: [{ ...categoryAxis }], - valueAxes: [{ ...valueAxis }], - } as any, - setValue, - } as any; + axisLabels: { ...valueAxis.labels }, + axisFilterCheckboxName: '', + setAxisLabel, + }; }); it('should init with the default set of props', () => { @@ -64,7 +58,7 @@ describe('LabelOptions component', () => { }); it('should disable other fields when axis.labels.show is false', () => { - defaultProps.axis.labels.show = false; + defaultProps.axisLabels.show = false; const comp = shallow(); expect(comp.find({ paramName: FILTER }).prop(DISABLED)).toBeTruthy(); @@ -76,25 +70,20 @@ describe('LabelOptions component', () => { const comp = shallow(); comp.find({ paramName: ROTATE }).prop('setValue')(ROTATE, '5'); - const newAxes = [{ ...categoryAxis, labels: { ...categoryAxis.labels, rotate: 5 } }]; - expect(setValue).toBeCalledWith(CATEGORY_AXES, newAxes); + expect(setAxisLabel).toBeCalledWith('rotate', 5); }); it('should set filter value', () => { const comp = shallow(); - expect(defaultProps.stateParams.categoryAxes[0].labels.filter).toBeTruthy(); comp.find({ paramName: FILTER }).prop('setValue')(FILTER, false); - const newAxes = [{ ...categoryAxis, labels: { ...categoryAxis.labels, filter: false } }]; - expect(setValue).toBeCalledWith(CATEGORY_AXES, newAxes); + expect(setAxisLabel).toBeCalledWith(FILTER, false); }); it('should set value for valueAxes', () => { - defaultProps.axesName = 'valueAxes'; const comp = shallow(); comp.find(TruncateLabelsOption).prop('setValue')('truncate', 10); - const newAxes = [{ ...valueAxis, labels: { ...valueAxis.labels, truncate: 10 } }]; - expect(setValue).toBeCalledWith('valueAxes', newAxes); + expect(setAxisLabel).toBeCalledWith('truncate', 10); }); }); diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/label_options.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/label_options.tsx index 2dc5889090dca..b6b54193e9f4a 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/label_options.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/label_options.tsx @@ -23,33 +23,21 @@ import { EuiTitle, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { VisOptionsProps } from '../../../../../vis_default_editor/public'; -import { BasicVislibParams, Axis } from '../../../types'; +import { Axis } from '../../../types'; import { SelectOption, SwitchOption, TruncateLabelsOption } from '../../common'; import { getRotateOptions } from '../../../utils/collections'; -export interface LabelOptionsProps extends VisOptionsProps { - axis: Axis; - axesName: 'categoryAxes' | 'valueAxes'; - index: number; +export type SetAxisLabel = ( + paramName: T, + value: Axis['labels'][T] +) => void; +export interface LabelOptionsProps { + axisLabels: Axis['labels']; + axisFilterCheckboxName: string; + setAxisLabel: SetAxisLabel; } -function LabelOptions({ stateParams, setValue, axis, axesName, index }: LabelOptionsProps) { - const setAxisLabel = useCallback( - (paramName: T, value: Axis['labels'][T]) => { - const axes = [...stateParams[axesName]]; - axes[index] = { - ...axes[index], - labels: { - ...axes[index].labels, - [paramName]: value, - }, - }; - setValue(axesName, axes); - }, - [axesName, index, setValue, stateParams] - ); - +function LabelOptions({ axisLabels, axisFilterCheckboxName, setAxisLabel }: LabelOptionsProps) { const setAxisLabelRotate = useCallback( (paramName: 'rotate', value: Axis['labels']['rotate']) => { setAxisLabel(paramName, Number(value)); @@ -77,20 +65,18 @@ function LabelOptions({ stateParams, setValue, axis, axesName, index }: LabelOpt defaultMessage: 'Show labels', })} paramName="show" - value={axis.labels.show} + value={axisLabels.show} setValue={setAxisLabel} /> @@ -99,20 +85,20 @@ function LabelOptions({ stateParams, setValue, axis, axesName, index }: LabelOpt diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/line_options.test.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/line_options.test.tsx index 98ef8a094a260..1d29d39bfcb7f 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/line_options.test.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/line_options.test.tsx @@ -21,14 +21,12 @@ import React from 'react'; import { shallow } from 'enzyme'; import { LineOptions, LineOptionsParams } from './line_options'; import { NumberInputOption } from '../../common'; -import { getInterpolationModes } from '../../../utils/collections'; -import { seriesParam } from './mocks'; +import { seriesParam, vis } from './mocks'; jest.mock('ui/new_platform'); const LINE_WIDTH = 'lineWidth'; const DRAW_LINES = 'drawLinesBetweenPoints'; -const interpolationModes = getInterpolationModes(); describe('LineOptions component', () => { let setChart: jest.Mock; @@ -39,15 +37,9 @@ describe('LineOptions component', () => { defaultProps = { chart: { ...seriesParam }, - vis: { - type: { - editorConfig: { - collections: { interpolationModes }, - }, - }, - }, + vis, setChart, - } as any; + }; }); it('should init with the default set of props', () => { diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/mocks.ts b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/mocks.ts index 7955bf79c24eb..58c75629f1fa1 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/mocks.ts +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/mocks.ts @@ -17,6 +17,7 @@ * under the License. */ +import { Vis } from 'src/legacy/core_plugins/visualizations/public'; import { Axis, ValueAxis, SeriesParam, Style } from '../../../types'; import { ChartTypes, @@ -25,6 +26,10 @@ import { ScaleTypes, Positions, AxisTypes, + getScaleTypes, + getAxisModes, + getPositions, + getInterpolationModes, } from '../../../utils/collections'; const defaultValueAxisId = 'ValueAxis-1'; @@ -84,4 +89,17 @@ const seriesParam: SeriesParam = { valueAxis: defaultValueAxisId, }; -export { defaultValueAxisId, categoryAxis, valueAxis, seriesParam }; +const positions = getPositions(); +const axisModes = getAxisModes(); +const scaleTypes = getScaleTypes(); +const interpolationModes = getInterpolationModes(); + +const vis = ({ + type: { + editorConfig: { + collections: { scaleTypes, axisModes, positions, interpolationModes }, + }, + }, +} as any) as Vis; + +export { defaultValueAxisId, categoryAxis, valueAxis, seriesParam, vis }; diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/series_panel.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/series_panel.tsx index db28256816f8d..44e7a4cfb0088 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/series_panel.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/series_panel.tsx @@ -23,19 +23,20 @@ import { EuiPanel, EuiTitle, EuiSpacer, EuiAccordion } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { VisOptionsProps } from '../../../../../vis_default_editor/public'; -import { BasicVislibParams } from '../../../types'; +import { Vis } from 'src/legacy/core_plugins/visualizations/public'; +import { ValueAxis, SeriesParam } from '../../../types'; import { ChartOptions } from './chart_options'; import { SetParamByIndex, ChangeValueAxis } from './'; -export interface SeriesPanelProps extends VisOptionsProps { +export interface SeriesPanelProps { changeValueAxis: ChangeValueAxis; setParamByIndex: SetParamByIndex; + seriesParams: SeriesParam[]; + valueAxes: ValueAxis[]; + vis: Vis; } -function SeriesPanel(props: SeriesPanelProps) { - const { stateParams } = props; - +function SeriesPanel({ seriesParams, ...chartProps }: SeriesPanelProps) { return ( @@ -48,7 +49,7 @@ function SeriesPanel(props: SeriesPanelProps) { - {stateParams.seriesParams.map((chart, index) => ( + {seriesParams.map((chart, index) => ( - + ))} diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axes_panel.test.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axes_panel.test.tsx index 7524c7a13435b..141273fa6bc3f 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axes_panel.test.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axes_panel.test.tsx @@ -21,16 +21,12 @@ import React from 'react'; import { shallow } from 'enzyme'; import { ValueAxesPanel, ValueAxesPanelProps } from './value_axes_panel'; import { ValueAxis, SeriesParam } from '../../../types'; -import { Positions, getScaleTypes, getAxisModes, getPositions } from '../../../utils/collections'; +import { Positions } from '../../../utils/collections'; import { mountWithIntl } from 'test_utils/enzyme_helpers'; -import { valueAxis, seriesParam } from './mocks'; +import { valueAxis, seriesParam, vis } from './mocks'; jest.mock('ui/new_platform'); -const positions = getPositions(); -const axisModes = getAxisModes(); -const scaleTypes = getScaleTypes(); - describe('ValueAxesPanel component', () => { let setParamByIndex: jest.Mock; let onValueAxisPositionChanged: jest.Mock; @@ -66,24 +62,16 @@ describe('ValueAxesPanel component', () => { }; defaultProps = { - stateParams: { - seriesParams: [seriesParamCount, seriesParamAverage], - valueAxes: [axisLeft, axisRight], - }, - vis: { - type: { - editorConfig: { - collections: { scaleTypes, axisModes, positions }, - }, - }, - }, + seriesParams: [seriesParamCount, seriesParamAverage], + valueAxes: [axisLeft, axisRight], + vis, isCategoryAxisHorizontal: false, setParamByIndex, onValueAxisPositionChanged, addValueAxis, removeValueAxis, setMultipleValidity, - } as any; + }; }); it('should init with the default set of props', () => { @@ -93,7 +81,7 @@ describe('ValueAxesPanel component', () => { }); it('should not allow to remove the last value axis', () => { - defaultProps.stateParams.valueAxes = [axisLeft]; + defaultProps.valueAxes = [axisLeft]; const comp = mountWithIntl(); expect(comp.find('[data-test-subj="removeValueAxisBtn"] button').exists()).toBeFalsy(); }); @@ -133,7 +121,7 @@ describe('ValueAxesPanel component', () => { }); it('should show when multiple series match value axis', () => { - defaultProps.stateParams.seriesParams[1].valueAxis = 'ValueAxis-1'; + defaultProps.seriesParams[1].valueAxis = 'ValueAxis-1'; const comp = mountWithIntl(); expect( comp @@ -144,7 +132,7 @@ describe('ValueAxesPanel component', () => { }); it('should not show when no series match value axis', () => { - defaultProps.stateParams.seriesParams[0].valueAxis = 'ValueAxis-2'; + defaultProps.seriesParams[0].valueAxis = 'ValueAxis-2'; const comp = mountWithIntl(); expect( comp diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axes_panel.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axes_panel.tsx index 4aa2aee083a67..30d80ed595fe7 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axes_panel.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axes_panel.tsx @@ -31,31 +31,35 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { BasicVislibParams, ValueAxis } from '../../../types'; +import { Vis } from 'src/legacy/core_plugins/visualizations/public'; +import { SeriesParam, ValueAxis } from '../../../types'; import { ValueAxisOptions } from './value_axis_options'; import { SetParamByIndex } from './'; -import { ValidationVisOptionsProps } from '../../common'; -export interface ValueAxesPanelProps extends ValidationVisOptionsProps { +export interface ValueAxesPanelProps { isCategoryAxisHorizontal: boolean; addValueAxis: () => ValueAxis; removeValueAxis: (axis: ValueAxis) => void; onValueAxisPositionChanged: (index: number, value: ValueAxis['position']) => void; setParamByIndex: SetParamByIndex; + seriesParams: SeriesParam[]; + valueAxes: ValueAxis[]; + vis: Vis; + setMultipleValidity: (paramName: string, isValid: boolean) => void; } function ValueAxesPanel(props: ValueAxesPanelProps) { - const { stateParams, addValueAxis, removeValueAxis } = props; + const { addValueAxis, removeValueAxis, seriesParams, valueAxes } = props; const getSeries = useCallback( (axis: ValueAxis) => { - const isFirst = stateParams.valueAxes[0].id === axis.id; - const series = stateParams.seriesParams.filter( + const isFirst = valueAxes[0].id === axis.id; + const series = seriesParams.filter( serie => serie.valueAxis === axis.id || (isFirst && !serie.valueAxis) ); return series.map(serie => serie.data.label).join(', '); }, - [stateParams.valueAxes, stateParams.seriesParams] + [seriesParams, valueAxes] ); const removeButtonTooltip = useMemo( @@ -131,7 +135,7 @@ function ValueAxesPanel(props: ValueAxesPanelProps) { - {stateParams.valueAxes.map((axis, index) => ( + {valueAxes.map((axis, index) => ( <> - + ))} diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axis_options.test.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axis_options.test.tsx index bd512e9365783..955867e66d09f 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axis_options.test.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axis_options.test.tsx @@ -20,24 +20,15 @@ import React from 'react'; import { shallow } from 'enzyme'; import { ValueAxisOptions, ValueAxisOptionsParams } from './value_axis_options'; -import { Axis } from '../../../types'; +import { ValueAxis } from '../../../types'; import { TextInputOption } from '../../common'; import { LabelOptions } from './label_options'; -import { - ScaleTypes, - Positions, - getScaleTypes, - getAxisModes, - getPositions, -} from '../../../utils/collections'; -import { valueAxis, categoryAxis } from './mocks'; +import { ScaleTypes, Positions } from '../../../utils/collections'; +import { valueAxis, vis } from './mocks'; jest.mock('ui/new_platform'); const POSITION = 'position'; -const positions = getPositions(); -const axisModes = getAxisModes(); -const scaleTypes = getScaleTypes(); interface PositionOption { text: string; @@ -50,7 +41,7 @@ describe('ValueAxisOptions component', () => { let onValueAxisPositionChanged: jest.Mock; let setMultipleValidity: jest.Mock; let defaultProps: ValueAxisOptionsParams; - let axis: Axis; + let axis: ValueAxis; beforeEach(() => { setParamByIndex = jest.fn(); @@ -61,22 +52,13 @@ describe('ValueAxisOptions component', () => { defaultProps = { axis, index: 0, - stateParams: { - categoryAxes: [{ ...categoryAxis }], - valueAxes: [axis], - }, - vis: { - type: { - editorConfig: { - collections: { scaleTypes, axisModes, positions }, - }, - }, - }, + valueAxis, + vis, isCategoryAxisHorizontal: false, setParamByIndex, onValueAxisPositionChanged, setMultipleValidity, - } as any; + }; }); it('should init with the default set of props', () => { diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axis_options.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axis_options.tsx index d094a1d422385..0e78bf2f31ef6 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axis_options.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/value_axis_options.tsx @@ -21,15 +21,11 @@ import React, { useCallback, useMemo } from 'react'; import { i18n } from '@kbn/i18n'; import { EuiSpacer, EuiAccordion, EuiHorizontalRule } from '@elastic/eui'; -import { BasicVislibParams, ValueAxis } from '../../../types'; +import { Vis } from 'src/legacy/core_plugins/visualizations/public'; +import { ValueAxis } from '../../../types'; import { Positions } from '../../../utils/collections'; -import { - SelectOption, - SwitchOption, - TextInputOption, - ValidationVisOptionsProps, -} from '../../common'; -import { LabelOptions } from './label_options'; +import { SelectOption, SwitchOption, TextInputOption } from '../../common'; +import { LabelOptions, SetAxisLabel } from './label_options'; import { CustomExtentsOptions } from './custom_extents_options'; import { isAxisHorizontal } from './utils'; import { SetParamByIndex } from './'; @@ -39,25 +35,27 @@ export type SetScale = ( value: ValueAxis['scale'][T] ) => void; -export interface ValueAxisOptionsParams extends ValidationVisOptionsProps { +export interface ValueAxisOptionsParams { axis: ValueAxis; index: number; isCategoryAxisHorizontal: boolean; onValueAxisPositionChanged: (index: number, value: ValueAxis['position']) => void; setParamByIndex: SetParamByIndex; + valueAxis: ValueAxis; + vis: Vis; + setMultipleValidity: (paramName: string, isValid: boolean) => void; } -function ValueAxisOptions(props: ValueAxisOptionsParams) { - const { - axis, - index, - isCategoryAxisHorizontal, - stateParams, - vis, - onValueAxisPositionChanged, - setParamByIndex, - } = props; - +function ValueAxisOptions({ + axis, + index, + isCategoryAxisHorizontal, + valueAxis, + vis, + onValueAxisPositionChanged, + setParamByIndex, + setMultipleValidity, +}: ValueAxisOptionsParams) { const setValueAxis = useCallback( (paramName: T, value: ValueAxis[T]) => setParamByIndex('valueAxes', index, paramName, value), @@ -67,25 +65,37 @@ function ValueAxisOptions(props: ValueAxisOptionsParams) { const setValueAxisTitle = useCallback( (paramName: T, value: ValueAxis['title'][T]) => { const title = { - ...stateParams.valueAxes[index].title, + ...valueAxis.title, [paramName]: value, }; setParamByIndex('valueAxes', index, 'title', title); }, - [setParamByIndex, index, stateParams.valueAxes] + [valueAxis.title, setParamByIndex, index] ); const setValueAxisScale: SetScale = useCallback( (paramName, value) => { const scale = { - ...stateParams.valueAxes[index].scale, + ...valueAxis.scale, [paramName]: value, }; setParamByIndex('valueAxes', index, 'scale', scale); }, - [setParamByIndex, index, stateParams.valueAxes] + [valueAxis.scale, setParamByIndex, index] + ); + + const setAxisLabel: SetAxisLabel = useCallback( + (paramName, value) => { + const labels = { + ...valueAxis.labels, + [paramName]: value, + }; + + setParamByIndex('valueAxes', index, 'labels', labels); + }, + [valueAxis.labels, setParamByIndex, index] ); const onPositionChanged = useCallback( @@ -175,7 +185,11 @@ function ValueAxisOptions(props: ValueAxisOptionsParams) { setValue={setValueAxisTitle} /> - + ) : ( @@ -204,9 +218,10 @@ function ValueAxisOptions(props: ValueAxisOptionsParams) { <> diff --git a/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts b/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts index 1c7245234b089..a50d65a48c2bb 100644 --- a/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts +++ b/x-pack/test/api_integration/apis/ml/bucket_span_estimator.ts @@ -16,6 +16,7 @@ const COMMON_HEADERS = { // eslint-disable-next-line import/no-default-export export default ({ getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); + const esSupertest = getService('esSupertest'); const supertest = getService('supertestWithoutAuth'); const mlSecurity = getService('mlSecurity'); @@ -97,8 +98,39 @@ export default ({ getService }: FtrProviderContext) => { await esArchiver.unload('ml/ecommerce'); }); - for (const testData of testDataList) { - it(`estimates the bucket span ${testData.testTitleSuffix}`, async () => { + describe('with default settings', function() { + for (const testData of testDataList) { + it(`estimates the bucket span ${testData.testTitleSuffix}`, async () => { + const { body } = await supertest + .post('/api/ml/validate/estimate_bucket_span') + .auth(testData.user, mlSecurity.getPasswordForUser(testData.user)) + .set(COMMON_HEADERS) + .send(testData.requestBody) + .expect(testData.expected.responseCode); + + expect(body).to.eql(testData.expected.responseBody); + }); + } + }); + + describe('with transient search.max_buckets setting', function() { + before(async () => { + await esSupertest + .put('/_cluster/settings') + .send({ transient: { 'search.max_buckets': 9000 } }) + .expect(200); + }); + + after(async () => { + await esSupertest + .put('/_cluster/settings') + .send({ transient: { 'search.max_buckets': null } }) + .expect(200); + }); + + const testData = testDataList[0]; + + it(`estimates the bucket span`, async () => { const { body } = await supertest .post('/api/ml/validate/estimate_bucket_span') .auth(testData.user, mlSecurity.getPasswordForUser(testData.user)) @@ -108,6 +140,35 @@ export default ({ getService }: FtrProviderContext) => { expect(body).to.eql(testData.expected.responseBody); }); - } + }); + + describe('with persistent search.max_buckets setting', function() { + before(async () => { + await esSupertest + .put('/_cluster/settings') + .send({ persistent: { 'search.max_buckets': 9000 } }) + .expect(200); + }); + + after(async () => { + await esSupertest + .put('/_cluster/settings') + .send({ persistent: { 'search.max_buckets': null } }) + .expect(200); + }); + + const testData = testDataList[0]; + + it(`estimates the bucket span`, async () => { + const { body } = await supertest + .post('/api/ml/validate/estimate_bucket_span') + .auth(testData.user, mlSecurity.getPasswordForUser(testData.user)) + .set(COMMON_HEADERS) + .send(testData.requestBody) + .expect(testData.expected.responseCode); + + expect(body).to.eql(testData.expected.responseBody); + }); + }); }); }; diff --git a/x-pack/test/functional/apps/machine_learning/anomaly_detection/saved_search_job.ts b/x-pack/test/functional/apps/machine_learning/anomaly_detection/saved_search_job.ts index 66b2f00009b18..a13cf3d61128e 100644 --- a/x-pack/test/functional/apps/machine_learning/anomaly_detection/saved_search_job.ts +++ b/x-pack/test/functional/apps/machine_learning/anomaly_detection/saved_search_job.ts @@ -271,8 +271,7 @@ export default function({ getService }: FtrProviderContext) { }, ]; - // test failures, see #59354 - describe.skip('saved search', function() { + describe('saved search', function() { this.tags(['smoke', 'mlqa']); before(async () => { await esArchiver.load('ml/farequote'); diff --git a/x-pack/test/functional/services/machine_learning/navigation.ts b/x-pack/test/functional/services/machine_learning/navigation.ts index 06ab99b3dcb9f..b0f993eab1a2b 100644 --- a/x-pack/test/functional/services/machine_learning/navigation.ts +++ b/x-pack/test/functional/services/machine_learning/navigation.ts @@ -17,7 +17,10 @@ export function MachineLearningNavigationProvider({ return { async navigateToMl() { - return await PageObjects.common.navigateToApp('ml'); + await retry.tryForTime(60 * 1000, async () => { + await PageObjects.common.navigateToApp('ml'); + await testSubjects.existOrFail('mlPageOverview', { timeout: 2000 }); + }); }, async assertTabsExist(tabTypeSubject: string, areaSubjects: string[]) {