forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SIEM] [Case] Insert timeline into case textarea (elastic#59586)
- Loading branch information
1 parent
4013b9f
commit dbf0177
Showing
19 changed files
with
692 additions
and
370 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
85 changes: 85 additions & 0 deletions
85
x-pack/legacy/plugins/siem/public/components/timeline/insert_timeline_popover/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,85 @@ | ||
/* | ||
* 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, EuiPopover, EuiSelectableOption } from '@elastic/eui'; | ||
import React, { memo, useCallback, useMemo, useState } from 'react'; | ||
|
||
import { OpenTimelineResult } from '../../open_timeline/types'; | ||
import { SelectableTimeline } from '../selectable_timeline'; | ||
import * as i18n from '../translations'; | ||
|
||
interface InsertTimelinePopoverProps { | ||
isDisabled: boolean; | ||
hideUntitled?: boolean; | ||
onTimelineChange: (timelineTitle: string, timelineId: string | null) => void; | ||
} | ||
|
||
const InsertTimelinePopoverComponent: React.FC<InsertTimelinePopoverProps> = ({ | ||
isDisabled, | ||
hideUntitled = false, | ||
onTimelineChange, | ||
}) => { | ||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
|
||
const handleClosePopover = useCallback(() => { | ||
setIsPopoverOpen(false); | ||
}, []); | ||
|
||
const handleOpenPopover = useCallback(() => { | ||
setIsPopoverOpen(true); | ||
}, []); | ||
|
||
const insertTimelineButton = useMemo( | ||
() => ( | ||
<EuiButtonIcon | ||
aria-label={i18n.INSERT_TIMELINE} | ||
data-test-subj="insert-timeline-button" | ||
iconType="timeline" | ||
isDisabled={isDisabled} | ||
onClick={handleOpenPopover} | ||
/> | ||
), | ||
[handleOpenPopover, isDisabled] | ||
); | ||
|
||
const handleGetSelectableOptions = useCallback( | ||
({ timelines }) => [ | ||
...timelines | ||
.filter((t: OpenTimelineResult) => !hideUntitled || t.title !== '') | ||
.map( | ||
(t: OpenTimelineResult, index: number) => | ||
({ | ||
description: t.description, | ||
favorite: t.favorite, | ||
label: t.title, | ||
id: t.savedObjectId, | ||
key: `${t.title}-${index}`, | ||
title: t.title, | ||
checked: undefined, | ||
} as EuiSelectableOption) | ||
), | ||
], | ||
[hideUntitled] | ||
); | ||
|
||
return ( | ||
<EuiPopover | ||
id="searchTimelinePopover" | ||
button={insertTimelineButton} | ||
isOpen={isPopoverOpen} | ||
closePopover={handleClosePopover} | ||
> | ||
<SelectableTimeline | ||
hideUntitled={hideUntitled} | ||
getSelectableOptions={handleGetSelectableOptions} | ||
onClosePopover={handleClosePopover} | ||
onTimelineChange={onTimelineChange} | ||
/> | ||
</EuiPopover> | ||
); | ||
}; | ||
|
||
export const InsertTimelinePopover = memo(InsertTimelinePopoverComponent); |
Oops, something went wrong.