-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Timeline] extract and cleanup timeline bottom bar…
… component (#173886)
- Loading branch information
1 parent
9f2df50
commit 2b45409
Showing
27 changed files
with
278 additions
and
411 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
x-pack/plugins/security_solution/public/timelines/components/bottom_bar/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { TestProviders } from '../../../common/mock/test_providers'; | ||
import { timelineActions } from '../../store'; | ||
import { TimelineBottomBar } from '.'; | ||
import { TimelineId } from '../../../../common/types'; | ||
|
||
jest.mock('react-redux', () => { | ||
const origin = jest.requireActual('react-redux'); | ||
return { | ||
...origin, | ||
useDispatch: jest.fn().mockReturnValue(jest.fn()), | ||
}; | ||
}); | ||
|
||
describe('TimelineBottomBar', () => { | ||
test('should render all components for bottom bar', () => { | ||
const { getByTestId } = render( | ||
<TestProviders> | ||
<TimelineBottomBar show={false} timelineId={TimelineId.test} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(getByTestId('timeline-bottom-bar')).toBeInTheDocument(); | ||
expect(getByTestId('timeline-event-count-badge')).toBeInTheDocument(); | ||
expect(getByTestId('timeline-save-status')).toBeInTheDocument(); | ||
expect(getByTestId('timeline-favorite-empty-star')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should not render the event count badge if timeline is open', () => { | ||
const { queryByTestId } = render( | ||
<TestProviders> | ||
<TimelineBottomBar show={true} timelineId={TimelineId.test} /> | ||
</TestProviders> | ||
); | ||
|
||
expect(queryByTestId('timeline-event-count-badge')).not.toBeInTheDocument(); | ||
}); | ||
|
||
test('should dispatch show action when clicking on the title', () => { | ||
const spy = jest.spyOn(timelineActions, 'showTimeline'); | ||
|
||
const { getByTestId } = render( | ||
<TestProviders> | ||
<TimelineBottomBar show={true} timelineId={TimelineId.test} /> | ||
</TestProviders> | ||
); | ||
|
||
getByTestId('timeline-bottom-bar-title-button').click(); | ||
|
||
expect(spy).toHaveBeenCalledWith({ | ||
id: TimelineId.test, | ||
show: true, | ||
}); | ||
}); | ||
}); |
80 changes: 80 additions & 0 deletions
80
x-pack/plugins/security_solution/public/timelines/components/bottom_bar/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import React, { useCallback } from 'react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiLink, EuiPanel } from '@elastic/eui'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { i18n } from '@kbn/i18n'; | ||
import type { State } from '../../../common/store'; | ||
import { selectTitleByTimelineById } from '../../store/selectors'; | ||
import { AddTimelineButton } from '../flyout/add_timeline_button'; | ||
import { timelineActions } from '../../store'; | ||
import { TimelineSaveStatus } from '../save_status'; | ||
import { AddToFavoritesButton } from '../timeline/properties/helpers'; | ||
import { TimelineEventsCountBadge } from '../../../common/hooks/use_timeline_events_count'; | ||
|
||
const openTimelineButton = (title: string) => | ||
i18n.translate('xpack.securitySolution.timeline.bottomBar.toggleButtonAriaLabel', { | ||
values: { title }, | ||
defaultMessage: 'Open timeline {title}', | ||
}); | ||
|
||
interface TimelineBottomBarProps { | ||
/** | ||
* Id of the timeline to be displayed in the bottom bar and within the portal | ||
*/ | ||
timelineId: string; | ||
/** | ||
* True if the timeline modal is open | ||
*/ | ||
show: boolean; | ||
} | ||
|
||
/** | ||
* This component renders the bottom bar for timeline displayed or most of the pages within Security Solution. | ||
*/ | ||
export const TimelineBottomBar = React.memo<TimelineBottomBarProps>(({ show, timelineId }) => { | ||
const dispatch = useDispatch(); | ||
|
||
const handleToggleOpen = useCallback( | ||
() => dispatch(timelineActions.showTimeline({ id: timelineId, show: true })), | ||
[dispatch, timelineId] | ||
); | ||
|
||
const title = useSelector((state: State) => selectTitleByTimelineById(state, timelineId)); | ||
|
||
return ( | ||
<EuiPanel borderRadius="none" data-test-subj="timeline-bottom-bar"> | ||
<EuiFlexGroup gutterSize="xs" alignItems="center" responsive={false}> | ||
<EuiFlexItem grow={false}> | ||
<AddTimelineButton timelineId={timelineId} /> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<AddToFavoritesButton timelineId={timelineId} compact /> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiLink | ||
aria-label={openTimelineButton(title)} | ||
onClick={handleToggleOpen} | ||
data-test-subj="timeline-bottom-bar-title-button" | ||
> | ||
{title} | ||
</EuiLink> | ||
</EuiFlexItem> | ||
{!show && ( // this is a hack because TimelineEventsCountBadge is using react-reverse-portal so the component which is used in multiple places cannot be visible in multiple places at the same time | ||
<EuiFlexItem grow={false} data-test-subj="timeline-event-count-badge"> | ||
<TimelineEventsCountBadge /> | ||
</EuiFlexItem> | ||
)} | ||
<EuiFlexItem grow={false}> | ||
<TimelineSaveStatus timelineId={timelineId} /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
}); | ||
|
||
TimelineBottomBar.displayName = 'TimelineBottomBar'; |
44 changes: 0 additions & 44 deletions
44
...ck/plugins/security_solution/public/timelines/components/flyout/bottom_bar/index.test.tsx
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
x-pack/plugins/security_solution/public/timelines/components/flyout/bottom_bar/index.tsx
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
...k/plugins/security_solution/public/timelines/components/flyout/bottom_bar/translations.ts
This file was deleted.
Oops, something went wrong.
96 changes: 0 additions & 96 deletions
96
...ins/security_solution/public/timelines/components/flyout/header/active_timelines.test.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.