Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaindik committed Jun 26, 2024
1 parent d5fdc48 commit b9c5d86
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

import type { RuleResponse } from './rule_schemas.gen';

export function isCustomizedPrebuiltRule(rule?: RuleResponse | null): boolean {
return rule?.rule_source?.type === 'external' && rule.rule_source.is_customized;
export function isCustomizedPrebuiltRule(rule: RuleResponse): boolean {
return rule.rule_source?.type === 'external' && rule.rule_source.is_customized;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
useDeepEqualSelector,
useShallowEqualSelector,
} from '../../../../common/hooks/use_selector';
import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features';
import { useKibana } from '../../../../common/lib/kibana';
import type { UpdateDateRange } from '../../../../common/components/charts/common';
import { FiltersGlobal } from '../../../../common/components/filters_global';
Expand Down Expand Up @@ -127,7 +126,6 @@ import { useRuleWithFallback } from '../../../rule_management/logic/use_rule_wit
import type { BadgeOptions } from '../../../../common/components/header_page/types';
import type { AlertsStackByField } from '../../../../detections/components/alerts_kpis/common/types';
import type { RuleResponse, Status } from '../../../../../common/api/detection_engine';
import { isCustomizedPrebuiltRule } from '../../../../../common/api/detection_engine';
import { AlertsTableFilterGroup } from '../../../../detections/components/alerts_table/alerts_filter_group';
import { useSignalHelpers } from '../../../../sourcerer/containers/use_signal_helpers';
import { HeaderPage } from '../../../../common/components/header_page';
Expand Down Expand Up @@ -184,10 +182,6 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
clearEventsLoading,
clearSelected,
}) => {
const isPrebuiltRulesCustomizationEnabled = useIsExperimentalFeatureEnabled(
'prebuiltRulesCustomizationEnabled'
);

const {
analytics,
i18n: i18nStart,
Expand Down Expand Up @@ -600,9 +594,7 @@ const RuleDetailsPageComponent: React.FC<DetectionEngineComponentProps> = ({
subtitle={subTitle}
subtitle2={
<EuiFlexGroup gutterSize="m" alignItems="center" justifyContent="flexStart">
{isPrebuiltRulesCustomizationEnabled && isCustomizedPrebuiltRule(rule) && (
<CustomizedPrebuiltRuleBadge />
)}
<CustomizedPrebuiltRuleBadge rule={rule} />
<EuiFlexGroup alignItems="center" gutterSize="xs">
<EuiFlexItem grow={false}>
{ruleStatusI18n.STATUS}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,28 @@
import React from 'react';
import { EuiBadge } from '@elastic/eui';
import * as i18n from './translations';
import { isCustomizedPrebuiltRule } from '../../../../../common/api/detection_engine/model/rule_schema/utils';
import type { RuleResponse } from '../../../../../common/api/detection_engine/model';
import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features';

export const CustomizedPrebuiltRuleBadge = () => (
<EuiBadge color="hollow">{i18n.CUSTOMIZED_PREBUILT_RULE_LABEL}</EuiBadge>
);
interface CustomizedPrebuiltRuleBadgeProps {
rule: RuleResponse | null;
}

export const CustomizedPrebuiltRuleBadge: React.FC<CustomizedPrebuiltRuleBadgeProps> = ({
rule,
}) => {
const isPrebuiltRulesCustomizationEnabled = useIsExperimentalFeatureEnabled(
'prebuiltRulesCustomizationEnabled'
);

if (!isPrebuiltRulesCustomizationEnabled) {
return null;
}

if (rule === null || !isCustomizedPrebuiltRule(rule)) {
return null;
}

return <EuiBadge color="hollow">{i18n.CUSTOMIZED_PREBUILT_RULE_LABEL}</EuiBadge>;
};

0 comments on commit b9c5d86

Please sign in to comment.