Skip to content

Commit bc39186

Browse files
author
Robert Austin
authored
[security_solution] enable react-hooks/exhaustive-deps (#68470)
* Enable `react-hooks/exhaustive-deps` rule for security_solution * Disable it anywhere that it would catch an issue
1 parent 2bedb59 commit bc39186

File tree

139 files changed

+313
-46
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+313
-46
lines changed

.eslintrc.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -758,10 +758,6 @@ module.exports = {
758758
'react/jsx-no-target-blank': 'error',
759759
'react/jsx-fragments': 'error',
760760
'react/jsx-sort-default-props': 'error',
761-
// might be introduced after the other warns are fixed
762-
// 'react/jsx-sort-props': 'error',
763-
// might be introduced after the other warns are fixed
764-
'react-hooks/exhaustive-deps': 'off',
765761
'require-atomic-updates': 'error',
766762
'symbol-description': 'error',
767763
'vars-on-top': 'error',

x-pack/plugins/security_solution/public/alerts/components/alerts_histogram_panel/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,15 @@ export const AlertsHistogramPanel = memo<AlertsHistogramPanelProps>(
131131
totalAlertsObj.value,
132132
totalAlertsObj.relation === 'gte' ? '>' : totalAlertsObj.relation === 'lte' ? '<' : ''
133133
),
134+
// eslint-disable-next-line react-hooks/exhaustive-deps
134135
[totalAlertsObj]
135136
);
136137

137138
const setSelectedOptionCallback = useCallback((event: React.ChangeEvent<HTMLSelectElement>) => {
138139
setSelectedStackByOption(
139140
stackByOptions?.find((co) => co.value === event.target.value) ?? defaultStackByOption
140141
);
142+
// eslint-disable-next-line react-hooks/exhaustive-deps
141143
}, []);
142144

143145
const formattedAlertsData = useMemo(() => formatAlertsData(alertsData), [alertsData]);
@@ -154,6 +156,7 @@ export const AlertsHistogramPanel = memo<AlertsHistogramPanelProps>(
154156
value: bucket.key,
155157
}))
156158
: NO_LEGEND_DATA,
159+
// eslint-disable-next-line react-hooks/exhaustive-deps
157160
[alertsData, selectedStackByOption.value]
158161
);
159162

@@ -175,6 +178,7 @@ export const AlertsHistogramPanel = memo<AlertsHistogramPanelProps>(
175178
deleteQuery({ id: uniqueQueryId });
176179
}
177180
};
181+
// eslint-disable-next-line react-hooks/exhaustive-deps
178182
}, []);
179183

180184
useEffect(() => {
@@ -189,6 +193,7 @@ export const AlertsHistogramPanel = memo<AlertsHistogramPanelProps>(
189193
refetch,
190194
});
191195
}
196+
// eslint-disable-next-line react-hooks/exhaustive-deps
192197
}, [setQuery, isLoadingAlerts, alertsData, response, request, refetch]);
193198

194199
useEffect(() => {
@@ -219,6 +224,7 @@ export const AlertsHistogramPanel = memo<AlertsHistogramPanelProps>(
219224
!isEmpty(converted) ? [converted] : []
220225
)
221226
);
227+
// eslint-disable-next-line react-hooks/exhaustive-deps
222228
}, [selectedStackByOption.value, from, to, query, filters]);
223229

224230
const linkButton = useMemo(() => {

x-pack/plugins/security_solution/public/alerts/components/alerts_table/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
117117
});
118118
}
119119
return null;
120+
// eslint-disable-next-line react-hooks/exhaustive-deps
120121
}, [browserFields, globalFilters, globalQuery, indexPatterns, kibana, to, from]);
121122

122123
// Callback for creating a new timeline -- utilized by row/batch actions
@@ -143,13 +144,15 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
143144
({ eventIds, isLoading }: SetEventsLoadingProps) => {
144145
setEventsLoading!({ id: ALERTS_TABLE_TIMELINE_ID, eventIds, isLoading });
145146
},
147+
// eslint-disable-next-line react-hooks/exhaustive-deps
146148
[setEventsLoading, ALERTS_TABLE_TIMELINE_ID]
147149
);
148150

149151
const setEventsDeletedCallback = useCallback(
150152
({ eventIds, isDeleted }: SetEventsDeletedProps) => {
151153
setEventsDeleted!({ id: ALERTS_TABLE_TIMELINE_ID, eventIds, isDeleted });
152154
},
155+
// eslint-disable-next-line react-hooks/exhaustive-deps
153156
[setEventsDeleted, ALERTS_TABLE_TIMELINE_ID]
154157
);
155158

@@ -210,7 +213,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
210213
}, [setSelectAll, setShowClearSelectionAction]);
211214

212215
const updateAlertsStatusCallback: UpdateAlertsStatusCallback = useCallback(
213-
async (refetchQuery: inputsModel.Refetch, { alertIds, status }: UpdateAlertsStatusProps) => {
216+
async (refetchQuery: inputsModel.Refetch, { status }: UpdateAlertsStatusProps) => {
214217
await updateAlertStatusAction({
215218
query: showClearSelectionAction ? getGlobalQuery()?.filterQuery : undefined,
216219
alertIds: Object.keys(selectedEventIds),
@@ -314,13 +317,15 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
314317
title: i18n.ALERTS_TABLE_TITLE,
315318
selectAll: canUserCRUD ? selectAll : false,
316319
});
320+
// eslint-disable-next-line react-hooks/exhaustive-deps
317321
}, []);
318322
useEffect(() => {
319323
setTimelineRowActions({
320324
id: ALERTS_TABLE_TIMELINE_ID,
321325
queryFields: requiredFieldsForActions,
322326
timelineRowActions: additionalActions,
323327
});
328+
// eslint-disable-next-line react-hooks/exhaustive-deps
324329
}, [additionalActions]);
325330
const headerFilterGroup = useMemo(
326331
() => <AlertsTableFilterGroup onFilterGroupChanged={onFilterGroupChangedCallback} />,

x-pack/plugins/security_solution/public/alerts/components/rules/add_item_form/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ export const AddItem = ({
126126
inputsRef.current[haveBeenKeyboardDeleted].focus();
127127
setHaveBeenKeyboardDeleted(-1);
128128
}
129+
// eslint-disable-next-line react-hooks/exhaustive-deps
129130
}, [haveBeenKeyboardDeleted, inputsRef.current]);
130131

131132
const values = field.value as string[];

x-pack/plugins/security_solution/public/alerts/components/rules/mitre/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ interface AddItemProps {
4040
isDisabled: boolean;
4141
}
4242

43-
export const AddMitreThreat = ({ dataTestSubj, field, idAria, isDisabled }: AddItemProps) => {
43+
export const AddMitreThreat = ({ field, idAria, isDisabled }: AddItemProps) => {
4444
const [showValidation, setShowValidation] = useState(false);
4545
const { isInvalid, errorMessage } = getFieldValidityAndErrorMessage(field);
4646

@@ -101,6 +101,7 @@ export const AddMitreThreat = ({ dataTestSubj, field, idAria, isDisabled }: AddI
101101
...values.slice(index + 1),
102102
]);
103103
},
104+
// eslint-disable-next-line react-hooks/exhaustive-deps
104105
[field]
105106
);
106107

x-pack/plugins/security_solution/public/alerts/components/rules/pick_timeline/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const PickTimeline = ({
3939
setTimelineId(id);
4040
setTimelineTitle(title);
4141
}
42+
// eslint-disable-next-line react-hooks/exhaustive-deps
4243
}, [field.value]);
4344

4445
const handleOnTimelineChange = useCallback(
@@ -49,6 +50,7 @@ export const PickTimeline = ({
4950
field.setValue({ id, title });
5051
}
5152
},
53+
// eslint-disable-next-line react-hooks/exhaustive-deps
5254
[field]
5355
);
5456

x-pack/plugins/security_solution/public/alerts/components/rules/query_bar/index.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
Query,
1717
FilterManager,
1818
SavedQuery,
19-
SavedQueryTimeFilter,
2019
} from '../../../../../../../../src/plugins/data/public';
2120

2221
import { BrowserFields } from '../../../../common/containers/source';
@@ -111,6 +110,7 @@ export const QueryBarDefineRule = ({
111110
isSubscribed = false;
112111
subscriptions.unsubscribe();
113112
};
113+
// eslint-disable-next-line react-hooks/exhaustive-deps
114114
}, [field.value]);
115115

116116
useEffect(() => {
@@ -143,10 +143,11 @@ export const QueryBarDefineRule = ({
143143
return () => {
144144
isSubscribed = false;
145145
};
146+
// eslint-disable-next-line react-hooks/exhaustive-deps
146147
}, [field.value]);
147148

148149
const onSubmitQuery = useCallback(
149-
(newQuery: Query, timefilter?: SavedQueryTimeFilter) => {
150+
(newQuery: Query) => {
150151
const { query } = field.value as FieldValueQueryBar;
151152
if (!deepEqual(query, newQuery)) {
152153
field.setValue({ ...(field.value as FieldValueQueryBar), query: newQuery });
@@ -179,6 +180,7 @@ export const QueryBarDefineRule = ({
179180
}
180181
}
181182
},
183+
// eslint-disable-next-line react-hooks/exhaustive-deps
182184
[field.value]
183185
);
184186

@@ -214,7 +216,7 @@ export const QueryBarDefineRule = ({
214216
[browserFields, field, indexPattern]
215217
);
216218

217-
const onMutation = (event: unknown, observer: unknown) => {
219+
const onMutation = () => {
218220
if (resizeParentContainer != null) {
219221
const suggestionContainer = document.getElementById('kbnTypeahead__items');
220222
if (suggestionContainer != null) {

x-pack/plugins/security_solution/public/alerts/components/rules/rule_actions_field/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const RuleActionsField: ThrottleSelectField = ({ field, messageVariables
5656
updatedActions[index] = deepMerge(updatedActions[index], { id });
5757
field.setValue(updatedActions);
5858
},
59+
// eslint-disable-next-line react-hooks/exhaustive-deps
5960
[field.setValue, actions]
6061
);
6162

@@ -71,6 +72,7 @@ export const RuleActionsField: ThrottleSelectField = ({ field, messageVariables
7172
updatedActions[index].params[key] = value;
7273
field.setValue(updatedActions);
7374
},
75+
// eslint-disable-next-line react-hooks/exhaustive-deps
7476
[field.setValue, actions]
7577
);
7678

@@ -82,6 +84,7 @@ export const RuleActionsField: ThrottleSelectField = ({ field, messageVariables
8284
);
8385
setSupportedActionTypes(supportedTypes);
8486
})();
87+
// eslint-disable-next-line react-hooks/exhaustive-deps
8588
}, []);
8689

8790
useEffect(() => {

x-pack/plugins/security_solution/public/alerts/components/rules/rule_actions_overflow/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ const RuleActionsOverflowComponent = ({
101101
</EuiContextMenuItem>,
102102
]
103103
: [],
104+
// eslint-disable-next-line react-hooks/exhaustive-deps
104105
[rule, userHasNoPermissions]
105106
);
106107

x-pack/plugins/security_solution/public/alerts/components/rules/rule_switch/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,22 @@ export const RuleSwitchComponent = ({
9494
}
9595
setMyIsLoading(false);
9696
},
97+
// eslint-disable-next-line react-hooks/exhaustive-deps
9798
[dispatch, id]
9899
);
99100

100101
useEffect(() => {
101102
if (myEnabled !== enabled) {
102103
setMyEnabled(enabled);
103104
}
105+
// eslint-disable-next-line react-hooks/exhaustive-deps
104106
}, [enabled]);
105107

106108
useEffect(() => {
107109
if (myIsLoading !== isLoading) {
108110
setMyIsLoading(isLoading ?? false);
109111
}
112+
// eslint-disable-next-line react-hooks/exhaustive-deps
110113
}, [isLoading]);
111114

112115
return (

0 commit comments

Comments
 (0)