Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use terms aggs instead of composite refactor of Authentications Table based on feedback #29283

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
droppableIdPrefix,
droppableTimelineFlyoutButtonPrefix,
droppableTimelineProvidersPrefix,
escapeDataProviderId,
getDraggableId,
getDroppableId,
getProviderIdFromDraggable,
Expand Down Expand Up @@ -444,4 +445,16 @@ describe('helpers', () => {
).toEqual(false);
});
});

describe('#escapeDataProviderId', () => {
test('it should escape dotted notation', () => {
const escaped = escapeDataProviderId('hello.how.are.you');
expect(escaped).toEqual('hello_how_are_you');
});

test('it should not escape a string without dotted notation', () => {
const escaped = escapeDataProviderId('hello how are you?');
expect(escaped).toEqual('hello how are you?');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export const getTimelineIdFromDestination = (result: DropResult): string =>
export const getProviderIdFromDraggable = (result: DropResult): string =>
result.draggableId.substring(result.draggableId.lastIndexOf('.') + 1);

export const escapeDataProviderId = (path: string) => path.replace(/\./g, '_');

export const providerWasDroppedOnTimeline = (result: DropResult): boolean =>
reasonIsDrop(result) &&
draggableIsContent(result) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import toJson from 'enzyme-to-json';
import React from 'react';
import { EmptyPage } from './index';

it('renders correctly', () => {
test('renders correctly', () => {
spong marked this conversation as resolved.
Show resolved Hide resolved
const EmptyComponent = shallow(
<EmptyPage
title="My Super Title"
Expand Down
120 changes: 110 additions & 10 deletions x-pack/plugins/secops/public/components/empty_value/empty_value.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,28 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { defaultToEmpty, getEmptyValue, getOrEmpty } from '.';
import { mount } from 'enzyme';
import React from 'react';
import {
defaultToEmpty,
defaultToEmptyTag,
getEmptyTagValue,
getEmptyValue,
getOrEmpty,
getOrEmptyTag,
} from '.';

describe('EmptyValue', () => {
describe('#getEmptyValue', () =>
it('should return an empty value', () => expect(getEmptyValue()).toBe('--')));
test('should return an empty value', () => expect(getEmptyValue()).toBe('--')));

describe('#getOr', () => {
it('should default empty value when a deep rooted value is null', () => {
describe('#getEmptyTagValue', () => {
const wrapper = mount(<p>{getEmptyTagValue()}</p>);
test('should return an empty tag value', () => expect(wrapper.text()).toBe('--'));
});

describe('#getOrEmpty', () => {
test('should default empty value when a deep rooted value is null', () => {
const test = {
a: {
b: {
Expand All @@ -22,7 +36,7 @@ describe('EmptyValue', () => {
expect(getOrEmpty('a.b.c', test)).toBe(getEmptyValue());
});

it('should default empty value when a deep rooted value is undefined', () => {
test('should default empty value when a deep rooted value is undefined', () => {
const test = {
a: {
b: {
Expand All @@ -33,7 +47,7 @@ describe('EmptyValue', () => {
expect(getOrEmpty('a.b.c', test)).toBe(getEmptyValue());
});

it('should default empty value when a deep rooted value is missing', () => {
test('should default empty value when a deep rooted value is missing', () => {
const test = {
a: {
b: {},
Expand All @@ -42,7 +56,7 @@ describe('EmptyValue', () => {
expect(getOrEmpty('a.b.c', test)).toBe(getEmptyValue());
});

it('should return a deep path value', () => {
test('should return a deep path value', () => {
const test = {
a: {
b: {
Expand All @@ -54,8 +68,56 @@ describe('EmptyValue', () => {
});
});

describe('#getOrEmptyTag', () => {
test('should default empty value when a deep rooted value is null', () => {
const test = {
a: {
b: {
c: null,
},
},
};
const wrapper = mount(<p>{getOrEmptyTag('a.b.c', test)}</p>);
expect(wrapper.text()).toBe(getEmptyValue());
});

test('should default empty value when a deep rooted value is undefined', () => {
const test = {
a: {
b: {
c: undefined,
},
},
};
const wrapper = mount(<p>{getOrEmptyTag('a.b.c', test)}</p>);
expect(wrapper.text()).toBe(getEmptyValue());
});

test('should default empty value when a deep rooted value is missing', () => {
const test = {
a: {
b: {},
},
};
const wrapper = mount(<p>{getOrEmptyTag('a.b.c', test)}</p>);
expect(wrapper.text()).toBe(getEmptyValue());
});

test('should return a deep path value', () => {
const test = {
a: {
b: {
c: 1,
},
},
};
const wrapper = mount(<p>{getOrEmptyTag('a.b.c', test)}</p>);
expect(wrapper.text()).toBe('1');
});
});

describe('#defaultToEmpty', () => {
it('should default to an empty value when a deep rooted value is null', () => {
test('should default to an empty value when a deep rooted value is null', () => {
const test = {
a: {
b: {
Expand All @@ -66,7 +128,7 @@ describe('EmptyValue', () => {
expect(defaultToEmpty(test.a.b.c)).toBe(getEmptyValue());
});

it('should default to an empty value when a deep rooted value is undefined', () => {
test('should default to an empty value when a deep rooted value is undefined', () => {
const test = {
a: {
b: {
Expand All @@ -77,7 +139,7 @@ describe('EmptyValue', () => {
expect(defaultToEmpty(test.a.b.c)).toBe(getEmptyValue());
});

it('should return a deep path value', () => {
test('should return a deep path value', () => {
const test = {
a: {
b: {
Expand All @@ -88,4 +150,42 @@ describe('EmptyValue', () => {
expect(defaultToEmpty(test.a.b.c)).toBe(1);
});
});

describe('#defaultToEmptyTag', () => {
test('should default to an empty value when a deep rooted value is null', () => {
const test = {
a: {
b: {
c: null,
},
},
};
const wrapper = mount(<p>{defaultToEmptyTag(test.a.b.c)}</p>);
expect(wrapper.text()).toBe(getEmptyValue());
});

test('should default to an empty value when a deep rooted value is undefined', () => {
const test = {
a: {
b: {
c: undefined,
},
},
};
const wrapper = mount(<p>{defaultToEmptyTag(test.a.b.c)}</p>);
expect(wrapper.text()).toBe(getEmptyValue());
});

test('should return a deep path value', () => {
const test = {
a: {
b: {
c: 1,
},
},
};
const wrapper = mount(<p>{defaultToEmptyTag(test.a.b.c)}</p>);
expect(wrapper.text()).toBe('1');
});
});
});
7 changes: 7 additions & 0 deletions x-pack/plugins/secops/public/components/empty_value/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
*/

import { defaultTo, get } from 'lodash/fp';
import React from 'react';

export const getEmptyTagValue = () => <>{getEmptyValue()}</>;

export const getEmptyValue = () => '--';

export const getOrEmptyTag = (path: string, item: unknown) => <>{getOrEmpty(path, item)}</>;

export const getOrEmpty = (path: string, item: unknown) =>
get(path, item) != null ? get(path, item) : getEmptyValue();

export const defaultToEmptyTag = <T extends unknown>(item: T) => <>{defaultToEmpty(item)}</>;

export const defaultToEmpty = <T extends unknown>(item: T) => defaultTo(getEmptyValue(), item);
5 changes: 3 additions & 2 deletions x-pack/plugins/secops/public/components/flyout/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Provider as ReduxStoreProvider } from 'react-redux';
import { ThemeProvider } from 'styled-components';

import * as euiVars from '@elastic/eui/dist/eui_theme_k6_light.json';
import { ActionCreator } from 'typescript-fsa';
import { Flyout, FlyoutComponent, flyoutHeaderHeight } from '.';
import { mockGlobalState } from '../../mock';
import { createStore, State } from '../../store';
Expand Down Expand Up @@ -204,7 +205,7 @@ describe('Flyout', () => {
});

test('should call the onOpen when the mouse is clicked for rendering', () => {
const showTimeline = jest.fn();
const showTimeline = (jest.fn() as unknown) as ActionCreator<{ id: string; show: boolean }>;
Copy link
Contributor Author

@FrankHassanabad FrankHassanabad Jan 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: with stricter types using ActionCreator, jest.fn() needs me to use this ugly casting to work? If there's another way I would like to know.

const wrapper = mount(
<ReduxStoreProvider store={store}>
<ThemeProvider theme={{ eui: euiVars }}>
Expand Down Expand Up @@ -234,7 +235,7 @@ describe('Flyout', () => {
const stateShowIsTrue = set('local.timeline.timelineById.test.show', true, state);
const storeShowIsTrue = createStore(stateShowIsTrue);

const showTimeline = jest.fn();
const showTimeline = (jest.fn() as unknown) as ActionCreator<{ id: string; show: boolean }>;
Copy link
Contributor Author

@FrankHassanabad FrankHassanabad Jan 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: with stricter types using ActionCreator, jest.fn() needs me to use this ugly casting to work? If there's another way I would like to know.

const wrapper = mount(
<ReduxStoreProvider store={storeShowIsTrue}>
<ThemeProvider theme={{ eui: euiVars }}>
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/secops/public/components/flyout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { connect } from 'react-redux';
import { pure } from 'recompose';
import styled from 'styled-components';

import { ActionCreator } from 'typescript-fsa';
import { State, timelineActions } from '../../store';
import { themeSelector } from '../../store/local/app';
import { Theme } from '../../store/local/app/model';
Expand Down Expand Up @@ -44,7 +45,7 @@ interface OwnProps {
}

interface DispatchProps {
showTimeline?: ({ id, show }: { id: string; show: boolean }) => void;
showTimeline?: ActionCreator<{ id: string; show: boolean }>;
applyDeltaToWidth?: (
{
id,
Expand Down
27 changes: 10 additions & 17 deletions x-pack/plugins/secops/public/components/flyout/resize_handle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

import * as React from 'react';
import { connect } from 'react-redux';
import styled from 'styled-components';

import { fromEvent, Observable } from 'rxjs';
import { mergeMap, takeUntil } from 'rxjs/operators';
import styled from 'styled-components';
import { ActionCreator } from 'typescript-fsa';

import { timelineActions } from '../../store';

interface OwnProps {
Expand All @@ -18,21 +19,13 @@ interface OwnProps {
}

interface DispatchProps {
applyDeltaToWidth: (
{
id,
delta,
bodyClientWidthPixels,
maxWidthPercent,
minWidthPixels,
}: {
id: string;
delta: number;
bodyClientWidthPixels: number;
maxWidthPercent: number;
minWidthPixels: number;
}
) => void;
applyDeltaToWidth: ActionCreator<{
id: string;
delta: number;
bodyClientWidthPixels: number;
maxWidthPercent: number;
minWidthPixels: number;
}>;
}

type Props = OwnProps & DispatchProps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { HostItem } from '../../graphql/types';
import { getOrEmpty } from '../empty_value';
import { ItemsPerRow } from './index';
import { HostsEdges } from '../../graphql/types';
import { getOrEmptyTag } from '../empty_value';
import { Columns, ItemsPerRow } from './index';

export const mockData = {
Hosts: {
Expand Down Expand Up @@ -47,30 +46,30 @@ export const mockData = {
},
};

export const getHostsColumns = () => [
export const getHostsColumns = (): Array<Columns<HostsEdges>> => [
{
name: 'Host',
truncateText: false,
hideForMobile: false,
render: (item: HostItem) => <>{getOrEmpty('host.name', item)}</>,
render: node => getOrEmptyTag('host.name', node),
},
{
name: 'First seen',
truncateText: false,
hideForMobile: false,
render: (item: HostItem) => <>{getOrEmpty('host.firstSeen', item)}</>,
render: node => getOrEmptyTag('host.firstSeen', node),
},
{
name: 'OS',
truncateText: false,
hideForMobile: false,
render: (item: HostItem) => <>{getOrEmpty('host.os', item)}</>,
render: node => getOrEmptyTag('host.os', node),
},
{
name: 'Version',
truncateText: false,
hideForMobile: false,
render: (item: HostItem) => <>{getOrEmpty('host.version', item)}</>,
render: node => getOrEmptyTag('host.version', node),
},
];

Expand Down
Loading