Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into task/EMT141-Polic…
Browse files Browse the repository at this point in the history
…y-UI-Route
  • Loading branch information
paul-tavares committed Feb 14, 2020
2 parents 546a193 + c965a9e commit b14f88a
Show file tree
Hide file tree
Showing 76 changed files with 1,523 additions and 2,276 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export function findKibanaPlatformPlugins(scanDirs: string[], paths: string[]) {
absolute: true,
}
)
.map(path => readKibanaPlatformPlugin(path));
.map(path =>
// absolute paths returned from globby are using normalize or something so the path separators are `/` even on windows, Path.resolve solves this
readKibanaPlatformPlugin(Path.resolve(path))
);
}

function readKibanaPlatformPlugin(manifestPath: string): KibanaPlatformPlugin {
Expand Down
49 changes: 21 additions & 28 deletions packages/kbn-optimizer/src/worker/run_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

import * as Rx from 'rxjs';
import { mergeMap } from 'rxjs/operators';

import { parseBundles, parseWorkerConfig, WorkerMsg, isWorkerMsg, WorkerMsgs } from '../common';

Expand Down Expand Up @@ -75,33 +74,27 @@ setInterval(() => {
}, 1000).unref();

Rx.defer(() => {
return Rx.of({
workerConfig: parseWorkerConfig(process.argv[2]),
bundles: parseBundles(process.argv[3]),
});
})
.pipe(
mergeMap(({ workerConfig, bundles }) => {
// set BROWSERSLIST_ENV so that style/babel loaders see it before running compilers
process.env.BROWSERSLIST_ENV = workerConfig.browserslistEnv;
const workerConfig = parseWorkerConfig(process.argv[2]);
const bundles = parseBundles(process.argv[3]);

return runCompilers(workerConfig, bundles);
})
)
.subscribe(
msg => {
send(msg);
},
error => {
if (isWorkerMsg(error)) {
send(error);
} else {
send(workerMsgs.error(error));
}
// set BROWSERSLIST_ENV so that style/babel loaders see it before running compilers
process.env.BROWSERSLIST_ENV = workerConfig.browserslistEnv;

exit(1);
},
() => {
exit(0);
return runCompilers(workerConfig, bundles);
}).subscribe(
msg => {
send(msg);
},
error => {
if (isWorkerMsg(error)) {
send(error);
} else {
send(workerMsgs.error(error));
}
);

exit(1);
},
() => {
exit(0);
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ class TimeseriesChartIntl extends Component {
this.renderFocusChart();
}

componentDidUpdate() {
if (this.props.renderFocusChartOnly === false) {
componentDidUpdate(prevProps) {
if (this.props.renderFocusChartOnly === false || prevProps.svgWidth !== this.props.svgWidth) {
this.renderChart();
this.drawContextChartSelection();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import * as i18n from './translations';
import { MatrixHistogramOption, MatrixHisrogramConfigs } from '../matrix_histogram/types';
import { HistogramType } from '../../graphql/types';

export const alertsStackByOptions: MatrixHistogramOption[] = [
{
text: 'event.category',
value: 'event.category',
},
{
text: 'event.module',
value: 'event.module',
},
];

const DEFAULT_STACK_BY = 'event.module';

export const histogramConfigs: MatrixHisrogramConfigs = {
defaultStackByOption:
alertsStackByOptions.find(o => o.text === DEFAULT_STACK_BY) ?? alertsStackByOptions[1],
errorMessage: i18n.ERROR_FETCHING_ALERTS_DATA,
histogramType: HistogramType.alerts,
stackByOptions: alertsStackByOptions,
subtitle: undefined,
title: i18n.ALERTS_GRAPH_TITLE,
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,62 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { noop } from 'lodash/fp';
import React, { useEffect, useCallback } from 'react';
import React, { useEffect, useCallback, useMemo } from 'react';
import numeral from '@elastic/numeral';

import { AlertsComponentsQueryProps } from './types';
import { AlertsTable } from './alerts_table';
import * as i18n from './translations';
import { MatrixHistogramOption } from '../matrix_histogram/types';
import { MatrixHistogramContainer } from '../../containers/matrix_histogram';
import { MatrixHistogramGqlQuery } from '../../containers/matrix_histogram/index.gql_query';
import { useUiSetting$ } from '../../lib/kibana';
import { DEFAULT_NUMBER_FORMAT } from '../../../common/constants';
import { MatrixHistogramContainer } from '../matrix_histogram';
import { histogramConfigs } from './histogram_configs';
import { MatrixHisrogramConfigs } from '../matrix_histogram/types';
const ID = 'alertsOverTimeQuery';
export const alertsStackByOptions: MatrixHistogramOption[] = [
{
text: 'event.category',
value: 'event.category',
},
{
text: 'event.module',
value: 'event.module',
},
];
const dataKey = 'AlertsHistogram';

export const AlertsView = ({
deleteQuery,
endDate,
filterQuery,
pageFilters,
setQuery,
skip,
startDate,
type,
updateDateRange = noop,
}: AlertsComponentsQueryProps) => {
const [defaultNumberFormat] = useUiSetting$<string>(DEFAULT_NUMBER_FORMAT);

useEffect(() => {
return () => {
if (deleteQuery) {
deleteQuery({ id: ID });
}
};
}, []);

const getSubtitle = useCallback(
(totalCount: number) =>
`${i18n.SHOWING}: ${numeral(totalCount).format(defaultNumberFormat)} ${i18n.UNIT(
totalCount
)}`,
[]
);
const alertsHistogramConfigs: MatrixHisrogramConfigs = useMemo(
() => ({
...histogramConfigs,
subtitle: getSubtitle,
}),
[getSubtitle]
);
useEffect(() => {
return () => {
if (deleteQuery) {
deleteQuery({ id: ID });
}
};
}, [deleteQuery]);

return (
<>
<MatrixHistogramContainer
dataKey={dataKey}
defaultStackByOption={alertsStackByOptions[1]}
endDate={endDate}
errorMessage={i18n.ERROR_FETCHING_ALERTS_DATA}
filterQuery={filterQuery}
id={ID}
isAlertsHistogram={true}
query={MatrixHistogramGqlQuery}
setQuery={setQuery}
skip={skip}
sourceId="default"
stackByOptions={alertsStackByOptions}
startDate={startDate}
subtitle={getSubtitle}
title={i18n.ALERTS_GRAPH_TITLE}
type={type}
updateDateRange={updateDateRange}
{...alertsHistogramConfigs}
/>
<AlertsTable endDate={endDate} startDate={startDate} pageFilters={pageFilters} />
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ type CommonQueryProps = HostsComponentsQueryProps | NetworkComponentQueryProps;
export interface AlertsComponentsQueryProps
extends Pick<
CommonQueryProps,
| 'deleteQuery'
| 'endDate'
| 'filterQuery'
| 'skip'
| 'setQuery'
| 'startDate'
| 'type'
| 'updateDateRange'
'deleteQuery' | 'endDate' | 'filterQuery' | 'skip' | 'setQuery' | 'startDate' | 'type'
> {
pageFilters: Filter[];
stackByOptions?: MatrixHistogramOption[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const chartDefaultRendering: Rendering = 'canvas';
export type UpdateDateRange = (min: number, max: number) => void;

export interface ChartData {
x: number | string | null;
y: number | string | null;
x?: number | string | null;
y?: number | string | null;
y0?: number;
g?: number | string;
g?: number | string | null;
}

export interface ChartSeriesConfigs {
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@

/* eslint-disable react/display-name */

import { shallow } from 'enzyme';
import { mount, ReactWrapper } from 'enzyme';
import React from 'react';

import { MatrixHistogram } from '.';
import { MatrixHistogramGqlQuery as mockQuery } from '../../containers/matrix_histogram/index.gql_query';

import { useQuery } from '../../containers/matrix_histogram';
import { HistogramType } from '../../graphql/types';
jest.mock('../../lib/kibana');

jest.mock('../loader', () => {
jest.mock('./matrix_loader', () => {
return {
Loader: () => <div className="loader" />,
MatrixLoader: () => {
return <div className="matrixLoader" />;
},
};
});

Expand All @@ -32,17 +34,31 @@ jest.mock('../charts/barchart', () => {
};
});

jest.mock('../../containers/matrix_histogram', () => {
return {
useQuery: jest.fn(),
};
});

jest.mock('../../components/matrix_histogram/utils', () => {
return {
getBarchartConfigs: jest.fn(),
getCustomChartData: jest.fn().mockReturnValue(true),
};
});

describe('Matrix Histogram Component', () => {
let wrapper: ReactWrapper;

const mockMatrixOverTimeHistogramProps = {
dataKey: 'mockDataKey',
defaultIndex: ['defaultIndex'],
defaultStackByOption: { text: 'text', value: 'value' },
endDate: new Date('2019-07-18T20:00:00.000Z').valueOf(),
errorMessage: 'error',
histogramType: HistogramType.alerts,
id: 'mockId',
isInspected: false,
isPtrIncluded: false,
query: mockQuery,
setQuery: jest.fn(),
skip: false,
sourceId: 'default',
Expand All @@ -52,36 +68,56 @@ describe('Matrix Histogram Component', () => {
subtitle: 'mockSubtitle',
totalCount: -1,
title: 'mockTitle',
updateDateRange: jest.fn(),
dispatchSetAbsoluteRangeDatePicker: jest.fn(),
};
describe('rendering', () => {
test('it renders EuiLoadingContent on initialLoad', () => {
const wrapper = shallow(<MatrixHistogram {...mockMatrixOverTimeHistogramProps} />);

expect(wrapper.find(`[data-test-subj="initialLoadingPanelMatrixOverTime"]`)).toBeTruthy();
beforeAll(() => {
(useQuery as jest.Mock).mockReturnValue({
data: null,
loading: false,
inspect: false,
totalCount: null,
});

test('it renders Loader while fetching data if visited before', () => {
const mockProps = {
...mockMatrixOverTimeHistogramProps,
data: [{ x: new Date('2019-09-16T02:20:00.000Z').valueOf(), y: 3787, g: 'config_change' }],
totalCount: 10,
loading: true,
};
const wrapper = shallow(<MatrixHistogram {...mockProps} />);
expect(wrapper.find('.loader')).toBeTruthy();
wrapper = mount(<MatrixHistogram {...mockMatrixOverTimeHistogramProps} />);
});
describe('on initial load', () => {
test('it renders MatrixLoader', () => {
expect(wrapper.html()).toMatchSnapshot();
expect(wrapper.find('MatrixLoader').exists()).toBe(true);
});
});

test('it renders BarChart if data available', () => {
const mockProps = {
...mockMatrixOverTimeHistogramProps,
data: [{ x: new Date('2019-09-16T02:20:00.000Z').valueOf(), y: 3787, g: 'config_change' }],
totalCount: 10,
describe('not initial load', () => {
beforeAll(() => {
(useQuery as jest.Mock).mockReturnValue({
data: [
{ x: 1, y: 2, g: 'g1' },
{ x: 2, y: 4, g: 'g1' },
{ x: 3, y: 6, g: 'g1' },
{ x: 1, y: 1, g: 'g2' },
{ x: 2, y: 3, g: 'g2' },
{ x: 3, y: 5, g: 'g2' },
],
loading: false,
};
const wrapper = shallow(<MatrixHistogram {...mockProps} />);
inspect: false,
totalCount: 1,
});
wrapper.setProps({ endDate: 100 });
wrapper.update();
});
test('it renders no MatrixLoader', () => {
expect(wrapper.html()).toMatchSnapshot();
expect(wrapper.find(`MatrixLoader`).exists()).toBe(false);
});

test('it shows BarChart if data available', () => {
expect(wrapper.find(`.barchart`).exists()).toBe(true);
});
});

expect(wrapper.find(`.barchart`)).toBeTruthy();
describe('select dropdown', () => {
test('should be hidden if only one option is provided', () => {
expect(wrapper.find('EuiSelect').exists()).toBe(false);
});
});
});
Loading

0 comments on commit b14f88a

Please sign in to comment.