-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove alert type charts feature flag
- Loading branch information
1 parent
49fb36c
commit da271eb
Showing
25 changed files
with
250 additions
and
929 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...ion/public/detections/components/alerts_kpis/alerts_by_rule_panel/alerts_by_rule.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { act, render } from '@testing-library/react'; | ||
import React from 'react'; | ||
import { TestProviders } from '../../../../common/mock'; | ||
import { AlertsByRule } from './alerts_by_rule'; | ||
import { parsedAlerts } from './mock_rule_data'; | ||
|
||
jest.mock('../../../../common/lib/kibana'); | ||
|
||
jest.mock('react-router-dom', () => { | ||
const actual = jest.requireActual('react-router-dom'); | ||
return { ...actual, useLocation: jest.fn().mockReturnValue({ pathname: '' }) }; | ||
}); | ||
|
||
describe('Alert by rule chart', () => { | ||
const defaultProps = { | ||
data: [], | ||
isLoading: false, | ||
}; | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test('renders table correctly without data', () => { | ||
act(() => { | ||
const { container } = render( | ||
<TestProviders> | ||
<AlertsByRule {...defaultProps} /> | ||
</TestProviders> | ||
); | ||
expect( | ||
container.querySelector('[data-test-subj="alerts-by-type-table"]') | ||
).toBeInTheDocument(); | ||
expect( | ||
container.querySelector('[data-test-subj="alerts-by-type-table"] tbody')?.textContent | ||
).toEqual('No items found'); | ||
}); | ||
}); | ||
|
||
test('renders table correctly with data', () => { | ||
act(() => { | ||
const { queryAllByRole } = render( | ||
<TestProviders> | ||
<AlertsByRule data={parsedAlerts} isLoading={false} /> | ||
</TestProviders> | ||
); | ||
|
||
parsedAlerts.forEach((_, i) => { | ||
expect(queryAllByRole('row')[i + 1].textContent).toContain(parsedAlerts[i].rule); | ||
expect(queryAllByRole('row')[i + 1].textContent).toContain( | ||
parsedAlerts[i].value.toString() | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
100 changes: 100 additions & 0 deletions
100
...solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/alerts_by_rule.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { EuiBasicTableColumn } from '@elastic/eui'; | ||
import { EuiInMemoryTable, EuiSpacer, EuiText } from '@elastic/eui'; | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import type { SortOrder } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import { ALERT_RULE_NAME } from '@kbn/rule-data-utils'; | ||
import { TableId } from '@kbn/securitysolution-data-table'; | ||
import type { AlertsByRuleData } from './types'; | ||
import { FormattedCount } from '../../../../common/components/formatted_number'; | ||
import { DefaultDraggable } from '../../../../common/components/draggables'; | ||
import { ALERTS_HEADERS_RULE_NAME } from '../../alerts_table/translations'; | ||
import { COUNT_TABLE_TITLE } from '../alerts_count_panel/translations'; | ||
|
||
const Wrapper = styled.div` | ||
margin-top: -${({ theme }) => theme.eui.euiSizeM}; | ||
`; | ||
const TableWrapper = styled.div` | ||
height: 178px; | ||
`; | ||
|
||
export interface AlertsByRuleProps { | ||
data: AlertsByRuleData[]; | ||
isLoading: boolean; | ||
} | ||
|
||
const COLUMNS: Array<EuiBasicTableColumn<AlertsByRuleData>> = [ | ||
{ | ||
field: 'rule', | ||
name: ALERTS_HEADERS_RULE_NAME, | ||
'data-test-subj': 'detectionsTable-rule', | ||
truncateText: true, | ||
render: (rule: string) => ( | ||
<EuiText size="xs" className="eui-textTruncate"> | ||
<DefaultDraggable | ||
isDraggable={false} | ||
field={ALERT_RULE_NAME} | ||
hideTopN={true} | ||
id={`alert-detection-draggable-${rule}`} | ||
value={rule} | ||
queryValue={rule} | ||
tooltipContent={null} | ||
truncate={true} | ||
scopeId={TableId.alertsOnAlertsPage} | ||
/> | ||
</EuiText> | ||
), | ||
}, | ||
{ | ||
field: 'value', | ||
name: COUNT_TABLE_TITLE, | ||
dataType: 'number', | ||
sortable: true, | ||
'data-test-subj': 'detectionsTable-count', | ||
render: (count: number) => ( | ||
<EuiText grow={false} size="xs"> | ||
<FormattedCount count={count} /> | ||
</EuiText> | ||
), | ||
width: '22%', | ||
}, | ||
]; | ||
|
||
export const AlertsByRule: React.FC<AlertsByRuleProps> = ({ data, isLoading }) => { | ||
const sorting: { sort: { field: keyof AlertsByRuleData; direction: SortOrder } } = { | ||
sort: { | ||
field: 'value', | ||
direction: 'desc', | ||
}, | ||
}; | ||
|
||
const pagination: {} = { | ||
pageSize: 25, | ||
showPerPageOptions: false, | ||
}; | ||
|
||
return ( | ||
<Wrapper data-test-subj="alerts-by-type"> | ||
<EuiSpacer size="xs" /> | ||
<TableWrapper className="eui-yScroll"> | ||
<EuiInMemoryTable | ||
data-test-subj="alerts-by-type-table" | ||
columns={COLUMNS} | ||
items={data} | ||
loading={isLoading} | ||
sorting={sorting} | ||
pagination={pagination} | ||
/> | ||
</TableWrapper> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
AlertsByRule.displayName = 'AlertsByRule'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...curity_solution/public/detections/components/alerts_kpis/alerts_by_rule_panel/helpers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { has } from 'lodash'; | ||
import type { AlertsByRuleData, AlertsByRuleAgg } from './types'; | ||
import type { AlertSearchResponse } from '../../../containers/detection_engine/alerts/types'; | ||
import type { SummaryChartsData, SummaryChartsAgg } from '../alerts_summary_charts_panel/types'; | ||
|
||
export const parseAlertsRuleData = ( | ||
response: AlertSearchResponse<{}, AlertsByRuleAgg> | ||
): AlertsByRuleData[] => { | ||
const rulesBuckets = response?.aggregations?.alertsByRule?.buckets ?? []; | ||
|
||
return rulesBuckets.length === 0 | ||
? [] | ||
: rulesBuckets.map((rule) => { | ||
return { | ||
rule: rule.key, | ||
value: rule.doc_count, | ||
}; | ||
}); | ||
}; | ||
|
||
export const getIsAlertsByRuleData = (data: SummaryChartsData[]): data is AlertsByRuleData[] => { | ||
return data?.every((x) => has(x, 'rule')); | ||
}; | ||
|
||
export const getIsAlertsByRuleAgg = ( | ||
data: AlertSearchResponse<{}, SummaryChartsAgg> | ||
): data is AlertSearchResponse<{}, AlertsByRuleAgg> => { | ||
return has(data, 'aggregations.alertsByRule'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.