Skip to content

Commit a220883

Browse files
[SIEM] Replace WithSource with useWithSource hook (#68722)
1 parent 0a30e34 commit a220883

25 files changed

Lines changed: 1215 additions & 1358 deletions

File tree

x-pack/plugins/security_solution/public/alerts/pages/detection_engine/detection_engine.test.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import '../../../common/mock/match_media';
1212
import { setAbsoluteRangeDatePicker } from '../../../common/store/inputs/actions';
1313
import { DetectionEnginePageComponent } from './detection_engine';
1414
import { useUserInfo } from '../../components/user_info';
15+
import { useWithSource } from '../../../common/containers/source';
1516

1617
jest.mock('../../components/user_info');
17-
jest.mock('../../../common/lib/kibana');
18+
jest.mock('../../../common/containers/source');
1819
jest.mock('../../../common/components/link_to');
1920
jest.mock('react-router-dom', () => {
2021
const originalModule = jest.requireActual('react-router-dom');
@@ -30,7 +31,12 @@ describe('DetectionEnginePageComponent', () => {
3031
beforeAll(() => {
3132
(useParams as jest.Mock).mockReturnValue({});
3233
(useUserInfo as jest.Mock).mockReturnValue({});
34+
(useWithSource as jest.Mock).mockReturnValue({
35+
indicesExist: true,
36+
indexPattern: {},
37+
});
3338
});
39+
3440
it('renders correctly', () => {
3541
const wrapper = shallow(
3642
<DetectionEnginePageComponent
@@ -40,6 +46,6 @@ describe('DetectionEnginePageComponent', () => {
4046
/>
4147
);
4248

43-
expect(wrapper.find('WithSource')).toHaveLength(1);
49+
expect(wrapper.find('FiltersGlobal')).toHaveLength(1);
4450
});
4551
});

x-pack/plugins/security_solution/public/alerts/pages/detection_engine/detection_engine.tsx

Lines changed: 68 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ import { useHistory } from 'react-router-dom';
1313
import { SecurityPageName } from '../../../app/types';
1414
import { TimelineId } from '../../../../common/types/timeline';
1515
import { GlobalTime } from '../../../common/containers/global_time';
16-
import {
17-
indicesExistOrDataTemporarilyUnavailable,
18-
WithSource,
19-
} from '../../../common/containers/source';
16+
import { useWithSource } from '../../../common/containers/source';
2017
import { UpdateDateRange } from '../../../common/components/charts/common';
2118
import { FiltersGlobal } from '../../../common/components/filters_global';
2219
import { getRulesUrl } from '../../../common/components/link_to/redirect_to_detection_engine';
@@ -82,6 +79,7 @@ export const DetectionEnginePageComponent: React.FC<PropsFromRedux> = ({
8279
const indexToAdd = useMemo(() => (signalIndexName == null ? [] : [signalIndexName]), [
8380
signalIndexName,
8481
]);
82+
const { indicesExist, indexPattern } = useWithSource('default', indexToAdd);
8583

8684
if (isUserAuthenticated != null && !isUserAuthenticated && !loading) {
8785
return (
@@ -104,77 +102,73 @@ export const DetectionEnginePageComponent: React.FC<PropsFromRedux> = ({
104102
<>
105103
{hasEncryptionKey != null && !hasEncryptionKey && <NoApiIntegrationKeyCallOut />}
106104
{hasIndexWrite != null && !hasIndexWrite && <NoWriteAlertsCallOut />}
107-
<WithSource sourceId="default" indexToAdd={indexToAdd}>
108-
{({ indicesExist, indexPattern }) => {
109-
return indicesExistOrDataTemporarilyUnavailable(indicesExist) ? (
110-
<StickyContainer>
111-
<FiltersGlobal>
112-
<SiemSearchBar id="global" indexPattern={indexPattern} />
113-
</FiltersGlobal>
114-
<WrapperPage>
115-
<DetectionEngineHeaderPage
116-
subtitle={
117-
lastAlerts != null && (
118-
<>
119-
{i18n.LAST_ALERT}
120-
{': '}
121-
{lastAlerts}
122-
</>
123-
)
124-
}
125-
title={i18n.PAGE_TITLE}
126-
>
127-
<LinkButton
128-
fill
129-
onClick={goToRules}
130-
href={formatUrl(getRulesUrl())}
131-
iconType="gear"
132-
data-test-subj="manage-alert-detection-rules"
133-
>
134-
{i18n.BUTTON_MANAGE_RULES}
135-
</LinkButton>
136-
</DetectionEngineHeaderPage>
105+
{indicesExist ? (
106+
<StickyContainer>
107+
<FiltersGlobal>
108+
<SiemSearchBar id="global" indexPattern={indexPattern} />
109+
</FiltersGlobal>
110+
<WrapperPage>
111+
<DetectionEngineHeaderPage
112+
subtitle={
113+
lastAlerts != null && (
114+
<>
115+
{i18n.LAST_ALERT}
116+
{': '}
117+
{lastAlerts}
118+
</>
119+
)
120+
}
121+
title={i18n.PAGE_TITLE}
122+
>
123+
<LinkButton
124+
fill
125+
onClick={goToRules}
126+
href={formatUrl(getRulesUrl())}
127+
iconType="gear"
128+
data-test-subj="manage-alert-detection-rules"
129+
>
130+
{i18n.BUTTON_MANAGE_RULES}
131+
</LinkButton>
132+
</DetectionEngineHeaderPage>
137133

138-
<GlobalTime>
139-
{({ to, from, deleteQuery, setQuery }) => (
140-
<>
141-
<>
142-
<AlertsHistogramPanel
143-
deleteQuery={deleteQuery}
144-
filters={filters}
145-
from={from}
146-
query={query}
147-
setQuery={setQuery}
148-
showTotalAlertsCount={true}
149-
signalIndexName={signalIndexName}
150-
stackByOptions={alertsHistogramOptions}
151-
to={to}
152-
updateDateRange={updateDateRangeCallback}
153-
/>
154-
<EuiSpacer size="l" />
155-
<AlertsTable
156-
timelineId={TimelineId.alertsPage}
157-
loading={loading}
158-
hasIndexWrite={hasIndexWrite ?? false}
159-
canUserCRUD={(canUserCRUD ?? false) && (hasEncryptionKey ?? false)}
160-
from={from}
161-
signalsIndex={signalIndexName ?? ''}
162-
to={to}
163-
/>
164-
</>
165-
</>
166-
)}
167-
</GlobalTime>
168-
</WrapperPage>
169-
</StickyContainer>
170-
) : (
171-
<WrapperPage>
172-
<DetectionEngineHeaderPage border title={i18n.PAGE_TITLE} />
173-
<DetectionEngineEmptyPage />
174-
</WrapperPage>
175-
);
176-
}}
177-
</WithSource>
134+
<GlobalTime>
135+
{({ to, from, deleteQuery, setQuery }) => (
136+
<>
137+
<>
138+
<AlertsHistogramPanel
139+
deleteQuery={deleteQuery}
140+
filters={filters}
141+
from={from}
142+
query={query}
143+
setQuery={setQuery}
144+
showTotalAlertsCount={true}
145+
signalIndexName={signalIndexName}
146+
stackByOptions={alertsHistogramOptions}
147+
to={to}
148+
updateDateRange={updateDateRangeCallback}
149+
/>
150+
<EuiSpacer size="l" />
151+
<AlertsTable
152+
timelineId={TimelineId.alertsPage}
153+
loading={loading}
154+
hasIndexWrite={hasIndexWrite ?? false}
155+
canUserCRUD={(canUserCRUD ?? false) && (hasEncryptionKey ?? false)}
156+
from={from}
157+
signalsIndex={signalIndexName ?? ''}
158+
to={to}
159+
/>
160+
</>
161+
</>
162+
)}
163+
</GlobalTime>
164+
</WrapperPage>
165+
</StickyContainer>
166+
) : (
167+
<WrapperPage>
168+
<DetectionEngineHeaderPage border title={i18n.PAGE_TITLE} />
169+
<DetectionEngineEmptyPage />
170+
</WrapperPage>
171+
)}
178172
<SpyRoute pageName={SecurityPageName.alerts} />
179173
</>
180174
);

x-pack/plugins/security_solution/public/alerts/pages/detection_engine/rules/details/index.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import { TestProviders } from '../../../../../common/mock';
1212
import { RuleDetailsPageComponent } from './index';
1313
import { setAbsoluteRangeDatePicker } from '../../../../../common/store/inputs/actions';
1414
import { useUserInfo } from '../../../../components/user_info';
15+
import { useWithSource } from '../../../../../common/containers/source';
1516
import { useParams } from 'react-router-dom';
1617

1718
jest.mock('../../../../../common/components/link_to');
1819
jest.mock('../../../../components/user_info');
20+
jest.mock('../../../../../common/containers/source');
1921
jest.mock('react-router-dom', () => {
2022
const originalModule = jest.requireActual('react-router-dom');
2123

@@ -30,6 +32,10 @@ describe('RuleDetailsPageComponent', () => {
3032
beforeAll(() => {
3133
(useUserInfo as jest.Mock).mockReturnValue({});
3234
(useParams as jest.Mock).mockReturnValue({});
35+
(useWithSource as jest.Mock).mockReturnValue({
36+
indicesExist: true,
37+
indexPattern: {},
38+
});
3339
});
3440

3541
it('renders correctly', () => {
@@ -44,6 +50,6 @@ describe('RuleDetailsPageComponent', () => {
4450
}
4551
);
4652

47-
expect(wrapper.find('WithSource')).toHaveLength(1);
53+
expect(wrapper.find('GlobalTime')).toHaveLength(1);
4854
});
4955
});

0 commit comments

Comments
 (0)