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 @@ -55,16 +55,6 @@ describe('AttackDetailsContainer', () => {
expect(tabs[1]).toHaveTextContent(String(mockAttack.alertIds.length));
});

it('renders only Alerts tab when attack is undefined', () => {
renderContainer({ attack: undefined });

const tabs = screen.getAllByRole('tab');
expect(tabs).toHaveLength(1);
expect(tabs[0]).toHaveTextContent('Alerts');
expect(screen.getByTestId('alertsTab')).toBeInTheDocument();
expect(screen.queryByTestId('attackSummaryTab')).not.toBeInTheDocument();
});

it('renders the attack summary tab by default with correct props', () => {
renderContainer({ showAnonymized: true });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ interface TabInfo {
}

interface AttackDetailsContainerProps {
/** The attack discovery alert document. If undefined, only the Alerts tab will be shown. */
attack?: AttackDiscoveryAlert;
/** The attack discovery alert document. */
attack: AttackDiscoveryAlert;
/** Whether to show anonymized values instead of replacements */
showAnonymized?: boolean;
/** Filters applied from grouping */
Expand All @@ -51,11 +51,9 @@ interface AttackDetailsContainerProps {
*/
export const AttackDetailsContainer = React.memo<AttackDetailsContainerProps>(
({ attack, groupingFilters, defaultFilters, isTableLoading, showAnonymized }) => {
const tabs = useMemo<TabInfo[]>(() => {
const tabsList: TabInfo[] = [];

if (attack) {
tabsList.push({
const tabs = useMemo<TabInfo[]>(
() => [
{
id: ATTACK_SUMMARY_TAB,
name: i18n.ATTACK_SUMMARY,
content: (
Expand All @@ -64,31 +62,29 @@ export const AttackDetailsContainer = React.memo<AttackDetailsContainerProps>(
<SummaryTab attack={attack} showAnonymized={showAnonymized} />
</>
),
});
}

tabsList.push({
id: ALERTS_TAB,
name: i18n.ALERTS,
content: (
<>
<EuiSpacer size="s" />
<AlertsTab
groupingFilters={groupingFilters}
defaultFilters={defaultFilters}
isTableLoading={isTableLoading}
/>
</>
),
append: attack ? (
<EuiNotificationBadge size="m" color="subdued">
{attack.alertIds.length}
</EuiNotificationBadge>
) : undefined,
});

return tabsList;
}, [attack, groupingFilters, defaultFilters, isTableLoading, showAnonymized]);
},
{
id: ALERTS_TAB,
name: i18n.ALERTS,
content: (
<>
<EuiSpacer size="s" />
<AlertsTab
groupingFilters={groupingFilters}
defaultFilters={defaultFilters}
isTableLoading={isTableLoading}
/>
</>
),
append: attack ? (
<EuiNotificationBadge size="m" color="subdued">
{attack.alertIds.length}
</EuiNotificationBadge>
) : undefined,
},
],
[attack, groupingFilters, defaultFilters, isTableLoading, showAnonymized]
);

const firstTabId = useMemo(() => (attack ? ATTACK_SUMMARY_TAB : ALERTS_TAB), [attack]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ import { GroupedAlertsTable } from '../../alerts_table/alerts_grouping';
import type { AlertsGroupingAggregation } from '../../alerts_table/grouping_settings/types';
import { useGetDefaultGroupTitleRenderers } from '../../../hooks/attacks/use_get_default_group_title_renderers';
import { useAttackGroupHandler } from '../../../hooks/attacks/use_attack_group_handler';
import type { AssigneesIdsSelection } from '../../../../common/components/assignees/types';

import { AttackDetailsContainer } from './attack_details/attack_details_container';
import { AlertsTab } from './attack_details/alerts_tab';
import { groupingOptions, groupingSettings } from './grouping_configs';
import * as i18n from './translations';
import type { AssigneesIdsSelection } from '../../../../common/components/assignees/types';

export const TABLE_SECTION_TEST_ID = 'attacks-page-table-section';
export const EXPAND_ATTACK_BUTTON_TEST_ID = 'expand-attack-button';
Expand Down Expand Up @@ -157,6 +158,16 @@ export const TableSection = React.memo(
const attack =
selectedGroup && fieldBucket ? getAttack(selectedGroup, fieldBucket) : undefined;

if (!attack) {
return (
<AlertsTab
groupingFilters={groupingFilters}
defaultFilters={defaultFilters}
isTableLoading={isLoading}
/>
);
}

return (
<AttackDetailsContainer
attack={attack}
Expand Down
Loading