Skip to content

Commit 2efee0b

Browse files
kevinlogefreeti
andauthored
[SECURITY_SOLUTION] Trusted apps list expand/collapse details (#78601) (#78989)
Co-authored-by: Bohdan Tsymbala <bohdan.tsymbala@elastic.co>
1 parent 7d55428 commit 2efee0b

File tree

19 files changed

+5693
-221
lines changed

19 files changed

+5693
-221
lines changed

x-pack/plugins/security_solution/public/common/components/conditions_table/__snapshots__/index.test.tsx.snap

Lines changed: 174 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import React from 'react';
7+
import { ThemeProvider } from 'styled-components';
8+
import { storiesOf, addDecorator } from '@storybook/react';
9+
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
10+
11+
import { createItems, TEST_COLUMNS } from './test_utils';
12+
import { ConditionsTable } from '.';
13+
14+
addDecorator((storyFn) => (
15+
<ThemeProvider theme={() => ({ eui: euiLightVars, darkMode: false })}>{storyFn()}</ThemeProvider>
16+
));
17+
18+
storiesOf('Components|ConditionsTable', module)
19+
.add('single item', () => {
20+
return <ConditionsTable items={createItems(1)} columns={TEST_COLUMNS} badge="and" />;
21+
})
22+
.add('and', () => {
23+
return <ConditionsTable items={createItems(3)} columns={TEST_COLUMNS} badge="and" />;
24+
})
25+
.add('or', () => {
26+
return <ConditionsTable items={createItems(3)} columns={TEST_COLUMNS} badge="or" />;
27+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import { shallow } from 'enzyme';
7+
import React from 'react';
8+
9+
import { ConditionsTable } from '.';
10+
import { createItems, TEST_COLUMNS } from './test_utils';
11+
12+
describe('conditions_table', () => {
13+
describe('ConditionsTable', () => {
14+
it('should render single item table correctly', () => {
15+
const element = shallow(
16+
<ConditionsTable badge="and" columns={TEST_COLUMNS} items={createItems(1)} />
17+
);
18+
19+
expect(element).toMatchSnapshot();
20+
});
21+
22+
it('should render multi item table with and badge correctly', () => {
23+
const element = shallow(
24+
<ConditionsTable badge="and" columns={TEST_COLUMNS} items={createItems(3)} />
25+
);
26+
27+
expect(element).toMatchSnapshot();
28+
});
29+
30+
it('should render multi item table with or badge correctly', () => {
31+
const element = shallow(
32+
<ConditionsTable badge="or" columns={TEST_COLUMNS} items={createItems(3)} />
33+
);
34+
35+
expect(element).toMatchSnapshot();
36+
});
37+
});
38+
});
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React from 'react';
8+
import styled from 'styled-components';
9+
import {
10+
EuiBasicTableProps,
11+
EuiBasicTable,
12+
EuiFlexGroup,
13+
EuiFlexItem,
14+
EuiHideFor,
15+
} from '@elastic/eui';
16+
17+
import { AndOr, AndOrBadge } from '../and_or_badge';
18+
19+
const AndOrBadgeContainer = styled(EuiFlexItem)`
20+
padding-top: ${({ theme }) => theme.eui.euiSizeXL};
21+
padding-bottom: ${({ theme }) => theme.eui.euiSizeS};
22+
`;
23+
24+
type ConditionsTableProps<T> = EuiBasicTableProps<T> & {
25+
badge: AndOr;
26+
};
27+
28+
export const ConditionsTable = <T,>({ badge, ...props }: ConditionsTableProps<T>) => {
29+
return (
30+
<EuiFlexGroup direction="row" gutterSize="none">
31+
{props.items.length > 1 && (
32+
<EuiHideFor sizes={['xs', 's']}>
33+
<AndOrBadgeContainer grow={false}>
34+
<AndOrBadge type={badge} includeAntennas />
35+
</AndOrBadgeContainer>
36+
</EuiHideFor>
37+
)}
38+
<EuiFlexItem grow={1}>
39+
<EuiBasicTable {...props} />
40+
</EuiFlexItem>
41+
</EuiFlexGroup>
42+
);
43+
};
44+
45+
ConditionsTable.displayName = 'ConditionsTable';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { EuiTableFieldDataColumnType } from '@elastic/eui';
8+
9+
export interface TestItem {
10+
name: string;
11+
value: string;
12+
}
13+
14+
export const TEST_COLUMNS: Array<EuiTableFieldDataColumnType<TestItem>> = [
15+
{ field: 'name', name: 'Name', textOnly: true, width: '50%' },
16+
{ field: 'value', name: 'Value', textOnly: true, width: '50%' },
17+
];
18+
19+
export const createItems = (count: number): TestItem[] =>
20+
[...new Array(count).keys()].map((item) => ({ name: `item ${item}`, value: `value ${item}` }));

0 commit comments

Comments
 (0)