-
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.
[Security Solution][Notes] - limit visible text from note content on …
…notes management page (#195296)
- Loading branch information
1 parent
d051743
commit 69ff471
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
x-pack/plugins/security_solution/public/notes/components/note_content.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,28 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { NoteContent } from './note_content'; | ||
import { NOTE_CONTENT_BUTTON_TEST_ID, NOTE_CONTENT_POPOVER_TEST_ID } from './test_ids'; | ||
|
||
const note = 'note-text'; | ||
|
||
describe('NoteContent', () => { | ||
it('should render a note and the popover', () => { | ||
const { getByTestId, getByText } = render(<NoteContent note={note} />); | ||
|
||
const button = getByTestId(NOTE_CONTENT_BUTTON_TEST_ID); | ||
|
||
expect(button).toBeInTheDocument(); | ||
expect(getByText(note)).toBeInTheDocument(); | ||
|
||
button.click(); | ||
|
||
expect(getByTestId(NOTE_CONTENT_POPOVER_TEST_ID)).toBeInTheDocument(); | ||
}); | ||
}); |
73 changes: 73 additions & 0 deletions
73
x-pack/plugins/security_solution/public/notes/components/note_content.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,73 @@ | ||
/* | ||
* 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, { memo, useCallback, useMemo, useState } from 'react'; | ||
import { EuiButtonEmpty, EuiMarkdownFormat, EuiPopover, useEuiTheme } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { css } from '@emotion/react'; | ||
import { NOTE_CONTENT_BUTTON_TEST_ID, NOTE_CONTENT_POPOVER_TEST_ID } from './test_ids'; | ||
|
||
const OPEN_POPOVER = i18n.translate('xpack.securitySolution.notes.expandRow.buttonLabel', { | ||
defaultMessage: 'Expand', | ||
}); | ||
|
||
export interface NoteContentProps { | ||
/** | ||
* The note content to display | ||
*/ | ||
note: string; | ||
} | ||
|
||
/** | ||
* Renders the note content to be displayed in the notes management table. | ||
* The content is truncated with an expand button to show the full content within the row. | ||
*/ | ||
export const NoteContent = memo(({ note }: NoteContentProps) => { | ||
const { euiTheme } = useEuiTheme(); | ||
|
||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
|
||
const togglePopover = useCallback(() => setIsPopoverOpen((value) => !value), []); | ||
const closePopover = useCallback(() => setIsPopoverOpen(false), []); | ||
|
||
const button = useMemo( | ||
() => ( | ||
<EuiButtonEmpty | ||
title={OPEN_POPOVER} | ||
aria-label={OPEN_POPOVER} | ||
color="text" | ||
flush="left" | ||
onClick={togglePopover} | ||
data-test-subj={NOTE_CONTENT_BUTTON_TEST_ID} | ||
css={css` | ||
height: ${euiTheme.size.l}; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
`} | ||
> | ||
{note} | ||
</EuiButtonEmpty> | ||
), | ||
[euiTheme.size.l, note, togglePopover] | ||
); | ||
|
||
return ( | ||
<EuiPopover | ||
button={button} | ||
isOpen={isPopoverOpen} | ||
closePopover={closePopover} | ||
panelStyle={{ maxWidth: '50%', maxHeight: '50%', overflow: 'auto' }} | ||
> | ||
<EuiMarkdownFormat textSize="s" data-test-subj={NOTE_CONTENT_POPOVER_TEST_ID}> | ||
{note} | ||
</EuiMarkdownFormat> | ||
</EuiPopover> | ||
); | ||
}); | ||
|
||
NoteContent.displayName = 'NoteContent'; |
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