-
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] [Endpoint] Event filters uses the new card design (…
…#114126) * Adds new card design to event filters and also adds comments list * Adds nested comments * Hides comments if there are no commentes * Fixes i18n check error because duplicated key * Fix wrong type and unit test * Fixes ts error * Address pr comments and fix unit tests Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
db4bcde
commit 0bf0b94
Showing
13 changed files
with
329 additions
and
77 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
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
68 changes: 68 additions & 0 deletions
68
...ty_solution/public/management/components/artifact_entry_card/components/card_comments.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,68 @@ | ||
/* | ||
* 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, useMemo, useCallback, useState } from 'react'; | ||
import { | ||
CommonProps, | ||
EuiAccordion, | ||
EuiCommentList, | ||
EuiCommentProps, | ||
EuiButtonEmpty, | ||
EuiSpacer, | ||
} from '@elastic/eui'; | ||
import { isEmpty } from 'lodash/fp'; | ||
import { useTestIdGenerator } from '../../hooks/use_test_id_generator'; | ||
import { CardActionsFlexItemProps } from './card_actions_flex_item'; | ||
import { ArtifactInfo } from '../types'; | ||
import { getFormattedComments } from '../utils/get_formatted_comments'; | ||
import { SHOW_COMMENTS_LABEL, HIDE_COMMENTS_LABEL } from './translations'; | ||
|
||
export interface CardCommentsProps | ||
extends CardActionsFlexItemProps, | ||
Pick<CommonProps, 'data-test-subj'> { | ||
comments: ArtifactInfo['comments']; | ||
} | ||
|
||
export const CardComments = memo<CardCommentsProps>( | ||
({ comments, 'data-test-subj': dataTestSubj }) => { | ||
const getTestId = useTestIdGenerator(dataTestSubj); | ||
|
||
const [showComments, setShowComments] = useState(false); | ||
const onCommentsClick = useCallback((): void => { | ||
setShowComments(!showComments); | ||
}, [setShowComments, showComments]); | ||
const formattedComments = useMemo((): EuiCommentProps[] => { | ||
return getFormattedComments(comments); | ||
}, [comments]); | ||
|
||
const buttonText = useMemo( | ||
() => | ||
showComments ? HIDE_COMMENTS_LABEL(comments.length) : SHOW_COMMENTS_LABEL(comments.length), | ||
[comments.length, showComments] | ||
); | ||
|
||
return !isEmpty(comments) ? ( | ||
<div data-test-subj={dataTestSubj}> | ||
<EuiSpacer size="s" /> | ||
<EuiButtonEmpty | ||
onClick={onCommentsClick} | ||
flush="left" | ||
size="xs" | ||
data-test-subj={getTestId('label')} | ||
> | ||
{buttonText} | ||
</EuiButtonEmpty> | ||
<EuiAccordion id={'1'} arrowDisplay="none" forceState={showComments ? 'open' : 'closed'}> | ||
<EuiSpacer size="m" /> | ||
<EuiCommentList comments={formattedComments} data-test-subj={getTestId('list')} /> | ||
</EuiAccordion> | ||
</div> | ||
) : null; | ||
} | ||
); | ||
|
||
CardComments.displayName = 'CardComments'; |
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
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
34 changes: 34 additions & 0 deletions
34
...olution/public/management/components/artifact_entry_card/utils/get_formatted_comments.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,34 @@ | ||
/* | ||
* 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 from 'react'; | ||
import { EuiAvatar, EuiText, EuiCommentProps } from '@elastic/eui'; | ||
import styled from 'styled-components'; | ||
import { CommentsArray } from '@kbn/securitysolution-io-ts-list-types'; | ||
import { COMMENT_EVENT } from '../../../../common/components/exceptions/translations'; | ||
import { FormattedRelativePreferenceDate } from '../../../../common/components/formatted_date'; | ||
|
||
const CustomEuiAvatar = styled(EuiAvatar)` | ||
background-color: ${({ theme }) => theme.eui.euiColorLightShade} !important; | ||
`; | ||
|
||
/** | ||
* Formats ExceptionItem.comments into EuiCommentList format | ||
* | ||
* @param comments ExceptionItem.comments | ||
*/ | ||
export const getFormattedComments = (comments: CommentsArray): EuiCommentProps[] => { | ||
return comments.map((commentItem) => ({ | ||
username: commentItem.created_by, | ||
timestamp: ( | ||
<FormattedRelativePreferenceDate value={commentItem.created_at} dateFormat="MMM D, YYYY" /> | ||
), | ||
event: COMMENT_EVENT, | ||
timelineIcon: <CustomEuiAvatar size="s" name={commentItem.created_by} />, | ||
children: <EuiText size="s">{commentItem.comment}</EuiText>, | ||
})); | ||
}; |
Oops, something went wrong.