Skip to content

Commit

Permalink
Fixes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHassanabad committed Oct 1, 2020
1 parent fbd9acf commit 32783a3
Show file tree
Hide file tree
Showing 10 changed files with 314 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
fields,
getField,
} from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
import { IndexPattern } from 'src/plugins/data/public';

jest.mock('../../../common/lib/kibana');

Expand All @@ -26,18 +27,22 @@ describe('EntryItem', () => {
type: 'mapping',
entryIndex: 0,
}}
indexPattern={{
id: '1234',
title: 'logstash-*',
fields,
}}
indexPattern={
{
id: '1234',
title: 'logstash-*',
fields,
} as IndexPattern
}
showLabel={true}
onChange={jest.fn()}
threatIndexPatterns={{
id: '1234',
title: 'logstash-*',
fields,
}}
threatIndexPatterns={
{
id: '1234',
title: 'logstash-*',
fields,
} as IndexPattern
}
/>
);

Expand All @@ -54,16 +59,20 @@ describe('EntryItem', () => {
value: getField('ip'),
entryIndex: 0,
}}
indexPattern={{
id: '1234',
title: 'logstash-*',
fields,
}}
threatIndexPatterns={{
id: '1234',
title: 'logstash-*',
fields,
}}
indexPattern={
{
id: '1234',
title: 'logstash-*',
fields,
} as IndexPattern
}
threatIndexPatterns={
{
id: '1234',
title: 'logstash-*',
fields,
} as IndexPattern
}
showLabel={false}
onChange={mockOnChange}
/>
Expand Down Expand Up @@ -93,16 +102,20 @@ describe('EntryItem', () => {
value: getField('ip'),
entryIndex: 0,
}}
indexPattern={{
id: '1234',
title: 'logstash-*',
fields,
}}
threatIndexPatterns={{
id: '1234',
title: 'logstash-*',
fields,
}}
indexPattern={
{
id: '1234',
title: 'logstash-*',
fields,
} as IndexPattern
}
threatIndexPatterns={
{
id: '1234',
title: 'logstash-*',
fields,
} as IndexPattern
}
showLabel={false}
onChange={mockOnChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import React, { useCallback, useMemo } from 'react';
import { EuiFormRow, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import styled from 'styled-components';

import { IFieldType, IIndexPattern } from '../../../../../../../src/plugins/data/common';
import { IFieldType, IndexPattern } from '../../../../../../../src/plugins/data/common';
import { FieldComponent } from '../autocomplete/field';
import { FormattedEntry, Entry } from './types';
import * as i18n from './translations';
import { getEntryOnFieldChange, getEntryOnThreatFieldChange } from './helpers';

interface EntryItemProps {
entry: FormattedEntry;
indexPattern: IIndexPattern;
threatIndexPatterns: IIndexPattern;
indexPattern: IndexPattern;
threatIndexPatterns: IndexPattern;
showLabel: boolean;
onChange: (arg: Entry, i: number) => void;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
getField,
} from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks';
import { Entry, EmptyEntry, ThreatMapEntries, FormattedEntry } from './types';
import { IIndexPattern } from '../../../../../../../src/plugins/data/common';
import { IndexPattern } from '../../../../../../../src/plugins/data/common';
import moment from 'moment-timezone';

import {
Expand All @@ -21,11 +21,12 @@ import {
} from './helpers';
import { ThreatMapEntry } from '../../../../common/detection_engine/schemas/types';

const getMockIndexPattern = (): IIndexPattern => ({
id: '1234',
title: 'logstash-*',
fields,
});
const getMockIndexPattern = (): IndexPattern =>
({
id: '1234',
title: 'logstash-*',
fields,
} as IndexPattern);

const getMockEntry = (): FormattedEntry => ({
field: getField('ip'),
Expand All @@ -45,7 +46,7 @@ describe('Helpers', () => {

describe('#getFormattedEntry', () => {
test('it returns entry with a value when "item.field" is of type "text" and matching keyword field exists', () => {
const payloadIndexPattern: IIndexPattern = {
const payloadIndexPattern: IndexPattern = {
...getMockIndexPattern(),
fields: [
...fields,
Expand All @@ -60,7 +61,7 @@ describe('Helpers', () => {
readFromDocValues: true,
},
],
};
} as IndexPattern;
const payloadItem: Entry = {
field: 'machine.os.raw.text',
type: 'mapping',
Expand Down Expand Up @@ -88,7 +89,7 @@ describe('Helpers', () => {

describe('#getFormattedEntries', () => {
test('it returns formatted entry with fields undefined if it unable to find a matching index pattern field', () => {
const payloadIndexPattern: IIndexPattern = getMockIndexPattern();
const payloadIndexPattern: IndexPattern = getMockIndexPattern();
const payloadItems: Entry[] = [{ field: 'field.one', type: 'mapping', value: 'field.one' }];
const output = getFormattedEntries(payloadIndexPattern, payloadItems);
const expected: FormattedEntry[] = [
Expand All @@ -103,7 +104,7 @@ describe('Helpers', () => {
});

test('it returns formatted entries', () => {
const payloadIndexPattern: IIndexPattern = getMockIndexPattern();
const payloadIndexPattern: IndexPattern = getMockIndexPattern();
const payloadItems: Entry[] = [
{ field: 'machine.os', type: 'mapping', value: 'machine.os' },
{ field: 'ip', type: 'mapping', value: 'ip' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import {
ThreatMapping,
} from '../../../../common/detection_engine/schemas/types';

import { IIndexPattern, IFieldType } from '../../../../../../../src/plugins/data/common';
import { IndexPattern, IFieldType } from '../../../../../../../src/plugins/data/common';
import { Entry, FormattedEntry, ThreatMapEntries, EmptyEntry } from './types';

/**
* Formats the entry into one that is easily usable for the UI.
*
* @param patterns IIndexPattern containing available fields on rule index
* @param patterns IndexPattern containing available fields on rule index
* @param item item entry
* @param itemIndex entry index
*/
export const getFormattedEntry = (
indexPattern: IIndexPattern,
indexPattern: IndexPattern,
item: Entry,
itemIndex: number
): FormattedEntry => {
Expand All @@ -43,11 +43,11 @@ export const getFormattedEntry = (
/**
* Formats the entries to be easily usable for the UI
*
* @param patterns IIndexPattern containing available fields on rule index
* @param patterns IndexPattern containing available fields on rule index
* @param entries item entries
*/
export const getFormattedEntries = (
indexPattern: IIndexPattern,
indexPattern: IndexPattern,
entries: Entry[]
): FormattedEntry[] => {
return entries.reduce<FormattedEntry[]>((acc, item, index) => {
Expand Down
Loading

0 comments on commit 32783a3

Please sign in to comment.