Skip to content
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

[Security Solution] Rule Diff Phase 2 components #174564

Merged
merged 27 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
95e1e59
working poc
dplumlee Jan 10, 2024
d6b55b3
adds feature flag
dplumlee Jan 10, 2024
78a7911
adds inline per field display
dplumlee Jan 10, 2024
3992626
adds field sort
dplumlee Jan 17, 2024
58803ca
updates ui
dplumlee Jan 18, 2024
e1ce9f3
updates ui
dplumlee Jan 23, 2024
3e01b6b
addresses comments and changes some types
dplumlee Jan 26, 2024
9405654
Merge remote-tracking branch 'upstream/main' into rule-upgrade-diff-p…
dplumlee Jan 26, 2024
c4fba65
fixes bugs and removes console logs
dplumlee Feb 1, 2024
35e99bd
changes header language
dplumlee Feb 5, 2024
57a92a6
Refactored getFormattedFieldDiff
jpdjere Feb 2, 2024
7bc88ff
Refactored per group util
jpdjere Feb 2, 2024
c0240f3
Renamed props
jpdjere Feb 2, 2024
da1375b
Fixed typing
jpdjere Feb 2, 2024
05070e6
Replace N/A with empty string for non existing fields
jpdjere Feb 2, 2024
1feb961
Merge remote-tracking branch 'upstream/main' into rule-upgrade-diff-p…
dplumlee Feb 5, 2024
0e34460
updates field name render dictionary
dplumlee Feb 5, 2024
2687192
fixes small bugs and adds code comments
dplumlee Feb 7, 2024
c92da27
turns off feature flag
dplumlee Feb 7, 2024
977eae3
typo
dplumlee Feb 7, 2024
18e0db2
turns off feature flag
dplumlee Feb 7, 2024
bc20d45
Merge remote-tracking branch 'upstream/main' into rule-upgrade-diff-p…
dplumlee Feb 7, 2024
95e5155
Merge remote-tracking branch 'upstream/main' into rule-upgrade-diff-p…
dplumlee Feb 8, 2024
4f7171e
adds remaining field groupings
dplumlee Feb 8, 2024
94b4cd8
addresses comments
dplumlee Feb 12, 2024
773501e
Merge remote-tracking branch 'upstream/main' into rule-upgrade-diff-p…
dplumlee Feb 12, 2024
faaec7f
addresses comments
dplumlee Feb 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixes small bugs and adds code comments
  • Loading branch information
dplumlee committed Feb 7, 2024
commit 268719263055731303381a484a4a45783405ab3b
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { EuiFlexGroup, EuiHorizontalRule, EuiTitle } from '@elastic/eui';
import { camelCase, startCase } from 'lodash';
import React from 'react';
import { DiffView } from '../json_diff/diff_view';
import { DiffMethod } from '../json_diff/mark_edits';
import { RuleDiffPanelWrapper } from './panel_wrapper';
import type { FormattedFieldDiff, FieldDiff } from '../../../model/rule_details/rule_field_diff';
import { fieldToDisplayNameMap } from './translations';
Expand All @@ -23,25 +22,19 @@ const SubFieldComponent = ({
}: FieldDiff & {
shouldShowSeparator: boolean;
shouldShowSubtitles: boolean;
}) => {
return (
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexGroup direction="column">
{shouldShowSubtitles ? (
<EuiTitle size="xxxs">
<h4>{fieldToDisplayNameMap[fieldName] ?? startCase(camelCase(fieldName))}</h4>
</EuiTitle>
) : null}
<DiffView
oldSource={currentVersion}
newSource={targetVersion}
diffMethod={DiffMethod.WORDS}
/>
{shouldShowSeparator ? <EuiHorizontalRule margin="s" size="full" /> : null}
</EuiFlexGroup>
}) => (
<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;
Expand All @@ -55,8 +48,8 @@ export const FieldGroupDiffComponent = ({
const { fieldDiffs, shouldShowSubtitles } = ruleDiffs;
return (
<RuleDiffPanelWrapper fieldName={fieldsGroupName}>
{fieldDiffs.map(({ currentVersion, targetVersion, fieldName: specificFieldName }, i) => {
const shouldShowSeparator = i !== fieldDiffs.length - 1;
{fieldDiffs.map(({ currentVersion, targetVersion, fieldName: specificFieldName }, index) => {
const shouldShowSeparator = index !== fieldDiffs.length - 1;
return (
<SubFieldComponent
key={specificFieldName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const RuleDiffHeaderBar = () => {
position: sticky;
top: 0;
background: ${euiTheme.colors.emptyShade};
z-index: 1; // Fixes accordion button displaying above header bug
`}
>
<EuiSpacer size="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import {
HISTORY_WINDOW_SIZE_FIELD_LABEL,
} from '../translations';

// Used when fields have different display names or formats than their corresponding rule object fields
/**
* Used when fields have different display names or formats than their corresponding rule object fields
*/
export const fieldToDisplayNameMap: Record<string, string> = {
data_source: i18n.translate(
'xpack.securitySolution.detectionEngine.rules.upgradeRuleFields.dataSourceLabel',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { FieldDiff } from '../../../model/rule_details/rule_field_diff';

export const sortAndStringifyJson = (fieldValue: unknown): string => {
if (!fieldValue) {
return '';
return ''; // The JSON diff package we use does not accept `undefined` as a valid entry, empty string renders the equivalent of no field
}

if (typeof fieldValue === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export const getFormattedFieldDiffGroups = (
fieldName: keyof AllFieldsDiff,
fields: Partial<RuleFieldsDiff>
): FormattedFieldDiff => {
/**
* Field types that contain groupings of rule fields must be formatted differently to compare and render
* each individual nested field and to satisfy types
*
* Setting shouldShowSubtitles to `true` displays the grouped field names in the rendered diff component
*/
switch (fieldName) {
case 'data_source':
const dataSourceThreeWayDiff = (fields as RuleFieldsDiffWithDataSource)[fieldName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export const UPDATES_TAB_LABEL = i18n.translate(
}
);

export const JSON_VIEW_UPDATES_TAB_LABEL = i18n.translate(
'xpack.securitySolution.detectionEngine.ruleDetails.jsonViewUpdatesTabLabel',
{
defaultMessage: 'JSON view',
}
);

export const DISMISS_BUTTON_LABEL = i18n.translate(
'xpack.securitySolution.detectionEngine.ruleDetails.dismissButtonLabel',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,20 +283,11 @@ export const UpgradePrebuiltRulesTableContextProvider = ({
}

return [
{
id: 'updates',
name: ruleDetailsI18n.UPDATES_TAB_LABEL,
content: (
<TabContentPadding>
<RuleDiffTab oldRule={activeRule.current_rule} newRule={activeRule.target_rule} />
</TabContentPadding>
),
},
...(isPerFieldPrebuiltRulesDiffingEnabled
? [
{
id: 'perFieldUpdates',
name: 'Per-field Updates', // TODO: eventually will be "updates" too
id: 'updates',
name: ruleDetailsI18n.UPDATES_TAB_LABEL,
content: (
<TabContentPadding>
<PerFieldRuleDiffTab ruleDiff={activeRule.diff} />
Expand All @@ -305,6 +296,15 @@ export const UpgradePrebuiltRulesTableContextProvider = ({
},
]
: []),
{
id: 'jsonViewUpdates',
name: ruleDetailsI18n.JSON_VIEW_UPDATES_TAB_LABEL,
content: (
<TabContentPadding>
<RuleDiffTab oldRule={activeRule.current_rule} newRule={activeRule.target_rule} />
</TabContentPadding>
),
},
];
}, [
previewedRule,
Expand Down