Skip to content

Commit

Permalink
Fix "Deleted rule" badge is not displayed if 'Rule Name' contains mor…
Browse files Browse the repository at this point in the history
…e than 55 words (#103164) (#103462)
  • Loading branch information
xcrzx authored Jun 28, 2021
1 parent 4863816 commit 61dd3db
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 24 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ const Badge = (styled(EuiBadge)`
` as unknown) as typeof EuiBadge;
Badge.displayName = 'Badge';

const HeaderSection = styled(EuiPageHeaderSection)`
// Without min-width: 0, as a flex child, it wouldn't shrink properly
// and could overflow its parent.
min-width: 0;
max-width: 100%;
`;
HeaderSection.displayName = 'HeaderSection';

interface BackOptions {
href: LinkIconProps['href'];
text: LinkIconProps['children'];
Expand Down Expand Up @@ -105,7 +113,7 @@ const HeaderPageComponent: React.FC<HeaderPageProps> = ({
return (
<>
<EuiPageHeader alignItems="center" bottomBorder={border}>
<EuiPageHeaderSection>
<HeaderSection>
{backOptions && (
<LinkBack>
<LinkIcon
Expand All @@ -132,7 +140,7 @@ const HeaderPageComponent: React.FC<HeaderPageProps> = ({
{subtitle && <Subtitle data-test-subj="header-page-subtitle" items={subtitle} />}
{subtitle2 && <Subtitle data-test-subj="header-page-subtitle-2" items={subtitle2} />}
{border && isLoading && <EuiProgress size="xs" color="accent" />}
</EuiPageHeaderSection>
</HeaderSection>

{children && (
<EuiPageHeaderSection data-test-subj="header-page-supplements">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ const Badge = (styled(EuiBadge)`
` as unknown) as typeof EuiBadge;
Badge.displayName = 'Badge';

const Header = styled.h1`
display: flex;
align-items: center;
`;
Header.displayName = 'Header';

const TitleWrapper = styled.span`
// Without min-width: 0, as a flex child, it wouldn't shrink properly
// and could overflow its parent.
min-width: 0;
`;
TitleWrapper.displayName = 'TitleWrapper';

interface Props {
badgeOptions?: BadgeOptions;
title: TitleProp;
Expand All @@ -32,9 +45,11 @@ interface Props {

const TitleComponent: React.FC<Props> = ({ draggableArguments, title, badgeOptions }) => (
<EuiTitle size="l">
<h1 data-test-subj="header-page-title">
<Header data-test-subj="header-page-title">
{!draggableArguments ? (
<TruncatableText tooltipContent={title}>{title}</TruncatableText>
<TitleWrapper>
<TruncatableText tooltipContent={title}>{title}</TruncatableText>
</TitleWrapper>
) : (
<DefaultDraggable
data-test-subj="header-page-draggable"
Expand All @@ -53,13 +68,13 @@ const TitleComponent: React.FC<Props> = ({ draggableArguments, title, badgeOptio
tooltipPosition="bottom"
/>
) : (
<Badge color="hollow" title="">
<Badge color={badgeOptions.color || 'hollow'} title="">
{badgeOptions.text}
</Badge>
)}
</>
)}
</h1>
</Header>
</EuiTitle>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/

import { EuiBadgeProps } from '@elastic/eui';
import type React from 'react';
export type TitleProp = string | React.ReactNode;

Expand All @@ -17,4 +18,5 @@ export interface BadgeOptions {
beta?: boolean;
text: string;
tooltip?: string;
color?: EuiBadgeProps['color'];
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
EuiTabs,
EuiToolTip,
EuiWindowEvent,
EuiBadge,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { noop } from 'lodash/fp';
Expand Down Expand Up @@ -115,6 +114,7 @@ import { NeedAdminForUpdateRulesCallOut } from '../../../../components/callouts/
import { getRuleStatusText } from '../../../../../../common/detection_engine/utils';
import { MissingPrivilegesCallOut } from '../../../../components/callouts/missing_privileges_callout';
import { useRuleWithFallback } from '../../../../containers/detection_engine/rules/use_rule_with_fallback';
import { BadgeOptions } from '../../../../../common/components/header_page/types';

/**
* Need a 100% height here to account for the graph/analyze tool, which sets no explicit height parameters, but fills the available space.
Expand Down Expand Up @@ -253,15 +253,20 @@ const RuleDetailsPageComponent = () => {
const title = useMemo(
() => (
<>
{rule?.name}{' '}
{ruleLoading ? (
<EuiLoadingSpinner size="m" />
) : (
!isExistingRule && <EuiBadge>{i18n.DELETED_RULE}</EuiBadge>
)}
{rule?.name} {ruleLoading && <EuiLoadingSpinner size="m" />}
</>
),
[rule, ruleLoading, isExistingRule]
[rule, ruleLoading]
);
const badgeOptions = useMemo<BadgeOptions | undefined>(
() =>
!ruleLoading && !isExistingRule
? {
text: i18n.DELETED_RULE,
color: 'default',
}
: undefined,
[isExistingRule, ruleLoading]
);
const subTitle = useMemo(
() =>
Expand Down Expand Up @@ -595,6 +600,7 @@ const RuleDetailsPageComponent = () => {
</>,
]}
title={title}
badgeOptions={badgeOptions}
>
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('Network Details', () => {
);
expect(
wrapper
.find('[data-test-subj="network-details-headline"] [data-test-subj="header-page-title"]')
.find('[data-test-subj="network-details-headline"] h1[data-test-subj="header-page-title"]')
.text()
).toEqual('fe80::24ce:f7ff:fede:a571');
});
Expand Down

0 comments on commit 61dd3db

Please sign in to comment.