-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[SIEM] Overview: Recent cases widget #60993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andrew-goldstein
merged 6 commits into
elastic:master
from
andrew-goldstein:recent-cases
Mar 24, 2020
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f4ec3d
## [SIEM] Overview: Recent cases widget
andrew-goldstein 8de3da2
Merge branch 'master' of github.com:elastic/kibana into recent-cases
andrew-goldstein 19e62ec
- pr feedback
andrew-goldstein 16e19a0
Merge branch 'master' of github.com:elastic/kibana into recent-cases
andrew-goldstein 8561c5b
- disable link rendering
andrew-goldstein 8a1a228
Merge branch 'master' of github.com:elastic/kibana into recent-cases
andrew-goldstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
54 changes: 54 additions & 0 deletions
54
x-pack/legacy/plugins/siem/public/components/recent_cases/filters/index.tsx
This file contains hidden or 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,54 @@ | ||
| /* | ||
| * 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 { EuiButtonGroup, EuiButtonGroupOption } from '@elastic/eui'; | ||
| import React, { useMemo } from 'react'; | ||
|
|
||
| import { FilterMode } from '../types'; | ||
|
|
||
| import * as i18n from '../translations'; | ||
|
|
||
| const MY_RECENTLY_REPORTED_ID = 'myRecentlyReported'; | ||
|
|
||
| const toggleButtonIcons: EuiButtonGroupOption[] = [ | ||
| { | ||
| id: 'recentlyCreated', | ||
| label: i18n.RECENTLY_CREATED_CASES, | ||
| iconType: 'folderExclamation', | ||
| }, | ||
| { | ||
| id: MY_RECENTLY_REPORTED_ID, | ||
| label: i18n.MY_RECENTLY_REPORTED_CASES, | ||
| iconType: 'reporter', | ||
| }, | ||
| ]; | ||
|
|
||
| export const Filters = React.memo<{ | ||
| filterBy: FilterMode; | ||
| setFilterBy: (filterBy: FilterMode) => void; | ||
| showMyRecentlyReported: boolean; | ||
| }>(({ filterBy, setFilterBy, showMyRecentlyReported }) => { | ||
| const options = useMemo( | ||
| () => | ||
| showMyRecentlyReported | ||
| ? toggleButtonIcons | ||
| : toggleButtonIcons.filter(x => x.id !== MY_RECENTLY_REPORTED_ID), | ||
| [showMyRecentlyReported] | ||
| ); | ||
|
|
||
| return ( | ||
| <EuiButtonGroup | ||
| options={options} | ||
| idSelected={filterBy} | ||
| onChange={f => { | ||
andrew-goldstein marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setFilterBy(f as FilterMode); | ||
| }} | ||
| isIconOnly | ||
| /> | ||
| ); | ||
| }); | ||
|
|
||
| Filters.displayName = 'Filters'; | ||
75 changes: 75 additions & 0 deletions
75
x-pack/legacy/plugins/siem/public/components/recent_cases/index.tsx
This file contains hidden or 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,75 @@ | ||
| /* | ||
| * 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 { EuiHorizontalRule, EuiLink, EuiText } from '@elastic/eui'; | ||
| import React, { useEffect, useMemo, useRef } from 'react'; | ||
|
|
||
| import { FilterOptions, QueryParams } from '../../containers/case/types'; | ||
| import { DEFAULT_QUERY_PARAMS, useGetCases } from '../../containers/case/use_get_cases'; | ||
| import { getCaseUrl } from '../link_to/redirect_to_case'; | ||
| import { useGetUrlSearch } from '../navigation/use_get_url_search'; | ||
| import { LoadingPlaceholders } from '../page/overview/loading_placeholders'; | ||
| import { navTabs } from '../../pages/home/home_navigations'; | ||
|
|
||
| import { NoCases } from './no_cases'; | ||
| import { RecentCases } from './recent_cases'; | ||
| import * as i18n from './translations'; | ||
|
|
||
| const usePrevious = (value: FilterOptions) => { | ||
| const ref = useRef(); | ||
| useEffect(() => { | ||
| (ref.current as unknown) = value; | ||
| }); | ||
| return ref.current; | ||
| }; | ||
|
|
||
| const MAX_CASES_TO_SHOW = 3; | ||
|
|
||
| const queryParams: QueryParams = { | ||
| ...DEFAULT_QUERY_PARAMS, | ||
| perPage: MAX_CASES_TO_SHOW, | ||
| }; | ||
|
|
||
| const StatefulRecentCasesComponent = React.memo( | ||
| ({ filterOptions }: { filterOptions: FilterOptions }) => { | ||
| const previousFilterOptions = usePrevious(filterOptions); | ||
| const { data, loading, setFilters } = useGetCases(queryParams); | ||
| const isLoadingCases = useMemo( | ||
| () => loading.indexOf('cases') > -1 || loading.indexOf('caseUpdate') > -1, | ||
| [loading] | ||
| ); | ||
| const search = useGetUrlSearch(navTabs.case); | ||
| const allCasesLink = useMemo( | ||
| () => <EuiLink href={getCaseUrl(search)}>{i18n.VIEW_ALL_CASES}</EuiLink>, | ||
| [search] | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| if (previousFilterOptions !== undefined && previousFilterOptions !== filterOptions) { | ||
| setFilters(filterOptions); | ||
| } | ||
| }, [previousFilterOptions, filterOptions, setFilters]); | ||
|
|
||
| return ( | ||
| <EuiText color="subdued" size="s"> | ||
| {isLoadingCases ? ( | ||
andrew-goldstein marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <LoadingPlaceholders lines={2} placeholders={3} /> | ||
| ) : !isLoadingCases && data.cases.length === 0 ? ( | ||
| <NoCases /> | ||
| ) : ( | ||
| <RecentCases cases={data.cases} /> | ||
| )} | ||
|
|
||
| <EuiHorizontalRule margin="s" /> | ||
| <EuiText size="xs">{allCasesLink}</EuiText> | ||
| </EuiText> | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| StatefulRecentCasesComponent.displayName = 'StatefulRecentCasesComponent'; | ||
|
|
||
| export const StatefulRecentCases = React.memo(StatefulRecentCasesComponent); | ||
34 changes: 34 additions & 0 deletions
34
x-pack/legacy/plugins/siem/public/components/recent_cases/no_cases/index.tsx
This file contains hidden or 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; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { EuiLink } from '@elastic/eui'; | ||
| import React, { useMemo } from 'react'; | ||
|
|
||
| import { getCreateCaseUrl } from '../../link_to/redirect_to_case'; | ||
| import { useGetUrlSearch } from '../../navigation/use_get_url_search'; | ||
| import { navTabs } from '../../../pages/home/home_navigations'; | ||
|
|
||
| import * as i18n from '../translations'; | ||
|
|
||
| const NoCasesComponent = () => { | ||
| const urlSearch = useGetUrlSearch(navTabs.case); | ||
| const newCaseLink = useMemo( | ||
| () => <EuiLink href={getCreateCaseUrl(urlSearch)}>{` ${i18n.START_A_NEW_CASE}`}</EuiLink>, | ||
| [urlSearch] | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| <span>{i18n.NO_CASES}</span> | ||
| {newCaseLink} | ||
| {'!'} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| NoCasesComponent.displayName = 'NoCasesComponent'; | ||
|
|
||
| export const NoCases = React.memo(NoCasesComponent); |
60 changes: 60 additions & 0 deletions
60
x-pack/legacy/plugins/siem/public/components/recent_cases/recent_cases.tsx
This file contains hidden or 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,60 @@ | ||
| /* | ||
| * 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, EuiSpacer, EuiText } from '@elastic/eui'; | ||
| import React from 'react'; | ||
| import styled from 'styled-components'; | ||
|
|
||
| import { Case } from '../../containers/case/types'; | ||
| import { getCaseDetailsUrl } from '../link_to/redirect_to_case'; | ||
| import { Markdown } from '../markdown'; | ||
| import { useGetUrlSearch } from '../navigation/use_get_url_search'; | ||
| import { navTabs } from '../../pages/home/home_navigations'; | ||
| import { IconWithCount } from '../recent_timelines/counts'; | ||
|
|
||
| import * as i18n from './translations'; | ||
|
|
||
| const MarkdownContainer = styled.div` | ||
| max-height: 150px; | ||
| overflow-y: auto; | ||
| width: 300px; | ||
| `; | ||
|
|
||
| const RecentCasesComponent = ({ cases }: { cases: Case[] }) => { | ||
| const search = useGetUrlSearch(navTabs.case); | ||
|
|
||
| return ( | ||
| <> | ||
| {cases.map((c, i) => ( | ||
| <EuiFlexGroup key={c.id} gutterSize="none" justifyContent="spaceBetween"> | ||
| <EuiFlexItem grow={false}> | ||
| <EuiText size="s"> | ||
| <EuiLink href={getCaseDetailsUrl({ id: c.id, search })}>{c.title}</EuiLink> | ||
| </EuiText> | ||
|
|
||
| <IconWithCount | ||
| count={c.commentIds.length} | ||
| icon={'editorComment'} | ||
| tooltip={i18n.COMMENTS} | ||
| /> | ||
| {c.description && c.description.length && ( | ||
| <MarkdownContainer> | ||
| <EuiText color="subdued" size="xs"> | ||
| <Markdown raw={c.description} /> | ||
| </EuiText> | ||
| </MarkdownContainer> | ||
| )} | ||
| {i !== cases.length - 1 && <EuiSpacer size="l" />} | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| ))} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| RecentCasesComponent.displayName = 'RecentCasesComponent'; | ||
|
|
||
| export const RecentCases = React.memo(RecentCasesComponent); |
37 changes: 37 additions & 0 deletions
37
x-pack/legacy/plugins/siem/public/components/recent_cases/translations.ts
This file contains hidden or 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,37 @@ | ||
| /* | ||
| * 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 { i18n } from '@kbn/i18n'; | ||
|
|
||
| export const COMMENTS = i18n.translate('xpack.siem.recentCases.commentsTooltip', { | ||
| defaultMessage: 'Comments', | ||
| }); | ||
|
|
||
| export const MY_RECENTLY_REPORTED_CASES = i18n.translate( | ||
| 'xpack.siem.overview.myRecentlyReportedCasesButtonLabel', | ||
| { | ||
| defaultMessage: 'My recently reported cases', | ||
| } | ||
| ); | ||
|
|
||
| export const NO_CASES = i18n.translate('xpack.siem.recentCases.noCasesMessage', { | ||
| defaultMessage: 'No cases have been created yet. Put your detective hat on and', | ||
| }); | ||
|
|
||
| export const RECENTLY_CREATED_CASES = i18n.translate( | ||
| 'xpack.siem.overview.recentlyCreatedCasesButtonLabel', | ||
| { | ||
| defaultMessage: 'Recently created cases', | ||
| } | ||
| ); | ||
|
|
||
| export const START_A_NEW_CASE = i18n.translate('xpack.siem.recentCases.startNewCaseLink', { | ||
| defaultMessage: 'start a new case', | ||
| }); | ||
|
|
||
| export const VIEW_ALL_CASES = i18n.translate('xpack.siem.recentCases.viewAllCasesLink', { | ||
| defaultMessage: 'View all cases', | ||
| }); |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/siem/public/components/recent_cases/types.ts
This file contains hidden or 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 type FilterMode = 'recentlyCreated' | 'myRecentlyReported'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.