Skip to content

Commit 60c5cd9

Browse files
authored
[Security Solution][Detections] - follow up cleanup on auto refresh rules (#83023) (#83089)
### Summary This is a follow up cleanup PR to #82062 . There were a few comments I hadn't gotten to and wanted to follow up on.
1 parent 3456bb3 commit 60c5cd9

File tree

4 files changed

+23
-26
lines changed

4 files changed

+23
-26
lines changed

x-pack/plugins/security_solution/cypress/tasks/alerts_detection_rules.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ export const waitForRulesToBeLoaded = () => {
125125
cy.get(ASYNC_LOADING_PROGRESS).should('not.exist');
126126
};
127127

128-
// when using, ensure you've called cy.clock prior in test
129128
export const checkAutoRefresh = (ms: number, condition: string) => {
130129
cy.get(ASYNC_LOADING_PROGRESS).should('not.be.visible');
131130
cy.tick(ms);

x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/index.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
EuiProgress,
1414
EuiOverlayMask,
1515
EuiConfirmModal,
16+
EuiWindowEvent,
1617
} from '@elastic/eui';
1718
import React, { useCallback, useEffect, useMemo, useReducer, useRef, useState } from 'react';
1819
import { useHistory } from 'react-router-dom';
@@ -406,18 +407,6 @@ export const AllRules = React.memo<AllRulesProps>(
406407
[setAutoRefreshOn, handleRefreshData]
407408
);
408409

409-
useEffect(() => {
410-
debounceResetIdleTimer();
411-
412-
window.addEventListener('mousemove', debounceResetIdleTimer, { passive: true });
413-
window.addEventListener('keydown', debounceResetIdleTimer);
414-
415-
return () => {
416-
window.removeEventListener('mousemove', debounceResetIdleTimer);
417-
window.removeEventListener('keydown', debounceResetIdleTimer);
418-
};
419-
}, [handleResetIdleTimer, debounceResetIdleTimer]);
420-
421410
const shouldShowRulesTable = useMemo(
422411
(): boolean => showRulesTable({ rulesCustomInstalled, rulesInstalled }) && !initLoading,
423412
[initLoading, rulesCustomInstalled, rulesInstalled]
@@ -470,6 +459,12 @@ export const AllRules = React.memo<AllRulesProps>(
470459

471460
return (
472461
<>
462+
<EuiWindowEvent event="mousemove" handler={debounceResetIdleTimer} />
463+
<EuiWindowEvent event="mousedown" handler={debounceResetIdleTimer} />
464+
<EuiWindowEvent event="click" handler={debounceResetIdleTimer} />
465+
<EuiWindowEvent event="keydown" handler={debounceResetIdleTimer} />
466+
<EuiWindowEvent event="scroll" handler={debounceResetIdleTimer} />
467+
<EuiWindowEvent event="load" handler={debounceResetIdleTimer} />
473468
<GenericDownloader
474469
filename={`${i18n.EXPORT_FILENAME}.ndjson`}
475470
ids={exportRuleIds}

x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/all/utility_bar.test.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ import { waitFor } from '@testing-library/react';
1212

1313
import { AllRulesUtilityBar } from './utility_bar';
1414

15+
const theme = () => ({ eui: euiDarkVars, darkMode: true });
16+
1517
describe('AllRules', () => {
1618
it('renders AllRulesUtilityBar total rules and selected rules', () => {
1719
const wrapper = mount(
18-
<ThemeProvider theme={() => ({ eui: euiDarkVars, darkMode: true })}>
20+
<ThemeProvider theme={theme}>
1921
<AllRulesUtilityBar
2022
userHasNoPermissions={false}
2123
onRefresh={jest.fn()}
@@ -36,7 +38,7 @@ describe('AllRules', () => {
3638

3739
it('renders utility actions if user has permissions', () => {
3840
const wrapper = mount(
39-
<ThemeProvider theme={() => ({ eui: euiDarkVars, darkMode: true })}>
41+
<ThemeProvider theme={theme}>
4042
<AllRulesUtilityBar
4143
userHasNoPermissions={false}
4244
onRefresh={jest.fn()}
@@ -54,7 +56,7 @@ describe('AllRules', () => {
5456

5557
it('renders no utility actions if user has no permissions', () => {
5658
const wrapper = mount(
57-
<ThemeProvider theme={() => ({ eui: euiDarkVars, darkMode: true })}>
59+
<ThemeProvider theme={theme}>
5860
<AllRulesUtilityBar
5961
userHasNoPermissions
6062
onRefresh={jest.fn()}
@@ -73,7 +75,7 @@ describe('AllRules', () => {
7375
it('invokes refresh on refresh action click', () => {
7476
const mockRefresh = jest.fn();
7577
const wrapper = mount(
76-
<ThemeProvider theme={() => ({ eui: euiDarkVars, darkMode: true })}>
78+
<ThemeProvider theme={theme}>
7779
<AllRulesUtilityBar
7880
userHasNoPermissions={false}
7981
onRefresh={mockRefresh}
@@ -94,7 +96,7 @@ describe('AllRules', () => {
9496
it('invokes onRefreshSwitch when auto refresh switch is clicked', async () => {
9597
const mockSwitch = jest.fn();
9698
const wrapper = mount(
97-
<ThemeProvider theme={() => ({ eui: euiDarkVars, darkMode: true })}>
99+
<ThemeProvider theme={theme}>
98100
<AllRulesUtilityBar
99101
userHasNoPermissions={false}
100102
onRefresh={jest.fn()}

x-pack/plugins/security_solution/server/ui_settings.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { schema } from '@kbn/config-schema';
99

1010
import { CoreSetup } from '../../../../src/core/server';
1111
import {
12+
APP_ID,
1213
DEFAULT_INDEX_KEY,
1314
DEFAULT_INDEX_PATTERN,
1415
DEFAULT_ANOMALY_SCORE,
@@ -47,7 +48,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => {
4748
'<p>Default refresh interval for the Security time filter, in milliseconds.</p>',
4849
}
4950
),
50-
category: ['securitySolution'],
51+
category: [APP_ID],
5152
requiresPageReload: true,
5253
schema: schema.object({
5354
value: schema.number(),
@@ -66,7 +67,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => {
6667
description: i18n.translate('xpack.securitySolution.uiSettings.defaultTimeRangeDescription', {
6768
defaultMessage: '<p>Default period of time in the Security time filter.</p>',
6869
}),
69-
category: ['securitySolution'],
70+
category: [APP_ID],
7071
requiresPageReload: true,
7172
schema: schema.object({
7273
from: schema.string(),
@@ -82,7 +83,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => {
8283
defaultMessage:
8384
'<p>Comma-delimited list of Elasticsearch indices from which the Security app collects events.</p>',
8485
}),
85-
category: ['securitySolution'],
86+
category: [APP_ID],
8687
requiresPageReload: true,
8788
schema: schema.arrayOf(schema.string()),
8889
},
@@ -99,7 +100,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => {
99100
'<p>Value above which Machine Learning job anomalies are displayed in the Security app.</p><p>Valid values: 0 to 100.</p>',
100101
}
101102
),
102-
category: ['securitySolution'],
103+
category: [APP_ID],
103104
requiresPageReload: true,
104105
schema: schema.number(),
105106
},
@@ -112,7 +113,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => {
112113
defaultMessage: '<p>Enables the News feed</p>',
113114
}),
114115
type: 'boolean',
115-
category: ['securitySolution'],
116+
category: [APP_ID],
116117
requiresPageReload: true,
117118
schema: schema.boolean(),
118119
},
@@ -133,7 +134,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => {
133134
"value": ${DEFAULT_RULE_REFRESH_INTERVAL_VALUE},
134135
"idleTimeout": ${DEFAULT_RULE_REFRESH_IDLE_VALUE}
135136
}`,
136-
category: ['securitySolution'],
137+
category: [APP_ID],
137138
requiresPageReload: true,
138139
schema: schema.object({
139140
idleTimeout: schema.number({ min: 300000 }),
@@ -149,7 +150,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => {
149150
description: i18n.translate('xpack.securitySolution.uiSettings.newsFeedUrlDescription', {
150151
defaultMessage: '<p>News feed content will be retrieved from this URL</p>',
151152
}),
152-
category: ['securitySolution'],
153+
category: [APP_ID],
153154
requiresPageReload: true,
154155
schema: schema.string(),
155156
},
@@ -166,7 +167,7 @@ export const initUiSettings = (uiSettings: CoreSetup['uiSettings']) => {
166167
'Array of URL templates to build the list of reputation URLs to be displayed on the IP Details page.',
167168
}
168169
),
169-
category: ['securitySolution'],
170+
category: [APP_ID],
170171
requiresPageReload: true,
171172
schema: schema.arrayOf(
172173
schema.object({

0 commit comments

Comments
 (0)