Skip to content

Commit

Permalink
Merge branch 'master' into np-migration/searchprofiler
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine committed Oct 31, 2019
2 parents 10b0425 + faa48d5 commit 55d8446
Show file tree
Hide file tree
Showing 19 changed files with 728 additions and 198 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,10 @@ module.exports = {
'!src/core/server/*.test.mocks.ts',

'src/plugins/**/public/**/*',
'!src/plugins/**/public/index*',
'!src/plugins/**/public/index.{js,ts,tsx}',

'src/plugins/**/server/**/*',
'!src/plugins/**/server/index*',
'!src/plugins/**/server/index.{js,ts,tsx}',
],
allowSameFolder: true,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* eslint-disable */
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
},
],
},

{
// Check if dirs that start with 'index' work correctly.
code: 'import { X } from "./index_patterns"',
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: ['files/no_restricted_paths/(public|server)/**/*'],
from: [
'files/no_restricted_paths/server/**/*',
'!files/no_restricted_paths/server/index.{ts,tsx}',
],
allowSameFolder: true,
},
],
},
],
},
],

invalid: [
Expand Down Expand Up @@ -369,5 +390,34 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
},
],
},

{
// Don't use index*.
// It won't work with dirs that start with 'index'.
code: 'import { X } from "./index_patterns"',
filename: path.join(__dirname, './files/no_restricted_paths/server/b.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: ['files/no_restricted_paths/(public|server)/**/*'],
from: [
'files/no_restricted_paths/server/**/*',
'!files/no_restricted_paths/server/index*',
],
allowSameFolder: true,
},
],
},
],
errors: [
{
message: 'Unexpected path "./index_patterns" imported in restricted zone.',
line: 1,
column: 19,
},
],
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ interface NumberInputOptionProps<ParamName extends string> {
setValue: (paramName: ParamName, value: number | '') => void;
}

/**
* Do not use this component anymore.
* Please, use NumberInputOption in 'required_number_input.tsx'.
* It is required for compatibility with TS 3.7.0
* This should be removed in the future
*/
function NumberInputOption<ParamName extends string>({
disabled,
error,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React, { ReactNode, useCallback, ChangeEvent } from 'react';
import { EuiFormRow, EuiFieldNumber } from '@elastic/eui';
import { useValidation } from './utils';

interface NumberInputOptionProps<ParamName extends string> {
disabled?: boolean;
error?: ReactNode;
isInvalid?: boolean;
label?: React.ReactNode;
max?: number;
min?: number;
paramName: ParamName;
step?: number;
value: number | null;
'data-test-subj'?: string;
setValue(paramName: ParamName, value: number | null): void;
setValidity(paramName: ParamName, isValid: boolean): void;
}

/**
* Use only this component instead of NumberInputOption in 'number_input.tsx'.
* It is required for compatibility with TS 3.7.0
*
* @param {number} props.value Should be numeric only
*/
function NumberInputOption<ParamName extends string>({
disabled,
error,
isInvalid,
label,
max,
min,
paramName,
step,
value,
setValue,
setValidity,
'data-test-subj': dataTestSubj,
}: NumberInputOptionProps<ParamName>) {
const isValid = value !== null;
useValidation(setValidity, paramName, isValid);

const onChange = useCallback(
(ev: ChangeEvent<HTMLInputElement>) =>
setValue(paramName, isNaN(ev.target.valueAsNumber) ? null : ev.target.valueAsNumber),
[setValue, paramName]
);

return (
<EuiFormRow label={label} error={error} isInvalid={isInvalid} fullWidth compressed>
<EuiFieldNumber
compressed
fullWidth
required
data-test-subj={dataTestSubj}
disabled={disabled}
isInvalid={!isValid}
step={step}
max={max}
min={min}
value={value === null ? '' : value}
onChange={onChange}
/>
</EuiFormRow>
);
}

export { NumberInputOption };
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { useEffect } from 'react';

function useValidation<ParamName extends string>(
setValidity: (paramName: ParamName, isValid: boolean) => void,
paramName: ParamName,
isValid: boolean
) {
useEffect(() => {
setValidity(paramName, isValid);

return () => setValidity(paramName, true);
}, [isValid, paramName, setValidity]);
}

export { useValidation };
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ import { EuiPanel, EuiTitle, EuiSpacer } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { VisOptionsProps } from 'ui/vis/editors/default';
import { BasicOptions, SwitchOption } from '../../common';
import { BasicOptions, SwitchOption, ValidationVisOptionsProps } from '../../common';
import { GridPanel } from './grid_panel';
import { ThresholdPanel } from './threshold_panel';
import { BasicVislibParams } from '../../../types';

function PointSeriesOptions(props: VisOptionsProps<BasicVislibParams>) {
function PointSeriesOptions(props: ValidationVisOptionsProps<BasicVislibParams>) {
const { stateParams, setValue, vis } = props;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ import { EuiPanel, EuiTitle, EuiColorPicker, EuiFormRow, EuiSpacer } from '@elas
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { VisOptionsProps } from 'ui/vis/editors/default';
import { NumberInputOption, SelectOption, SwitchOption } from '../../common';
import { SelectOption, SwitchOption, ValidationVisOptionsProps } from '../../common';
import { NumberInputOption } from '../../common/required_number_input';
import { BasicVislibParams } from '../../../types';

function ThresholdPanel({ stateParams, setValue, vis }: VisOptionsProps<BasicVislibParams>) {
function ThresholdPanel({
stateParams,
setValue,
setMultipleValidity,
vis,
}: ValidationVisOptionsProps<BasicVislibParams>) {
const setThresholdLine = useCallback(
<T extends keyof BasicVislibParams['thresholdLine']>(
paramName: T,
Expand All @@ -39,6 +44,12 @@ function ThresholdPanel({ stateParams, setValue, vis }: VisOptionsProps<BasicVis
[setThresholdLine]
);

const setThresholdLineValidity = useCallback(
(paramName: keyof BasicVislibParams['thresholdLine'], isValid: boolean) =>
setMultipleValidity(`thresholdLine__${paramName}`, isValid),
[setMultipleValidity]
);

return (
<EuiPanel paddingSize="s">
<EuiTitle size="xs">
Expand Down Expand Up @@ -72,6 +83,7 @@ function ThresholdPanel({ stateParams, setValue, vis }: VisOptionsProps<BasicVis
paramName="value"
value={stateParams.thresholdLine.value}
setValue={setThresholdLine}
setValidity={setThresholdLineValidity}
/>

<NumberInputOption
Expand All @@ -86,6 +98,7 @@ function ThresholdPanel({ stateParams, setValue, vis }: VisOptionsProps<BasicVis
step={1}
value={stateParams.thresholdLine.width}
setValue={setThresholdLine}
setValidity={setThresholdLineValidity}
/>

<SelectOption
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/core_plugins/kbn_vislib_vis_types/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export interface Scale {

interface ThresholdLine {
show: boolean;
value: number;
width: number;
value: number | null;
width: number | null;
style: ThresholdLineStyles;
color: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ function getAreaOptionTabs() {
title: i18n.translate('kbnVislibVisTypes.area.tabs.panelSettingsTitle', {
defaultMessage: 'Panel settings',
}),
editor: PointSeriesOptions,
editor: (props: VisOptionsProps<BasicVislibParams>) => (
<ValidationWrapper {...props} component={PointSeriesOptions} />
),
},
];
}
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/ml/common/types/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ export interface DataRecognizerConfigResponse {
dashboard: KibanaObjectResponse;
};
}

export type JobOverride = Partial<Job>;
Loading

0 comments on commit 55d8446

Please sign in to comment.