Skip to content

Commit

Permalink
[Security Solution][Sourcerer] Colocate sourcerer files (#184149)
Browse files Browse the repository at this point in the history
## Summary

**TLDR; Even though many files are changed here, its only about sorting
out the imports and file locations.**

Moving sourcerer to a single directory, to keep entire feature
implmentation close - in an effort to draw clear boundaries over its
api, imports and exports - similar to how `security flyout` is
implemented.

**This is a starting point towards refactoring the component to use
discover picker and apis.**
  • Loading branch information
lgestc authored May 30, 2024
1 parent 1bd6c24 commit 4c5afdf
Show file tree
Hide file tree
Showing 247 changed files with 500 additions and 474 deletions.
4 changes: 2 additions & 2 deletions api_docs/timelines.devdocs.json
Original file line number Diff line number Diff line change
Expand Up @@ -4164,11 +4164,11 @@
},
{
"plugin": "securitySolution",
"path": "x-pack/plugins/security_solution/public/common/store/sourcerer/model.ts"
"path": "x-pack/plugins/security_solution/public/sourcerer/store/model.ts"
},
{
"plugin": "securitySolution",
"path": "x-pack/plugins/security_solution/public/common/store/sourcerer/model.ts"
"path": "x-pack/plugins/security_solution/public/sourcerer/store/model.ts"
},
{
"plugin": "securitySolution",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EuiWrappingPopover } from '@elastic/eui';
import { useLocation } from 'react-router-dom';
import { useObservable } from 'react-use';
import { StatefulTopN } from '../../../common/components/top_n';
import { getScopeFromPath, useSourcererDataView } from '../../../common/containers/sourcerer';
import { getScopeFromPath, useSourcererDataView } from '../../../sourcerer/containers';
import { useKibana } from '../../../common/lib/kibana';

export const TopValuesPopover = React.memo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
TestProviders,
} from '../../../common/mock';
import { TimelineId } from '../../../../common/types/timeline';
import { sourcererPaths } from '../../../common/containers/sourcerer';
import { sourcererPaths } from '../../../sourcerer/containers';

jest.mock('react-router-dom', () => {
const actual = jest.requireActual('react-router-dom');
Expand All @@ -35,7 +35,7 @@ jest.mock('../../../common/containers/source', () => ({
useFetchIndex: () => [false, { indicesExist: true, indexPatterns: mockIndexPattern }],
}));

jest.mock('../../../common/containers/sourcerer/use_signal_helpers', () => ({
jest.mock('../../../sourcerer/containers/use_signal_helpers', () => ({
useSignalHelpers: () => ({ signalIndexNeedsInit: false }),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ import { toMountPoint } from '@kbn/react-kibana-mount';
import { MlPopover } from '../../../common/components/ml_popover/ml_popover';
import { useKibana } from '../../../common/lib/kibana';
import { isDetectionsPath, isDashboardViewPath } from '../../../helpers';
import { Sourcerer } from '../../../common/components/sourcerer';
import { Sourcerer } from '../../../sourcerer/components';
import { TimelineId } from '../../../../common/types/timeline';
import { timelineDefaults } from '../../../timelines/store/defaults';
import { timelineSelectors } from '../../../timelines/store';
import { useShallowEqualSelector } from '../../../common/hooks/use_selector';
import { getScopeFromPath, showSourcererByPath } from '../../../common/containers/sourcerer';
import { getScopeFromPath, showSourcererByPath } from '../../../sourcerer/containers';
import { useAddIntegrationsUrl } from '../../../common/hooks/use_add_integrations_url';
import { AssistantHeaderLink } from '../../../assistant/header_link';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security_solution/public/app/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
useInitSourcerer,
getScopeFromPath,
useSourcererDataView,
} from '../../common/containers/sourcerer';
} from '../../sourcerer/containers';
import { GlobalHeader } from './global_header';
import { ConsoleManager } from '../../management/components/console/components/console_manager';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { sourcererActions } from '../../common/store/actions';
import { inputsActions } from '../../common/store/inputs';
import { InputsModelId } from '../../common/store/inputs/constants';
import type { TimeRange } from '../../common/store/inputs/model';
import { SourcererScopeName } from '../../common/store/sourcerer/model';
import { SourcererScopeName } from '../../sourcerer/store/model';
import { TimelineTabs, TimelineId } from '../../../common/types/timeline';
import {
ACTION_CANNOT_INVESTIGATE_IN_TIMELINE,
Expand All @@ -35,7 +35,7 @@ import {
import { useDiscoverInTimelineContext } from '../../common/components/discover_in_timeline/use_discover_in_timeline_context';
import { useShowTimeline } from '../../common/utils/timeline/use_show_timeline';
import { useIsExperimentalFeatureEnabled } from '../../common/hooks/use_experimental_features';
import { useSourcererDataView } from '../../common/containers/sourcerer';
import { useSourcererDataView } from '../../sourcerer/containers';
import { useDiscoverState } from '../../timelines/components/timeline/tabs/esql/use_discover_state';

export interface SendToTimelineButtonProps {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/security_solution/public/cases/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
SecurityPageName,
} from '../../../common/constants';
import { timelineActions } from '../../timelines/store';
import { useSourcererDataView } from '../../common/containers/sourcerer';
import { SourcererScopeName } from '../../common/store/sourcerer/model';
import { useSourcererDataView } from '../../sourcerer/containers';
import { SourcererScopeName } from '../../sourcerer/store/model';
import { CaseDetailsRefreshContext } from '../../common/components/endpoint/host_isolation/endpoint_host_isolation_cases_context';
import { SecuritySolutionPageWrapper } from '../../common/components/page_wrapper';
import { getEndpointDetailsPath } from '../../management/common/routing';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { useMemo } from 'react';
import type { Ecs } from '@kbn/cases-plugin/common';
import { useSourcererDataView } from '../../common/containers/sourcerer';
import { SourcererScopeName } from '../../common/store/sourcerer/model';
import { useSourcererDataView } from '../../sourcerer/containers';
import { SourcererScopeName } from '../../sourcerer/store/model';
import { useQueryAlerts } from '../../detections/containers/detection_engine/alerts/use_query';
import { ALERTS_QUERY_NAMES } from '../../detections/containers/detection_engine/alerts/constants';
import type { SignalHit } from '../../common/utils/alerts';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import React, { useMemo } from 'react';
import type { CellActionFieldValue, CellActionsData } from '@kbn/cell-actions/src/types';
import type { SecurityCellActionMetadata } from '../../../app/actions/types';
import { SecurityCellActionsTrigger, SecurityCellActionType } from '../../../app/actions/constants';
import { SourcererScopeName } from '../../store/sourcerer/model';
import { SourcererScopeName } from '../../../sourcerer/store/model';
import { useGetFieldSpec } from '../../hooks/use_get_field_spec';
import { useDataViewId } from '../../hooks/use_data_view_id';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { TimeRange } from '../../../store/inputs/model';
import { inputsActions } from '../../../store/inputs';
import { updateProviders, setFilters } from '../../../../timelines/store/actions';
import { sourcererActions } from '../../../store/actions';
import { SourcererScopeName } from '../../../store/sourcerer/model';
import { SourcererScopeName } from '../../../../sourcerer/store/model';
import type { DataProvider } from '../../../../../common/types';
import { TimelineId } from '../../../../../common/types/timeline';
import { TimelineType } from '../../../../../common/api/timeline';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
import { getDefaultControlColumn } from '../../../timelines/components/timeline/body/control_columns';
import { defaultRowRenderers } from '../../../timelines/components/timeline/body/renderers';
import { DefaultCellRenderer } from '../../../timelines/components/timeline/cell_rendering/default_cell_renderer';
import { SourcererScopeName } from '../../store/sourcerer/model';
import { SourcererScopeName } from '../../../sourcerer/store/model';
import type { GlobalTimeArgs } from '../../containers/use_global_time';
import type { QueryTabBodyProps as UserQueryTabBodyProps } from '../../../explore/users/pages/navigation/types';
import type { QueryTabBodyProps as HostQueryTabBodyProps } from '../../../explore/hosts/pages/navigation/types';
Expand Down Expand Up @@ -65,7 +65,6 @@ const EventsQueryTabBodyComponent: React.FC<EventsQueryTabBodyComponentProps> =
deleteQuery,
endDate,
filterQuery,
indexNames,
setQuery,
startDate,
tableId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { mockEventViewerResponse } from './mock';
import { StatefulEventsViewer, type EventsViewerProps } from '.';
import { eventsDefaultModel } from './default_model';
import { EntityType } from '@kbn/timelines-plugin/common';
import { SourcererScopeName } from '../../store/sourcerer/model';
import { SourcererScopeName } from '../../../sourcerer/store/model';
import { DefaultCellRenderer } from '../../../timelines/components/timeline/cell_rendering/default_cell_renderer';
import { useTimelineEvents } from './use_timelines_events';
import { getDefaultControlColumn } from '../../../timelines/components/timeline/body/control_columns';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ import { inputsActions } from '../../store/actions';
import { InspectButtonContainer } from '../inspect';
import { useGlobalFullScreen } from '../../containers/use_full_screen';
import { eventsViewerSelector } from './selectors';
import type { SourcererScopeName } from '../../store/sourcerer/model';
import { useSourcererDataView } from '../../containers/sourcerer';
import type { SourcererScopeName } from '../../../sourcerer/store/model';
import { useSourcererDataView } from '../../../sourcerer/containers';
import type { CellValueElementProps } from '../../../timelines/components/timeline/cell_rendering';
import { useKibana } from '../../lib/kibana';
import { GraphOverlay } from '../../../timelines/components/graph_overlay';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
TimelineStrategyResponseType,
} from '@kbn/timelines-plugin/common/search_strategy';
import { dataTableActions, Direction, TableId } from '@kbn/securitysolution-data-table';
import type { RunTimeMappings } from '../../store/sourcerer/model';
import type { RunTimeMappings } from '../../../sourcerer/store/model';
import { TimelineEventsQueries } from '../../../../common/search_strategy';
import type { KueryFilterQueryKind } from '../../../../common/types';
import type { ESQuery } from '../../../../common/typed_json';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import { useLocation } from 'react-router-dom';
import type { InputsModelId } from '../../store/inputs/constants';
import { NO_ALERT_INDEX } from '../../../../common/constants';
import * as i18n from './translations';
import { getScopeFromPath, useSourcererDataView } from '../../containers/sourcerer';
import { SourcererScopeName } from '../../store/sourcerer/model';
import { getScopeFromPath, useSourcererDataView } from '../../../sourcerer/containers';
import { SourcererScopeName } from '../../../sourcerer/store/model';

export interface ModalInspectProps {
adHocDataViews?: string[] | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react';
import { render } from '@testing-library/react';
import { LandingPageComponent } from '.';

jest.mock('../../containers/sourcerer', () => ({
jest.mock('../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({ indicesExist: false }),
}));
jest.mock('./onboarding');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React, { memo } from 'react';
import { useSourcererDataView } from '../../containers/sourcerer';
import { useSourcererDataView } from '../../../sourcerer/containers';
import { Onboarding } from './onboarding';

export const LandingPageComponent = memo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ import {
} from '../../../../utils/default_date_settings';
import type { TimeRange } from '../../../../store/inputs/model';
import { DEFAULT_TIMEPICKER_QUICK_RANGES } from '../../../../../../common/constants';
import { useSourcererDataView } from '../../../../containers/sourcerer';
import { SourcererScopeName } from '../../../../store/sourcerer/model';
import { useSourcererDataView } from '../../../../../sourcerer/containers';
import { SourcererScopeName } from '../../../../../sourcerer/store/model';
import { filtersToInsightProviders } from './provider';
import { useLicense } from '../../../../hooks/use_license';
import { isProviderValid } from './helpers';
import * as i18n from './translations';
import { useGetScopedSourcererDataView } from '../../../sourcerer/use_get_sourcerer_data_view';
import { useGetScopedSourcererDataView } from '../../../../../sourcerer/components/use_get_sourcerer_data_view';

interface InsightComponentProps {
label?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { TimelineId } from '../../../../../../common/types/timeline';
import { useKibana } from '../../../../lib/kibana';
import { combineQueries } from '../../../../lib/kuery';
import { useTimelineEvents } from '../../../../../timelines/containers';
import { useSourcererDataView } from '../../../../containers/sourcerer';
import { SourcererScopeName } from '../../../../store/sourcerer/model';
import { useSourcererDataView } from '../../../../../sourcerer/containers';
import { SourcererScopeName } from '../../../../../sourcerer/store/model';
import type { TimeRange } from '../../../../store/inputs/model';

export interface UseInsightQuery {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { useQueryToggle } from '../../containers/query_toggle';
import { VISUALIZATION_ACTIONS_BUTTON_CLASS } from '../visualization_actions/utils';
import { VisualizationEmbeddable } from '../visualization_actions/visualization_embeddable';
import { useVisualizationResponse } from '../visualization_actions/use_visualization_response';
import type { SourcererScopeName } from '../../store/sourcerer/model';
import type { SourcererScopeName } from '../../../sourcerer/store/model';

export type MatrixHistogramComponentProps = MatrixHistogramQueryProps &
MatrixHistogramConfigs & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { getSessionsDefaultModel, sessionsHeaders } from './default_headers';
import { defaultRowRenderers } from '../../../timelines/components/timeline/body/renderers';
import { DefaultCellRenderer } from '../../../timelines/components/timeline/cell_rendering/default_cell_renderer';
import * as i18n from './translations';
import { SourcererScopeName } from '../../store/sourcerer/model';
import { SourcererScopeName } from '../../../sourcerer/store/model';
import { getDefaultControlColumn } from '../../../timelines/components/timeline/body/control_columns';
import { useLicense } from '../../hooks/use_license';
import { eventsDefaultModel } from '../events_viewer/default_model';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
shouldIgnoreAlertFilters,
detectionAlertsTables,
} from './helpers';
import { SourcererScopeName } from '../../store/sourcerer/model';
import { SourcererScopeName } from '../../../sourcerer/store/model';
import { TableId } from '@kbn/securitysolution-data-table';

/** the following scopes are NOT detection alert tables */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { TableId } from '@kbn/securitysolution-data-table';

import type { TimelineEventsType } from '../../../../common/types/timeline';
import { TimelineId } from '../../../../common/types/timeline';
import { SourcererScopeName } from '../../store/sourcerer/model';
import { SourcererScopeName } from '../../../sourcerer/store/model';

import * as i18n from './translations';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { TestProviders } from '../../mock';

import type { VisualizationActionsProps } from './types';
import * as useLensAttributesModule from './use_lens_attributes';
import { SourcererScopeName } from '../../store/sourcerer/model';
import { SourcererScopeName } from '../../../sourcerer/store/model';

jest.mock('./use_actions');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { VisualizationActionsProps } from './types';
import { MORE_ACTIONS } from './translations';
import { VISUALIZATION_ACTIONS_BUTTON_CLASS } from './utils';
import { DEFAULT_ACTIONS, useActions, VISUALIZATION_CONTEXT_MENU_TRIGGER } from './use_actions';
import { SourcererScopeName } from '../../store/sourcerer/model';
import { SourcererScopeName } from '../../../sourcerer/store/model';

const Wrapper = styled.div`
&.viz-actions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.mock('uuid', () => ({
v4: jest.fn().mockReturnValue('b9b43606-7ff7-46ae-a47c-85bed80fab9a'),
}));

jest.mock('../../../../../containers/sourcerer', () => ({
jest.mock('../../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
dataViewId: 'security-solution-my-test',
indicesExist: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jest.mock('uuid', () => ({
v4: jest.fn().mockReturnValue('0039eb0c-9a1a-4687-ae54-0f4e239bec75'),
}));

jest.mock('../../../../../containers/sourcerer', () => ({
jest.mock('../../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
dataViewId: 'security-solution-my-test',
indicesExist: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jest.mock('uuid', () => ({
.mockReturnValueOnce('mockTopValuesOfBreakdownFieldColumnId'),
}));

jest.mock('../../../../../containers/sourcerer', () => ({
jest.mock('../../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
dataViewId: 'security-solution-my-test',
indicesExist: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jest.mock('uuid', () => ({
v4: jest.fn().mockReturnValueOnce('mockLayerId').mockReturnValueOnce('mockInternalReferenceId'),
}));

jest.mock('../../../../../containers/sourcerer', () => ({
jest.mock('../../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
dataViewId: 'security-solution-my-test',
indicesExist: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useLensAttributes } from '../../use_lens_attributes';

import { authenticationLensAttributes } from './authentication';

jest.mock('../../../../containers/sourcerer', () => ({
jest.mock('../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
selectedPatterns: ['auditbeat-mytest-*'],
dataViewId: 'security-solution-my-test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jest.mock('uuid', () => ({
v4: jest.fn().mockReturnValue('0039eb0c-9a1a-4687-ae54-0f4e239bec75'),
}));

jest.mock('../../../../containers/sourcerer', () => ({
jest.mock('../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
selectedPatterns: ['auditbeat-mytest-*'],
dataViewId: 'security-solution-my-test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useLensAttributes } from '../../use_lens_attributes';

import { getExternalAlertLensAttributes } from './external_alert';

jest.mock('../../../../containers/sourcerer', () => ({
jest.mock('../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
selectedPatterns: ['auditbeat-mytest-*'],
dataViewId: 'security-solution-my-test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useLensAttributes } from '../../use_lens_attributes';

import { kpiHostAreaLensAttributes } from './kpi_host_area';

jest.mock('../../../../containers/sourcerer', () => ({
jest.mock('../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
selectedPatterns: ['auditbeat-mytest-*'],
dataViewId: 'security-solution-my-test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useLensAttributes } from '../../use_lens_attributes';

import { kpiHostMetricLensAttributes } from './kpi_host_metric';

jest.mock('../../../../containers/sourcerer', () => ({
jest.mock('../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
selectedPatterns: ['auditbeat-mytest-*'],
dataViewId: 'security-solution-my-test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useLensAttributes } from '../../use_lens_attributes';

import { kpiUniqueIpsAreaLensAttributes } from './kpi_unique_ips_area';

jest.mock('../../../../containers/sourcerer', () => ({
jest.mock('../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
selectedPatterns: ['auditbeat-mytest-*'],
dataViewId: 'security-solution-my-test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useLensAttributes } from '../../use_lens_attributes';

import { kpiUniqueIpsBarLensAttributes } from './kpi_unique_ips_bar';

jest.mock('../../../../containers/sourcerer', () => ({
jest.mock('../../../../../sourcerer/containers', () => ({
useSourcererDataView: jest.fn().mockReturnValue({
selectedPatterns: ['auditbeat-mytest-*'],
dataViewId: 'security-solution-my-test',
Expand Down
Loading

0 comments on commit 4c5afdf

Please sign in to comment.