Skip to content

Commit

Permalink
Merge branch 'master' into task-manager/decouple-store-from-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Oct 28, 2019
2 parents 4a3da73 + d010997 commit fb6d0de
Show file tree
Hide file tree
Showing 32 changed files with 1,294 additions and 831 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,16 +317,16 @@ export default function({
coreEditor: editor,
parser,
execCommand,
getCursor,
isCompleteActive,
getCursorPosition,
isCompleterActive,
addChangeListener,
removeChangeListener,
}: {
coreEditor: LegacyEditor;
parser: any;
execCommand: (cmd: string) => void;
getCursor: () => any;
isCompleteActive: () => boolean;
getCursorPosition: () => Position | null;
isCompleterActive: () => boolean;
addChangeListener: (fn: any) => void;
removeChangeListener: (fn: any) => void;
}) {
Expand Down Expand Up @@ -969,11 +969,10 @@ export default function({
100);

function editorChangeListener() {
const cursor = getCursor();
if (isCompleteActive()) {
return;
const position = getCursorPosition();
if (position && !isCompleterActive()) {
evaluateCurrentTokenAfterAChange(position);
}
evaluateCurrentTokenAfterAChange(cursor);
}

function getCompletions(
Expand Down
15 changes: 13 additions & 2 deletions src/legacy/core_plugins/console/public/quarantined/src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { LegacyEditor } from '../../../np_ready/public/application/models';

// @ts-ignore
import SenseEditor from './sense_editor/editor';
import { Position } from '../../../np_ready/public/types';

let input: any;
export function initializeEditor($el: JQuery<HTMLElement>, $actionsEl: JQuery<HTMLElement>) {
Expand All @@ -35,8 +36,18 @@ export function initializeEditor($el: JQuery<HTMLElement>, $actionsEl: JQuery<HT
coreEditor: new LegacyEditor(input),
parser: input.parser,
execCommand: (cmd: string) => input.execCommand(cmd),
getCursor: () => input.selection.lead,
isCompleteActive: () => input.__ace.completer && input.__ace.completer.activated,
getCursorPosition: (): Position | null => {
if (input.selection && input.selection.lead) {
return {
lineNumber: input.selection.lead.row + 1,
column: input.selection.lead.column + 1,
};
}
return null;
},
isCompleterActive: () => {
return Boolean(input.__ace.completer && input.__ace.completer.activated);
},
addChangeListener: (fn: any) => input.on('changeSelection', fn),
removeChangeListener: (fn: any) => input.off('changeSelection', fn),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,25 @@ interface ValidationWrapperProps<T> extends VisOptionsProps<T> {
}

interface Item {
valid: boolean;
isValid: boolean;
}

function ValidationWrapper<T = unknown>({
component: Component,
...rest
}: ValidationWrapperProps<T>) {
const [panelState, setPanelState] = useState({} as { [key: string]: Item });
const isPanelValid = Object.values(panelState).every(item => item.valid);
const isPanelValid = Object.values(panelState).every(item => item.isValid);
const { setValidity } = rest;

const setValidityHandler = useCallback(
(paramName: string, isValid: boolean) => {
setPanelState({
...panelState,
[paramName]: {
valid: isValid,
},
});
},
[panelState]
);
const setValidityHandler = useCallback((paramName: string, isValid: boolean) => {
setPanelState(state => ({
...state,
[paramName]: {
isValid,
},
}));
}, []);

useEffect(() => {
setValidity(isPanelValid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import React from 'react';
import { shallow } from 'enzyme';
import { shallow, mount } from 'enzyme';
import { CustomExtentsOptions, CustomExtentsOptionsProps } from './custom_extents_options';
import { YExtents } from './y_extents';
import { valueAxis } from './mocks';
Expand Down Expand Up @@ -55,23 +55,27 @@ describe('CustomExtentsOptions component', () => {

describe('boundsMargin', () => {
it('should set validity as true when value is positive', () => {
const comp = shallow(<CustomExtentsOptions {...defaultProps} />);
comp.find({ paramName: BOUNDS_MARGIN }).prop('setValue')(BOUNDS_MARGIN, 5);
defaultProps.axis.scale.boundsMargin = 5;
mount(<CustomExtentsOptions {...defaultProps} />);

expect(setMultipleValidity).toBeCalledWith(BOUNDS_MARGIN, true);
});

it('should set validity as true when value is empty', () => {
const comp = shallow(<CustomExtentsOptions {...defaultProps} />);
comp.find({ paramName: BOUNDS_MARGIN }).prop('setValue')(BOUNDS_MARGIN, '');
const comp = mount(<CustomExtentsOptions {...defaultProps} />);
comp.setProps({
axis: { ...valueAxis, scale: { ...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;
const comp = shallow(<CustomExtentsOptions {...defaultProps} />);
comp.find({ paramName: BOUNDS_MARGIN }).prop('setValue')(BOUNDS_MARGIN, -1);
const comp = mount(<CustomExtentsOptions {...defaultProps} />);
comp.setProps({
axis: { ...valueAxis, scale: { ...valueAxis.scale, boundsMargin: -1 } },
});

expect(setMultipleValidity).toBeCalledWith(BOUNDS_MARGIN, false);
});
Expand Down Expand Up @@ -103,7 +107,6 @@ describe('CustomExtentsOptions component', () => {
const comp = shallow(<CustomExtentsOptions {...defaultProps} />);
comp.find({ paramName: DEFAULT_Y_EXTENTS }).prop('setValue')(DEFAULT_Y_EXTENTS, false);

expect(setMultipleValidity).toBeCalledWith(BOUNDS_MARGIN, true);
const newScale = {
...defaultProps.axis.scale,
boundsMargin: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import React, { useState, useCallback } from 'react';
import React, { useCallback, useEffect } from 'react';
import { i18n } from '@kbn/i18n';

import { ValueAxis } from '../../../types';
Expand All @@ -38,29 +38,25 @@ function CustomExtentsOptions({
setValueAxis,
setValueAxisScale,
}: CustomExtentsOptionsProps) {
const [isBoundsMarginValid, setIsBoundsMarginValid] = useState(true);
const invalidBoundsMarginMessage = i18n.translate(
'kbnVislibVisTypes.controls.pointSeries.valueAxes.scaleToDataBounds.minNeededBoundsMargin',
{ defaultMessage: 'Bounds margin must be greater than or equal to 0.' }
);

const setBoundsMargin = useCallback(
(paramName: 'boundsMargin', value: number | '') => {
const isValid = value === '' ? true : value >= 0;
setIsBoundsMarginValid(isValid);
setMultipleValidity('boundsMargin', isValid);
const isBoundsMarginValid =
!axis.scale.defaultYExtents || !axis.scale.boundsMargin || axis.scale.boundsMargin >= 0;

setValueAxisScale(paramName, value);
},
[setMultipleValidity, setValueAxisScale]
const setBoundsMargin = useCallback(
(paramName: 'boundsMargin', value: number | '') =>
setValueAxisScale(paramName, value === '' ? undefined : value),
[setValueAxisScale]
);

const onDefaultYExtentsChange = useCallback(
(paramName: 'defaultYExtents', value: boolean) => {
const scale = { ...axis.scale, [paramName]: value };
if (!scale.defaultYExtents) {
delete scale.boundsMargin;
setMultipleValidity('boundsMargin', true);
}
setValueAxis('scale', scale);
},
Expand All @@ -79,6 +75,12 @@ function CustomExtentsOptions({
[setValueAxis, axis.scale]
);

useEffect(() => {
setMultipleValidity('boundsMargin', isBoundsMarginValid);

return () => setMultipleValidity('boundsMargin', true);
}, [isBoundsMarginValid, setMultipleValidity]);

return (
<>
<SwitchOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function YExtents({ scale, setScale, setMultipleValidity }: YExtentsProps) {
setMultipleValidity('yExtents', isValid);

return () => setMultipleValidity('yExtents', true);
}, [isValid]);
}, [isValid, setMultipleValidity]);

return (
<EuiFormRow error={errors} isInvalid={!!errors.length} fullWidth compressed>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fb6d0de

Please sign in to comment.