-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
374e3c8
commit 5c8e98a
Showing
62 changed files
with
1,356 additions
and
456 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
2 changes: 1 addition & 1 deletion
2
x-pack/legacy/plugins/siem/public/components/header_global/__snapshots__/index.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...acy/plugins/siem/public/components/header_page/__snapshots__/editable_title.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/siem/public/components/markdown_editor/constants.ts
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,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const MARKDOWN_HELP_LINK = 'https://www.markdownguide.org/cheat-sheet/'; |
58 changes: 58 additions & 0 deletions
58
x-pack/legacy/plugins/siem/public/components/markdown_editor/form.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,58 @@ | ||
/* | ||
* 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 { EuiFormRow } from '@elastic/eui'; | ||
import React, { useCallback } from 'react'; | ||
|
||
import { FieldHook, getFieldValidityAndErrorMessage } from '../../shared_imports'; | ||
import { MarkdownEditor } from '.'; | ||
|
||
interface IMarkdownEditorForm { | ||
dataTestSubj: string; | ||
field: FieldHook; | ||
idAria: string; | ||
isDisabled: boolean; | ||
placeholder?: string; | ||
footerContentRight?: React.ReactNode; | ||
} | ||
export const MarkdownEditorForm = ({ | ||
dataTestSubj, | ||
field, | ||
idAria, | ||
isDisabled = false, | ||
placeholder, | ||
footerContentRight, | ||
}: IMarkdownEditorForm) => { | ||
const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage(field); | ||
|
||
const handleContentChange = useCallback( | ||
(newContent: string) => { | ||
field.setValue(newContent); | ||
}, | ||
[field] | ||
); | ||
|
||
return ( | ||
<EuiFormRow | ||
label={field.label} | ||
labelAppend={field.labelAppend} | ||
helpText={field.helpText} | ||
error={errorMessage} | ||
isInvalid={isInvalid} | ||
fullWidth | ||
data-test-subj={dataTestSubj} | ||
describedByIds={idAria ? [idAria] : undefined} | ||
> | ||
<MarkdownEditor | ||
initialContent={field.value as string} | ||
isDisabled={isDisabled} | ||
footerContentRight={footerContentRight} | ||
onChange={handleContentChange} | ||
placeholder={placeholder} | ||
/> | ||
</EuiFormRow> | ||
); | ||
}; |
121 changes: 121 additions & 0 deletions
121
x-pack/legacy/plugins/siem/public/components/markdown_editor/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,121 @@ | ||
/* | ||
* 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 { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiLink, | ||
EuiPanel, | ||
EuiTabbedContent, | ||
EuiTextArea, | ||
} from '@elastic/eui'; | ||
import React, { useEffect, useMemo, useState } from 'react'; | ||
import styled, { css } from 'styled-components'; | ||
|
||
import { Markdown } from '../markdown'; | ||
import * as i18n from './translations'; | ||
import { MARKDOWN_HELP_LINK } from './constants'; | ||
|
||
const TextArea = styled(EuiTextArea)` | ||
width: 100%; | ||
`; | ||
|
||
const Container = styled(EuiPanel)` | ||
${({ theme }) => css` | ||
padding: 0; | ||
background: ${theme.eui.euiColorLightestShade}; | ||
position: relative; | ||
.euiTab { | ||
padding: 10px; | ||
} | ||
.euiFormRow__labelWrapper { | ||
position: absolute; | ||
top: -${theme.eui.euiSizeL}; | ||
} | ||
.euiFormErrorText { | ||
padding: 0 ${theme.eui.euiSizeM}; | ||
} | ||
`} | ||
`; | ||
|
||
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; | ||
`; | ||
|
||
/** An input for entering a new case description */ | ||
export const MarkdownEditor = React.memo<{ | ||
placeholder?: string; | ||
footerContentRight?: React.ReactNode; | ||
initialContent: 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: ( | ||
<TextArea | ||
onChange={e => { | ||
setContent(e.target.value); | ||
}} | ||
aria-label={`markdown-editor-comment`} | ||
fullWidth={true} | ||
disabled={isDisabled} | ||
placeholder={placeholder ?? ''} | ||
spellCheck={false} | ||
value={content} | ||
/> | ||
), | ||
}, | ||
{ | ||
id: 'preview', | ||
name: i18n.PREVIEW, | ||
content: ( | ||
<MarkdownContainer data-test-subj="markdown-container" paddingSize="s"> | ||
<Markdown raw={content} /> | ||
</MarkdownContainer> | ||
), | ||
}, | ||
], | ||
[content, isDisabled, placeholder] | ||
); | ||
return ( | ||
<Container> | ||
<Tabs data-test-subj={`markdown-tabs`} size="s" tabs={tabs} initialSelectedTab={tabs[0]} /> | ||
<Footer alignItems="center" gutterSize="none" justifyContent="spaceBetween"> | ||
<EuiFlexItem grow={false}> | ||
<EuiLink href={MARKDOWN_HELP_LINK} external target="_blank"> | ||
{i18n.MARKDOWN_SYNTAX_HELP} | ||
</EuiLink> | ||
</EuiFlexItem> | ||
{footerContentRight && <EuiFlexItem grow={false}>{footerContentRight}</EuiFlexItem>} | ||
</Footer> | ||
</Container> | ||
); | ||
}); | ||
|
||
MarkdownEditor.displayName = 'MarkdownEditor'; |
Oops, something went wrong.