Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into 59630
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Mar 17, 2020
2 parents d4cd3d2 + 55003b6 commit fcc640c
Show file tree
Hide file tree
Showing 110 changed files with 2,425 additions and 3,235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/
import { uniq } from 'lodash';
import { stringify } from 'query-string';
import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition } from '../../expression_functions';
import { KibanaContext } from '../../expression_types';
Expand All @@ -37,17 +36,24 @@ export type ExpressionFunctionKibanaContext = ExpressionFunctionDefinition<
Promise<KibanaContext>
>;

export const mergeInput = <T = any>(object: T | T[] = [], other: string | T | T[]): T[] => {
const parsed: T | T[] = typeof other === 'string' ? JSON.parse(other || '[]') : other;
const mergeInput = <T = any>(
first: T | T[] = [],
second: string | T | T[],
iteratee: Function
): T[] => {
const parsed: T | T[] = typeof second === 'string' ? JSON.parse(second || '[]') : second;
return uniq<T>(
[
...(Array.isArray(parsed) ? parsed : [parsed]),
...(Array.isArray(object) ? object : [object]),
],
(n: any) => stringify(n)
[...(Array.isArray(parsed) ? parsed : [parsed]), ...(Array.isArray(first) ? first : [first])],
iteratee
);
};

const mergeQueries = (first: Query | Query[] = [], second: string | Query | Query[]) =>
mergeInput(first, second, (n: any) => JSON.stringify(n.query));

const mergeFilters = (first: Filter | Filter[] = [], second: string | Filter | Filter[]) =>
mergeInput(first, second, (n: any) => JSON.stringify(n.meta));

export const kibanaContextFunction: ExpressionFunctionKibanaContext = {
name: 'kibana_context',
type: 'kibana_context',
Expand Down Expand Up @@ -89,8 +95,8 @@ export const kibanaContextFunction: ExpressionFunctionKibanaContext = {

async fn(input, args, { getSavedObject }) {
const timeRange = args.timeRange ? JSON.parse(args.timeRange) : input?.timeRange;
let queries = mergeInput<Query>(input?.query, args?.q || '[]');
let filters = mergeInput<Filter>(input?.filters, args?.filters || '[]');
let queries = mergeQueries(input?.query, args?.q || '[]');
let filters = mergeFilters(input?.filters, args?.filters || '[]');

if (args.savedSearchId) {
if (typeof getSavedObject !== 'function') {
Expand All @@ -104,8 +110,8 @@ export const kibanaContextFunction: ExpressionFunctionKibanaContext = {
const search = obj.attributes.kibanaSavedObjectMeta as { searchSourceJSON: string };
const data = JSON.parse(search.searchSourceJSON) as { query: Query[]; filter: Filter[] };

queries = mergeInput(queries, data.query);
filters = mergeInput(filters, data.filter);
queries = mergeQueries(queries, data.query);
filters = mergeFilters(filters, data.filter);
}

return {
Expand Down
12 changes: 12 additions & 0 deletions src/setup_node_env/exit_on_warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ if (process.noProcessWarnings !== true) {

process.exit(1);
});

// While the above warning listener would also be called on
// unhandledRejection warnings, we can give a better error message if we
// handle them separately:
process.on('unhandledRejection', function(reason) {
console.error('Unhandled Promise rejection detected:');
console.error();
console.error(reason);
console.error();
console.error('Terminating process...');
process.exit(1);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('timeline data providers', () => {
.first()
.invoke('text')
.should(hostname => {
expect(dataProviderText).to.eq(`host.name: "${hostname}"`);
expect(dataProviderText).to.eq(hostname);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { TIMELINE_FLYOUT_BODY, TIMELINE_NOT_READY_TO_DROP_BUTTON } from '../screens/timeline';
import { TIMELINE_FLYOUT_HEADER, TIMELINE_NOT_READY_TO_DROP_BUTTON } from '../screens/timeline';

import { dragFirstHostToTimeline, waitForAllHostsToBeLoaded } from '../tasks/hosts/all_hosts';
import { loginAndWaitForPage } from '../tasks/login';
Expand All @@ -26,7 +26,7 @@ describe('timeline flyout button', () => {

it('toggles open the timeline', () => {
openTimeline();
cy.get(TIMELINE_FLYOUT_BODY).should('have.css', 'visibility', 'visible');
cy.get(TIMELINE_FLYOUT_HEADER).should('have.css', 'visibility', 'visible');
});

it('sets the flyout button background to euiColorSuccess with a 10% alpha channel when the user starts dragging a host, but is not hovering over the flyout button', () => {
Expand Down
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/screens/timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export const TIMELINE_DROPPED_DATA_PROVIDERS = '[data-test-subj="providerContain
export const TIMELINE_FIELDS_BUTTON =
'[data-test-subj="timeline"] [data-test-subj="show-field-browser"]';

export const TIMELINE_FLYOUT_HEADER = '[data-test-subj="eui-flyout-header"]';

export const TIMELINE_FLYOUT_BODY = '[data-test-subj="eui-flyout-body"]';

export const TIMELINE_INSPECT_BUTTON = '[data-test-subj="inspect-empty-button"]';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/siem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@types/lodash": "^4.14.110",
"@types/js-yaml": "^3.12.1",
"@types/react-beautiful-dnd": "^11.0.4"
"@types/react-beautiful-dnd": "^12.1.1"
},
"dependencies": {
"lodash": "^4.17.15",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
RecursivePartial,
} from '@elastic/charts';
import { getOr, get, isNull, isNumber } from 'lodash/fp';
import useResizeObserver from 'use-resize-observer/polyfilled';

import { useThrottledResizeObserver } from '../utils';
import { ChartPlaceHolder } from './chart_place_holder';
import { useTimeZone } from '../../lib/kibana';
import {
Expand Down Expand Up @@ -131,7 +131,7 @@ interface AreaChartComponentProps {
}

export const AreaChartComponent: React.FC<AreaChartComponentProps> = ({ areaChart, configs }) => {
const { ref: measureRef, width, height } = useResizeObserver<HTMLDivElement>({});
const { ref: measureRef, width, height } = useThrottledResizeObserver();
const customHeight = get('customHeight', configs);
const customWidth = get('customWidth', configs);
const chartHeight = getChartHeight(customHeight, height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import React from 'react';
import { Chart, BarSeries, Axis, Position, ScaleType, Settings } from '@elastic/charts';
import { getOr, get, isNumber } from 'lodash/fp';
import deepmerge from 'deepmerge';
import useResizeObserver from 'use-resize-observer/polyfilled';

import { useThrottledResizeObserver } from '../utils';
import { useTimeZone } from '../../lib/kibana';
import { ChartPlaceHolder } from './chart_place_holder';
import {
Expand Down Expand Up @@ -105,7 +105,7 @@ interface BarChartComponentProps {
}

export const BarChartComponent: React.FC<BarChartComponentProps> = ({ barChart, configs }) => {
const { ref: measureRef, width, height } = useResizeObserver<HTMLDivElement>({});
const { ref: measureRef, width, height } = useThrottledResizeObserver();
const customHeight = get('customHeight', configs);
const customWidth = get('customWidth', configs);
const chartHeight = getChartHeight(customHeight, height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { defaultTo, noop } from 'lodash/fp';
import { noop } from 'lodash/fp';
import React, { useCallback } from 'react';
import { DropResult, DragDropContext } from 'react-beautiful-dnd';
import { connect, ConnectedProps } from 'react-redux';
Expand Down Expand Up @@ -103,10 +103,7 @@ DragDropContextWrapperComponent.displayName = 'DragDropContextWrapperComponent';
const emptyDataProviders: dragAndDropModel.IdToDataProvider = {}; // stable reference

const mapStateToProps = (state: State) => {
const dataProviders = defaultTo(
emptyDataProviders,
dragAndDropSelectors.dataProvidersSelector(state)
);
const dataProviders = dragAndDropSelectors.dataProvidersSelector(state) ?? emptyDataProviders;

return { dataProviders };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,21 +88,9 @@ describe('DraggableWrapper', () => {
describe('ConditionalPortal', () => {
const mount = useMountAppended();
const props = {
usePortal: false,
registerProvider: jest.fn(),
isDragging: true,
};

it(`doesn't call registerProvider is NOT isDragging`, () => {
mount(
<ConditionalPortal {...props} isDragging={false}>
<div />
</ConditionalPortal>
);

expect(props.registerProvider.mock.calls.length).toEqual(0);
});

it('calls registerProvider when isDragging', () => {
mount(
<ConditionalPortal {...props}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { createContext, useCallback, useContext, useEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import {
Draggable,
DraggableProvided,
Expand All @@ -15,7 +15,6 @@ import { useDispatch } from 'react-redux';
import styled from 'styled-components';
import deepEqual from 'fast-deep-equal';

import { EuiPortal } from '@elastic/eui';
import { dragAndDropActions } from '../../store/drag_and_drop';
import { DataProvider } from '../timeline/data_providers/data_provider';
import { TruncatableText } from '../truncatable_text';
Expand All @@ -27,9 +26,6 @@ export const DragEffects = styled.div``;

DragEffects.displayName = 'DragEffects';

export const DraggablePortalContext = createContext<boolean>(false);
export const useDraggablePortalContext = () => useContext(DraggablePortalContext);

/**
* Wraps the `react-beautiful-dnd` error boundary. See also:
* https://github.com/atlassian/react-beautiful-dnd/blob/v12.0.0/docs/guides/setup-problem-detection-and-error-recovery.md
Expand Down Expand Up @@ -89,7 +85,6 @@ export const DraggableWrapper = React.memo<Props>(
({ dataProvider, render, truncate }) => {
const [providerRegistered, setProviderRegistered] = useState(false);
const dispatch = useDispatch();
const usePortal = useDraggablePortalContext();

const registerProvider = useCallback(() => {
if (!providerRegistered) {
Expand All @@ -113,7 +108,26 @@ export const DraggableWrapper = React.memo<Props>(
return (
<Wrapper data-test-subj="draggableWrapperDiv">
<DragDropErrorBoundary>
<Droppable isDropDisabled={true} droppableId={getDroppableId(dataProvider.id)}>
<Droppable
isDropDisabled={true}
droppableId={getDroppableId(dataProvider.id)}
renderClone={(provided, snapshot) => (
<ConditionalPortal registerProvider={registerProvider}>
<div
{...provided.draggableProps}
{...provided.dragHandleProps}
ref={provided.innerRef}
data-test-subj="providerContainer"
>
<ProviderContentWrapper
data-test-subj={`draggable-content-${dataProvider.queryMatch.field}`}
>
{render(dataProvider, provided, snapshot)}
</ProviderContentWrapper>
</div>
</ConditionalPortal>
)}
>
{droppableProvided => (
<div ref={droppableProvided.innerRef} {...droppableProvided.droppableProps}>
<Draggable
Expand All @@ -122,35 +136,26 @@ export const DraggableWrapper = React.memo<Props>(
key={getDraggableId(dataProvider.id)}
>
{(provided, snapshot) => (
<ConditionalPortal
<ProviderContainer
{...provided.draggableProps}
{...provided.dragHandleProps}
ref={provided.innerRef}
data-test-subj="providerContainer"
isDragging={snapshot.isDragging}
registerProvider={registerProvider}
usePortal={snapshot.isDragging && usePortal}
>
<ProviderContainer
{...provided.draggableProps}
{...provided.dragHandleProps}
ref={provided.innerRef}
data-test-subj="providerContainer"
isDragging={snapshot.isDragging}
registerProvider={registerProvider}
style={{
...provided.draggableProps.style,
}}
>
{truncate && !snapshot.isDragging ? (
<TruncatableText data-test-subj="draggable-truncatable-content">
{render(dataProvider, provided, snapshot)}
</TruncatableText>
) : (
<ProviderContentWrapper
data-test-subj={`draggable-content-${dataProvider.queryMatch.field}`}
>
{render(dataProvider, provided, snapshot)}
</ProviderContentWrapper>
)}
</ProviderContainer>
</ConditionalPortal>
{truncate && !snapshot.isDragging ? (
<TruncatableText data-test-subj="draggable-truncatable-content">
{render(dataProvider, provided, snapshot)}
</TruncatableText>
) : (
<ProviderContentWrapper
data-test-subj={`draggable-content-${dataProvider.queryMatch.field}`}
>
{render(dataProvider, provided, snapshot)}
</ProviderContentWrapper>
)}
</ProviderContainer>
)}
</Draggable>
{droppableProvided.placeholder}
Expand Down Expand Up @@ -178,20 +183,16 @@ DraggableWrapper.displayName = 'DraggableWrapper';

interface ConditionalPortalProps {
children: React.ReactNode;
usePortal: boolean;
isDragging: boolean;
registerProvider: () => void;
}

export const ConditionalPortal = React.memo<ConditionalPortalProps>(
({ children, usePortal, registerProvider, isDragging }) => {
({ children, registerProvider }) => {
useEffect(() => {
if (isDragging) {
registerProvider();
}
}, [isDragging, registerProvider]);
registerProvider();
}, [registerProvider]);

return usePortal ? <EuiPortal>{children}</EuiPortal> : <>{children}</>;
return <>{children}</>;
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { rgba } from 'polished';
import React from 'react';
import { Droppable } from 'react-beautiful-dnd';
import { Droppable, DraggableChildrenFn } from 'react-beautiful-dnd';
import styled from 'styled-components';

interface Props {
Expand All @@ -16,6 +16,7 @@ interface Props {
isDropDisabled?: boolean;
type?: string;
render?: ({ isDraggingOver }: { isDraggingOver: boolean }) => React.ReactNode;
renderClone?: DraggableChildrenFn;
}

const ReactDndDropTarget = styled.div<{ isDraggingOver: boolean; height: string }>`
Expand Down Expand Up @@ -94,12 +95,14 @@ export const DroppableWrapper = React.memo<Props>(
isDropDisabled = false,
type,
render = null,
renderClone,
}) => (
<Droppable
isDropDisabled={isDropDisabled}
droppableId={droppableId}
direction={'horizontal'}
type={type}
renderClone={renderClone}
>
{(provided, snapshot) => (
<ReactDndDropTarget
Expand Down
Loading

0 comments on commit fcc640c

Please sign in to comment.