Skip to content

Commit ba0db38

Browse files
authored
[SIEM] update ip/hosts details tables to zero when detailName changes (#48253) (#48369)
1 parent 9745502 commit ba0db38

File tree

10 files changed

+320
-347
lines changed

10 files changed

+320
-347
lines changed

x-pack/legacy/plugins/siem/public/components/page/network/network_top_n_flow_table/index.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
import { EuiFlexItem } from '@elastic/eui';
77
import { isEqual, last } from 'lodash/fp';
8-
import React, { useEffect } from 'react';
8+
import React from 'react';
99
import { connect } from 'react-redux';
1010
import styled from 'styled-components';
1111
import { ActionCreator } from 'typescript-fsa';
@@ -31,7 +31,6 @@ interface OwnProps {
3131
flowTargeted: FlowTargetSourceDest;
3232
id: string;
3333
indexPattern: StaticIndexPattern;
34-
ip?: string;
3534
isInspect: boolean;
3635
loading: boolean;
3736
loadPage: (newActivePage: number) => void;
@@ -47,7 +46,6 @@ interface NetworkTopNFlowTableReduxProps {
4746
}
4847

4948
interface NetworkTopNFlowTableDispatchProps {
50-
setIpDetailsTablesActivePageToZero: ActionCreator<null>;
5149
updateIpDetailsTableActivePage: ActionCreator<{
5250
activePage: number;
5351
tableType: networkModel.IpDetailsTableType;
@@ -93,12 +91,10 @@ const NetworkTopNFlowTableComponent = React.memo<NetworkTopNFlowTableProps>(
9391
flowTargeted,
9492
id,
9593
indexPattern,
96-
ip,
9794
isInspect,
9895
limit,
9996
loading,
10097
loadPage,
101-
setIpDetailsTablesActivePageToZero,
10298
showMorePagesIndicator,
10399
topNFlowSort,
104100
totalCount,
@@ -108,11 +104,6 @@ const NetworkTopNFlowTableComponent = React.memo<NetworkTopNFlowTableProps>(
108104
updateTopNFlowLimit,
109105
updateTopNFlowSort,
110106
}) => {
111-
useEffect(() => {
112-
if (ip && activePage !== 0) {
113-
setIpDetailsTablesActivePageToZero(null);
114-
}
115-
}, [ip]);
116107
const onChange = (criteria: Criteria, tableType: networkModel.TopNTableType) => {
117108
if (criteria.sort != null) {
118109
const splitField = criteria.sort.field.split('.');
@@ -200,7 +191,6 @@ const mapStateToProps = (state: State, ownProps: OwnProps) =>
200191
export const NetworkTopNFlowTable = connect(
201192
mapStateToProps,
202193
{
203-
setIpDetailsTablesActivePageToZero: networkActions.setIpDetailsTablesActivePageToZero,
204194
updateTopNFlowLimit: networkActions.updateTopNFlowLimit,
205195
updateTopNFlowSort: networkActions.updateTopNFlowSort,
206196
updateNetworkPageTableActivePage: networkActions.updateNetworkPageTableActivePage,

x-pack/legacy/plugins/siem/public/containers/source/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,7 @@ export const WithSource = React.memo<WithSourceProps>(({ children, sourceId }) =
108108
);
109109
});
110110

111+
WithSource.displayName = 'WithSource';
112+
111113
export const indicesExistOrDataTemporarilyUnavailable = (indicesExist: boolean | undefined) =>
112114
indicesExist || isUndefined(indicesExist);

x-pack/legacy/plugins/siem/public/pages/hosts/details/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { EuiHorizontalRule, EuiSpacer } from '@elastic/eui';
8-
import React, { useContext } from 'react';
8+
import React, { useContext, useEffect } from 'react';
99
import { compose } from 'redux';
1010
import { connect } from 'react-redux';
1111
import { StickyContainer } from 'react-sticky';
@@ -19,6 +19,7 @@ import { MlCapabilitiesContext } from '../../../components/ml/permissions/ml_cap
1919
import { hasMlUserPermissions } from '../../../components/ml/permissions/has_ml_user_permissions';
2020
import { AnomalyTableProvider } from '../../../components/ml/anomaly/anomaly_table_provider';
2121
import { scoreIntervalToDateTime } from '../../../components/ml/score/score_interval_to_datetime';
22+
import { setHostDetailsTablesActivePageToZero as dispatchHostDetailsTablesActivePageToZero } from '../../../store/hosts/actions';
2223
import { SiemNavigation } from '../../../components/navigation';
2324
import { manageQuery } from '../../../components/page/manage_query';
2425
import { HostOverview } from '../../../components/page/hosts/host_overview';
@@ -45,14 +46,18 @@ const KpiHostDetailsManage = manageQuery(KpiHostsComponent);
4546
const HostDetailsComponent = React.memo<HostDetailsComponentProps>(
4647
({
4748
detailName,
48-
isInitializing,
4949
filters,
5050
from,
51+
isInitializing,
5152
query,
52-
setQuery,
5353
setAbsoluteRangeDatePicker,
54+
setHostDetailsTablesActivePageToZero,
55+
setQuery,
5456
to,
5557
}) => {
58+
useEffect(() => {
59+
setHostDetailsTablesActivePageToZero(null);
60+
}, [detailName]);
5661
const capabilities = useContext(MlCapabilitiesContext);
5762
return (
5863
<>
@@ -193,6 +198,7 @@ export const HostDetails = compose<React.ComponentClass<HostsQueryProps & { deta
193198
makeMapStateToProps,
194199
{
195200
setAbsoluteRangeDatePicker: dispatchAbsoluteRangeDatePicker,
201+
setHostDetailsTablesActivePageToZero: dispatchHostDetailsTablesActivePageToZero,
196202
}
197203
)
198204
)(HostDetailsComponent);

x-pack/legacy/plugins/siem/public/pages/hosts/details/types.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface HostDetailsComponentReduxProps {
2424
filters: Filter[];
2525
}
2626

27-
interface HostDetailsComponentDispatchProps {
27+
interface HostBodyComponentDispatchProps {
2828
setAbsoluteRangeDatePicker: ActionCreator<{
2929
id: InputsModelId;
3030
from: number;
@@ -33,6 +33,10 @@ interface HostDetailsComponentDispatchProps {
3333
detailName: string;
3434
}
3535

36+
interface HostDetailsComponentDispatchProps extends HostBodyComponentDispatchProps {
37+
setHostDetailsTablesActivePageToZero: ActionCreator<null>;
38+
}
39+
3640
export interface HostDetailsBodyProps extends HostsQueryProps {
3741
children: CommonChildren | AnomaliesChildren;
3842
}
@@ -43,7 +47,7 @@ export type HostDetailsComponentProps = HostDetailsComponentReduxProps &
4347
HostsQueryProps;
4448

4549
export type HostDetailsBodyComponentProps = HostDetailsComponentReduxProps &
46-
HostDetailsComponentDispatchProps &
50+
HostBodyComponentDispatchProps &
4751
HostDetailsBodyProps;
4852

4953
type KeyHostDetailsNavTabWithoutMlPermission = HostsTableType.authentications &

x-pack/legacy/plugins/siem/public/pages/network/__snapshots__/ip_details.test.tsx.snap

Lines changed: 9 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/legacy/plugins/siem/public/pages/network/ip_details.test.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const getMockHistory = (ip: string) => ({
7575

7676
const to = new Date('2018-03-23T18:49:23.132Z').valueOf();
7777
const from = new Date('2018-03-24T03:33:52.253Z').valueOf();
78-
7978
const getMockProps = (ip: string) => ({
8079
to,
8180
from,
@@ -98,6 +97,7 @@ const getMockProps = (ip: string) => ({
9897
from: number;
9998
to: number;
10099
}>,
100+
setIpDetailsTablesActivePageToZero: (jest.fn() as unknown) as ActionCreator<null>,
101101
});
102102

103103
jest.mock('ui/documentation_links', () => ({
@@ -137,12 +137,7 @@ describe('Ip Details', () => {
137137
});
138138
test('it renders', () => {
139139
const wrapper = shallow(<IPDetailsComponent {...getMockProps('123.456.78.90')} />);
140-
expect(
141-
wrapper
142-
.dive()
143-
.find('[data-test-subj="ip-details-page"]')
144-
.exists()
145-
).toBe(true);
140+
expect(wrapper.find('[data-test-subj="ip-details-page"]').exists()).toBe(true);
146141
});
147142

148143
test('it matches the snapshot', () => {

0 commit comments

Comments
 (0)