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

[Security Solution] Fix the status of timelines' bulk actions #74560

Merged
merged 4 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -7,7 +7,7 @@
import { EuiContextMenuPanel, EuiContextMenuItem, EuiBasicTable } from '@elastic/eui';
import React, { useCallback, useMemo } from 'react';

import { TimelineType, TimelineStatus } from '../../../../common/types/timeline';
import { TimelineType } from '../../../../common/types/timeline';

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

const getBatchItemsPopoverContent = useCallback(
(closePopover: () => void) => {
const disabled = selectedItems?.some((item) => item.status === TimelineStatus.immutable);
const disabled = selectedItems == null || selectedItems.length === 0;
return (
<>
<EditTimelineActions
Expand All @@ -87,6 +87,7 @@ export const useEditTimelineBatchActions = ({
<EuiContextMenuPanel
items={[
<EuiContextMenuItem
data-test-subj="export-timeline-action"
disabled={disabled}
icon="exportAction"
key="ExportItemKey"
Expand All @@ -95,6 +96,7 @@ export const useEditTimelineBatchActions = ({
{i18n.EXPORT_SELECTED}
</EuiContextMenuItem>,
<EuiContextMenuItem
data-test-subj="delete-timeline-action"
disabled={disabled}
icon="trash"
key="DeleteItemKey"
Expand All @@ -107,7 +109,6 @@ export const useEditTimelineBatchActions = ({
</>
);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[
selectedItems,
deleteTimelines,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { cloneDeep } from 'lodash/fp';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import React from 'react';
import { ThemeProvider } from 'styled-components';
import { act } from '@testing-library/react';

import '../../../common/mock/match_media';
import { DEFAULT_SEARCH_RESULTS_PER_PAGE } from '../../pages/timelines_page';
Expand Down Expand Up @@ -51,7 +52,7 @@ describe('OpenTimeline', () => {
title,
timelineType: TimelineType.default,
timelineStatus: TimelineStatus.active,
templateTimelineFilter: [<div />],
templateTimelineFilter: [<div key="mock-a" />, <div key="mock-b" />],
totalSearchResultsCount: mockSearchResults.length,
});

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

test('it should disable export-timeline if no timeline is selected', async () => {
const defaultProps = {
...getDefaultTestProps(mockResults),
timelineStatus: null,
selectedItems: [],
};
const wrapper = mountWithIntl(
<ThemeProvider theme={theme}>
<OpenTimeline {...defaultProps} />
</ThemeProvider>
);

wrapper.find('[data-test-subj="utility-bar-action"]').find('EuiLink').simulate('click');
await act(async () => {
expect(
wrapper.find('[data-test-subj="export-timeline-action"]').first().prop('disabled')
).toEqual(true);
});
});

test('it should disable delete timeline if no timeline is selected', async () => {
const defaultProps = {
...getDefaultTestProps(mockResults),
timelineStatus: null,
selectedItems: [],
};
const wrapper = mountWithIntl(
<ThemeProvider theme={theme}>
<OpenTimeline {...defaultProps} />
</ThemeProvider>
);

wrapper.find('[data-test-subj="utility-bar-action"]').find('EuiLink').simulate('click');
await act(async () => {
expect(
wrapper.find('[data-test-subj="delete-timeline-action"]').first().prop('disabled')
).toEqual(true);
});
});

test('it should enable export-timeline if a timeline is selected', async () => {
const defaultProps = {
...getDefaultTestProps(mockResults),
timelineStatus: null,
selectedItems: [{}],
};
const wrapper = mountWithIntl(
<ThemeProvider theme={theme}>
<OpenTimeline {...defaultProps} />
</ThemeProvider>
);

wrapper.find('[data-test-subj="utility-bar-action"]').find('EuiLink').simulate('click');
await act(async () => {
expect(
wrapper.find('[data-test-subj="export-timeline-action"]').first().prop('disabled')
).toEqual(false);
});
});

test('it should enable delete timeline if a timeline is selected', async () => {
const defaultProps = {
...getDefaultTestProps(mockResults),
timelineStatus: null,
selectedItems: [{}],
};
const wrapper = mountWithIntl(
<ThemeProvider theme={theme}>
<OpenTimeline {...defaultProps} />
</ThemeProvider>
);

wrapper.find('[data-test-subj="utility-bar-action"]').find('EuiLink').simulate('click');
await act(async () => {
expect(
wrapper.find('[data-test-subj="delete-timeline-action"]').first().prop('disabled')
).toEqual(false);
});
});

test("it should render a selectable timeline table if timelineStatus is active (selecting custom templates' tab)", () => {
const defaultProps = {
...getDefaultTestProps(mockResults),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ export const OpenTimeline = React.memo<OpenTimelineProps>(
}, [onDeleteSelected, deleteTimelines, timelineStatus]);

const SearchRowContent = useMemo(() => <>{templateTimelineFilter}</>, [templateTimelineFilter]);

return (
<>
<EditOneTimelineAction
Expand Down