Skip to content

Commit

Permalink
[Security Solution] Reorganize kpi visualization folders (elastic#189234
Browse files Browse the repository at this point in the history
)

## Summary

Moving some folders around so all the kpi related components sit in the
same folder:

x-pack/plugins/security_solution/public/
- detections/pages/detection_engine/chart_panels =>
detections/components/alerts_kpis/chart_panels
- common/components/alerts_treemap_panel =>
detections/components/alerts_kpis/alerts_treemap_panel
- common/components/alerts_treemap =>
detections/components/alerts_kpis/alerts_treemap_panel/alerts_treemap

<img width="988" alt="image"
src="https://github.com/user-attachments/assets/04ad7753-7f5a-451a-a396-19323ce86d37">

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
christineweng and kibanamachine authored Jul 30, 2024
1 parent 39bde9d commit 2f1acf9
Show file tree
Hide file tree
Showing 61 changed files with 83 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TREEMAP_CATEGORY,
ALERTS_PAGE,
STACK_BY_SETTING_NAME,
} from '../../../detections/pages/detection_engine/chart_panels/alerts_local_storage/constants';
} from '../../../detections/components/alerts_kpis/chart_panels/alerts_local_storage/constants';
import { getSettingKey, isDefaultWhenEmptyString } from './helpers';

describe('helpers', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
EXPAND_SETTING_NAME,
STACK_BY_SETTING_NAME,
TREEMAP_CATEGORY,
} from '../../../detections/pages/detection_engine/chart_panels/alerts_local_storage/constants';
} from '../../../detections/components/alerts_kpis/chart_panels/alerts_local_storage/constants';
import { getSettingKey, isDefaultWhenEmptyString } from './helpers';
import { useKibana as mockUseKibana } from '../../lib/kibana/__mocks__';
import { useLocalStorage } from '.';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ import type { AlertSearchResponse } from '../../../containers/detection_engine/a
import {
getMaxRiskSubAggregations,
getUpToMaxBuckets,
} from '../../../../common/components/alerts_treemap/lib/helpers';
import { getFlattenedBuckets } from '../../../../common/components/alerts_treemap/lib/flatten/get_flattened_buckets';
import type {
FlattenedBucket,
RawBucket,
} from '../../../../common/components/alerts_treemap/types';
} from '../alerts_treemap_panel/alerts_treemap/lib/helpers';
import { getFlattenedBuckets } from '../alerts_treemap_panel/alerts_treemap/lib/flatten/get_flattened_buckets';
import type { FlattenedBucket, RawBucket } from '../alerts_treemap_panel/alerts_treemap/types';
import {
getMultiGroupAlertsCountTableColumns,
getSingleGroupByAlertsCountTableColumns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { EuiBasicTableColumn } from '@elastic/eui';
import numeral from '@elastic/numeral';

import { TableId } from '@kbn/securitysolution-data-table';
import type { FlattenedBucket } from '../../../../common/components/alerts_treemap/types';
import type { FlattenedBucket } from '../alerts_treemap_panel/alerts_treemap/types';
import { DefaultDraggable } from '../../../../common/components/draggables';
import type { GenericBuckets } from '../../../../../common/search_strategy/common';
import * as i18n from './translations';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { MappingRuntimeFields } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { getOptionalSubAggregation } from '../../../../common/components/alerts_treemap/query';
import { getOptionalSubAggregation } from '../alerts_treemap_panel/alerts_treemap/query';

export const DEFAULT_STACK_BY_FIELD0_SIZE = 1000;
export const DEFAULT_STACK_BY_FIELD1_SIZE = 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import type { Status } from '../../../../../common/api/detection_engine';
import { useQueryToggle } from '../../../../common/containers/query_toggle';
import { DEFAULT_STACK_BY_FIELD, DEFAULT_STACK_BY_FIELD1 } from '../common/config';
import { TestProviders } from '../../../../common/mock';
import { ChartContextMenu } from '../../../pages/detection_engine/chart_panels/chart_context_menu';
import { TABLE } from '../../../pages/detection_engine/chart_panels/chart_select/translations';
import { ChartContextMenu } from '../chart_panels/chart_context_menu';
import { TABLE } from '../chart_panels/chart_select/translations';
import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features';
import { VisualizationEmbeddable } from '../../../../common/components/visualization_actions/visualization_embeddable';
import type { ExperimentalFeatures } from '../../../../../common/experimental_features';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { RawBucket } from '../../../../common/components/alerts_treemap/types';
import type { RawBucket } from '../alerts_treemap_panel/alerts_treemap/types';

export interface AlertsCountAggregation {
stackByField0: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import {
parseChartCollapseData,
getIsChartCollapseAgg,
} from '../../../pages/detection_engine/chart_panels/chart_collapse/helpers';
} from '../chart_panels/chart_collapse/helpers';

export const parseData = (data: AlertSearchResponse<{}, SummaryChartsAgg>) => {
if (getIsAlertsBySeverityAgg(data)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import type {
AlertsByGroupingAgg,
AlertsProgressBarData,
} from '../alerts_progress_bar_panel/types';
import type {
ChartCollapseAgg,
ChartCollapseData,
} from '../../../pages/detection_engine/chart_panels/chart_collapse/types';
import type { ChartCollapseAgg, ChartCollapseData } from '../chart_panels/chart_collapse/types';

export type SummaryChartsAgg = Partial<
AlertsBySeverityAgg | AlertsByTypeAgg | AlertsByGroupingAgg | ChartCollapseAgg | AlertsByRuleAgg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { render, screen } from '@testing-library/react';
import { Settings } from '@elastic/charts';
import React from 'react';

import { TestProviders } from '../../mock';
import { TestProviders } from '../../../../../common/mock';
import {
mockAlertSearchResponse,
mockNoDataAlertSearchResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import React, { useCallback, useMemo } from 'react';
import styled from 'styled-components';

import { i18n } from '@kbn/i18n';
import { useThemes } from '../charts/common';
import { DraggableLegend } from '../charts/draggable_legend';
import type { LegendItem } from '../charts/draggable_legend_item';
import type { AlertSearchResponse } from '../../../detections/containers/detection_engine/alerts/types';
import { useThemes } from '../../../../../common/components/charts/common';
import { DraggableLegend } from '../../../../../common/components/charts/draggable_legend';
import type { LegendItem } from '../../../../../common/components/charts/draggable_legend_item';
import type { AlertSearchResponse } from '../../../../containers/detection_engine/alerts/types';
import { getRiskScorePalette, RISK_SCORE_STEPS } from './lib/chart_palette';
import { getFlattenedBuckets } from './lib/flatten/get_flattened_buckets';
import { getFlattenedLegendItems } from './lib/legend/get_flattened_legend_items';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
RISK_SCORE_MEDIUM,
RISK_SCORE_HIGH,
RISK_SCORE_CRITICAL,
} from '../../../../constants';
} from '../../../../../../../common/constants';
import { getFillColor, getRiskScorePalette, RISK_SCORE_STEPS } from '.';

describe('getFillColor', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
RISK_SCORE_MEDIUM,
RISK_SCORE_HIGH,
RISK_SCORE_CRITICAL,
} from '../../../../constants';
} from '../../../../../../../common/constants';

/**
* The detection engine creates risk scores in the range 1 - 100.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { firstNonNullValue } from '../../../../../../common/endpoint/models/ecs_safety_helpers';
import { firstNonNullValue } from '../../../../../../../../common/endpoint/models/ecs_safety_helpers';
import type { RawBucket, FlattenedBucket } from '../../types';

export const flattenBucket = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
WordCloudElementEvent,
XYChartElementEvent,
} from '@elastic/charts';
import { firstNonNullValue } from '../../../../../common/endpoint/models/ecs_safety_helpers';
import { firstNonNullValue } from '../../../../../../../common/endpoint/models/ecs_safety_helpers';

import type { RawBucket } from '../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { omit } from 'lodash/fp';

import type { LegendItem } from '../../../charts/draggable_legend_item';
import type { LegendItem } from '../../../../../../../common/components/charts/draggable_legend_item';
import { getRiskScorePalette, RISK_SCORE_STEPS } from '../chart_palette';
import { getFlattenedLegendItems } from './get_flattened_legend_items';
import { bucketsWithStackByField1, maxRiskSubAggregations } from '../flatten/mocks/mock_buckets';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { firstNonNullValue } from '../../../../../../common/endpoint/models/ecs_safety_helpers';
import type { LegendItem } from '../../../charts/draggable_legend_item';
import { firstNonNullValue } from '../../../../../../../../common/endpoint/models/ecs_safety_helpers';
import type { LegendItem } from '../../../../../../../common/components/charts/draggable_legend_item';
import { getLegendMap, getLegendItemFromFlattenedBucket } from '.';
import type { FlattenedBucket, RawBucket } from '../../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { omit } from 'lodash/fp';

import type { LegendItem } from '../../../charts/draggable_legend_item';
import type { LegendItem } from '../../../../../../../common/components/charts/draggable_legend_item';
import { getRiskScorePalette, RISK_SCORE_STEPS } from '../chart_palette';
import { bucketsWithStackByField1, maxRiskSubAggregations } from '../flatten/mocks/mock_buckets';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import { v4 as uuidv4 } from 'uuid';

import { TableId } from '@kbn/securitysolution-data-table';
import { firstNonNullValue } from '../../../../../../common/endpoint/models/ecs_safety_helpers';
import type { LegendItem } from '../../../charts/draggable_legend_item';
import { firstNonNullValue } from '../../../../../../../../common/endpoint/models/ecs_safety_helpers';
import type { LegendItem } from '../../../../../../../common/components/charts/draggable_legend_item';
import { getFillColor } from '../chart_palette';
import { escapeDataProviderId } from '../../../drag_and_drop/helpers';
import { escapeDataProviderId } from '../../../../../../../common/components/drag_and_drop/helpers';
import { getLabel } from '../labels';
import type { FlattenedBucket, RawBucket } from '../../types';

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

import type { AlertSearchResponse } from '../../../../../detections/containers/detection_engine/alerts/types';
import type { AlertSearchResponse } from '../../../../../../containers/detection_engine/alerts/types';
import type { AlertsTreeMapAggregation } from '../../types';

export const mockAlertSearchResponse: AlertSearchResponse<unknown, AlertsTreeMapAggregation> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { GenericBuckets } from '../../../../common/search_strategy/common';
import type { GenericBuckets } from '../../../../../../common/search_strategy/common';

export type RawBucket = GenericBuckets & {
maxRiskSubAggregation?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@ import { render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import { useLocation } from 'react-router-dom';

import { SecurityPageName } from '../../../../common/constants';
import {
DEFAULT_STACK_BY_FIELD,
DEFAULT_STACK_BY_FIELD1,
} from '../../../detections/components/alerts_kpis/common/config';
import { useQueryAlerts } from '../../../detections/containers/detection_engine/alerts/use_query';
import { ChartContextMenu } from '../../../detections/pages/detection_engine/chart_panels/chart_context_menu';
import { ChartSelect } from '../../../detections/pages/detection_engine/chart_panels/chart_select';
import { TREEMAP } from '../../../detections/pages/detection_engine/chart_panels/chart_select/translations';
import { TestProviders } from '../../mock/test_providers';
import { SecurityPageName } from '../../../../../common/constants';
import { DEFAULT_STACK_BY_FIELD, DEFAULT_STACK_BY_FIELD1 } from '../common/config';
import { useQueryAlerts } from '../../../containers/detection_engine/alerts/use_query';
import { ChartContextMenu } from '../chart_panels/chart_context_menu';
import { ChartSelect } from '../chart_panels/chart_select';
import { TREEMAP } from '../chart_panels/chart_select/translations';
import { TestProviders } from '../../../../common/mock/test_providers';
import type { Props } from '.';
import { AlertsTreemapPanel } from '.';
import { mockAlertSearchResponse } from '../alerts_treemap/lib/mocks/mock_alert_search_response';
import { mockAlertSearchResponse } from './alerts_treemap/lib/mocks/mock_alert_search_response';

const from = '2022-07-28T08:20:18.966Z';
const to = '2022-07-28T08:20:18.966Z';
jest.mock('../../containers/use_global_time', () => {
const actual = jest.requireActual('../../containers/use_global_time');
jest.mock('../../../../common/containers/use_global_time', () => {
const actual = jest.requireActual('../../../../common/containers/use_global_time');
return {
...actual,
useGlobalTime: jest
Expand All @@ -40,15 +37,15 @@ jest.mock('react-router-dom', () => {
return { ...actual, useLocation: jest.fn().mockReturnValue({ pathname: '' }) };
});

jest.mock('../../lib/kibana', () => {
const originalModule = jest.requireActual('../../lib/kibana');
jest.mock('../../../../common/lib/kibana', () => {
const originalModule = jest.requireActual('../../../../common/lib/kibana');
return {
...originalModule,
useUiSetting$: () => ['0,0.[000]'],
};
});

jest.mock('../../../detections/containers/detection_engine/alerts/use_query', () => ({
jest.mock('../../../containers/detection_engine/alerts/use_query', () => ({
useQueryAlerts: jest.fn(),
}));

Expand Down Expand Up @@ -275,7 +272,7 @@ describe('AlertsTreemapPanel', () => {
});

it('renders the treemap when data is available and `isPanelExpanded` is true', async () => {
jest.mock('../../../detections/containers/detection_engine/alerts/use_query', () => {
jest.mock('../../../containers/detection_engine/alerts/use_query', () => {
return {
useQueryAlerts: () => ({
loading: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import { getEsQueryConfig } from '@kbn/data-plugin/common';
import React, { useEffect, useMemo } from 'react';
import { v4 as uuidv4 } from 'uuid';

import { useGlobalTime } from '../../containers/use_global_time';
import { AlertsTreemap, DEFAULT_MIN_CHART_HEIGHT } from '../alerts_treemap';
import { KpiPanel } from '../../../detections/components/alerts_kpis/common/components';
import { useInspectButton } from '../../../detections/components/alerts_kpis/common/hooks';
import { useQueryAlerts } from '../../../detections/containers/detection_engine/alerts/use_query';
import { ALERTS_QUERY_NAMES } from '../../../detections/containers/detection_engine/alerts/constants';
import { FieldSelection } from '../field_selection';
import { HeaderSection } from '../header_section';
import { InspectButtonContainer } from '../inspect';
import { DEFAULT_STACK_BY_FIELD0_SIZE, getAlertsRiskQuery } from '../alerts_treemap/query';
import type { AlertsTreeMapAggregation } from '../alerts_treemap/types';
import { useKibana } from '../../lib/kibana';
import { useGlobalTime } from '../../../../common/containers/use_global_time';
import { AlertsTreemap, DEFAULT_MIN_CHART_HEIGHT } from './alerts_treemap';
import { KpiPanel } from '../common/components';
import { useInspectButton } from '../common/hooks';
import { useQueryAlerts } from '../../../containers/detection_engine/alerts/use_query';
import { ALERTS_QUERY_NAMES } from '../../../containers/detection_engine/alerts/constants';
import { FieldSelection } from '../../../../common/components/field_selection';
import { HeaderSection } from '../../../../common/components/header_section';
import { InspectButtonContainer } from '../../../../common/components/inspect';
import { DEFAULT_STACK_BY_FIELD0_SIZE, getAlertsRiskQuery } from './alerts_treemap/query';
import type { AlertsTreeMapAggregation } from './alerts_treemap/types';
import { useKibana } from '../../../../common/lib/kibana';

const DEFAULT_HEIGHT = DEFAULT_MIN_CHART_HEIGHT + 134; // px

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ import {
VIEW_CATEGORY,
GROUP_BY_SETTING_NAME,
} from './constants';
import {
DEFAULT_STACK_BY_FIELD,
DEFAULT_STACK_BY_FIELD1,
} from '../../../../components/alerts_kpis/common/config';
import { DEFAULT_STACK_BY_FIELD, DEFAULT_STACK_BY_FIELD1 } from '../../common/config';
import type { AlertsSettings } from './types';
import type { AlertViewSelection } from '../chart_select/helpers';
import { CHARTS_ID, TREND_ID } from '../chart_select/helpers';
import type { GroupBySelection } from '../../../../components/alerts_kpis/alerts_progress_bar_panel/types';
import type { GroupBySelection } from '../../alerts_progress_bar_panel/types';
import { useIsExperimentalFeatureEnabled } from '../../../../../common/hooks/use_experimental_features';

export const useAlertsLocalStorage = (): AlertsSettings => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { AlertViewSelection } from '../chart_select/helpers';
import type { GroupBySelection } from '../../../../components/alerts_kpis/alerts_progress_bar_panel/types';
import type { GroupBySelection } from '../../alerts_progress_bar_panel/types';
export interface AlertsSettings {
alertViewSelection: AlertViewSelection;
countTableStackBy0: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { parseChartCollapseData } from './helpers';
import * as mock from './mock_data';
import type { ChartCollapseAgg } from './types';
import type { AlertSearchResponse } from '../../../../containers/detection_engine/alerts/types';
import { getGroupByLabel } from '../../../../components/alerts_kpis/alerts_progress_bar_panel/helpers';
import * as i18n from '../../../../components/alerts_kpis/alerts_progress_bar_panel/translations';
import { getGroupByLabel } from '../../alerts_progress_bar_panel/helpers';
import * as i18n from '../../alerts_progress_bar_panel/translations';

describe('parse chart collapse data', () => {
test('parse alerts with data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
import { has } from 'lodash';
import type { ChartCollapseAgg, ChartCollapseData } from './types';
import type { AlertSearchResponse } from '../../../../containers/detection_engine/alerts/types';
import type {
SummaryChartsData,
SummaryChartsAgg,
} from '../../../../components/alerts_kpis/alerts_summary_charts_panel/types';
import type { SummaryChartsData, SummaryChartsAgg } from '../../alerts_summary_charts_panel/types';
import { severityLabels } from '../../../../../overview/components/detection_response/alerts_by_status/use_alerts_by_status';
import { UNKNOWN_SEVERITY } from '../../../../components/alerts_kpis/severity_level_panel/translations';
import { UNKNOWN_SEVERITY } from '../../severity_level_panel/translations';

export const parseChartCollapseData = (
response: AlertSearchResponse<{}, ChartCollapseAgg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import { render } from '@testing-library/react';
import React from 'react';
import type { GroupBySelection } from '../../../../components/alerts_kpis/alerts_progress_bar_panel/types';
import type { GroupBySelection } from '../../alerts_progress_bar_panel/types';
import { TestProviders } from '../../../../../common/mock';
import { ChartCollapse } from '.';
import { useSummaryChartData } from '../../../../components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data';
import { useSummaryChartData } from '../../alerts_summary_charts_panel/use_summary_chart_data';
import * as mock from './mock_data';

jest.mock('../../../../../common/lib/kibana');
Expand All @@ -19,7 +19,7 @@ jest.mock('react-router-dom', () => {
const actual = jest.requireActual('react-router-dom');
return { ...actual, useLocation: jest.fn().mockReturnValue({ pathname: '' }) };
});
jest.mock('../../../../components/alerts_kpis/alerts_summary_charts_panel/use_summary_chart_data');
jest.mock('../../alerts_summary_charts_panel/use_summary_chart_data');

const defaultProps = {
groupBySelection: 'host.name' as GroupBySelection,
Expand Down
Loading

0 comments on commit 2f1acf9

Please sign in to comment.