Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import { HeaderSection } from '../../../../common/components/header_section';
import { StepAboutRule } from '../../../rule_creation_ui/components/step_about_rule';
import type { AboutStepRule } from '../../../common/types';
import { getMockTheme } from '../../../../common/lib/kibana/kibana_react.mock';
import { usePrebuiltRuleBaseVersionContext } from '../../../rule_management/components/rule_details/base_version_diff/base_version_context';
import { useRuleCustomizationsContext } from '../../../rule_management/components/rule_details/rule_customizations_diff/rule_customizations_context';

jest.mock('../../../../common/lib/kibana');
jest.mock(
'../../../rule_management/components/rule_details/base_version_diff/base_version_context'
'../../../rule_management/components/rule_details/rule_customizations_diff/rule_customizations_context'
);

const usePrebuiltRuleBaseVersionContextMock = usePrebuiltRuleBaseVersionContext as jest.Mock;
const useRuleCustomizationsContextMock = useRuleCustomizationsContext as jest.Mock;

const mockTheme = getMockTheme({
eui: { euiSizeL: '10px', euiBreakpoints: { s: '450px' }, euiSizeM: '10px' },
Expand All @@ -37,7 +37,7 @@ describe('StepAboutRuleToggleDetails', () => {

beforeEach(() => {
stepDataMock = mockAboutStepRule();
usePrebuiltRuleBaseVersionContextMock.mockReturnValue({
useRuleCustomizationsContextMock.mockReturnValue({
actions: { openCustomizationsPreviewFlyout: jest.fn() },
state: { doesBaseVersionExist: true, modifiedFields: new Set() },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import type { AboutStepRule, AboutStepRuleDetails } from '../../../common/types'
import * as i18n from './translations';
import { fullHeight } from './styles';
import type { RuleResponse } from '../../../../../common/api/detection_engine';
import { ModifiedFieldBadge } from '../../../rule_management/components/rule_details/modified_field_badge';
import { RuleFieldName } from '../../../rule_management/components/rule_details/rule_field_name';

const detailsOption: EuiButtonGroupOptionProps = {
Expand All @@ -47,7 +46,6 @@ const setupOption: EuiButtonGroupOptionProps = {
label: i18n.ABOUT_PANEL_SETUP_TAB,
'data-test-subj': 'stepAboutDetailsToggle-setup',
};

interface StepPanelProps {
stepData: AboutStepRule | null;
stepDataDetails: AboutStepRuleDetails | null;
Expand Down Expand Up @@ -79,7 +77,7 @@ const StepAboutRuleToggleDetailsComponent: React.FC<StepPanelProps> = ({
...(notesExist ? [notesOption] : []),
...(setupExists ? [setupOption] : []),
];
}, [stepDataDetails]);
}, [stepDataDetails?.note, stepDataDetails?.setup]);

return (
<EuiPanel
Expand Down Expand Up @@ -122,34 +120,22 @@ const StepAboutRuleToggleDetailsComponent: React.FC<StepPanelProps> = ({
</VerticalOverflowContent>
</VerticalOverflowContainer>
<EuiSpacer size="m" />
<RuleAboutSection rule={rule} hideName hideDescription showModifiedFields />
<RuleAboutSection rule={rule} hideName hideDescription />
</div>
)}
</EuiResizeObserver>
)}
{selectedToggleOption === 'notes' && (
<VerticalOverflowContainer
data-test-subj="stepAboutDetailsNoteContent"
maxHeight={aboutPanelHeight}
>
<VerticalOverflowContainer maxHeight={aboutPanelHeight}>
<VerticalOverflowContent maxHeight={aboutPanelHeight}>
<EuiFlexGroup gutterSize="xs" direction="column" alignItems="flexStart">
<ModifiedFieldBadge fieldName={'note'} />
<MarkdownRenderer>{stepDataDetails.note}</MarkdownRenderer>
</EuiFlexGroup>
<RuleInvestigationGuide note={stepDataDetails.note} />
</VerticalOverflowContent>
</VerticalOverflowContainer>
)}
{selectedToggleOption === 'setup' && (
<VerticalOverflowContainer
data-test-subj="stepAboutDetailsSetupContent"
maxHeight={aboutPanelHeight}
>
<VerticalOverflowContainer maxHeight={aboutPanelHeight}>
<VerticalOverflowContent maxHeight={aboutPanelHeight}>
<EuiFlexGroup gutterSize="xs" direction="column" alignItems="flexStart">
<ModifiedFieldBadge fieldName={'setup'} />
<MarkdownRenderer>{stepDataDetails.setup}</MarkdownRenderer>
</EuiFlexGroup>
<RuleSetupGuide setup={stepDataDetails.setup} />
</VerticalOverflowContent>
</VerticalOverflowContainer>
)}
Expand All @@ -164,12 +150,10 @@ export const StepAboutRuleToggleDetails = memo(StepAboutRuleToggleDetailsCompone

interface VerticalOverflowContainerProps {
maxHeight: number;
'data-test-subj'?: string;
}

function VerticalOverflowContainer({
maxHeight,
'data-test-subj': dataTestSubject,
children,
}: PropsWithChildren<VerticalOverflowContainerProps>): JSX.Element {
return (
Expand All @@ -179,7 +163,6 @@ function VerticalOverflowContainer({
overflow-y: hidden;
word-break: break-word;
`}
data-test-subj={dataTestSubject}
>
{children}
</div>
Expand Down Expand Up @@ -209,13 +192,7 @@ const RuleDescription = ({ description }: { description: string }) => (
<EuiDescriptionList
listItems={[
{
title: (
<RuleFieldName
label={i18n.ABOUT_PANEL_DESCRIPTION_LABEL}
fieldName="description"
showModifiedFields
/>
),
title: <RuleFieldName label={i18n.ABOUT_PANEL_DESCRIPTION_LABEL} fieldName="description" />,
description: (
<EuiText size="s" data-test-subj="stepAboutRuleDetailsToggleDescriptionText">
{description}
Expand All @@ -225,3 +202,27 @@ const RuleDescription = ({ description }: { description: string }) => (
]}
/>
);

const RuleInvestigationGuide = ({ note }: { note: string }) => (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these live within this file, now, or do you intend to reuse them?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they are fine to live here for now, we don't display either of these fields this way anywhere else - they usually get split up into their own section or tab. I broke them out into the smaller fragment stubs for overall readability in the main component

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While these two components aren't explicitly reused they are actually reused, please check setup and note components from the Prebuilt Rule Upgrade Flyout.

Ideally we should reuse Investigation Guide and Setup Guide components. You may see some readonly components are defined in rule_definition_section.tsx. note component in the Prebuilt Rule Upgrade Flyout should be renamed to investigation_guide.

nit: IMHO functions have higher readability

interface MyComponentProps {
  propA: string;
}

function MyComponent(props: MyComponentProps): JSX.Element {
  // implementation...
}

vs

interface MyComponentProps {
  propA: string;
}

const MyComponent = (props: MyComponentProps) => {
  // implementation...
};

<EuiDescriptionList
listItems={[
{
title: <RuleFieldName fieldName="note" />,
description: <MarkdownRenderer>{note}</MarkdownRenderer>,
},
]}
descriptionProps={{ 'data-test-subj': 'stepAboutDetailsNoteContent' }}
/>
);

const RuleSetupGuide = ({ setup }: { setup: string }) => (
<EuiDescriptionList
listItems={[
{
title: <RuleFieldName fieldName="setup" />,
description: <MarkdownRenderer>{setup}</MarkdownRenderer>,
},
]}
descriptionProps={{ 'data-test-subj': 'stepAboutDetailsSetupContent' }}
/>
);
Loading