-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[SecuritySolution][Detections] Adds UI for new Rule Fields: Related Integrations, Required Fields, and Setup #131475
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
Changes from 5 commits
d2058fd
788acc7
cd706e2
0b48577
b0247a9
8646667
7afa4f7
b38c920
17ede9c
ede4c60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * 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 { EuiLink } from '@elastic/eui'; | ||
| import { capitalize } from 'lodash'; | ||
| import React from 'react'; | ||
| import { RelatedIntegration } from '../../../../common/detection_engine/schemas/common'; | ||
|
|
||
| export const getIntegrationLink = (integration: RelatedIntegration, basePath: string) => { | ||
| const integrationURL = `${basePath}/app/integrations/detail/${integration.package}-${ | ||
| integration.version | ||
| }/overview${integration.integration ? `?integration=${integration.integration}` : ''}`; | ||
| return ( | ||
| <EuiLink href={integrationURL} target="_blank"> | ||
| {`${capitalize(integration.package)} ${capitalize(integration.integration)}`} | ||
| </EuiLink> | ||
| ); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| /* | ||
| * 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, { useState } from 'react'; | ||
| import { | ||
| EuiPopover, | ||
| EuiBadgeGroup, | ||
| EuiBadge, | ||
| EuiPopoverTitle, | ||
| EuiFlexGroup, | ||
| EuiText, | ||
| } from '@elastic/eui'; | ||
| import styled from 'styled-components'; | ||
| import { useBasePath } from '../../lib/kibana'; | ||
| import { getIntegrationLink } from './helpers'; | ||
| import { useInstalledIntegrations } from '../../../detections/containers/detection_engine/rules/use_installed_integrations'; | ||
| import type { | ||
| RelatedIntegration, | ||
| RelatedIntegrationArray, | ||
| } from '../../../../common/detection_engine/schemas/common'; | ||
|
|
||
| import * as i18n from '../../../detections/pages/detection_engine/rules/translations'; | ||
|
|
||
| export interface IntegrationsPopoverProps { | ||
| integrations: RelatedIntegrationArray; | ||
| } | ||
|
|
||
| const IntegrationsPopoverWrapper = styled(EuiFlexGroup)` | ||
| width: 100%; | ||
| `; | ||
|
|
||
| const PopoverWrapper = styled(EuiBadgeGroup)` | ||
| max-height: 400px; | ||
| max-width: 368px; | ||
| overflow: auto; | ||
| line-height: ${({ theme }) => theme.eui.euiLineHeight}; | ||
| `; | ||
|
|
||
| const IntegrationListItem = styled('li')` | ||
| list-style-type: disc; | ||
| margin-left: 25px; | ||
| `; | ||
| /** | ||
| * Component to render installed and available integrations | ||
| * @param integrations - array of integrations to display | ||
| */ | ||
| const IntegrationsPopoverComponent = ({ integrations }: IntegrationsPopoverProps) => { | ||
| const [isPopoverOpen, setPopoverOpen] = useState(false); | ||
| const { data } = useInstalledIntegrations({ packages: [] }); | ||
| // const data = undefined; // To test with installed_integrations endpoint not implemented | ||
| const basePath = useBasePath(); | ||
|
|
||
| const allInstalledIntegrations: RelatedIntegrationArray = data ?? []; | ||
| const availableIntegrations: RelatedIntegrationArray = []; | ||
| const installedIntegrations: RelatedIntegrationArray = []; | ||
|
|
||
| integrations.forEach((i: RelatedIntegration) => { | ||
| const match = allInstalledIntegrations.find( | ||
| (installed) => installed.package === i.package && installed?.integration === i?.integration | ||
| ); | ||
| if (match != null) { | ||
| // TODO: Do version check | ||
| installedIntegrations.push(match); | ||
| } else { | ||
| availableIntegrations.push(i); | ||
| } | ||
| }); | ||
|
|
||
| const badgeTitle = | ||
| data != null | ||
| ? `${installedIntegrations.length}/${integrations.length} ${i18n.INTEGRATIONS_BADGE}` | ||
| : `${integrations.length} ${i18n.INTEGRATIONS_BADGE}`; | ||
|
|
||
| return ( | ||
| <IntegrationsPopoverWrapper | ||
| alignItems="center" | ||
| gutterSize="s" | ||
| data-test-subj={'IntegrationsWrapper'} | ||
| > | ||
| <EuiPopover | ||
| ownFocus | ||
| data-test-subj={'IntegrationsDisplayPopover'} | ||
| button={ | ||
| <EuiBadge | ||
| iconType={'tag'} | ||
| color="hollow" | ||
| data-test-subj={'IntegrationsDisplayPopoverButton'} | ||
| onClick={() => setPopoverOpen(!isPopoverOpen)} | ||
| onClickAriaLabel={badgeTitle} | ||
| > | ||
| {badgeTitle} | ||
| </EuiBadge> | ||
| } | ||
| isOpen={isPopoverOpen} | ||
| closePopover={() => setPopoverOpen(!isPopoverOpen)} | ||
| repositionOnScroll | ||
| > | ||
| <EuiPopoverTitle data-test-subj={'IntegrationsDisplayPopoverTitle'}> | ||
| {i18n.INTEGRATIONS_POPOVER_TITLE(integrations.length)} | ||
| </EuiPopoverTitle> | ||
|
|
||
| <PopoverWrapper data-test-subj={'IntegrationsDisplayPopoverWrapper'}> | ||
| {data != null && ( | ||
| <> | ||
| <EuiText size={'s'}> | ||
| {i18n.INTEGRATIONS_POPOVER_DESCRIPTION_INSTALLED(installedIntegrations.length)} | ||
| </EuiText> | ||
| <ul> | ||
| {installedIntegrations.map((integration, index) => ( | ||
| <IntegrationListItem key={index}> | ||
| {getIntegrationLink(integration, basePath)} | ||
| </IntegrationListItem> | ||
| ))} | ||
| </ul> | ||
| </> | ||
| )} | ||
| {availableIntegrations.length > 0 && ( | ||
| <> | ||
| <EuiText size={'s'}> | ||
| {i18n.INTEGRATIONS_POPOVER_DESCRIPTION_UNINSTALLED(availableIntegrations.length)} | ||
| </EuiText> | ||
| <ul> | ||
| {availableIntegrations.map((integration, index) => ( | ||
| <IntegrationListItem key={index}> | ||
| {getIntegrationLink(integration, basePath)} | ||
| </IntegrationListItem> | ||
| ))} | ||
| </ul> | ||
| </> | ||
| )} | ||
| </PopoverWrapper> | ||
| </EuiPopover> | ||
| </IntegrationsPopoverWrapper> | ||
| ); | ||
| }; | ||
|
|
||
| const MemoizedIntegrationsPopover = React.memo(IntegrationsPopoverComponent); | ||
| MemoizedIntegrationsPopover.displayName = 'IntegrationsPopover'; | ||
|
|
||
| export const IntegrationsPopover = | ||
| MemoizedIntegrationsPopover as typeof IntegrationsPopoverComponent; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,15 +13,14 @@ import { | |
| EuiBasicTable, | ||
| EuiButton, | ||
| EuiEmptyPrompt, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiIcon, | ||
| EuiLink, | ||
| EuiText, | ||
| } from '@elastic/eui'; | ||
|
|
||
| import styled from 'styled-components'; | ||
| import { useMlHref, ML_PAGES } from '@kbn/ml-plugin/public'; | ||
| import { PopoverItems } from '../../popover_items'; | ||
| import { useBasePath, useKibana } from '../../../lib/kibana'; | ||
| import * as i18n from './translations'; | ||
| import { JobSwitch } from './job_switch'; | ||
|
|
@@ -82,16 +81,24 @@ const getJobsTableColumns = ( | |
| }, | ||
| { | ||
| name: i18n.COLUMN_GROUPS, | ||
| render: ({ groups }: SecurityJob) => ( | ||
| <EuiFlexGroup wrap responsive={true} gutterSize="xs"> | ||
| {groups.map((group) => ( | ||
| <EuiFlexItem grow={false} key={group}> | ||
| <EuiBadge color={'hollow'}>{group}</EuiBadge> | ||
| </EuiFlexItem> | ||
| ))} | ||
| </EuiFlexGroup> | ||
| ), | ||
| width: '140px', | ||
| render: ({ groups }: SecurityJob) => { | ||
| const renderItem = (group: string, i: number) => ( | ||
| <EuiBadge color="hollow" key={`${group}-${i}`} data-test-subj="group"> | ||
| {group} | ||
| </EuiBadge> | ||
| ); | ||
|
|
||
| return ( | ||
| <PopoverItems | ||
| items={groups} | ||
| numberOfItemsToDisplay={0} | ||
| popoverButtonTitle={`${groups.length} Groups`} | ||
| renderItem={renderItem} | ||
| dataTestPrefix="groups" | ||
| /> | ||
|
Comment on lines
+92
to
+98
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't mind this... 😅 I was testing #131166 the other day and had it with the badge overflow. Since in doing this PR I learned of the |
||
| ); | ||
| }, | ||
| width: '80px', | ||
| }, | ||
|
|
||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,9 +76,11 @@ const PopoverItemsComponent = <T extends unknown>({ | |
|
|
||
| return ( | ||
| <PopoverItemsWrapper alignItems="center" gutterSize="s" data-test-subj={dataTestPrefix}> | ||
| <EuiFlexItem grow={1} className="eui-textTruncate"> | ||
| <OverflowList items={items.slice(0, numberOfItemsToDisplay)} /> | ||
| </EuiFlexItem> | ||
| {numberOfItemsToDisplay !== 0 && ( | ||
| <EuiFlexItem grow={1} className="eui-textTruncate"> | ||
| <OverflowList items={items.slice(0, numberOfItemsToDisplay)} /> | ||
| </EuiFlexItem> | ||
| )} | ||
|
Comment on lines
+79
to
+83
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spacing fix from leftover element when displaying empty items. Current implementation/use on Rules Table for Tags didn't exercise this path. |
||
| <EuiPopover | ||
| ownFocus | ||
| data-test-subj={`${dataTestPrefix}DisplayPopover`} | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@banderror -- this is as far as I went with plumbing for the
installed_integrationsAPI. Created this route, and also wired it up to to theuseInstalledIntegrationshook, so should just start working if you return aRelatedIntegrationArrayfrom this route 🙂