-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Security Solution] Modal for saving timeline #81802
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f6ac479
init modal for saving timeline
angorayc 75b0f65
disable auto save
angorayc 16e35a5
unit test
angorayc 952c036
fix type error
angorayc 6483597
update translation
angorayc 0e8dc51
add unit tests
angorayc d7686f6
rename constant
angorayc b707677
break components into files
angorayc 899336b
autoFocus and close modal on finish
angorayc aa33e3f
rename constant
angorayc acc014b
fix description label
angorayc cbf08e7
update wording
angorayc 6530242
Merge branch 'master' into save-timeline
kibanamachine d453fa2
review
angorayc f272e1c
Merge branch 'save-timeline' of github.com:angorayc/kibana into save-…
angorayc 43104b5
fix dependency
angorayc 44a6cac
remove classname
angorayc d770bcf
update wording
angorayc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
76 changes: 76 additions & 0 deletions
76
...curity_solution/public/timelines/components/timeline/header/save_timeline_button.test.tsx
This file contains hidden or 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,76 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import { shallow, mount } from 'enzyme'; | ||
|
|
||
| import { SaveTimelineButton } from './save_timeline_button'; | ||
| import { act } from '@testing-library/react-hooks'; | ||
|
|
||
| jest.mock('react-redux', () => { | ||
| const actual = jest.requireActual('react-redux'); | ||
| return { | ||
| ...actual, | ||
| useDispatch: jest.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| jest.mock('./title_and_description'); | ||
|
|
||
| describe('SaveTimelineButton', () => { | ||
| const props = { | ||
| timelineId: 'timeline-1', | ||
| showOverlay: false, | ||
| toolTip: 'tooltip message', | ||
| toggleSaveTimeline: jest.fn(), | ||
| onSaveTimeline: jest.fn(), | ||
| updateTitle: jest.fn(), | ||
| updateDescription: jest.fn(), | ||
| }; | ||
| test('Show tooltip', () => { | ||
| const component = shallow(<SaveTimelineButton {...props} />); | ||
| expect(component.find('[data-test-subj="save-timeline-btn-tooltip"]').exists()).toEqual(true); | ||
| }); | ||
|
|
||
| test('Hide tooltip', () => { | ||
| const testProps = { | ||
| ...props, | ||
| showOverlay: true, | ||
| }; | ||
| const component = mount(<SaveTimelineButton {...testProps} />); | ||
| component.find('[data-test-subj="save-timeline-button-icon"]').first().simulate('click'); | ||
|
|
||
| act(() => { | ||
| expect(component.find('[data-test-subj="save-timeline-btn-tooltip"]').exists()).toEqual( | ||
| false | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| test('should show a button with pencil icon', () => { | ||
| const component = shallow(<SaveTimelineButton {...props} />); | ||
| expect(component.find('[data-test-subj="save-timeline-button-icon"]').prop('iconType')).toEqual( | ||
| 'pencil' | ||
| ); | ||
| }); | ||
|
|
||
| test('should not show a modal when showOverlay equals false', () => { | ||
| const component = shallow(<SaveTimelineButton {...props} />); | ||
| expect(component.find('[data-test-subj="save-timeline-modal"]').exists()).toEqual(false); | ||
| }); | ||
|
|
||
| test('should show a modal when showOverlay equals true', () => { | ||
| const testProps = { | ||
| ...props, | ||
| showOverlay: true, | ||
| }; | ||
| const component = mount(<SaveTimelineButton {...testProps} />); | ||
| component.find('[data-test-subj="save-timeline-button-icon"]').first().simulate('click'); | ||
| act(() => { | ||
| expect(component.find('[data-test-subj="save-timeline-modal"]').exists()).toEqual(true); | ||
| }); | ||
| }); | ||
| }); |
87 changes: 87 additions & 0 deletions
87
...ns/security_solution/public/timelines/components/timeline/header/save_timeline_button.tsx
This file contains hidden or 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,87 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { EuiButtonIcon, EuiOverlayMask, EuiModal, EuiToolTip } from '@elastic/eui'; | ||
|
|
||
| import React, { useCallback, useMemo, useState } from 'react'; | ||
| import { useDispatch } from 'react-redux'; | ||
| import { timelineActions } from '../../../store/timeline'; | ||
| import { NOTES_PANEL_WIDTH } from '../properties/notes_size'; | ||
|
|
||
| import { TimelineTitleAndDescription } from './title_and_description'; | ||
| import { EDIT } from './translations'; | ||
|
|
||
| export interface SaveTimelineComponentProps { | ||
| timelineId: string; | ||
| toolTip?: string; | ||
| } | ||
|
|
||
| export const SaveTimelineButton = React.memo<SaveTimelineComponentProps>( | ||
| ({ timelineId, toolTip }) => { | ||
| const [showSaveTimelineOverlay, setShowSaveTimelineOverlay] = useState<boolean>(false); | ||
| const onToggleSaveTimeline = useCallback(() => { | ||
| setShowSaveTimelineOverlay((prevShowSaveTimelineOverlay) => !prevShowSaveTimelineOverlay); | ||
| }, [setShowSaveTimelineOverlay]); | ||
|
|
||
| const dispatch = useDispatch(); | ||
| const updateTitle = useCallback( | ||
| ({ id, title, disableAutoSave }: { id: string; title: string; disableAutoSave?: boolean }) => | ||
| dispatch(timelineActions.updateTitle({ id, title, disableAutoSave })), | ||
| [dispatch] | ||
| ); | ||
|
|
||
| const updateDescription = useCallback( | ||
| ({ | ||
| id, | ||
| description, | ||
| disableAutoSave, | ||
| }: { | ||
| id: string; | ||
| description: string; | ||
| disableAutoSave?: boolean; | ||
| }) => dispatch(timelineActions.updateDescription({ id, description, disableAutoSave })), | ||
| [dispatch] | ||
| ); | ||
|
|
||
| const saveTimelineButtonIcon = useMemo( | ||
| () => ( | ||
| <EuiButtonIcon | ||
| aria-label={EDIT} | ||
| onClick={onToggleSaveTimeline} | ||
| iconType="pencil" | ||
| data-test-subj="save-timeline-button-icon" | ||
| /> | ||
| ), | ||
| [onToggleSaveTimeline] | ||
| ); | ||
|
|
||
| return showSaveTimelineOverlay ? ( | ||
| <> | ||
| {saveTimelineButtonIcon} | ||
| <EuiOverlayMask> | ||
| <EuiModal | ||
| data-test-subj="save-timeline-modal" | ||
| maxWidth={NOTES_PANEL_WIDTH} | ||
| onClose={onToggleSaveTimeline} | ||
| > | ||
| <TimelineTitleAndDescription | ||
| timelineId={timelineId} | ||
| toggleSaveTimeline={onToggleSaveTimeline} | ||
| updateTitle={updateTitle} | ||
| updateDescription={updateDescription} | ||
| /> | ||
| </EuiModal> | ||
| </EuiOverlayMask> | ||
| </> | ||
| ) : ( | ||
| <EuiToolTip content={toolTip || ''} data-test-subj="save-timeline-btn-tooltip"> | ||
| {saveTimelineButtonIcon} | ||
| </EuiToolTip> | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| SaveTimelineButton.displayName = 'SaveTimelineButton'; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.