Skip to content

Commit

Permalink
Merge branch 'master' into fix/cannot-set-boolean-value-for-boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Jan 16, 2020
2 parents c44ee7b + 8a07023 commit 500227e
Show file tree
Hide file tree
Showing 38 changed files with 1,188 additions and 649 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,32 @@ import {
TIMELINE_DROPPED_DATA_PROVIDERS,
TIMELINE_DATA_PROVIDERS_EMPTY,
} from '../../lib/timeline/selectors';
import { dragFromAllHostsToTimeline, toggleTimelineVisibility } from '../../lib/timeline/helpers';
import {
createNewTimeline,
dragFromAllHostsToTimeline,
toggleTimelineVisibility,
} from '../../lib/timeline/helpers';
import { ALL_HOSTS_WIDGET_DRAGGABLE_HOSTS } from '../../lib/hosts/selectors';
import { HOSTS_PAGE } from '../../lib/urls';
import { waitForAllHostsWidget } from '../../lib/hosts/helpers';
import { DEFAULT_TIMEOUT, loginAndWaitForPage } from '../../lib/util/helpers';
import { drag, dragWithoutDrop } from '../../lib/drag_n_drop/helpers';

describe('timeline data providers', () => {
beforeEach(() => {
before(() => {
loginAndWaitForPage(HOSTS_PAGE);
});

it('renders the data provider of a host dragged from the All Hosts widget on the hosts page', () => {
waitForAllHostsWidget();
});

beforeEach(() => {
toggleTimelineVisibility();
});

afterEach(() => {
createNewTimeline();
});

it('renders the data provider of a host dragged from the All Hosts widget on the hosts page', () => {
dragFromAllHostsToTimeline();

cy.get(TIMELINE_DROPPED_DATA_PROVIDERS, {
Expand All @@ -45,10 +54,6 @@ describe('timeline data providers', () => {
});

it('sets the background to euiColorSuccess with a 10% alpha channel when the user starts dragging a host, but is not hovering over the data providers', () => {
waitForAllHostsWidget();

toggleTimelineVisibility();

cy.get(ALL_HOSTS_WIDGET_DRAGGABLE_HOSTS)
.first()
.then(host => drag(host));
Expand All @@ -61,10 +66,6 @@ describe('timeline data providers', () => {
});

it('sets the background to euiColorSuccess with a 20% alpha channel when the user starts dragging a host AND is hovering over the data providers', () => {
waitForAllHostsWidget();

toggleTimelineVisibility();

cy.get(ALL_HOSTS_WIDGET_DRAGGABLE_HOSTS)
.first()
.then(host => drag(host));
Expand All @@ -81,10 +82,6 @@ describe('timeline data providers', () => {
});

it('renders the dashed border color as euiColorSuccess when hovering over the data providers', () => {
waitForAllHostsWidget();

toggleTimelineVisibility();

cy.get(ALL_HOSTS_WIDGET_DRAGGABLE_HOSTS)
.first()
.then(host => drag(host));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@

import { drag, drop } from '../../lib/drag_n_drop/helpers';
import { populateTimeline } from '../../lib/fields_browser/helpers';
import { toggleFirstTimelineEventDetails } from '../../lib/timeline/helpers';
import { createNewTimeline, toggleFirstTimelineEventDetails } from '../../lib/timeline/helpers';
import { HOSTS_PAGE } from '../../lib/urls';
import { loginAndWaitForPage, DEFAULT_TIMEOUT } from '../../lib/util/helpers';

describe('toggle column in timeline', () => {
beforeEach(() => {
before(() => {
loginAndWaitForPage(HOSTS_PAGE);
});

afterEach(() => {
createNewTimeline();
});

const timestampField = '@timestamp';
const idField = '_id';

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, { useState, useEffect, useCallback, useMemo } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import { ScaleType } from '@elastic/charts';

import darkTheme from '@elastic/eui/dist/eui_theme_dark.json';
Expand All @@ -26,14 +26,12 @@ import {
HistogramAggregation,
MatrixHistogramQueryProps,
} from './types';
import { generateTablePaginationOptions } from '../paginated_table/helpers';
import { ChartSeriesData } from '../charts/common';
import { InspectButtonContainer } from '../inspect';

export const MatrixHistogramComponent: React.FC<MatrixHistogramProps &
MatrixHistogramQueryProps> = ({
activePage,

dataKey,
defaultStackByOption,
endDate,
Expand All @@ -45,12 +43,10 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramProps &
isAlertsHistogram,
isAnomaliesHistogram,
isAuthenticationsHistogram,
isDNSHistogram,
isEventsType,
isPtrIncluded,
isDnsHistogram,
isEventsHistogram,
isInspected,
legendPosition,
limit,
mapping,
query,
scaleType = ScaleType.Time,
Expand Down Expand Up @@ -104,10 +100,6 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramProps &
},
[]
);
const getPagination = () =>
activePage != null && limit != null
? generateTablePaginationOptions(activePage, limit)
: undefined;

const { data, loading, inspect, totalCount, refetch = noop } = useQuery<{}, HistogramAggregation>(
{
Expand All @@ -118,16 +110,13 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramProps &
query,
skip,
startDate,
sort,
title,
isAlertsHistogram,
isAnomaliesHistogram,
isAuthenticationsHistogram,
isDNSHistogram,
isEventsType,
isDnsHistogram,
isEventsHistogram,
isInspected,
isPtrIncluded,
pagination: useMemo(() => getPagination(), [activePage, limit]),
stackByField: selectedStackByOption.value,
}
);
Expand Down Expand Up @@ -179,7 +168,7 @@ export const MatrixHistogramComponent: React.FC<MatrixHistogramProps &
>
<EuiFlexGroup alignItems="center" gutterSize="none">
<EuiFlexItem grow={false}>
{stackByOptions && (
{stackByOptions?.length > 1 && (
<EuiSelect
onChange={setSelectedChartOptionCallback}
options={stackByOptions}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export interface MatrixHistogramQueryProps {
isAlertsHistogram?: boolean;
isAnomaliesHistogram?: boolean;
isAuthenticationsHistogram?: boolean;
isDNSHistogram?: boolean;
isEventsType?: boolean;
isDnsHistogram?: boolean;
isEventsHistogram?: boolean;
isInspected: boolean;
isPtrIncluded?: boolean;
pagination?: PaginationInputPaginated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const getBarchartConfigs = ({
settings: {
legendPosition: legendPosition ?? Position.Bottom,
onBrushEnd,
showLegend: showLegend || true,
showLegend: showLegend ?? true,
theme: {
scales: {
barsPadding: 0.08,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ export const MatrixHistogramGqlQuery = gql`
$isAlertsHistogram: Boolean!
$isAnomaliesHistogram: Boolean!
$isAuthenticationsHistogram: Boolean!
$isDnsHistogram: Boolean!
$defaultIndex: [String!]!
$isEventsType: Boolean!
$isEventsHistogram: Boolean!
$filterQuery: String
$inspect: Boolean!
$sourceId: ID!
Expand Down Expand Up @@ -77,7 +78,24 @@ export const MatrixHistogramGqlQuery = gql`
filterQuery: $filterQuery
defaultIndex: $defaultIndex
stackByField: $stackByField
) @include(if: $isEventsType) {
) @include(if: $isEventsHistogram) {
matrixHistogramData {
x
y
g
}
totalCount
inspect @include(if: $inspect) {
dsl
response
}
}
NetworkDnsHistogram(
timerange: $timerange
filterQuery: $filterQuery
defaultIndex: $defaultIndex
stackByField: $stackByField
) @include(if: $isDnsHistogram) {
matrixHistogramData {
x
y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,23 @@ import { UpdateDateRange } from '../../components/charts/common';
import { SetQuery } from '../../pages/hosts/navigation/types';

export interface OwnProps extends QueryTemplateProps {
isAlertsHistogram?: boolean;
isAnomaliesHistogram?: boolean;
isAuthenticationsHistogram?: boolean;
dataKey: string | string[];
defaultStackByOption: MatrixHistogramOption;
deleteQuery?: ({ id }: { id: string }) => void;
isEventsType?: boolean;
errorMessage: string;
headerChildren?: React.ReactNode;
hideHistogramIfEmpty?: boolean;
isAlertsHistogram?: boolean;
isAnomaliesHistogram?: boolean;
isAuthenticationsHistogram?: boolean;
id: string;
isDnsHistogram?: boolean;
isEventsHistogram?: boolean;
legendPosition?: Position;
mapping?: MatrixHistogramMappingTypes;
query: Maybe<string>;
setQuery: SetQuery;
showLegend?: boolean;
sourceId: string;
stackByOptions: MatrixHistogramOption[];
subtitle?: string | GetSubTitle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useUiSetting$ } from '../../lib/kibana';
import { createFilter } from '../helpers';
import { useApolloClient } from '../../utils/apollo_context';
import { inputsModel } from '../../store';
import { GetMatrixHistogramQuery, GetNetworkDnsQuery } from '../../graphql/types';
import { GetMatrixHistogramQuery } from '../../graphql/types';

export const useQuery = <Hit, Aggs, TCache = object>({
dataKey,
Expand All @@ -26,15 +26,12 @@ export const useQuery = <Hit, Aggs, TCache = object>({
isAlertsHistogram = false,
isAnomaliesHistogram = false,
isAuthenticationsHistogram = false,
isEventsType = false,
isDNSHistogram,
isPtrIncluded,
isEventsHistogram = false,
isDnsHistogram = false,
isInspected,
query,
stackByField,
startDate,
sort,
pagination,
}: MatrixHistogramQueryProps) => {
const [defaultIndex] = useUiSetting$<string[]>(DEFAULT_INDEX_KEY);
const [, dispatchToaster] = useStateToaster();
Expand All @@ -45,21 +42,7 @@ export const useQuery = <Hit, Aggs, TCache = object>({
const [totalCount, setTotalCount] = useState(-1);
const apolloClient = useApolloClient();

const isDNSQuery = (
variable: Pick<
MatrixHistogramQueryProps,
'isDNSHistogram' | 'isPtrIncluded' | 'sort' | 'pagination'
>
): variable is GetNetworkDnsQuery.Variables => {
return (
!!isDNSHistogram &&
variable.isDNSHistogram !== undefined &&
variable.isPtrIncluded !== undefined &&
variable.sort !== undefined &&
variable.pagination !== undefined
);
};
const basicVariables = {
const matrixHistogramVariables: GetMatrixHistogramQuery.Variables = {
filterQuery: createFilter(filterQuery),
sourceId: 'default',
timerange: {
Expand All @@ -70,20 +53,11 @@ export const useQuery = <Hit, Aggs, TCache = object>({
defaultIndex,
inspect: isInspected,
stackByField,
};
const dnsVariables = {
...basicVariables,
isDNSHistogram,
isPtrIncluded,
sort,
pagination,
};
const matrixHistogramVariables: GetMatrixHistogramQuery.Variables = {
...basicVariables,
isAlertsHistogram,
isAnomaliesHistogram,
isAuthenticationsHistogram,
isEventsType,
isDnsHistogram,
isEventsHistogram,
};

useEffect(() => {
Expand All @@ -92,16 +66,13 @@ export const useQuery = <Hit, Aggs, TCache = object>({
const abortSignal = abortCtrl.signal;

async function fetchData() {
if (!apolloClient || (pagination != null && pagination.querySize < 0)) return null;
if (!apolloClient) return null;
setLoading(true);
return apolloClient
.query<
GetMatrixHistogramQuery.Query | GetNetworkDnsQuery.Query,
GetMatrixHistogramQuery.Variables | GetNetworkDnsQuery.Variables
>({
.query<GetMatrixHistogramQuery.Query, GetMatrixHistogramQuery.Variables>({
query,
fetchPolicy: 'cache-first',
variables: isDNSQuery(dnsVariables) ? dnsVariables : matrixHistogramVariables,
variables: matrixHistogramVariables,
context: {
fetchOptions: {
abortSignal,
Expand Down Expand Up @@ -145,11 +116,8 @@ export const useQuery = <Hit, Aggs, TCache = object>({
query,
filterQuery,
isInspected,
isDNSHistogram,
isDnsHistogram,
stackByField,
sort,
isPtrIncluded,
pagination,
startDate,
endDate,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const networkDnsQuery = gql`
$defaultIndex: [String!]!
$filterQuery: String
$inspect: Boolean!
$isDNSHistogram: Boolean!
$isPtrIncluded: Boolean!
$pagination: PaginationInputPaginated!
$sort: NetworkDnsSortField!
Expand All @@ -31,7 +30,7 @@ export const networkDnsQuery = gql`
stackByField: $stackByField
) {
totalCount
edges @skip(if: $isDNSHistogram) {
edges {
node {
_id
dnsBytesIn
Expand All @@ -44,7 +43,7 @@ export const networkDnsQuery = gql`
value
}
}
pageInfo @skip(if: $isDNSHistogram) {
pageInfo {
activePage
fakeTotalCount
showMorePagesIndicator
Expand All @@ -53,11 +52,6 @@ export const networkDnsQuery = gql`
dsl
response
}
histogram @include(if: $isDNSHistogram) {
x
y
g
}
}
}
}
Expand Down
Loading

0 comments on commit 500227e

Please sign in to comment.