Skip to content

Commit

Permalink
[8.x] [Security Solution] Update footer link in rule preview to go to…
Browse files Browse the repository at this point in the history
… rule details page (#195806) (#195833)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] Update footer link in rule preview to go to rule
details page (#195806)](#195806)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"christineweng","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-10T21:59:54Z","message":"[Security
Solution] Update footer link in rule preview to go to rule details page
(#195806)\n\n## Summary\r\n\r\nCurrently, the rule preview footer will
open the rule flyout. Although\r\nthis behavior is consistent with other
previews (host, user, alert\r\netc.), the rule flyout does not provide
additional information for\r\nusers. This PR updates the footer go to
rule details page
instead.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/6de03775-b1a4-41b9-b233-7817d6cca8ec\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Jan Monschke
<[email protected]>","sha":"a397bb72d52e865d0f44c6983bf01c85875251e8","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Threat
Hunting","Team:Threat
Hunting:Investigations","backport:prev-major","v8.16.0"],"title":"[Security
Solution] Update footer link in rule preview to go to rule details
page","number":195806,"url":"https://github.com/elastic/kibana/pull/195806","mergeCommit":{"message":"[Security
Solution] Update footer link in rule preview to go to rule details page
(#195806)\n\n## Summary\r\n\r\nCurrently, the rule preview footer will
open the rule flyout. Although\r\nthis behavior is consistent with other
previews (host, user, alert\r\netc.), the rule flyout does not provide
additional information for\r\nusers. This PR updates the footer go to
rule details page
instead.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/6de03775-b1a4-41b9-b233-7817d6cca8ec\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Jan Monschke
<[email protected]>","sha":"a397bb72d52e865d0f44c6983bf01c85875251e8"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195806","number":195806,"mergeCommit":{"message":"[Security
Solution] Update footer link in rule preview to go to rule details page
(#195806)\n\n## Summary\r\n\r\nCurrently, the rule preview footer will
open the rule flyout. Although\r\nthis behavior is consistent with other
previews (host, user, alert\r\netc.), the rule flyout does not provide
additional information for\r\nusers. This PR updates the footer go to
rule details page
instead.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/6de03775-b1a4-41b9-b233-7817d6cca8ec\r\n\r\n\r\n###
Checklist\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Jan Monschke
<[email protected]>","sha":"a397bb72d52e865d0f44c6983bf01c85875251e8"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: christineweng <[email protected]>
  • Loading branch information
kibanamachine and christineweng authored Oct 10, 2024
1 parent afebfae commit 7f4fd42
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ import { render } from '@testing-library/react';
import React from 'react';
import { RULE_PREVIEW_FOOTER_TEST_ID, RULE_PREVIEW_OPEN_RULE_FLYOUT_TEST_ID } from './test_ids';
import { PreviewFooter } from './footer';
import { mockFlyoutApi } from '../../document_details/shared/mocks/mock_flyout_context';
import { useExpandableFlyoutApi } from '@kbn/expandable-flyout';
import { RulePanelKey } from '../right';
import { useRuleDetailsLink } from '../../document_details/shared/hooks/use_rule_details_link';
import { TestProviders } from '../../../common/mock';

jest.mock('@kbn/expandable-flyout');
jest.mock('../../document_details/shared/hooks/use_rule_details_link');

const renderRulePreviewFooter = () => render(<PreviewFooter ruleId="ruleid" />);
const renderRulePreviewFooter = () =>
render(
<TestProviders>
<PreviewFooter ruleId="ruleid" />
</TestProviders>
);

describe('<RulePreviewFooter />', () => {
beforeAll(() => {
jest.mocked(useExpandableFlyoutApi).mockReturnValue(mockFlyoutApi);
});

it('should render rule details link correctly when ruleId is available', () => {
(useRuleDetailsLink as jest.Mock).mockReturnValue('rule_details_link');
const { getByTestId } = renderRulePreviewFooter();

expect(getByTestId(RULE_PREVIEW_FOOTER_TEST_ID)).toBeInTheDocument();
Expand All @@ -32,13 +33,9 @@ describe('<RulePreviewFooter />', () => {
);
});

it('should open rule flyout when clicked', () => {
const { getByTestId } = renderRulePreviewFooter();

getByTestId(RULE_PREVIEW_OPEN_RULE_FLYOUT_TEST_ID).click();

expect(mockFlyoutApi.openFlyout).toHaveBeenCalledWith({
right: { id: RulePanelKey, params: { ruleId: 'ruleid' } },
});
it('should not render the footer if rule link is not available', () => {
(useRuleDetailsLink as jest.Mock).mockReturnValue(null);
const { container } = renderRulePreviewFooter();
expect(container).toBeEmptyDOMElement();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,27 @@
* 2.0.
*/

import React, { memo, useCallback } from 'react';
import React, { memo } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FlyoutFooter } from '@kbn/security-solution-common';
import { useExpandableFlyoutApi } from '@kbn/expandable-flyout';
import { RULE_PREVIEW_FOOTER_TEST_ID, RULE_PREVIEW_OPEN_RULE_FLYOUT_TEST_ID } from './test_ids';
import { RulePanelKey } from '../right';
import { useRuleDetailsLink } from '../../document_details/shared/hooks/use_rule_details_link';

/**
* Footer in rule preview panel
*/
export const PreviewFooter = memo(({ ruleId }: { ruleId: string }) => {
const { openFlyout } = useExpandableFlyoutApi();
const href = useRuleDetailsLink({ ruleId });

const openRuleFlyout = useCallback(() => {
openFlyout({
right: {
id: RulePanelKey,
params: {
ruleId,
},
},
});
}, [openFlyout, ruleId]);

return (
return href ? (
<FlyoutFooter data-test-subj={RULE_PREVIEW_FOOTER_TEST_ID}>
<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<EuiLink
onClick={openRuleFlyout}
href={href}
target="_blank"
external={false}
data-test-subj={RULE_PREVIEW_OPEN_RULE_FLYOUT_TEST_ID}
>
{i18n.translate('xpack.securitySolution.flyout.preview.rule.viewDetailsLabel', {
Expand All @@ -46,7 +35,7 @@ export const PreviewFooter = memo(({ ruleId }: { ruleId: string }) => {
</EuiFlexItem>
</EuiFlexGroup>
</FlyoutFooter>
);
) : null;
});

PreviewFooter.displayName = 'PreviewFooter';
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { render } from '@testing-library/react';
import { ThemeProvider } from 'styled-components';
import { getMockTheme } from '../../../common/lib/kibana/kibana_react.mock';
import { TestProviders } from '../../../common/mock';
// import { TestProvider } from '@kbn/expandable-flyout/src/test/provider';
import { useRuleDetailsLink } from '../../document_details/shared/hooks/use_rule_details_link';
import { RulePanel } from '.';
import { getStepsData } from '../../../detections/pages/detection_engine/rules/helpers';
import { useRuleDetails } from '../hooks/use_rule_details';
Expand All @@ -23,6 +23,8 @@ import type { RuleResponse } from '../../../../common/api/detection_engine';
import { BODY_TEST_ID, LOADING_TEST_ID } from './test_ids';
import { RULE_PREVIEW_FOOTER_TEST_ID } from '../preview/test_ids';

jest.mock('../../document_details/shared/hooks/use_rule_details_link');

const mockUseRuleDetails = useRuleDetails as jest.Mock;
jest.mock('../hooks/use_rule_details');

Expand Down Expand Up @@ -89,6 +91,7 @@ describe('<RulePanel />', () => {
});

it('should render preview footer when isPreviewMode is true', () => {
(useRuleDetailsLink as jest.Mock).mockReturnValue('rule_details_link');
mockUseRuleDetails.mockReturnValue({
rule,
loading: false,
Expand All @@ -97,8 +100,6 @@ describe('<RulePanel />', () => {
mockGetStepsData.mockReturnValue({});
const { getByTestId } = renderRulePanel(true);

// await act(async () => {
expect(getByTestId(RULE_PREVIEW_FOOTER_TEST_ID)).toBeInTheDocument();
// });
});
});

0 comments on commit 7f4fd42

Please sign in to comment.