From feec81c7b3d345bd36fb50e27a200cca8f62a222 Mon Sep 17 00:00:00 2001 From: Steph Milovic Date: Tue, 10 Mar 2020 15:51:34 -0500 Subject: [PATCH] [SIEM] [Case] Insert timeline into case textarea (#59586) (#59802) --- .../components/markdown_editor/form.tsx | 28 +- .../components/markdown_editor/index.tsx | 177 ++++++----- .../insert_timeline_popover/index.tsx | 85 ++++++ .../use_insert_timeline.tsx | 44 +++ .../timeline/search_super_select/index.tsx | 283 ++---------------- .../timeline/selectable_timeline/index.tsx | 276 +++++++++++++++++ .../{search_super_select => }/translations.ts | 4 + .../siem/public/containers/case/api.ts | 12 +- .../containers/case/use_update_comment.tsx | 11 +- .../case/components/add_comment/index.tsx | 19 +- .../case/components/all_cases/index.test.tsx | 8 +- .../pages/case/components/create/index.tsx | 16 +- .../components/user_action_tree/index.tsx | 2 +- .../components/user_action_tree/schema.ts | 23 ++ .../user_action_tree/user_action_markdown.tsx | 64 ++-- .../siem/public/pages/case/translations.ts | 4 + .../components/description_step/index.tsx | 2 +- .../step_about_rule/default_value.ts | 2 +- .../api/cases/comments/patch_comment.ts | 2 +- 19 files changed, 692 insertions(+), 370 deletions(-) create mode 100644 x-pack/legacy/plugins/siem/public/components/timeline/insert_timeline_popover/index.tsx create mode 100644 x-pack/legacy/plugins/siem/public/components/timeline/insert_timeline_popover/use_insert_timeline.tsx create mode 100644 x-pack/legacy/plugins/siem/public/components/timeline/selectable_timeline/index.tsx rename x-pack/legacy/plugins/siem/public/components/timeline/{search_super_select => }/translations.ts (84%) create mode 100644 x-pack/legacy/plugins/siem/public/pages/case/components/user_action_tree/schema.ts diff --git a/x-pack/legacy/plugins/siem/public/components/markdown_editor/form.tsx b/x-pack/legacy/plugins/siem/public/components/markdown_editor/form.tsx index 3c5287a6fac24..17c321b15418c 100644 --- a/x-pack/legacy/plugins/siem/public/components/markdown_editor/form.tsx +++ b/x-pack/legacy/plugins/siem/public/components/markdown_editor/form.tsx @@ -8,23 +8,27 @@ import { EuiFormRow } from '@elastic/eui'; import React, { useCallback } from 'react'; import { FieldHook, getFieldValidityAndErrorMessage } from '../../shared_imports'; -import { MarkdownEditor } from '.'; +import { CursorPosition, MarkdownEditor } from '.'; interface IMarkdownEditorForm { + bottomRightContent?: React.ReactNode; dataTestSubj: string; field: FieldHook; idAria: string; isDisabled: boolean; + onCursorPositionUpdate?: (cursorPosition: CursorPosition) => void; placeholder?: string; - footerContentRight?: React.ReactNode; + topRightContent?: React.ReactNode; } export const MarkdownEditorForm = ({ + bottomRightContent, dataTestSubj, field, idAria, isDisabled = false, + onCursorPositionUpdate, placeholder, - footerContentRight, + topRightContent, }: IMarkdownEditorForm) => { const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage(field); @@ -37,21 +41,23 @@ export const MarkdownEditorForm = ({ return ( ); diff --git a/x-pack/legacy/plugins/siem/public/components/markdown_editor/index.tsx b/x-pack/legacy/plugins/siem/public/components/markdown_editor/index.tsx index 8572b447cced8..ee004a3c572bb 100644 --- a/x-pack/legacy/plugins/siem/public/components/markdown_editor/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/markdown_editor/index.tsx @@ -12,7 +12,7 @@ import { EuiTabbedContent, EuiTextArea, } from '@elastic/eui'; -import React, { useEffect, useMemo, useState } from 'react'; +import React, { useMemo, useCallback, ChangeEvent } from 'react'; import styled, { css } from 'styled-components'; import { Markdown } from '../markdown'; @@ -28,9 +28,25 @@ const Container = styled(EuiPanel)` padding: 0; background: ${theme.eui.euiColorLightestShade}; position: relative; + .markdown-tabs-header { + position: absolute; + top: ${theme.eui.euiSizeS}; + right: ${theme.eui.euiSizeS}; + z-index: ${theme.eui.euiZContentMenu}; + } .euiTab { padding: 10px; } + .markdown-tabs { + width: 100%; + } + .markdown-tabs-footer { + height: 41px; + padding: 0 ${theme.eui.euiSizeM}; + .euiLink { + font-size: ${theme.eui.euiSizeM}; + } + } .euiFormRow__labelWrapper { position: absolute; top: -${theme.eui.euiSizeL}; @@ -41,81 +57,108 @@ const Container = styled(EuiPanel)` `} `; -const Tabs = styled(EuiTabbedContent)` - width: 100%; -`; - -const Footer = styled(EuiFlexGroup)` - ${({ theme }) => css` - height: 41px; - padding: 0 ${theme.eui.euiSizeM}; - .euiLink { - font-size: ${theme.eui.euiSizeM}; - } - `} -`; - const MarkdownContainer = styled(EuiPanel)` min-height: 150px; overflow: auto; `; +export interface CursorPosition { + start: number; + end: number; +} + /** An input for entering a new case description */ export const MarkdownEditor = React.memo<{ - placeholder?: string; - footerContentRight?: React.ReactNode; - initialContent: string; + bottomRightContent?: React.ReactNode; + topRightContent?: React.ReactNode; + content: string; isDisabled?: boolean; onChange: (description: string) => void; -}>(({ placeholder, footerContentRight, initialContent, isDisabled = false, onChange }) => { - const [content, setContent] = useState(initialContent); - useEffect(() => { - onChange(content); - }, [content]); - const tabs = useMemo( - () => [ - { - id: 'comment', - name: i18n.MARKDOWN, - content: ( -