Skip to content

Commit

Permalink
Merge branch 'master' into ilm/surfacing-policy-error-state
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Feb 2, 2021
2 parents 35471f0 + 3f97a04 commit 4097309
Show file tree
Hide file tree
Showing 132 changed files with 2,682 additions and 2,738 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { resolve } from 'path';
import execa from 'execa';
import expect from '@kbn/expect';
import shell from 'shelljs';

const ROOT_DIR = resolve(__dirname, '../../../../..');
Expand Down Expand Up @@ -38,11 +37,14 @@ describe('Team Assignment', () => {
describe(`when the codeowners file contains #CC#`, () => {
it(`should strip the prefix and still drill down through the fs`, async () => {
const { stdout } = await execa('grep', ['tre', teamAssignmentsPath], { cwd: ROOT_DIR });
expect(stdout).to.be(`x-pack/plugins/code/jest.config.js kibana-tre
x-pack/plugins/code/server/config.ts kibana-tre
x-pack/plugins/code/server/index.ts kibana-tre
x-pack/plugins/code/server/plugin.test.ts kibana-tre
x-pack/plugins/code/server/plugin.ts kibana-tre`);
const lines = stdout.split('\n').filter((line) => !line.includes('/target'));
expect(lines).toEqual([
'x-pack/plugins/code/jest.config.js kibana-tre',
'x-pack/plugins/code/server/config.ts kibana-tre',
'x-pack/plugins/code/server/index.ts kibana-tre',
'x-pack/plugins/code/server/plugin.test.ts kibana-tre',
'x-pack/plugins/code/server/plugin.ts kibana-tre',
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -287,4 +287,55 @@ describe('<UseField />', () => {
expect(formHook?.getFormData()).toEqual({ name: 'myName' });
});
});

describe('change handlers', () => {
const onError = jest.fn();

beforeEach(() => {
jest.resetAllMocks();
});

const getTestComp = (fieldConfig: FieldConfig) => {
const TestComp = () => {
const { form } = useForm<any>();

return (
<Form form={form}>
<UseField path="name" config={fieldConfig} data-test-subj="myField" onError={onError} />
</Form>
);
};
return TestComp;
};

const setup = (fieldConfig: FieldConfig) => {
return registerTestBed(getTestComp(fieldConfig), {
memoryRouter: { wrapComponent: false },
})() as TestBed;
};

it('calls onError when validation state changes', async () => {
const {
form: { setInputValue },
} = setup({
validations: [
{
validator: ({ value }) => (value === '1' ? undefined : { message: 'oops!' }),
},
],
});

expect(onError).toBeCalledTimes(0);
await act(async () => {
setInputValue('myField', '0');
});
expect(onError).toBeCalledTimes(1);
expect(onError).toBeCalledWith(['oops!']);
await act(async () => {
setInputValue('myField', '1');
});
expect(onError).toBeCalledTimes(2);
expect(onError).toBeCalledWith(null);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface Props<T, FormType = FormData, I = T> {
componentProps?: Record<string, any>;
readDefaultValueOnForm?: boolean;
onChange?: (value: I) => void;
onError?: (errors: string[] | null) => void;
children?: (field: FieldHook<T, I>) => JSX.Element | null;
[key: string]: any;
}
Expand All @@ -33,6 +34,7 @@ function UseFieldComp<T = unknown, FormType = FormData, I = T>(props: Props<T, F
componentProps,
readDefaultValueOnForm = true,
onChange,
onError,
children,
...rest
} = props;
Expand Down Expand Up @@ -62,7 +64,7 @@ function UseFieldComp<T = unknown, FormType = FormData, I = T>(props: Props<T, F
}
}

const field = useField<T, FormType, I>(form, path, fieldConfig, onChange);
const field = useField<T, FormType, I>(form, path, fieldConfig, onChange, onError);

// Children prevails over anything else provided.
if (children) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const useField = <T, FormType = FormData, I = T>(
form: FormHook<FormType>,
path: string,
config: FieldConfig<T, FormType, I> & InternalFieldConfig<T> = {},
valueChangeListener?: (value: I) => void
valueChangeListener?: (value: I) => void,
errorChangeListener?: (errors: string[] | null) => void
) => {
const {
type = FIELD_TYPES.TEXT,
Expand Down Expand Up @@ -596,6 +597,15 @@ export const useField = <T, FormType = FormData, I = T>(
};
}, [onValueChange]);

useEffect(() => {
if (!isMounted.current) {
return;
}
if (errorChangeListener) {
errorChangeListener(errors.length ? errors.map((error) => error.message) : null);
}
}, [errors, errorChangeListener]);

useEffect(() => {
isMounted.current = true;

Expand Down
23 changes: 23 additions & 0 deletions src/plugins/kibana_overview/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"composite": true,
"outDir": "./target/types",
"emitDeclarationOnly": true,
"declaration": true,
"declarationMap": true
},
"include": [
"public/**/*",
"common/**/*",
],
"references": [
{ "path": "../../core/tsconfig.json" },
{ "path": "../../plugins/navigation/tsconfig.json" },
{ "path": "../../plugins/data/tsconfig.json" },
{ "path": "../../plugins/home/tsconfig.json" },
{ "path": "../../plugins/newsfeed/tsconfig.json" },
{ "path": "../../plugins/usage_collection/tsconfig.json" },
{ "path": "../../plugins/kibana_react/tsconfig.json" },
]
}
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
{ "path": "../src/plugins/expressions/tsconfig.json" },
{ "path": "../src/plugins/home/tsconfig.json" },
{ "path": "../src/plugins/inspector/tsconfig.json" },
{ "path": "../src/plugins/kibana_overview/tsconfig.json" },
{ "path": "../src/plugins/kibana_react/tsconfig.json" },
{ "path": "../src/plugins/kibana_usage_collection/tsconfig.json" },
{ "path": "../src/plugins/kibana_utils/tsconfig.json" },
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"src/plugins/input_control_vis/**/*",
"src/plugins/inspector/**/*",
"src/plugins/kibana_legacy/**/*",
"src/plugins/kibana_overview/**/*",
"src/plugins/kibana_react/**/*",
"src/plugins/kibana_usage_collection/**/*",
"src/plugins/kibana_utils/**/*",
Expand Down Expand Up @@ -84,6 +85,7 @@
{ "path": "./src/plugins/home/tsconfig.json" },
{ "path": "./src/plugins/inspector/tsconfig.json" },
{ "path": "./src/plugins/kibana_legacy/tsconfig.json" },
{ "path": "./src/plugins/kibana_overview/tsconfig.json" },
{ "path": "./src/plugins/kibana_react/tsconfig.json" },
{ "path": "./src/plugins/kibana_usage_collection/tsconfig.json" },
{ "path": "./src/plugins/kibana_utils/tsconfig.json" },
Expand Down
1 change: 1 addition & 0 deletions tsconfig.refs.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{ "path": "./src/plugins/home/tsconfig.json" },
{ "path": "./src/plugins/inspector/tsconfig.json" },
{ "path": "./src/plugins/kibana_legacy/tsconfig.json" },
{ "path": "./src/plugins/kibana_overview/tsconfig.json" },
{ "path": "./src/plugins/kibana_react/tsconfig.json" },
{ "path": "./src/plugins/kibana_usage_collection/tsconfig.json" },
{ "path": "./src/plugins/kibana_utils/tsconfig.json" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export function AnomalyDetectionSetupLink() {
export function MissingJobsAlert({ environment }: { environment?: string }) {
const { data = DEFAULT_DATA, status } = useFetcher(
(callApmApi) =>
callApmApi({ endpoint: `GET /api/apm/settings/anomaly-detection/jobs` }),
callApmApi({
endpoint: `GET /api/apm/settings/anomaly-detection/jobs`,
}),
[],
{ preservePreviousData: false, showToastOnError: false }
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { asInteger } from '../../../../common/utils/formatters';
import { useUrlParams } from '../../../context/url_params_context/use_url_params';
import { useEnvironmentsFetcher } from '../../../hooks/use_environments_fetcher';
import { useFetcher } from '../../../hooks/use_fetcher';
import { callApmApi } from '../../../services/rest/createCallApmApi';
import { ChartPreview } from '../chart_preview';
import { EnvironmentField, IsAboveField, ServiceField } from '../fields';
import { getAbsoluteTimeRange } from '../helper';
Expand Down Expand Up @@ -46,20 +45,23 @@ export function ErrorCountAlertTrigger(props: Props) {

const { threshold, windowSize, windowUnit, environment } = alertParams;

const { data } = useFetcher(() => {
if (windowSize && windowUnit) {
return callApmApi({
endpoint: 'GET /api/apm/alerts/chart_preview/transaction_error_count',
params: {
query: {
...getAbsoluteTimeRange(windowSize, windowUnit),
environment,
serviceName,
const { data } = useFetcher(
(callApmApi) => {
if (windowSize && windowUnit) {
return callApmApi({
endpoint: 'GET /api/apm/alerts/chart_preview/transaction_error_count',
params: {
query: {
...getAbsoluteTimeRange(windowSize, windowUnit),
environment,
serviceName,
},
},
},
});
}
}, [windowSize, windowUnit, environment, serviceName]);
});
}
},
[windowSize, windowUnit, environment, serviceName]
);

const defaults = {
threshold: 25,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import { i18n } from '@kbn/i18n';
import { map } from 'lodash';
import React from 'react';
import { useParams } from 'react-router-dom';
import { useFetcher } from '../../../../../observability/public';
import { ForLastExpression } from '../../../../../triggers_actions_ui/public';
import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values';
import { getDurationFormatter } from '../../../../common/utils/formatters';
import { TimeSeries } from '../../../../typings/timeseries';
import { useApmServiceContext } from '../../../context/apm_service/use_apm_service_context';
import { useUrlParams } from '../../../context/url_params_context/use_url_params';
import { useEnvironmentsFetcher } from '../../../hooks/use_environments_fetcher';
import { callApmApi } from '../../../services/rest/createCallApmApi';
import { useFetcher } from '../../../hooks/use_fetcher';
import {
getMaxY,
getResponseTimeTickFormatter,
Expand Down Expand Up @@ -88,29 +87,32 @@ export function TransactionDurationAlertTrigger(props: Props) {
windowUnit,
} = alertParams;

const { data } = useFetcher(() => {
if (windowSize && windowUnit) {
return callApmApi({
endpoint: 'GET /api/apm/alerts/chart_preview/transaction_duration',
params: {
query: {
...getAbsoluteTimeRange(windowSize, windowUnit),
aggregationType,
environment,
serviceName,
transactionType: alertParams.transactionType,
const { data } = useFetcher(
(callApmApi) => {
if (windowSize && windowUnit) {
return callApmApi({
endpoint: 'GET /api/apm/alerts/chart_preview/transaction_duration',
params: {
query: {
...getAbsoluteTimeRange(windowSize, windowUnit),
aggregationType,
environment,
serviceName,
transactionType: alertParams.transactionType,
},
},
},
});
}
}, [
aggregationType,
environment,
serviceName,
alertParams.transactionType,
windowSize,
windowUnit,
]);
});
}
},
[
aggregationType,
environment,
serviceName,
alertParams.transactionType,
windowSize,
windowUnit,
]
);

const maxY = getMaxY([
{ data: data ?? [] } as TimeSeries<{ x: number; y: number | null }>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { useApmServiceContext } from '../../../context/apm_service/use_apm_servi
import { useUrlParams } from '../../../context/url_params_context/use_url_params';
import { useEnvironmentsFetcher } from '../../../hooks/use_environments_fetcher';
import { useFetcher } from '../../../hooks/use_fetcher';
import { callApmApi } from '../../../services/rest/createCallApmApi';
import { ChartPreview } from '../chart_preview';
import {
EnvironmentField,
Expand Down Expand Up @@ -54,27 +53,30 @@ export function TransactionErrorRateAlertTrigger(props: Props) {

const thresholdAsPercent = (threshold ?? 0) / 100;

const { data } = useFetcher(() => {
if (windowSize && windowUnit) {
return callApmApi({
endpoint: 'GET /api/apm/alerts/chart_preview/transaction_error_rate',
params: {
query: {
...getAbsoluteTimeRange(windowSize, windowUnit),
environment,
serviceName,
transactionType: alertParams.transactionType,
const { data } = useFetcher(
(callApmApi) => {
if (windowSize && windowUnit) {
return callApmApi({
endpoint: 'GET /api/apm/alerts/chart_preview/transaction_error_rate',
params: {
query: {
...getAbsoluteTimeRange(windowSize, windowUnit),
environment,
serviceName,
transactionType: alertParams.transactionType,
},
},
},
});
}
}, [
alertParams.transactionType,
environment,
serviceName,
windowSize,
windowUnit,
]);
});
}
},
[
alertParams.transactionType,
environment,
serviceName,
windowSize,
windowUnit,
]
);

if (serviceName && !transactionTypes.length) {
return null;
Expand Down
Loading

0 comments on commit 4097309

Please sign in to comment.