forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Rule Diff Phase 2 components (elastic#174564)
## Summary Addresses elastic#166489 Docs issue: elastic/security-docs#4783 Adds per-field diffs for the rule upgrade flyout ### Acceptance Criteria - [x] The tab with per-field diffs is hidden behind a new feature flag. When the flag is off, the tab does not appear in the flyout. The tab should work regardless of the value of `jsonPrebuiltRulesDiffingEnabled`. - [x] Per-field diffs are read-only components. We don't need to let the user "merge" differences using these components. - [x] Diffs for complex fields are rendered as JSON diffs using the same component used for rendering the JSON diff for the whole rule. This means this component should be abstracted away and should accept `unknown` values in props instead of `RuleResponse`. - [x] Diffs for related fields are grouped or rendered close to each other. For example: - [x] Index patterns + Data view id - [x] Custom query + Filters + Language + Saved query id - [x] The tab uses the response from the `upgrade/_review` API endpoint and doesn't need any other API calls to render itself. - [x] The tab renders itself under 150ms. ### Screenshots <img width="1587" alt="Screenshot 2024-02-07 at 1 36 34 AM" src="https://github.com/elastic/kibana/assets/56367316/85dce529-064e-4025-b82c-2e89f6ec800b"> <img width="994" alt="Screenshot 2024-02-07 at 1 36 52 AM" src="https://github.com/elastic/kibana/assets/56367316/c226973f-ad46-4565-90c0-437316b138b4"> ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: jpdjere <[email protected]>
- Loading branch information
1 parent
d273ca4
commit e8ddd22
Showing
21 changed files
with
1,187 additions
and
18 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
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
66 changes: 66 additions & 0 deletions
66
...c/detection_engine/rule_management/components/rule_details/diff_components/field_diff.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,66 @@ | ||
/* | ||
* 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 { EuiFlexGroup, EuiHorizontalRule, EuiTitle } from '@elastic/eui'; | ||
import { camelCase, startCase } from 'lodash'; | ||
import React from 'react'; | ||
import { DiffView } from '../json_diff/diff_view'; | ||
import { RuleDiffPanelWrapper } from './panel_wrapper'; | ||
import type { FormattedFieldDiff, FieldDiff } from '../../../model/rule_details/rule_field_diff'; | ||
import { fieldToDisplayNameMap } from './translations'; | ||
|
||
const SubFieldComponent = ({ | ||
currentVersion, | ||
targetVersion, | ||
fieldName, | ||
shouldShowSeparator, | ||
shouldShowSubtitles, | ||
}: FieldDiff & { | ||
shouldShowSeparator: boolean; | ||
shouldShowSubtitles: boolean; | ||
}) => ( | ||
<EuiFlexGroup justifyContent="spaceBetween"> | ||
<EuiFlexGroup direction="column"> | ||
{shouldShowSubtitles ? ( | ||
<EuiTitle size="xxxs"> | ||
<h4>{fieldToDisplayNameMap[fieldName] ?? startCase(camelCase(fieldName))}</h4> | ||
</EuiTitle> | ||
) : null} | ||
<DiffView oldSource={currentVersion} newSource={targetVersion} /> | ||
{shouldShowSeparator ? <EuiHorizontalRule margin="s" size="full" /> : null} | ||
</EuiFlexGroup> | ||
</EuiFlexGroup> | ||
); | ||
|
||
export interface FieldDiffComponentProps { | ||
ruleDiffs: FormattedFieldDiff; | ||
fieldsGroupName: string; | ||
} | ||
|
||
export const FieldGroupDiffComponent = ({ | ||
ruleDiffs, | ||
fieldsGroupName, | ||
}: FieldDiffComponentProps) => { | ||
const { fieldDiffs, shouldShowSubtitles } = ruleDiffs; | ||
return ( | ||
<RuleDiffPanelWrapper fieldName={fieldsGroupName}> | ||
{fieldDiffs.map(({ currentVersion, targetVersion, fieldName: specificFieldName }, index) => { | ||
const shouldShowSeparator = index !== fieldDiffs.length - 1; | ||
return ( | ||
<SubFieldComponent | ||
key={specificFieldName} | ||
shouldShowSeparator={shouldShowSeparator} | ||
shouldShowSubtitles={shouldShowSubtitles} | ||
currentVersion={currentVersion} | ||
targetVersion={targetVersion} | ||
fieldName={specificFieldName} | ||
/> | ||
); | ||
})} | ||
</RuleDiffPanelWrapper> | ||
); | ||
}; |
60 changes: 60 additions & 0 deletions
60
...c/detection_engine/rule_management/components/rule_details/diff_components/header_bar.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,60 @@ | ||
/* | ||
* 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 { | ||
EuiFlexGroup, | ||
EuiHorizontalRule, | ||
EuiIconTip, | ||
EuiSpacer, | ||
EuiTitle, | ||
useEuiTheme, | ||
} from '@elastic/eui'; | ||
import React from 'react'; | ||
import { css } from '@emotion/css'; | ||
import * as i18n from '../json_diff/translations'; | ||
|
||
export const RuleDiffHeaderBar = () => { | ||
const { euiTheme } = useEuiTheme(); | ||
return ( | ||
<div | ||
css={css` | ||
position: sticky; | ||
top: 0; | ||
background: ${euiTheme.colors.emptyShade}; | ||
z-index: 1; // Fixes accordion button displaying above header bug | ||
`} | ||
> | ||
<EuiSpacer size="m" /> | ||
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center"> | ||
<EuiFlexGroup alignItems="baseline" gutterSize="xs"> | ||
<EuiIconTip | ||
color="subdued" | ||
content={i18n.CURRENT_VERSION_DESCRIPTION} | ||
type="iInCircle" | ||
size="m" | ||
display="block" | ||
/> | ||
<EuiTitle size="xxs"> | ||
<h6>{i18n.CURRENT_RULE_VERSION}</h6> | ||
</EuiTitle> | ||
</EuiFlexGroup> | ||
<EuiFlexGroup alignItems="baseline" gutterSize="xs"> | ||
<EuiIconTip | ||
color="subdued" | ||
content={i18n.UPDATED_VERSION_DESCRIPTION} | ||
type="iInCircle" | ||
size="m" | ||
/> | ||
<EuiTitle size="xxs"> | ||
<h6>{i18n.ELASTIC_UPDATE_VERSION}</h6> | ||
</EuiTitle> | ||
</EuiFlexGroup> | ||
</EuiFlexGroup> | ||
<EuiHorizontalRule margin="s" size="full" /> | ||
</div> | ||
); | ||
}; |
11 changes: 11 additions & 0 deletions
11
.../public/detection_engine/rule_management/components/rule_details/diff_components/index.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,11 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './field_diff'; | ||
export * from './header_bar'; | ||
export * from './panel_wrapper'; | ||
export * from './rule_diff_section'; |
43 changes: 43 additions & 0 deletions
43
...etection_engine/rule_management/components/rule_details/diff_components/panel_wrapper.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,43 @@ | ||
/* | ||
* 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 { EuiAccordion, EuiSplitPanel, EuiTitle, useEuiTheme } from '@elastic/eui'; | ||
import { camelCase, startCase } from 'lodash'; | ||
import { css } from '@emotion/css'; | ||
import React from 'react'; | ||
import { fieldToDisplayNameMap } from './translations'; | ||
|
||
interface RuleDiffPanelWrapperProps { | ||
fieldName: string; | ||
children: React.ReactNode; | ||
} | ||
|
||
export const RuleDiffPanelWrapper = ({ fieldName, children }: RuleDiffPanelWrapperProps) => { | ||
const { euiTheme } = useEuiTheme(); | ||
|
||
return ( | ||
<EuiSplitPanel.Outer hasBorder> | ||
<EuiAccordion | ||
initialIsOpen={true} | ||
css={css` | ||
.euiAccordion__triggerWrapper { | ||
background: ${euiTheme.colors.lightestShade}; | ||
padding: ${euiTheme.size.m}; | ||
} | ||
`} | ||
id={fieldName} | ||
buttonContent={ | ||
<EuiTitle size="xs"> | ||
<h5>{fieldToDisplayNameMap[fieldName] ?? startCase(camelCase(fieldName))}</h5> | ||
</EuiTitle> | ||
} | ||
> | ||
<EuiSplitPanel.Inner color="transparent">{children}</EuiSplitPanel.Inner> | ||
</EuiAccordion> | ||
</EuiSplitPanel.Outer> | ||
); | ||
}; |
43 changes: 43 additions & 0 deletions
43
...tion_engine/rule_management/components/rule_details/diff_components/rule_diff_section.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,43 @@ | ||
/* | ||
* 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 { EuiAccordion, EuiSpacer, EuiTitle } from '@elastic/eui'; | ||
import React from 'react'; | ||
import { css } from '@emotion/css'; | ||
import type { FieldsGroupDiff } from '../../../model/rule_details/rule_field_diff'; | ||
import { FieldGroupDiffComponent } from './field_diff'; | ||
|
||
interface RuleDiffSectionProps { | ||
title: string; | ||
fieldGroups: FieldsGroupDiff[]; | ||
} | ||
|
||
export const RuleDiffSection = ({ title, fieldGroups }: RuleDiffSectionProps) => ( | ||
<> | ||
<EuiSpacer size="m" /> | ||
<EuiAccordion | ||
initialIsOpen={true} | ||
id={title} | ||
css={css` | ||
padding-top: 1px; // Fixes border disappearing bug | ||
`} | ||
buttonContent={ | ||
<EuiTitle size="s"> | ||
<h3>{title}</h3> | ||
</EuiTitle> | ||
} | ||
> | ||
{fieldGroups.map(({ fieldsGroupName, formattedDiffs }) => { | ||
return ( | ||
<React.Fragment key={fieldsGroupName}> | ||
<EuiSpacer size="m" /> | ||
<FieldGroupDiffComponent ruleDiffs={formattedDiffs} fieldsGroupName={fieldsGroupName} /> | ||
</React.Fragment> | ||
); | ||
})} | ||
</EuiAccordion> | ||
</> | ||
); |
Oops, something went wrong.