Skip to content

Commit 117bd21

Browse files
committed
fix bulk actions
1 parent 3fb77fb commit 117bd21

File tree

3 files changed

+86
-4
lines changed

3 files changed

+86
-4
lines changed

x-pack/plugins/security_solution/public/timelines/components/open_timeline/edit_timeline_batch_actions.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { EuiContextMenuPanel, EuiContextMenuItem, EuiBasicTable } from '@elastic/eui';
88
import React, { useCallback, useMemo } from 'react';
99

10-
import { TimelineType, TimelineStatus } from '../../../../common/types/timeline';
10+
import { TimelineType } from '../../../../common/types/timeline';
1111

1212
import * as i18n from './translations';
1313
import { DeleteTimelines, OpenTimelineResult } from './types';
@@ -66,7 +66,7 @@ export const useEditTimelineBatchActions = ({
6666

6767
const getBatchItemsPopoverContent = useCallback(
6868
(closePopover: () => void) => {
69-
const disabled = selectedItems?.some((item) => item.status === TimelineStatus.immutable);
69+
const disabled = selectedItems == null || selectedItems.length === 0;
7070
return (
7171
<>
7272
<EditTimelineActions
@@ -87,6 +87,7 @@ export const useEditTimelineBatchActions = ({
8787
<EuiContextMenuPanel
8888
items={[
8989
<EuiContextMenuItem
90+
data-test-subj="export-timeline-action"
9091
disabled={disabled}
9192
icon="exportAction"
9293
key="ExportItemKey"
@@ -95,6 +96,7 @@ export const useEditTimelineBatchActions = ({
9596
{i18n.EXPORT_SELECTED}
9697
</EuiContextMenuItem>,
9798
<EuiContextMenuItem
99+
data-test-subj="delete-timeline-action"
98100
disabled={disabled}
99101
icon="trash"
100102
key="DeleteItemKey"

x-pack/plugins/security_solution/public/timelines/components/open_timeline/open_timeline.test.tsx

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { cloneDeep } from 'lodash/fp';
99
import { mountWithIntl } from 'test_utils/enzyme_helpers';
1010
import React from 'react';
1111
import { ThemeProvider } from 'styled-components';
12+
import { act } from '@testing-library/react';
1213

1314
import '../../../common/mock/match_media';
1415
import { DEFAULT_SEARCH_RESULTS_PER_PAGE } from '../../pages/timelines_page';
@@ -51,7 +52,7 @@ describe('OpenTimeline', () => {
5152
title,
5253
timelineType: TimelineType.default,
5354
timelineStatus: TimelineStatus.active,
54-
templateTimelineFilter: [<div />],
55+
templateTimelineFilter: [<div key="mock-a" />, <div key="mock-b" />],
5556
totalSearchResultsCount: mockSearchResults.length,
5657
});
5758

@@ -279,6 +280,86 @@ describe('OpenTimeline', () => {
279280
expect(wrapper.find('[data-test-subj="utility-bar-action"]').exists()).toEqual(true);
280281
});
281282

283+
test('it should disable export-timeline if no timeline is selected', async () => {
284+
const defaultProps = {
285+
...getDefaultTestProps(mockResults),
286+
timelineStatus: null,
287+
selectedItems: [],
288+
};
289+
const wrapper = mountWithIntl(
290+
<ThemeProvider theme={theme}>
291+
<OpenTimeline {...defaultProps} />
292+
</ThemeProvider>
293+
);
294+
295+
wrapper.find('[data-test-subj="utility-bar-action"]').find('EuiLink').simulate('click');
296+
await act(async () => {
297+
expect(
298+
wrapper.find('[data-test-subj="export-timeline-action"]').first().prop('disabled')
299+
).toEqual(true);
300+
});
301+
});
302+
303+
test('it should disable delete timeline if no timeline is selected', async () => {
304+
const defaultProps = {
305+
...getDefaultTestProps(mockResults),
306+
timelineStatus: null,
307+
selectedItems: [],
308+
};
309+
const wrapper = mountWithIntl(
310+
<ThemeProvider theme={theme}>
311+
<OpenTimeline {...defaultProps} />
312+
</ThemeProvider>
313+
);
314+
315+
wrapper.find('[data-test-subj="utility-bar-action"]').find('EuiLink').simulate('click');
316+
await act(async () => {
317+
expect(
318+
wrapper.find('[data-test-subj="delete-timeline-action"]').first().prop('disabled')
319+
).toEqual(true);
320+
});
321+
});
322+
323+
test('it should enable export-timeline if a timeline is selected', async () => {
324+
const defaultProps = {
325+
...getDefaultTestProps(mockResults),
326+
timelineStatus: null,
327+
selectedItems: [{}],
328+
};
329+
const wrapper = mountWithIntl(
330+
<ThemeProvider theme={theme}>
331+
<OpenTimeline {...defaultProps} />
332+
</ThemeProvider>
333+
);
334+
335+
wrapper.find('[data-test-subj="utility-bar-action"]').find('EuiLink').simulate('click');
336+
await act(async () => {
337+
expect(
338+
wrapper.find('[data-test-subj="export-timeline-action"]').first().prop('disabled')
339+
).toEqual(false);
340+
});
341+
});
342+
343+
test('it should enable delete timeline if a timeline is selected', async () => {
344+
const defaultProps = {
345+
...getDefaultTestProps(mockResults),
346+
timelineStatus: null,
347+
selectedItems: [{}],
348+
};
349+
const wrapper = mountWithIntl(
350+
<ThemeProvider theme={theme}>
351+
<OpenTimeline {...defaultProps} />
352+
</ThemeProvider>
353+
);
354+
355+
wrapper.find('[data-test-subj="utility-bar-action"]').find('EuiLink').simulate('click');
356+
await act(async () => {
357+
expect(
358+
wrapper.find('[data-test-subj="delete-timeline-action"]').first().prop('disabled')
359+
).toEqual(false);
360+
});
361+
});
362+
282363
test("it should render a selectable timeline table if timelineStatus is active (selecting custom templates' tab)", () => {
283364
const defaultProps = {
284365
...getDefaultTestProps(mockResults),

x-pack/plugins/security_solution/public/timelines/components/open_timeline/open_timeline.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ export const OpenTimeline = React.memo<OpenTimelineProps>(
160160
}, [onDeleteSelected, deleteTimelines, timelineStatus]);
161161

162162
const SearchRowContent = useMemo(() => <>{templateTimelineFilter}</>, [templateTimelineFilter]);
163-
164163
return (
165164
<>
166165
<EditOneTimelineAction

0 commit comments

Comments
 (0)