Skip to content

Commit

Permalink
Fix types, rename updates tab to "Updates", upgrade the "diff" lib
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaindik committed Nov 30, 2023
1 parent 56afbfb commit 26ef3e7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@
"deep-freeze-strict": "^1.1.1",
"deepmerge": "^4.2.2",
"del": "^6.1.0",
"diff": "^4.0.1",
"diff": "^5.1.0",
"diff-match-patch": "^1.0.5",
"diff-match-patch-line-and-word": "^0.1.3",
"elastic-apm-node": "^4.1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function splitDiffToLines(diffs: Diff[]): Diff[][] {
const next: Diff[][] = [
...lines.slice(0, -1),
[...lines[lines.length - 1], currentLineRemaining],
...nextLines.map((line: string) => [line]),
...nextLines.map((line) => [line]),
];
return next;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@ import {
import 'react-diff-view/style/index.css';
import type { RenderGutter, HunkData, DecorationProps, TokenizeOptions } from 'react-diff-view';
import unidiff from 'unidiff';
import stringify from 'json-stable-stringify';
import { EuiSpacer, EuiIcon, EuiLink, useEuiTheme, EuiSwitch, EuiRadioGroup } from '@elastic/eui';
import type { RuleResponse } from '../../../../../../common/api/detection_engine/model/rule_schema/rule_schemas.gen';
import { markEditsBy, DiffMethod } from './mark_edits_by_word';
import { sortAndStringifyJson } from './sort_stringify_json';

const sortAndStringifyJson = (jsObject: Record<string, unknown>): string =>
stringify(jsObject, { space: 2 });

interface UnfoldProps extends Omit<DecorationProps, 'children'> {
start: number;
Expand Down Expand Up @@ -407,7 +410,7 @@ interface RuleDiffTabProps {
newRule: RuleResponse;
}

export const RuleDiffTabReactDiffView = ({ oldRule, newRule }: RuleDiffTabProps) => {
export const RuleDiffTab = ({ oldRule, newRule }: RuleDiffTabProps) => {
const options = [
{
id: DiffMethod.CHARS,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ export const INVESTIGATION_GUIDE_TAB_LABEL = i18n.translate(
}
);

export const UPDATES_TAB_LABEL = i18n.translate(
'xpack.securitySolution.detectionEngine.ruleDetails.updatesTabLabel',
{
defaultMessage: 'Updates',
}
);

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 @@ -28,11 +28,10 @@ import {
RuleDetailsFlyout,
TabContentPadding,
} from '../../../../rule_management/components/rule_details/rule_details_flyout';
import * as i18n from './translations';

import { RuleDiffTab } from '../../../../rule_management/components/rule_details/json_diff/rule_diff_tab';
import { MlJobUpgradeModal } from '../../../../../detections/components/modals/ml_job_upgrade_modal';

import { RuleDiffTabReactDiffView } from '../../../../rule_management/components/rule_details/json_diff/rule_diff_tab_react_diff_view';
import * as ruleDetailsI18n from '../../../../rule_management/components/rule_details/translations';
import * as i18n from './translations';

export interface UpgradePrebuiltRulesTableState {
/**
Expand Down Expand Up @@ -292,25 +291,26 @@ export const UpgradePrebuiltRulesTableContextProvider = ({
</EuiButton>
}
getRuleTabs={(rule, defaultTabs) => {
const activeRule = filteredRules.find(({ id }) => rule.id);
const activeRule = filteredRules.find(({ id }) => id === rule.id);

if (!activeRule) {
return defaultTabs;
}

const diffTabReactDiffView = {
id: 'react-diff-view',
name: 'react-diff-view',
const diffTab = {
id: 'updates',
name: ruleDetailsI18n.UPDATES_TAB_LABEL,
content: (
<TabContentPadding>
<RuleDiffTabReactDiffView
<RuleDiffTab
oldRule={activeRule.current_rule}
newRule={activeRule.target_rule}
/>
</TabContentPadding>
),
};

return [diffTabReactDiffView, ...defaultTabs];
return [diffTab, ...defaultTabs];
}}
/>
)}
Expand Down

0 comments on commit 26ef3e7

Please sign in to comment.