Skip to content

Commit

Permalink
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
Browse files Browse the repository at this point in the history
…-fix'
  • Loading branch information
kibanamachine committed Jun 27, 2022
1 parent a6b1070 commit 187278a
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ describe('ExceptionItemCardConditions', () => {
<ExceptionItemCardConditions
entries={[
{
field: "host.name",
operator: "included",
type: "match",
value: "host",
field: 'host.name',
operator: 'included',
type: 'match',
value: 'host',
},
{
field: "threat.indicator.port",
operator: "included",
type: "exists",
field: 'threat.indicator.port',
operator: 'included',
type: 'exists',
},
{
entries: [
{
field: "valid",
operator: "included",
type: "match",
value: "true"
}
field: 'valid',
operator: 'included',
type: 'match',
value: 'true',
},
],
field: "file.Ext.code_signature",
type: "nested",
}
field: 'file.Ext.code_signature',
type: 'nested',
},
]}
dataTestSubj="exceptionItemConditions"
/>
</TestProviders>
);

// Text is gonna look a bit off unformatted
expect(
wrapper.find('[data-test-subj="exceptionItemConditions-condition"]').at(0).text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
*/

import React, { memo, useCallback } from 'react';
import {
EuiExpression,
EuiToken,
EuiFlexGroup,
EuiFlexItem,
EuiBadge,
} from '@elastic/eui';
import { EuiExpression, EuiToken, EuiFlexGroup, EuiFlexItem, EuiBadge } from '@elastic/eui';
import styled from 'styled-components';
import { ExceptionListItemSchema, ListOperatorTypeEnum, NonEmptyNestedEntriesArray } from '@kbn/securitysolution-io-ts-list-types';
import {
ExceptionListItemSchema,
ListOperatorTypeEnum,
NonEmptyNestedEntriesArray,
} from '@kbn/securitysolution-io-ts-list-types';

import * as i18n from './translations';

Expand Down Expand Up @@ -65,40 +63,34 @@ export const ExceptionItemCardConditions = memo<CriteriaConditionsProps>(
const getNestedEntriesContent = useCallback(
(type: string, nestedEntries: NonEmptyNestedEntriesArray) => {
if (type === 'nested' && nestedEntries.length) {
return nestedEntries.map(
(entry) => {
const {
field: nestedField,
type: nestedType,
operator: nestedOperator,
} = entry;
const nestedValue = "value" in entry ? entry.value : '';
return nestedEntries.map((entry) => {
const { field: nestedField, type: nestedType, operator: nestedOperator } = entry;
const nestedValue = 'value' in entry ? entry.value : '';

return (
<EuiFlexGroupNested
data-test-subj={`${dataTestSubj}-nestedCondition`}
key={nestedField + nestedType + nestedValue}
direction="row"
alignItems="center"
gutterSize="m"
responsive={false}
>
<EuiFlexItemNested grow={false}>
<EuiToken iconType="tokenNested" size="s" />
</EuiFlexItemNested>
<EuiFlexItemNested grow={false}>
<EuiExpression description={''} value={nestedField} color="subdued" />
</EuiFlexItemNested>
<EuiFlexItemNested grow={false}>
<EuiExpression
description={getEntryOperator(nestedType, nestedOperator)}
value={getEntryValue(nestedType, nestedValue)}
/>
</EuiFlexItemNested>
</EuiFlexGroupNested>
);
}
);
return (
<EuiFlexGroupNested
data-test-subj={`${dataTestSubj}-nestedCondition`}
key={nestedField + nestedType + nestedValue}
direction="row"
alignItems="center"
gutterSize="m"
responsive={false}
>
<EuiFlexItemNested grow={false}>
<EuiToken iconType="tokenNested" size="s" />
</EuiFlexItemNested>
<EuiFlexItemNested grow={false}>
<EuiExpression description={''} value={nestedField} color="subdued" />
</EuiFlexItemNested>
<EuiFlexItemNested grow={false}>
<EuiExpression
description={getEntryOperator(nestedType, nestedOperator)}
value={getEntryValue(nestedType, nestedValue)}
/>
</EuiFlexItemNested>
</EuiFlexGroupNested>
);
});
}
},
[]
Expand All @@ -107,21 +99,18 @@ export const ExceptionItemCardConditions = memo<CriteriaConditionsProps>(
return (
<div data-test-subj={dataTestSubj}>
{entries.map((entry, index) => {
const {
field,
type
} = entry;
const value = "value" in entry ? entry.value : '';
const nestedEntries = "entries" in entry ? entry.entries : [];
const operator = "operator" in entry ? entry.operator : '';
const { field, type } = entry;
const value = 'value' in entry ? entry.value : '';
const nestedEntries = 'entries' in entry ? entry.entries : [];
const operator = 'operator' in entry ? entry.operator : '';

return (
<div data-test-subj={`${dataTestSubj}-condition`} key={field + type + value + index}>
<div className="eui-xScroll">
<EuiExpression
description={index === 0 ? i18n.DESCRIPTOR_WHEN : i18n.CONDITION_AND}
value={field}
color={index === 0 ? "primary" : "subdued"}
color={index === 0 ? 'primary' : 'subdued'}
/>
<EuiExpression
description={getEntryOperator(type, operator)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ describe('ExceptionItemCardHeader', () => {
key: 'edit',
icon: 'pencil',
label: i18n.EXCEPTION_ITEM_EDIT_BUTTON,
onClick: jest.fn()
onClick: jest.fn(),
},
{
key: 'delete',
icon: 'trash',
label: i18n.EXCEPTION_ITEM_DELETE_BUTTON,
onClick: jest.fn()
onClick: jest.fn(),
},
]}
/>
</ThemeProvider>
);

expect(
wrapper.find('[data-test-subj="exceptionItemHeader-title"]').at(0).text()
).toEqual('some name');
expect(wrapper.find('[data-test-subj="exceptionItemHeader-title"]').at(0).text()).toEqual(
'some name'
);
});

it('it displays actions', () => {
Expand All @@ -59,29 +59,32 @@ describe('ExceptionItemCardHeader', () => {
<ThemeProvider theme={mockTheme}>
<ExceptionItemCardHeader
actions={[
{
key: 'edit',
icon: 'pencil',
label: i18n.EXCEPTION_ITEM_EDIT_BUTTON,
onClick: handleEdit
},
{
key: 'delete',
icon: 'trash',
label: i18n.EXCEPTION_ITEM_DELETE_BUTTON,
onClick: handleDelete
},
]}
{
key: 'edit',
icon: 'pencil',
label: i18n.EXCEPTION_ITEM_EDIT_BUTTON,
onClick: handleEdit,
},
{
key: 'delete',
icon: 'trash',
label: i18n.EXCEPTION_ITEM_DELETE_BUTTON,
onClick: handleDelete,
},
]}
item={getExceptionListItemSchemaMock()}
dataTestSubj="exceptionItemHeader"
/>
</ThemeProvider>
);

// click on popover
wrapper.find('button[data-test-subj="exceptionItemHeader-actionButton"]').at(0).simulate('click');
wrapper
.find('button[data-test-subj="exceptionItemHeader-actionButton"]')
.at(0)
.simulate('click');
expect(wrapper.find('button[data-test-subj="exceptionItemHeader-actionItem"]')).toHaveLength(2);

wrapper.find('button[data-test-subj="exceptionItemHeader-actionItem"]').at(0).simulate('click');
expect(handleEdit).toHaveBeenCalled();

Expand All @@ -96,26 +99,29 @@ describe('ExceptionItemCardHeader', () => {
<ThemeProvider theme={mockTheme}>
<ExceptionItemCardHeader
actions={[
{
key: 'edit',
icon: 'pencil',
label: i18n.EXCEPTION_ITEM_EDIT_BUTTON,
onClick: handleEdit
},
{
key: 'delete',
icon: 'trash',
label: i18n.EXCEPTION_ITEM_DELETE_BUTTON,
onClick: handleDelete
},
]}
{
key: 'edit',
icon: 'pencil',
label: i18n.EXCEPTION_ITEM_EDIT_BUTTON,
onClick: handleEdit,
},
{
key: 'delete',
icon: 'trash',
label: i18n.EXCEPTION_ITEM_DELETE_BUTTON,
onClick: handleDelete,
},
]}
item={getExceptionListItemSchemaMock()}
disableActions
dataTestSubj="exceptionItemHeader"
/>
</ThemeProvider>
);

expect(wrapper.find('button[data-test-subj="exceptionItemHeader-actionButton"]').at(0).props().disabled).toBeTruthy();

expect(
wrapper.find('button[data-test-subj="exceptionItemHeader-actionButton"]').at(0).props()
.disabled
).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
*/

import React, { memo, useMemo, useState } from 'react';
import { EuiButtonIcon, EuiContextMenuPanelProps, EuiContextMenuPanel, EuiFlexGroup, EuiFlexItem, EuiPopover, EuiTitle, EuiContextMenuItem } from '@elastic/eui';
import {
EuiButtonIcon,
EuiContextMenuPanelProps,
EuiContextMenuPanel,
EuiFlexGroup,
EuiFlexItem,
EuiPopover,
EuiTitle,
EuiContextMenuItem,
} from '@elastic/eui';
import { ExceptionListItemSchema } from '@kbn/securitysolution-io-ts-list-types';

export interface ExceptionItemCardHeaderProps {
item: ExceptionListItemSchema;
actions: Array<{ key: string; icon: string; label: string; onClick: () => void; }>;
actions: Array<{ key: string; icon: string; label: string; onClick: () => void }>;
disableActions?: boolean;
dataTestSubj: string;
}
Expand All @@ -36,9 +45,9 @@ export const ExceptionItemCardHeader = memo<ExceptionItemCardHeaderProps>(
>
{action.label}
</EuiContextMenuItem>
))
));
}, []);

return (
<EuiFlexGroup data-test-subj={dataTestSubj} justifyContent="spaceBetween">
<EuiFlexItem grow={9}>
Expand All @@ -48,21 +57,21 @@ export const ExceptionItemCardHeader = memo<ExceptionItemCardHeaderProps>(
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiPopover
button={(
button={
<EuiButtonIcon
isDisabled={disableActions}
aria-label="Exception item actions menu"
iconType="boxesHorizontal"
onClick={onItemActionsClick}
data-test-subj={`${dataTestSubj}-actionButton`}
/>
)}
}
panelPaddingSize="none"
isOpen={isPopoverOpen}
closePopover={onClosePopover}
data-test-subj={`${dataTestSubj}-items`}
>
<EuiContextMenuPanel size='s' items={itemActions} />
<EuiContextMenuPanel size="s" items={itemActions} />
</EuiPopover>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Loading

0 comments on commit 187278a

Please sign in to comment.