From 8ce6dbda5fcf58d5dc85f51b04ac0c5425b5ec1d Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 1 Jun 2020 08:31:07 -0400 Subject: [PATCH 1/3] Restore react-hooks eslint rule --- .eslintrc.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index aeaf6e04fdc01d..f7bb0289385629 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -755,8 +755,6 @@ module.exports = { 'react/jsx-sort-default-props': 'error', // might be introduced after the other warns are fixed // 'react/jsx-sort-props': 'error', - // might be introduced after the other warns are fixed - 'react-hooks/exhaustive-deps': 'off', 'require-atomic-updates': 'error', 'symbol-description': 'error', 'vars-on-top': 'error', From 50254477211a19dc929901da0f2590739f860005 Mon Sep 17 00:00:00 2001 From: oatkiller Date: Mon, 1 Jun 2020 10:08:41 -0400 Subject: [PATCH 2/3] Autofix hooks errors --- .../components/rules/add_item_form/index.tsx | 2 +- .../alerts/components/rules/mitre/index.tsx | 2 +- .../components/rules/pick_timeline/index.tsx | 4 +- .../components/rules/query_bar/index.tsx | 6 +- .../rules/rule_actions_field/index.tsx | 6 +- .../rules/rule_actions_overflow/index.tsx | 2 +- .../components/rules/rule_switch/index.tsx | 6 +- .../rules/schedule_item_form/index.tsx | 6 +- .../rules/step_about_rule/index.tsx | 6 +- .../rules/step_define_rule/index.tsx | 6 +- .../rules/step_rule_actions/index.tsx | 8 +- .../rules/step_schedule_rule/index.tsx | 6 +- .../rules/throttle_select_field/index.tsx | 2 +- .../alerts/components/signals/index.tsx | 15 ++- .../signals_histogram_panel/index.tsx | 29 ++++-- .../alerts/components/user_info/index.tsx | 16 ++-- .../rules/fetch_index_patterns.tsx | 2 +- .../detection_engine/rules/persist_rule.tsx | 2 +- .../rules/use_pre_packaged_rules.tsx | 9 +- .../detection_engine/rules/use_rule.tsx | 2 +- .../rules/use_rule_status.tsx | 4 +- .../detection_engine/rules/use_rules.tsx | 5 +- .../detection_engine/rules/use_tags.tsx | 2 +- .../signals/use_privilege_user.tsx | 2 +- .../signals/use_signal_index.tsx | 2 +- .../detection_engine/rules/all/index.tsx | 4 +- .../rules_table_filters.tsx | 2 +- .../detection_engine/rules/create/index.tsx | 4 +- .../detection_engine/rules/details/index.tsx | 2 +- .../detection_engine/rules/edit/index.tsx | 19 ++-- .../cases/components/add_comment/index.tsx | 4 +- .../cases/components/all_cases/index.tsx | 44 +++++---- .../components/all_cases/table_filters.tsx | 12 +-- .../cases/components/case_view/actions.tsx | 8 +- .../components/configure_cases/connectors.tsx | 2 +- .../configure_cases/connectors_dropdown.tsx | 2 +- .../configure_cases/field_mapping.tsx | 4 +- .../components/configure_cases/index.tsx | 28 +++--- .../components/connector_selector/form.tsx | 2 +- .../public/cases/components/create/index.tsx | 2 +- .../components/open_closed_stats/index.tsx | 2 +- .../components/use_push_to_service/index.tsx | 18 +++- .../components/user_action_tree/index.tsx | 45 ++++----- .../user_action_tree/user_action_markdown.tsx | 61 ++++++------ .../cases/components/user_list/index.tsx | 2 +- .../containers/configure/use_configure.tsx | 23 ++++- .../containers/configure/use_connectors.tsx | 4 +- .../cases/containers/use_bulk_update_case.tsx | 96 ++++++++++--------- .../cases/containers/use_delete_cases.tsx | 71 +++++++------- .../containers/use_get_action_license.tsx | 4 +- .../public/cases/containers/use_get_case.tsx | 4 +- .../containers/use_get_case_user_actions.tsx | 4 +- .../public/cases/containers/use_get_cases.tsx | 74 +++++++------- .../cases/containers/use_get_cases_status.tsx | 4 +- .../cases/containers/use_get_reporters.tsx | 4 +- .../public/cases/containers/use_get_tags.tsx | 6 +- .../public/cases/containers/use_post_case.tsx | 55 ++++++----- .../cases/containers/use_post_comment.tsx | 2 +- .../containers/use_post_push_to_service.tsx | 2 +- .../cases/containers/use_update_case.tsx | 2 +- .../cases/containers/use_update_comment.tsx | 2 +- .../common/components/alerts_viewer/index.tsx | 2 +- .../common/components/charts/common.tsx | 2 +- .../drag_drop_context_wrapper.tsx | 2 +- .../drag_and_drop/draggable_wrapper.tsx | 2 +- .../common/components/events_viewer/index.tsx | 11 ++- .../components/generic_downloader/index.tsx | 2 +- .../components/header_page/editable_title.tsx | 2 +- .../common/components/help_menu/index.tsx | 2 +- .../components/import_data_modal/index.tsx | 12 ++- .../public/common/components/links/index.tsx | 2 +- .../components/markdown_editor/index.tsx | 2 +- .../components/matrix_histogram/index.tsx | 5 +- .../ml/anomaly/use_anomalies_table_data.ts | 10 +- .../permissions/ml_capabilities_provider.tsx | 2 +- .../ml_popover/hooks/use_siem_jobs.tsx | 2 +- .../filters/groups_filter_popover.tsx | 2 +- .../common/components/navigation/index.tsx | 13 ++- .../common/components/search_bar/index.tsx | 12 +-- .../common/components/stat_items/index.tsx | 2 +- .../components/super_date_picker/index.tsx | 16 +++- .../common/components/toasters/index.test.tsx | 2 +- .../components/url_state/use_url_state.tsx | 4 +- .../anomalies_query_tab_body/index.tsx | 2 +- .../events/last_event_time/index.ts | 2 +- .../common/containers/global_time/index.tsx | 2 +- .../containers/matrix_histogram/index.ts | 2 + .../public/common/containers/source/index.tsx | 2 +- .../common/hooks/use_add_to_timeline.tsx | 2 +- .../common/hooks/use_index_patterns.tsx | 2 +- .../components/connector_flyout/index.tsx | 12 +-- .../siem/public/common/lib/kibana/hooks.ts | 4 +- .../public/common/utils/route/spy_routes.tsx | 17 +++- .../utils/timeline/use_show_timeline.tsx | 2 +- .../view/details/overview/index.tsx | 2 +- .../containers/hosts/first_last_seen/index.ts | 2 +- .../components/embeddables/embedded_map.tsx | 20 +++- .../embeddables/map_tool_tip/map_tool_tip.tsx | 9 +- .../source_destination/country_flag.tsx | 2 +- .../network/components/tls_table/index.tsx | 2 +- .../network/components/users_table/index.tsx | 5 +- .../components/alerts_by_category/index.tsx | 4 +- .../components/recent_timelines/index.tsx | 2 +- .../components/signals_by_category/index.tsx | 2 +- .../fields_browser/field_browser.tsx | 2 +- .../components/fields_browser/index.tsx | 11 ++- .../components/flyout/pane/index.tsx | 4 +- .../open_timeline/edit_timeline_actions.tsx | 2 +- .../edit_timeline_batch_actions.tsx | 2 +- .../components/open_timeline/index.tsx | 15 ++- .../open_timeline/use_timeline_types.tsx | 48 +++++----- .../timeline/body/column_headers/index.tsx | 1 + .../body/events/event_column_view.tsx | 2 +- .../timeline/body/events/stateful_event.tsx | 2 +- .../timeline/body/stateful_body.tsx | 26 +++-- .../data_providers/provider_item_badge.tsx | 6 +- .../timeline/fetch_kql_timeline.tsx | 2 +- .../components/timeline/footer/index.tsx | 2 +- .../timelines/components/timeline/index.tsx | 14 +-- .../insert_timeline_popover/index.tsx | 2 +- .../use_insert_timeline.tsx | 11 +-- .../timeline/properties/helpers.tsx | 2 +- .../components/timeline/properties/index.tsx | 2 +- .../components/timeline/query_bar/index.tsx | 12 +-- .../timeline/search_or_filter/index.tsx | 10 +- .../timeline/selectable_timeline/index.tsx | 2 +- .../public/timelines/containers/all/index.tsx | 2 +- 127 files changed, 665 insertions(+), 503 deletions(-) diff --git a/x-pack/plugins/siem/public/alerts/components/rules/add_item_form/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/add_item_form/index.tsx index c8eb6f69c95ba7..01d5e64b8a4d0f 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/add_item_form/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/add_item_form/index.tsx @@ -126,7 +126,7 @@ export const AddItem = ({ inputsRef.current[haveBeenKeyboardDeleted].focus(); setHaveBeenKeyboardDeleted(-1); } - }, [haveBeenKeyboardDeleted, inputsRef.current]); + }, [haveBeenKeyboardDeleted]); const values = field.value as string[]; return ( diff --git a/x-pack/plugins/siem/public/alerts/components/rules/mitre/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/mitre/index.tsx index 88edd0e7955313..5afa74c0e1afcb 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/mitre/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/mitre/index.tsx @@ -101,7 +101,7 @@ export const AddMitreThreat = ({ dataTestSubj, field, idAria, isDisabled }: AddI ...values.slice(index + 1), ]); }, - [field] + [field, values] ); const values = field.value as IMitreEnterpriseAttack[]; diff --git a/x-pack/plugins/siem/public/alerts/components/rules/pick_timeline/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/pick_timeline/index.tsx index 0029e70e4edda8..901981946a8491 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/pick_timeline/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/pick_timeline/index.tsx @@ -39,7 +39,7 @@ export const PickTimeline = ({ setTimelineId(id); setTimelineTitle(title); } - }, [field.value]); + }, [field.value, timelineId, timelineTitle]); const handleOnTimelineChange = useCallback( (title: string, id: string | null) => { @@ -49,7 +49,7 @@ export const PickTimeline = ({ field.setValue({ id, title }); } }, - [field] + [field, timelineId, timelineTitle] ); return ( diff --git a/x-pack/plugins/siem/public/alerts/components/rules/query_bar/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/query_bar/index.tsx index 82206b6ba5e3db..57a50bb6ac8130 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/query_bar/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/query_bar/index.tsx @@ -111,7 +111,7 @@ export const QueryBarDefineRule = ({ isSubscribed = false; subscriptions.unsubscribe(); }; - }, [field.value]); + }, [field, field.value, filterManager]); useEffect(() => { let isSubscribed = true; @@ -143,7 +143,7 @@ export const QueryBarDefineRule = ({ return () => { isSubscribed = false; }; - }, [field.value]); + }, [field.value, filterManager, queryDraft, savedQuery, savedQueryServices]); const onSubmitQuery = useCallback( (newQuery: Query, timefilter?: SavedQueryTimeFilter) => { @@ -179,7 +179,7 @@ export const QueryBarDefineRule = ({ } } }, - [field.value] + [field] ); const onCloseTimelineModal = useCallback(() => { diff --git a/x-pack/plugins/siem/public/alerts/components/rules/rule_actions_field/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/rule_actions_field/index.tsx index d8064eb4ad391d..9647e70ec037a5 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/rule_actions_field/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/rule_actions_field/index.tsx @@ -56,7 +56,7 @@ export const RuleActionsField: ThrottleSelectField = ({ field, messageVariables updatedActions[index] = deepMerge(updatedActions[index], { id }); field.setValue(updatedActions); }, - [field.setValue, actions] + [actions, field] ); const setAlertProperty = useCallback( @@ -71,7 +71,7 @@ export const RuleActionsField: ThrottleSelectField = ({ field, messageVariables updatedActions[index].params[key] = value; field.setValue(updatedActions); }, - [field.setValue, actions] + [actions, field] ); useEffect(() => { @@ -82,7 +82,7 @@ export const RuleActionsField: ThrottleSelectField = ({ field, messageVariables ); setSupportedActionTypes(supportedTypes); })(); - }, []); + }, [http]); useEffect(() => { if (field.form.isSubmitting || !field.errors.length) { diff --git a/x-pack/plugins/siem/public/alerts/components/rules/rule_actions_overflow/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/rule_actions_overflow/index.tsx index 5a5156fa2b9a36..bc30bd2f29f7e1 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/rule_actions_overflow/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/rule_actions_overflow/index.tsx @@ -101,7 +101,7 @@ const RuleActionsOverflowComponent = ({ , ] : [], - [rule, userHasNoPermissions] + [dispatchToaster, onRuleDeletedCallback, rule, userHasNoPermissions] ); const handlePopoverOpen = useCallback(() => { diff --git a/x-pack/plugins/siem/public/alerts/components/rules/rule_switch/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/rule_switch/index.tsx index 79a16bfb386ec6..9ec0a8641124f5 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/rule_switch/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/rule_switch/index.tsx @@ -94,20 +94,20 @@ export const RuleSwitchComponent = ({ } setMyIsLoading(false); }, - [dispatch, id] + [dispatch, dispatchToaster, id, onChange] ); useEffect(() => { if (myEnabled !== enabled) { setMyEnabled(enabled); } - }, [enabled]); + }, [enabled, myEnabled]); useEffect(() => { if (myIsLoading !== isLoading) { setMyIsLoading(isLoading ?? false); } - }, [isLoading]); + }, [isLoading, myIsLoading]); return ( diff --git a/x-pack/plugins/siem/public/alerts/components/rules/schedule_item_form/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/schedule_item_form/index.tsx index 9a4f9b25e01f45..105d0fe20bbc47 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/schedule_item_form/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/schedule_item_form/index.tsx @@ -78,7 +78,7 @@ export const ScheduleItem = ({ setTimeType(e.target.value); field.setValue(`${timeVal}${e.target.value}`); }, - [timeVal] + [field, timeVal] ); const onChangeTimeVal = useCallback( @@ -87,7 +87,7 @@ export const ScheduleItem = ({ setTimeVal(sanitizedValue); field.setValue(`${sanitizedValue}${timeType}`); }, - [timeType] + [field, timeType] ); useEffect(() => { @@ -111,7 +111,7 @@ export const ScheduleItem = ({ setTimeType(filterTimeType[0]); } } - }, [field.value]); + }, [field.value, timeType, timeVal]); // EUI missing some props const rest = { disabled: isDisabled }; diff --git a/x-pack/plugins/siem/public/alerts/components/rules/step_about_rule/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/step_about_rule/index.tsx index e41416f2a0ccb2..4f4c5213c95e02 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/step_about_rule/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/step_about_rule/index.tsx @@ -101,7 +101,7 @@ const StepAboutRuleComponent: FC = ({ setMyStepData({ ...data, isNew: false } as AboutStepRule); } } - }, [form]); + }, [form, setStepData]); useEffect(() => { const { isNew, ...initDefaultValue } = myStepData; @@ -113,13 +113,13 @@ const StepAboutRuleComponent: FC = ({ setMyStepData(myDefaultValues); setFieldValue(form, schema, myDefaultValues); } - }, [defaultValues]); + }, [defaultValues, form, myStepData]); useEffect(() => { if (setForm != null) { setForm(RuleStep.aboutRule, form); } - }, [form]); + }, [form, setForm]); return isReadOnlyView && myStepData.name != null ? ( diff --git a/x-pack/plugins/siem/public/alerts/components/rules/step_define_rule/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/step_define_rule/index.tsx index fc875908bd4ef9..6acfdf93aa8360 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/step_define_rule/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/step_define_rule/index.tsx @@ -123,7 +123,7 @@ const StepDefineRuleComponent: FC = ({ setMyStepData({ ...data, isNew: false } as DefineStepRule); } } - }, [form]); + }, [form, setStepData]); useEffect(() => { const { isNew, ...values } = myStepData; @@ -132,13 +132,13 @@ const StepDefineRuleComponent: FC = ({ setMyStepData(newValues); setFieldValue(form, schema, newValues); } - }, [defaultValues, setMyStepData, setFieldValue]); + }, [defaultValues, setMyStepData, myStepData, form]); useEffect(() => { if (setForm != null) { setForm(RuleStep.defineRule, form); } - }, [form]); + }, [form, setForm]); const handleResetIndices = useCallback(() => { const indexField = form.getFields().index; diff --git a/x-pack/plugins/siem/public/alerts/components/rules/step_rule_actions/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/step_rule_actions/index.tsx index ad71059984a8b0..177d45101fa467 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/step_rule_actions/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/step_rule_actions/index.tsx @@ -99,7 +99,7 @@ const StepRuleActionsComponent: FC = ({ } } }, - [form] + [form, setStepData] ); useEffect(() => { @@ -112,13 +112,13 @@ const StepRuleActionsComponent: FC = ({ setMyStepData(myDefaultValues); setFieldValue(form, schema, myDefaultValues); } - }, [defaultValues]); + }, [defaultValues, form, myStepData, schema]); useEffect(() => { if (setForm != null) { setForm(RuleStep.ruleActions, form); } - }, [form]); + }, [form, setForm]); const updateThrottle = useCallback((throttle) => setMyStepData({ ...myStepData, throttle }), [ myStepData, @@ -142,7 +142,7 @@ const StepRuleActionsComponent: FC = ({ options: throttleOptions, }, }), - [isLoading, updateThrottle] + [isLoading, throttleOptions, updateThrottle] ); return isReadOnlyView && myStepData != null ? ( diff --git a/x-pack/plugins/siem/public/alerts/components/rules/step_schedule_rule/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/step_schedule_rule/index.tsx index fa49637a0c830d..ca54cfc8adcb3d 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/step_schedule_rule/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/step_schedule_rule/index.tsx @@ -62,7 +62,7 @@ const StepScheduleRuleComponent: FC = ({ setMyStepData({ ...data, isNew: false } as ScheduleStepRule); } } - }, [form]); + }, [form, setStepData]); useEffect(() => { const { isNew, ...initDefaultValue } = myStepData; @@ -74,13 +74,13 @@ const StepScheduleRuleComponent: FC = ({ setMyStepData(myDefaultValues); setFieldValue(form, schema, myDefaultValues); } - }, [defaultValues]); + }, [defaultValues, form, myStepData]); useEffect(() => { if (setForm != null) { setForm(RuleStep.scheduleRule, form); } - }, [form]); + }, [form, setForm]); return isReadOnlyView && myStepData != null ? ( diff --git a/x-pack/plugins/siem/public/alerts/components/rules/throttle_select_field/index.tsx b/x-pack/plugins/siem/public/alerts/components/rules/throttle_select_field/index.tsx index 133f25ef3a03f6..7b56367f60da78 100644 --- a/x-pack/plugins/siem/public/alerts/components/rules/throttle_select_field/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/rules/throttle_select_field/index.tsx @@ -31,7 +31,7 @@ export const ThrottleSelectField: ThrottleSelectField = (props) => { props.field.setValue(throttle); props.handleChange(throttle); }, - [props.field.setValue, props.handleChange] + [props] ); const newEuiFieldProps = { ...props.euiFieldProps, onChange }; return ; diff --git a/x-pack/plugins/siem/public/alerts/components/signals/index.tsx b/x-pack/plugins/siem/public/alerts/components/signals/index.tsx index eb19cfea97324f..49e26848044248 100644 --- a/x-pack/plugins/siem/public/alerts/components/signals/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/signals/index.tsx @@ -110,7 +110,16 @@ export const SignalsTableComponent: React.FC = ({ }); } return null; - }, [browserFields, globalFilters, globalQuery, indexPatterns, kibana, to, from]); + }, [ + browserFields, + indexPatterns, + kibana.services.uiSettings, + defaultFilters, + globalFilters, + globalQuery, + from, + to, + ]); // Callback for creating a new timeline -- utilized by row/batch actions const createTimelineCallback = useCallback( @@ -136,14 +145,14 @@ export const SignalsTableComponent: React.FC = ({ ({ eventIds, isLoading }: SetEventsLoadingProps) => { setEventsLoading!({ id: SIGNALS_PAGE_TIMELINE_ID, eventIds, isLoading }); }, - [setEventsLoading, SIGNALS_PAGE_TIMELINE_ID] + [setEventsLoading] ); const setEventsDeletedCallback = useCallback( ({ eventIds, isDeleted }: SetEventsDeletedProps) => { setEventsDeleted!({ id: SIGNALS_PAGE_TIMELINE_ID, eventIds, isDeleted }); }, - [setEventsDeleted, SIGNALS_PAGE_TIMELINE_ID] + [setEventsDeleted] ); // Catches state change isSelectAllChecked->false upon user selection change to reset utility bar diff --git a/x-pack/plugins/siem/public/alerts/components/signals_histogram_panel/index.tsx b/x-pack/plugins/siem/public/alerts/components/signals_histogram_panel/index.tsx index add39ad6ccf0f9..e6eb4168cb8b56 100644 --- a/x-pack/plugins/siem/public/alerts/components/signals_histogram_panel/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/signals_histogram_panel/index.tsx @@ -131,14 +131,17 @@ export const SignalsHistogramPanel = memo( totalSignalsObj.value, totalSignalsObj.relation === 'gte' ? '>' : totalSignalsObj.relation === 'lte' ? '<' : '' ), - [totalSignalsObj] + [defaultNumberFormat, totalSignalsObj.relation, totalSignalsObj.value] ); - const setSelectedOptionCallback = useCallback((event: React.ChangeEvent) => { - setSelectedStackByOption( - stackByOptions?.find((co) => co.value === event.target.value) ?? defaultStackByOption - ); - }, []); + const setSelectedOptionCallback = useCallback( + (event: React.ChangeEvent) => { + setSelectedStackByOption( + stackByOptions?.find((co) => co.value === event.target.value) ?? defaultStackByOption + ); + }, + [defaultStackByOption, stackByOptions] + ); const formattedSignalsData = useMemo(() => formatSignalsData(signalsData), [signalsData]); @@ -175,7 +178,7 @@ export const SignalsHistogramPanel = memo( deleteQuery({ id: uniqueQueryId }); } }; - }, []); + }, [deleteQuery, uniqueQueryId]); useEffect(() => { if (refetch != null && setQuery != null) { @@ -189,7 +192,7 @@ export const SignalsHistogramPanel = memo( refetch, }); } - }, [setQuery, isLoadingSignals, signalsData, response, request, refetch]); + }, [setQuery, isLoadingSignals, signalsData, response, request, refetch, uniqueQueryId]); useEffect(() => { setTotalSignalsObj( @@ -219,7 +222,15 @@ export const SignalsHistogramPanel = memo( !isEmpty(converted) ? [converted] : [] ) ); - }, [selectedStackByOption.value, from, to, query, filters]); + }, [ + selectedStackByOption.value, + from, + to, + query, + filters, + kibana.services.uiSettings, + setSignalsQuery, + ]); const linkButton = useMemo(() => { if (showLinkToSignals) { diff --git a/x-pack/plugins/siem/public/alerts/components/user_info/index.tsx b/x-pack/plugins/siem/public/alerts/components/user_info/index.tsx index faf90162925595..aa5660da0aabb4 100644 --- a/x-pack/plugins/siem/public/alerts/components/user_info/index.tsx +++ b/x-pack/plugins/siem/public/alerts/components/user_info/index.tsx @@ -169,19 +169,19 @@ export const useUserInfo = (): State => { if (loading !== privilegeLoading || indexNameLoading) { dispatch({ type: 'updateLoading', loading: privilegeLoading || indexNameLoading }); } - }, [loading, privilegeLoading, indexNameLoading]); + }, [loading, privilegeLoading, indexNameLoading, dispatch]); useEffect(() => { if (!loading && hasIndexManage !== hasApiIndexManage && hasApiIndexManage != null) { dispatch({ type: 'updateHasIndexManage', hasIndexManage: hasApiIndexManage }); } - }, [loading, hasIndexManage, hasApiIndexManage]); + }, [loading, hasIndexManage, hasApiIndexManage, dispatch]); useEffect(() => { if (!loading && hasIndexWrite !== hasApiIndexWrite && hasApiIndexWrite != null) { dispatch({ type: 'updateHasIndexWrite', hasIndexWrite: hasApiIndexWrite }); } - }, [loading, hasIndexWrite, hasApiIndexWrite]); + }, [loading, hasIndexWrite, hasApiIndexWrite, dispatch]); useEffect(() => { if ( @@ -191,31 +191,31 @@ export const useUserInfo = (): State => { ) { dispatch({ type: 'updateIsSignalIndexExists', isSignalIndexExists: isApiSignalIndexExists }); } - }, [loading, isSignalIndexExists, isApiSignalIndexExists]); + }, [loading, isSignalIndexExists, isApiSignalIndexExists, dispatch]); useEffect(() => { if (!loading && isAuthenticated !== isApiAuthenticated && isApiAuthenticated != null) { dispatch({ type: 'updateIsAuthenticated', isAuthenticated: isApiAuthenticated }); } - }, [loading, isAuthenticated, isApiAuthenticated]); + }, [loading, isAuthenticated, isApiAuthenticated, dispatch]); useEffect(() => { if (!loading && hasEncryptionKey !== isApiEncryptionKey && isApiEncryptionKey != null) { dispatch({ type: 'updateHasEncryptionKey', hasEncryptionKey: isApiEncryptionKey }); } - }, [loading, hasEncryptionKey, isApiEncryptionKey]); + }, [loading, hasEncryptionKey, isApiEncryptionKey, dispatch]); useEffect(() => { if (!loading && canUserCRUD !== capabilitiesCanUserCRUD && capabilitiesCanUserCRUD != null) { dispatch({ type: 'updateCanUserCRUD', canUserCRUD: capabilitiesCanUserCRUD }); } - }, [loading, canUserCRUD, capabilitiesCanUserCRUD]); + }, [loading, canUserCRUD, capabilitiesCanUserCRUD, dispatch]); useEffect(() => { if (!loading && signalIndexName !== apiSignalIndexName && apiSignalIndexName != null) { dispatch({ type: 'updateSignalIndexName', signalIndexName: apiSignalIndexName }); } - }, [loading, signalIndexName, apiSignalIndexName]); + }, [loading, signalIndexName, apiSignalIndexName, dispatch]); useEffect(() => { if ( diff --git a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/fetch_index_patterns.tsx b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/fetch_index_patterns.tsx index 157f1490971f15..30653d582369e0 100644 --- a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/fetch_index_patterns.tsx +++ b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/fetch_index_patterns.tsx @@ -94,7 +94,7 @@ export const useFetchIndexPatterns = (defaultIndices: string[] = []): Return => isSubscribed = false; abortCtrl.abort(); }; - }, [indices]); + }, [apolloClient, dispatchToaster, indices]); return [{ browserFields, isLoading, indices, indicesExists, indexPatterns }, setIndices]; }; diff --git a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/persist_rule.tsx b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/persist_rule.tsx index 03080bf68cbf53..1e09ac00413549 100644 --- a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/persist_rule.tsx +++ b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/persist_rule.tsx @@ -53,7 +53,7 @@ export const usePersistRule = (): ReturnPersistRule => { isSubscribed = false; abortCtrl.abort(); }; - }, [rule]); + }, [dispatchToaster, rule]); return [{ isLoading, isSaved }, setRule]; }; diff --git a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_pre_packaged_rules.tsx b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_pre_packaged_rules.tsx index de4037ce7134ca..f2bc0fad2842de 100644 --- a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_pre_packaged_rules.tsx +++ b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_pre_packaged_rules.tsx @@ -185,7 +185,14 @@ export const usePrePackagedRules = ({ isSubscribed = false; abortCtrl.abort(); }; - }, [canUserCRUD, hasIndexWrite, isAuthenticated, hasEncryptionKey, isSignalIndexExists]); + }, [ + canUserCRUD, + hasIndexWrite, + isAuthenticated, + hasEncryptionKey, + isSignalIndexExists, + dispatchToaster, + ]); return { loading, diff --git a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rule.tsx b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rule.tsx index 6ae5da3e56ff64..090b4026a28c48 100644 --- a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rule.tsx +++ b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rule.tsx @@ -55,7 +55,7 @@ export const useRule = (id: string | undefined): ReturnRule => { isSubscribed = false; abortCtrl.abort(); }; - }, [id]); + }, [dispatchToaster, id]); return [loading, rule]; }; diff --git a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rule_status.tsx b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rule_status.tsx index b9f5e1f152c218..dd05fa091da9c8 100644 --- a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rule_status.tsx +++ b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rule_status.tsx @@ -64,7 +64,7 @@ export const useRuleStatus = (id: string | undefined | null): ReturnRuleStatus = isSubscribed = false; abortCtrl.abort(); }; - }, [id]); + }, [dispatchToaster, id]); return [loading, ruleStatus, fetchRuleStatus.current]; }; @@ -119,7 +119,7 @@ export const useRulesStatuses = (rules: Rules): ReturnRulesStatuses => { isSubscribed = false; abortCtrl.abort(); }; - }, [rules]); + }, [dispatchToaster, rules]); return { loading, rulesStatuses }; }; diff --git a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rules.tsx b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rules.tsx index 3a074f2bc3785a..a8c998e60af9c0 100644 --- a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rules.tsx +++ b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_rules.tsx @@ -95,10 +95,13 @@ export const useRules = ({ filterOptions.filter, filterOptions.sortField, filterOptions.sortOrder, - filterOptions.tags?.sort().join(), filterOptions.showCustomRules, filterOptions.showElasticRules, refetchPrePackagedRulesStatus, + filterOptions, + pagination, + dispatchRulesInReducer, + dispatchToaster, ]); return [loading, rules, reFetchRules.current]; diff --git a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_tags.tsx b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_tags.tsx index ebfe73f2f08639..0e82d1b27787e9 100644 --- a/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_tags.tsx +++ b/x-pack/plugins/siem/public/alerts/containers/detection_engine/rules/use_tags.tsx @@ -53,7 +53,7 @@ export const useTags = (): ReturnTags => { isSubscribed = false; abortCtrl.abort(); }; - }, []); + }, [dispatchToaster]); return [loading, tags, reFetchTags.current]; }; diff --git a/x-pack/plugins/siem/public/alerts/containers/detection_engine/signals/use_privilege_user.tsx b/x-pack/plugins/siem/public/alerts/containers/detection_engine/signals/use_privilege_user.tsx index e67afd686a7cab..fbe45bd220fbd6 100644 --- a/x-pack/plugins/siem/public/alerts/containers/detection_engine/signals/use_privilege_user.tsx +++ b/x-pack/plugins/siem/public/alerts/containers/detection_engine/signals/use_privilege_user.tsx @@ -83,7 +83,7 @@ export const usePrivilegeUser = (): ReturnPrivilegeUser => { isSubscribed = false; abortCtrl.abort(); }; - }, []); + }, [dispatchToaster]); return { loading, ...privilegeUser }; }; diff --git a/x-pack/plugins/siem/public/alerts/containers/detection_engine/signals/use_signal_index.tsx b/x-pack/plugins/siem/public/alerts/containers/detection_engine/signals/use_signal_index.tsx index 6c428bd9354ee3..b17e719b5f3c5d 100644 --- a/x-pack/plugins/siem/public/alerts/containers/detection_engine/signals/use_signal_index.tsx +++ b/x-pack/plugins/siem/public/alerts/containers/detection_engine/signals/use_signal_index.tsx @@ -103,7 +103,7 @@ export const useSignalIndex = (): ReturnSignalIndex => { isSubscribed = false; abortCtrl.abort(); }; - }, []); + }, [dispatchToaster]); return { loading, ...signalIndex }; }; diff --git a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/all/index.tsx b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/all/index.tsx index 9e61ec0eb3bcf8..39af78d6e10cc5 100644 --- a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/all/index.tsx +++ b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/all/index.tsx @@ -236,9 +236,9 @@ export const AllRules = React.memo( reFetchRules: reFetchRulesData, }); }, [ - dispatch, dispatchToaster, hasMlPermissions, + hasNoPermissions, history, loadingRuleIds, loadingRulesAction, @@ -313,7 +313,7 @@ export const AllRules = React.memo( ))} ), - [allRulesTabs, allRulesTab, setAllRulesTab] + [allRulesTab, setAllRulesTab] ); return ( diff --git a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/all/rules_table_filters/rules_table_filters.tsx b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/all/rules_table_filters/rules_table_filters.tsx index 2bc19ae45a0788..70accc532d1cc6 100644 --- a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/all/rules_table_filters/rules_table_filters.tsx +++ b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/all/rules_table_filters/rules_table_filters.tsx @@ -45,7 +45,7 @@ const RulesTableFiltersComponent = ({ useEffect(() => { reFetchTags(); - }, [rulesCustomInstalled, rulesInstalled]); + }, [reFetchTags, rulesCustomInstalled, rulesInstalled]); // Propagate filter changes to parent useEffect(() => { diff --git a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/create/index.tsx b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/create/index.tsx index dd290ec1ae582b..13f6085203e422 100644 --- a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/create/index.tsx +++ b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/create/index.tsx @@ -155,7 +155,7 @@ const CreateRulePageComponent: React.FC = () => { } } }, - [isStepRuleInReadOnlyView, openAccordionId, stepsData.current, setRule] + [isStepRuleInReadOnlyView, openAccordionId, setRule] ); const setStepsForm = useCallback((step: RuleStep, form: FormHook) => { @@ -171,7 +171,7 @@ const CreateRulePageComponent: React.FC = () => { } return 'passive'; }, - [openAccordionId, stepsData.current] + [openAccordionId] ); const defineRuleButton = ( diff --git a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/details/index.tsx b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/details/index.tsx index 74110e25cc9400..c79bbb699edb3d 100644 --- a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/details/index.tsx +++ b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/details/index.tsx @@ -191,7 +191,7 @@ export const RuleDetailsPageComponent: FC = ({ ))} ), - [ruleDetailTabs, ruleDetailTab, setRuleDetailTab] + [ruleDetailTab, setRuleDetailTab] ); const ruleError = useMemo( () => diff --git a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/edit/index.tsx b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/edit/index.tsx index 59322e58da83fb..3839f943ce712f 100644 --- a/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/edit/index.tsx +++ b/x-pack/plugins/siem/public/alerts/pages/detection_engine/rules/edit/index.tsx @@ -216,7 +216,6 @@ const EditRulePageComponent: FC = () => { myScheduleRuleForm, myActionsRuleForm, setStepsForm, - stepsForm, actionMessageParams, ] ); @@ -266,12 +265,16 @@ const EditRulePageComponent: FC = () => { setTabHasError(invalidForms); } }, [ - stepsForm, - myAboutRuleForm, - myDefineRuleForm, - myScheduleRuleForm, - myActionsRuleForm, selectedTab, + myAboutRuleForm.isValid, + myAboutRuleForm.data, + myDefineRuleForm.isValid, + myDefineRuleForm.data, + myScheduleRuleForm.isValid, + myScheduleRuleForm.data, + myActionsRuleForm.isValid, + myActionsRuleForm.data, + setRule, ruleId, ]); @@ -320,7 +323,7 @@ const EditRulePageComponent: FC = () => { setInitForm(true); setSelectedTab(tab); }, - [selectedTab, stepsForm.current] + [selectedTab] ); useEffect(() => { @@ -338,7 +341,7 @@ const EditRulePageComponent: FC = () => { useEffect(() => { const tabIndex = rule?.immutable ? 3 : 0; setSelectedTab(tabs[tabIndex]); - }, [rule]); + }, [rule, tabs]); if (isSaved) { displaySuccessToast(i18n.SUCCESSFULLY_SAVED_RULE(rule?.name ?? ''), dispatchToaster); diff --git a/x-pack/plugins/siem/public/cases/components/add_comment/index.tsx b/x-pack/plugins/siem/public/cases/components/add_comment/index.tsx index 277352c39df65e..a9d20f015e2a6c 100644 --- a/x-pack/plugins/siem/public/cases/components/add_comment/index.tsx +++ b/x-pack/plugins/siem/public/cases/components/add_comment/index.tsx @@ -59,7 +59,7 @@ export const AddComment = React.memo( `${comment}${comment.length > 0 ? '\n\n' : ''}${insertQuote}` ); } - }, [insertQuote]); + }, [form, insertQuote]); const onSubmit = useCallback(async () => { const { isValid, data } = await form.submit(); @@ -70,7 +70,7 @@ export const AddComment = React.memo( await postComment(data, onCommentPosted); form.reset(); } - }, [form, onCommentPosted, onCommentSaving]); + }, [form, onCommentPosted, onCommentSaving, postComment]); return ( {isLoading && showLoading && } diff --git a/x-pack/plugins/siem/public/cases/components/all_cases/index.tsx b/x-pack/plugins/siem/public/cases/components/all_cases/index.tsx index 12f0d02eb10f69..1891a2853ce2b2 100644 --- a/x-pack/plugins/siem/public/cases/components/all_cases/index.tsx +++ b/x-pack/plugins/siem/public/cases/components/all_cases/index.tsx @@ -130,12 +130,9 @@ export const AllCases = React.memo(({ userCanCrud }) => { }); const [deleteBulk, setDeleteBulk] = useState([]); const filterRefetch = useRef<() => void>(); - const setFilterRefetch = useCallback( - (refetchFilter: () => void) => { - filterRefetch.current = refetchFilter; - }, - [filterRefetch.current] - ); + const setFilterRefetch = useCallback((refetchFilter: () => void) => { + filterRefetch.current = refetchFilter; + }, []); const refreshCases = useCallback( (dataRefresh = true) => { if (dataRefresh) refetchCases(); @@ -146,7 +143,7 @@ export const AllCases = React.memo(({ userCanCrud }) => { filterRefetch.current(); } }, - [filterOptions, queryParams, filterRefetch.current] + [refetchCases, fetchCasesStatus, setSelectedCases] ); useEffect(() => { @@ -158,7 +155,7 @@ export const AllCases = React.memo(({ userCanCrud }) => { refreshCases(); dispatchResetIsUpdated(); } - }, [isDeleted, isUpdated]); + }, [dispatchResetIsDeleted, dispatchResetIsUpdated, isDeleted, isUpdated, refreshCases]); const confirmDeleteModal = useMemo( () => ( (({ userCanCrud }) => { )} /> ), - [deleteBulk, deleteThisCase, isDisplayConfirmDeleteModal] + [ + deleteBulk, + deleteThisCase, + handleOnDeleteConfirm, + handleToggleModal, + isDisplayConfirmDeleteModal, + ] ); - const toggleDeleteModal = useCallback((deleteCase: Case) => { - handleToggleModal(); - setDeleteThisCase(deleteCase); - }, []); + const toggleDeleteModal = useCallback( + (deleteCase: Case) => { + handleToggleModal(); + setDeleteThisCase(deleteCase); + }, + [handleToggleModal] + ); const toggleBulkDeleteModal = useCallback( (caseIds: string[]) => { @@ -192,14 +198,14 @@ export const AllCases = React.memo(({ userCanCrud }) => { const convertToDeleteCases: DeleteCase[] = caseIds.map((id) => ({ id })); setDeleteBulk(convertToDeleteCases); }, - [selectedCases] + [handleToggleModal, selectedCases] ); const handleUpdateCaseStatus = useCallback( (status: string) => { updateBulkStatus(selectedCases, status); }, - [selectedCases] + [selectedCases, updateBulkStatus] ); const selectedCaseIds = useMemo( @@ -220,7 +226,7 @@ export const AllCases = React.memo(({ userCanCrud }) => { })} /> ), - [selectedCaseIds, filterOptions.status, toggleBulkDeleteModal] + [filterOptions.status, toggleBulkDeleteModal, selectedCaseIds, handleUpdateCaseStatus] ); const handleDispatchUpdate = useCallback( (args: Omit) => { @@ -261,7 +267,7 @@ export const AllCases = React.memo(({ userCanCrud }) => { setQueryParams(newQueryParams); refreshCases(false); }, - [queryParams] + [queryParams, refreshCases, setQueryParams] ); const onFilterChangedCallback = useCallback( @@ -274,7 +280,7 @@ export const AllCases = React.memo(({ userCanCrud }) => { setFilters(newFilterOptions); refreshCases(false); }, - [filterOptions, queryParams] + [refreshCases, setFilters, setQueryParams] ); const memoizedGetCasesColumns = useMemo( @@ -296,7 +302,7 @@ export const AllCases = React.memo(({ userCanCrud }) => { }; const euiBasicTableSelectionProps = useMemo>( () => ({ onSelectionChange: setSelectedCases }), - [selectedCases] + [setSelectedCases] ); const isCasesLoading = useMemo( () => loading.indexOf('cases') > -1 || loading.indexOf('caseUpdate') > -1, diff --git a/x-pack/plugins/siem/public/cases/components/all_cases/table_filters.tsx b/x-pack/plugins/siem/public/cases/components/all_cases/table_filters.tsx index 42340b455c3af6..d8207f6d09cad8 100644 --- a/x-pack/plugins/siem/public/cases/components/all_cases/table_filters.tsx +++ b/x-pack/plugins/siem/public/cases/components/all_cases/table_filters.tsx @@ -66,13 +66,13 @@ const CasesTableFiltersComponent = ({ const newReporters = selectedReporters.filter((r) => reporters.includes(r)); handleSelectedReporters(newReporters); } - }, [reporters]); + }, [handleSelectedReporters, reporters, selectedReporters]); useEffect(() => { if (selectedTags.length) { const newTags = selectedTags.filter((t) => tags.includes(t)); handleSelectedTags(newTags); } - }, [tags]); + }, [handleSelectedTags, selectedTags, tags]); const handleSelectedReporters = useCallback( (newReporters) => { @@ -84,7 +84,7 @@ const CasesTableFiltersComponent = ({ onFilterChanged({ reporters: reportersObj }); } }, - [selectedReporters, respReporters] + [selectedReporters, respReporters, onFilterChanged] ); const handleSelectedTags = useCallback( @@ -94,7 +94,7 @@ const CasesTableFiltersComponent = ({ onFilterChanged({ tags: newTags }); } }, - [selectedTags] + [onFilterChanged, selectedTags] ); const handleOnSearch = useCallback( (newSearch) => { @@ -104,7 +104,7 @@ const CasesTableFiltersComponent = ({ onFilterChanged({ search: trimSearch }); } }, - [search] + [onFilterChanged, search] ); const handleToggleFilter = useCallback( (showOpen) => { @@ -113,7 +113,7 @@ const CasesTableFiltersComponent = ({ onFilterChanged({ status: showOpen ? 'open' : 'closed' }); } }, - [showOpenCases] + [onFilterChanged, showOpenCases] ); return ( diff --git a/x-pack/plugins/siem/public/cases/components/case_view/actions.tsx b/x-pack/plugins/siem/public/cases/components/case_view/actions.tsx index cd9318a355e3c7..993d01df3e65fa 100644 --- a/x-pack/plugins/siem/public/cases/components/case_view/actions.tsx +++ b/x-pack/plugins/siem/public/cases/components/case_view/actions.tsx @@ -44,7 +44,13 @@ const CaseViewActionsComponent: React.FC = ({ onConfirm={handleOnDeleteConfirm.bind(null, [{ id: caseData.id, title: caseData.title }])} /> ), - [isDisplayConfirmDeleteModal, caseData] + [ + caseData.title, + caseData.id, + isDisplayConfirmDeleteModal, + handleToggleModal, + handleOnDeleteConfirm, + ] ); const propertyActions = useMemo( () => [ diff --git a/x-pack/plugins/siem/public/cases/components/configure_cases/connectors.tsx b/x-pack/plugins/siem/public/cases/components/configure_cases/connectors.tsx index 947d68fd04f7bb..adaa620f60a847 100644 --- a/x-pack/plugins/siem/public/cases/components/configure_cases/connectors.tsx +++ b/x-pack/plugins/siem/public/cases/components/configure_cases/connectors.tsx @@ -68,7 +68,7 @@ const ConnectorsComponent: React.FC = ({ ), - [connectorsName, updateConnectorDisabled] + [connectorsName, handleShowEditFlyout, updateConnectorDisabled] ); return ( diff --git a/x-pack/plugins/siem/public/cases/components/configure_cases/connectors_dropdown.tsx b/x-pack/plugins/siem/public/cases/components/configure_cases/connectors_dropdown.tsx index c5481f592e7504..d283f0eff9e03e 100644 --- a/x-pack/plugins/siem/public/cases/components/configure_cases/connectors_dropdown.tsx +++ b/x-pack/plugins/siem/public/cases/components/configure_cases/connectors_dropdown.tsx @@ -91,7 +91,7 @@ const ConnectorsDropdownComponent: React.FC = ({ } return connectorsFormatted; - }, [connectors]); + }, [appendAddConnectorButton, connectors]); return ( = ({ const myMapping = mapping ?? defaultMapping; onChangeMapping(setActionTypeToMapping(caseField, newActionType, myMapping)); }, - [mapping] + [defaultMapping, mapping, onChangeMapping] ); const onChangeThirdParty = useCallback( @@ -103,7 +103,7 @@ const FieldMappingComponent: React.FC = ({ const myMapping = mapping ?? defaultMapping; onChangeMapping(setThirdPartyToMapping(caseField, newThirdPartyField, myMapping)); }, - [mapping] + [defaultMapping, mapping, onChangeMapping] ); const selectedConnector = connectorsConfiguration[connectorActionTypeId] ?? { fields: {} }; diff --git a/x-pack/plugins/siem/public/cases/components/configure_cases/index.tsx b/x-pack/plugins/siem/public/cases/components/configure_cases/index.tsx index 6e1ef293fd5c4d..8cbfd7a80865fb 100644 --- a/x-pack/plugins/siem/public/cases/components/configure_cases/index.tsx +++ b/x-pack/plugins/siem/public/cases/components/configure_cases/index.tsx @@ -77,7 +77,7 @@ const ConfigureCasesComponent: React.FC = ({ userC // ActionsConnectorsContextProvider reloadConnectors prop expects a Promise. // TODO: Fix it if reloadConnectors type change. - const reloadConnectors = useCallback(async () => refetchConnectors(), []); + const reloadConnectors = useCallback(async () => refetchConnectors(), [refetchConnectors]); const isLoadingAny = isLoadingConnectors || persistLoading || loadingCaseConfigure; const updateConnectorDisabled = isLoadingAny || !connectorIsValid || connectorId === 'none'; @@ -85,19 +85,13 @@ const ConfigureCasesComponent: React.FC = ({ userC setEditFlyoutVisibility(true); }, []); - const handleSetAddFlyoutVisibility = useCallback( - (isVisible: boolean) => { - setAddFlyoutVisibility(isVisible); - }, - [currentConfiguration, connectorId, closureType] - ); + const handleSetAddFlyoutVisibility = useCallback((isVisible: boolean) => { + setAddFlyoutVisibility(isVisible); + }, []); - const handleSetEditFlyoutVisibility = useCallback( - (isVisible: boolean) => { - setEditFlyoutVisibility(isVisible); - }, - [currentConfiguration, connectorId, closureType] - ); + const handleSetEditFlyoutVisibility = useCallback((isVisible: boolean) => { + setEditFlyoutVisibility(isVisible); + }, []); const onChangeConnector = useCallback( (id: string) => { @@ -113,7 +107,7 @@ const ConfigureCasesComponent: React.FC = ({ userC closureType, }); }, - [connectorId, closureType, version] + [setConnector, persistCaseConfigure, connectors, closureType] ); const onChangeClosureType = useCallback( @@ -125,7 +119,7 @@ const ConfigureCasesComponent: React.FC = ({ userC closureType: type, }); }, - [connectorId, closureType, version] + [setClosureType, persistCaseConfigure, connectorId, connectors] ); useEffect(() => { @@ -141,7 +135,7 @@ const ConfigureCasesComponent: React.FC = ({ userC ) { setConnectorIsValid(true); } - }, [connectors, connectorId]); + }, [connectors, connectorId, isLoadingConnectors]); useEffect(() => { if (!isLoadingConnectors && connectorId !== 'none') { @@ -149,7 +143,7 @@ const ConfigureCasesComponent: React.FC = ({ userC connectors.find((c) => c.id === connectorId) as ActionConnectorTableItem ); } - }, [connectors, connectorId]); + }, [connectors, connectorId, isLoadingConnectors]); return ( diff --git a/x-pack/plugins/siem/public/cases/components/connector_selector/form.tsx b/x-pack/plugins/siem/public/cases/components/connector_selector/form.tsx index 9e058ee5cf09e1..c77871476a0042 100644 --- a/x-pack/plugins/siem/public/cases/components/connector_selector/form.tsx +++ b/x-pack/plugins/siem/public/cases/components/connector_selector/form.tsx @@ -33,7 +33,7 @@ export const ConnectorSelector = ({ useEffect(() => { field.setValue(defaultValue); - }, [defaultValue]); + }, [defaultValue, field]); const handleContentChange = useCallback( (newContent: string) => { diff --git a/x-pack/plugins/siem/public/cases/components/create/index.tsx b/x-pack/plugins/siem/public/cases/components/create/index.tsx index ae0ffe498c3913..c5e28224419007 100644 --- a/x-pack/plugins/siem/public/cases/components/create/index.tsx +++ b/x-pack/plugins/siem/public/cases/components/create/index.tsx @@ -93,7 +93,7 @@ export const Create = React.memo(() => { if (isValid) { await postCase(data); } - }, [form]); + }, [form, postCase]); const handleSetIsCancel = useCallback(() => { setIsCancel(true); diff --git a/x-pack/plugins/siem/public/cases/components/open_closed_stats/index.tsx b/x-pack/plugins/siem/public/cases/components/open_closed_stats/index.tsx index b9dab13090acaf..6d9712abe95f17 100644 --- a/x-pack/plugins/siem/public/cases/components/open_closed_stats/index.tsx +++ b/x-pack/plugins/siem/public/cases/components/open_closed_stats/index.tsx @@ -24,7 +24,7 @@ export const OpenClosedStats = React.memo( description: isLoading ? : caseCount ?? 'N/A', }, ], - [caseCount, caseStatus, isLoading, dataTestSubj] + [caseCount, caseStatus, isLoading] ); return ( { return ( @@ -161,15 +169,15 @@ export const usePushToService = ({ ); }, [ - caseConnectorId, - caseConnectorName, - connectors, - errorsMsg, handlePushToService, isLoading, loadingLicense, + errorsMsg.length, userCanCrud, isValidConnector, + caseServices, + caseConnectorId, + caseConnectorName, ]); const objToReturn = useMemo(() => { diff --git a/x-pack/plugins/siem/public/cases/components/user_action_tree/index.tsx b/x-pack/plugins/siem/public/cases/components/user_action_tree/index.tsx index da49014eb0204d..b58543a2ed95d0 100644 --- a/x-pack/plugins/siem/public/cases/components/user_action_tree/index.tsx +++ b/x-pack/plugins/siem/public/cases/components/user_action_tree/index.tsx @@ -85,32 +85,29 @@ export const UserActionTree = React.memo( updateCase, }); }, - [caseData, handleManageMarkdownEditId, patchComment, updateCase] + [caseData.id, fetchUserActions, patchComment, updateCase] ); - const handleOutlineComment = useCallback( - (id: string) => { - const moveToTarget = document.getElementById(`${id}-permLink`); - if (moveToTarget != null) { - const yOffset = -60; - const y = moveToTarget.getBoundingClientRect().top + window.pageYOffset + yOffset; - window.scrollTo({ - top: y, - behavior: 'smooth', - }); - if (id === 'add-comment') { - moveToTarget.getElementsByTagName('textarea')[0].focus(); - } + const handleOutlineComment = useCallback((id: string) => { + const moveToTarget = document.getElementById(`${id}-permLink`); + if (moveToTarget != null) { + const yOffset = -60; + const y = moveToTarget.getBoundingClientRect().top + window.pageYOffset + yOffset; + window.scrollTo({ + top: y, + behavior: 'smooth', + }); + if (id === 'add-comment') { + moveToTarget.getElementsByTagName('textarea')[0].focus(); } + } + window.clearTimeout(handlerTimeoutId.current); + setSelectedOutlineCommentId(id); + handlerTimeoutId.current = window.setTimeout(() => { + setSelectedOutlineCommentId(''); window.clearTimeout(handlerTimeoutId.current); - setSelectedOutlineCommentId(id); - handlerTimeoutId.current = window.setTimeout(() => { - setSelectedOutlineCommentId(''); - window.clearTimeout(handlerTimeoutId.current); - }, 2400); - }, - [handlerTimeoutId.current] - ); + }, 2400); + }, []); const handleManageQuote = useCallback( (quote: string) => { @@ -155,7 +152,7 @@ export const UserActionTree = React.memo( showLoading={false} /> ), - [caseData.id, handleUpdate, insertQuote, userCanCrud] + [caseData.id, handleManageMarkdownEditId, handleUpdate, insertQuote, userCanCrud] ); useEffect(() => { @@ -165,7 +162,7 @@ export const UserActionTree = React.memo( handleOutlineComment(commentId); } } - }, [commentId, initLoading, isLoadingUserActions, isLoadingIds]); + }, [commentId, initLoading, isLoadingUserActions, isLoadingIds, handleOutlineComment]); return ( <> { @@ -85,37 +85,34 @@ export const UserActionMarkdown = ({ onChangeEditable(id); }, [form, id, onChangeEditable, onSaveContent]); - const renderButtons = useCallback( - ({ cancelAction, saveAction }) => { - return ( - - - - {i18n.CANCEL} - - - - - {i18n.SAVE} - - - - ); - }, - [handleCancelAction, handleSaveAction] - ); + const renderButtons = useCallback(({ cancelAction, saveAction }) => { + return ( + + + + {i18n.CANCEL} + + + + + {i18n.SAVE} + + + + ); + }, []); return isEditable ? (
username != null && username !== '').length > 0 ? ( diff --git a/x-pack/plugins/siem/public/cases/containers/configure/use_configure.tsx b/x-pack/plugins/siem/public/cases/containers/configure/use_configure.tsx index 5a85a3a0633bc8..dc68915e81150f 100644 --- a/x-pack/plugins/siem/public/cases/containers/configure/use_configure.tsx +++ b/x-pack/plugins/siem/public/cases/containers/configure/use_configure.tsx @@ -253,7 +253,16 @@ export const useCaseConfigure = (): ReturnUseCaseConfigure => { didCancel = true; abortCtrl.abort(); }; - }, [state.firstLoad]); + }, [ + dispatchToaster, + setClosureType, + setConnector, + setCurrentConfiguration, + setFirstLoad, + setLoading, + setVersion, + state.firstLoad, + ]); const persistCaseConfigure = useCallback( async ({ connectorId, connectorName, closureType }: ConnectorConfiguration) => { @@ -311,12 +320,20 @@ export const useCaseConfigure = (): ReturnUseCaseConfigure => { abortCtrl.abort(); }; }, - [state.version] + [ + dispatchToaster, + setClosureType, + setConnector, + setCurrentConfiguration, + setPersistLoading, + setVersion, + state.version, + ] ); useEffect(() => { refetchCaseConfigure(); - }, []); + }, [refetchCaseConfigure]); return { ...state, diff --git a/x-pack/plugins/siem/public/cases/containers/configure/use_connectors.tsx b/x-pack/plugins/siem/public/cases/containers/configure/use_connectors.tsx index 9cd755864d37b2..60982bfe9baabe 100644 --- a/x-pack/plugins/siem/public/cases/containers/configure/use_connectors.tsx +++ b/x-pack/plugins/siem/public/cases/containers/configure/use_connectors.tsx @@ -50,11 +50,11 @@ export const useConnectors = (): ReturnConnectors => { didCancel = true; abortCtrl.abort(); }; - }, []); + }, [dispatchToaster]); useEffect(() => { refetchConnectors(); - }, []); + }, [refetchConnectors]); return { loading, diff --git a/x-pack/plugins/siem/public/cases/containers/use_bulk_update_case.tsx b/x-pack/plugins/siem/public/cases/containers/use_bulk_update_case.tsx index ef68f4f48b1a07..1dfc5c80aa757e 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_bulk_update_case.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_bulk_update_case.tsx @@ -68,59 +68,65 @@ export const useUpdateCases = (): UseUpdateCases => { }); const [, dispatchToaster] = useStateToaster(); - const dispatchUpdateCases = useCallback((cases: BulkUpdateStatus[]) => { - let cancel = false; - const abortCtrl = new AbortController(); + const dispatchUpdateCases = useCallback( + (cases: BulkUpdateStatus[]) => { + let cancel = false; + const abortCtrl = new AbortController(); - const patchData = async () => { - try { - dispatch({ type: 'FETCH_INIT' }); - const patchResponse = await patchCasesStatus(cases, abortCtrl.signal); - if (!cancel) { - const resultCount = Object.keys(patchResponse).length; - const firstTitle = patchResponse[0].title; + const patchData = async () => { + try { + dispatch({ type: 'FETCH_INIT' }); + const patchResponse = await patchCasesStatus(cases, abortCtrl.signal); + if (!cancel) { + const resultCount = Object.keys(patchResponse).length; + const firstTitle = patchResponse[0].title; - dispatch({ type: 'FETCH_SUCCESS', payload: true }); - const messageArgs = { - totalCases: resultCount, - caseTitle: resultCount === 1 ? firstTitle : '', - }; - const message = - resultCount && patchResponse[0].status === 'open' - ? i18n.REOPENED_CASES(messageArgs) - : i18n.CLOSED_CASES(messageArgs); + dispatch({ type: 'FETCH_SUCCESS', payload: true }); + const messageArgs = { + totalCases: resultCount, + caseTitle: resultCount === 1 ? firstTitle : '', + }; + const message = + resultCount && patchResponse[0].status === 'open' + ? i18n.REOPENED_CASES(messageArgs) + : i18n.CLOSED_CASES(messageArgs); - displaySuccessToast(message, dispatchToaster); + displaySuccessToast(message, dispatchToaster); + } + } catch (error) { + if (!cancel) { + errorToToaster({ + title: i18n.ERROR_TITLE, + error: error.body && error.body.message ? new Error(error.body.message) : error, + dispatchToaster, + }); + dispatch({ type: 'FETCH_FAILURE' }); + } } - } catch (error) { - if (!cancel) { - errorToToaster({ - title: i18n.ERROR_TITLE, - error: error.body && error.body.message ? new Error(error.body.message) : error, - dispatchToaster, - }); - dispatch({ type: 'FETCH_FAILURE' }); - } - } - }; - patchData(); - return () => { - cancel = true; - abortCtrl.abort(); - }; - }, []); + }; + patchData(); + return () => { + cancel = true; + abortCtrl.abort(); + }; + }, + [dispatchToaster] + ); const dispatchResetIsUpdated = useCallback(() => { dispatch({ type: 'RESET_IS_UPDATED' }); }, []); - const updateBulkStatus = useCallback((cases: Case[], status: string) => { - const updateCasesStatus: BulkUpdateStatus[] = cases.map((theCase) => ({ - status, - id: theCase.id, - version: theCase.version, - })); - dispatchUpdateCases(updateCasesStatus); - }, []); + const updateBulkStatus = useCallback( + (cases: Case[], status: string) => { + const updateCasesStatus: BulkUpdateStatus[] = cases.map((theCase) => ({ + status, + id: theCase.id, + version: theCase.version, + })); + dispatchUpdateCases(updateCasesStatus); + }, + [dispatchUpdateCases] + ); return { ...state, updateBulkStatus, dispatchResetIsUpdated }; }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_delete_cases.tsx b/x-pack/plugins/siem/public/cases/containers/use_delete_cases.tsx index 2e8c7dfae2313f..be33f1d6a42055 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_delete_cases.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_delete_cases.tsx @@ -78,39 +78,42 @@ export const useDeleteCases = (): UseDeleteCase => { }); const [, dispatchToaster] = useStateToaster(); - const dispatchDeleteCases = useCallback((cases: DeleteCase[]) => { - let cancel = false; - const abortCtrl = new AbortController(); + const dispatchDeleteCases = useCallback( + (cases: DeleteCase[]) => { + let cancel = false; + const abortCtrl = new AbortController(); - const deleteData = async () => { - try { - dispatch({ type: 'FETCH_INIT' }); - const caseIds = cases.map((theCase) => theCase.id); - await deleteCases(caseIds, abortCtrl.signal); - if (!cancel) { - dispatch({ type: 'FETCH_SUCCESS', payload: true }); - displaySuccessToast( - i18n.DELETED_CASES(cases.length, cases.length === 1 ? cases[0].title : ''), - dispatchToaster - ); - } - } catch (error) { - if (!cancel) { - errorToToaster({ - title: i18n.ERROR_DELETING, - error: error.body && error.body.message ? new Error(error.body.message) : error, - dispatchToaster, - }); - dispatch({ type: 'FETCH_FAILURE' }); + const deleteData = async () => { + try { + dispatch({ type: 'FETCH_INIT' }); + const caseIds = cases.map((theCase) => theCase.id); + await deleteCases(caseIds, abortCtrl.signal); + if (!cancel) { + dispatch({ type: 'FETCH_SUCCESS', payload: true }); + displaySuccessToast( + i18n.DELETED_CASES(cases.length, cases.length === 1 ? cases[0].title : ''), + dispatchToaster + ); + } + } catch (error) { + if (!cancel) { + errorToToaster({ + title: i18n.ERROR_DELETING, + error: error.body && error.body.message ? new Error(error.body.message) : error, + dispatchToaster, + }); + dispatch({ type: 'FETCH_FAILURE' }); + } } - } - }; - deleteData(); - return () => { - abortCtrl.abort(); - cancel = true; - }; - }, []); + }; + deleteData(); + return () => { + abortCtrl.abort(); + cancel = true; + }; + }, + [dispatchToaster] + ); const dispatchToggleDeleteModal = useCallback(() => { dispatch({ type: 'DISPLAY_MODAL', payload: !state.isDisplayConfirmDeleteModal }); @@ -118,18 +121,18 @@ export const useDeleteCases = (): UseDeleteCase => { const dispatchResetIsDeleted = useCallback(() => { dispatch({ type: 'RESET_IS_DELETED' }); - }, [state.isDisplayConfirmDeleteModal]); + }, []); const handleOnDeleteConfirm = useCallback( (cases: DeleteCase[]) => { dispatchDeleteCases(cases); dispatchToggleDeleteModal(); }, - [state.isDisplayConfirmDeleteModal] + [dispatchDeleteCases, dispatchToggleDeleteModal] ); const handleToggleModal = useCallback(() => { dispatchToggleDeleteModal(); - }, [state.isDisplayConfirmDeleteModal]); + }, [dispatchToggleDeleteModal]); return { ...state, dispatchResetIsDeleted, handleOnDeleteConfirm, handleToggleModal }; }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_get_action_license.tsx b/x-pack/plugins/siem/public/cases/containers/use_get_action_license.tsx index 563e2a4a58c70e..5f541e82b150b6 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_get_action_license.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_get_action_license.tsx @@ -65,10 +65,10 @@ export const useGetActionLicense = (): ActionLicenseState => { didCancel = true; abortCtrl.abort(); }; - }, [actionLicenseState]); + }, [actionLicenseState, dispatchToaster]); useEffect(() => { fetchActionLicense(); - }, []); + }, [fetchActionLicense]); return { ...actionLicenseState }; }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_get_case.tsx b/x-pack/plugins/siem/public/cases/containers/use_get_case.tsx index 01ada00ba9b72d..1bb61a85855c50 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_get_case.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_get_case.tsx @@ -118,10 +118,10 @@ export const useGetCase = (caseId: string): UseGetCase => { didCancel = true; abortCtrl.abort(); }; - }, [caseId]); + }, [caseId, dispatchToaster]); useEffect(() => { callFetch(); - }, [caseId]); + }, [callFetch, caseId]); return { ...state, fetchCase: callFetch, updateCase }; }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_get_case_user_actions.tsx b/x-pack/plugins/siem/public/cases/containers/use_get_case_user_actions.tsx index 050b2815dc5110..5821f8f378b1dc 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_get_case_user_actions.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_get_case_user_actions.tsx @@ -210,13 +210,13 @@ export const useGetCaseUserActions = ( abortCtrl.abort(); }; }, - [caseUserActionsState, caseConnectorId] + [caseUserActionsState, caseConnectorId, dispatchToaster] ); useEffect(() => { if (!isEmpty(caseId)) { fetchCaseUserActions(caseId); } - }, [caseId, caseConnectorId]); + }, [caseId, caseConnectorId, fetchCaseUserActions]); return { ...caseUserActionsState, fetchCaseUserActions }; }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_get_cases.tsx b/x-pack/plugins/siem/public/cases/containers/use_get_cases.tsx index 45b571a8fe7e23..77a53347a15b7e 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_get_cases.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_get_cases.tsx @@ -150,45 +150,49 @@ export const useGetCases = (initialQueryParams?: QueryParams): UseGetCases => { dispatch({ type: 'UPDATE_FILTER_OPTIONS', payload: newFilters }); }, []); - const fetchCases = useCallback((filterOptions: FilterOptions, queryParams: QueryParams) => { - let didCancel = false; - const abortCtrl = new AbortController(); - - const fetchData = async () => { - dispatch({ type: 'FETCH_INIT', payload: 'cases' }); - try { - const response = await getCases({ - filterOptions, - queryParams, - signal: abortCtrl.signal, - }); - if (!didCancel) { - dispatch({ - type: 'FETCH_CASES_SUCCESS', - payload: response, - }); - } - } catch (error) { - if (!didCancel) { - errorToToaster({ - title: i18n.ERROR_TITLE, - error: error.body && error.body.message ? new Error(error.body.message) : error, - dispatchToaster, + const fetchCases = useCallback( + (filterOptions: FilterOptions, queryParams: QueryParams) => { + let didCancel = false; + const abortCtrl = new AbortController(); + + const fetchData = async () => { + dispatch({ type: 'FETCH_INIT', payload: 'cases' }); + try { + const response = await getCases({ + filterOptions, + queryParams, + signal: abortCtrl.signal, }); - dispatch({ type: 'FETCH_FAILURE', payload: 'cases' }); + if (!didCancel) { + dispatch({ + type: 'FETCH_CASES_SUCCESS', + payload: response, + }); + } + } catch (error) { + if (!didCancel) { + errorToToaster({ + title: i18n.ERROR_TITLE, + error: error.body && error.body.message ? new Error(error.body.message) : error, + dispatchToaster, + }); + dispatch({ type: 'FETCH_FAILURE', payload: 'cases' }); + } } - } - }; - fetchData(); - return () => { - abortCtrl.abort(); - didCancel = true; - }; - }, []); + }; + fetchData(); + return () => { + abortCtrl.abort(); + didCancel = true; + }; + }, + [dispatchToaster] + ); useEffect(() => fetchCases(state.filterOptions, state.queryParams), [ state.queryParams, state.filterOptions, + fetchCases, ]); const dispatchUpdateCaseProperty = useCallback( @@ -224,12 +228,12 @@ export const useGetCases = (initialQueryParams?: QueryParams): UseGetCases => { didCancel = true; }; }, - [state.filterOptions, state.queryParams] + [dispatchToaster, fetchCases, state.filterOptions, state.queryParams] ); const refetchCases = useCallback(() => { fetchCases(state.filterOptions, state.queryParams); - }, [state.filterOptions, state.queryParams]); + }, [fetchCases, state.filterOptions, state.queryParams]); return { ...state, diff --git a/x-pack/plugins/siem/public/cases/containers/use_get_cases_status.tsx b/x-pack/plugins/siem/public/cases/containers/use_get_cases_status.tsx index 476462b7e4c28f..e235d108ff895d 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_get_cases_status.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_get_cases_status.tsx @@ -69,11 +69,11 @@ export const useGetCasesStatus = (): UseGetCasesStatus => { didCancel = true; abortCtrl.abort(); }; - }, [casesStatusState]); + }, [casesStatusState, dispatchToaster]); useEffect(() => { fetchCasesStatus(); - }, []); + }, [fetchCasesStatus]); return { ...casesStatusState, diff --git a/x-pack/plugins/siem/public/cases/containers/use_get_reporters.tsx b/x-pack/plugins/siem/public/cases/containers/use_get_reporters.tsx index d723b8cc37c232..617e38c7b62f2b 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_get_reporters.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_get_reporters.tsx @@ -79,10 +79,10 @@ export const useGetReporters = (): UseGetReporters => { didCancel = true; abortCtrl.abort(); }; - }, [reportersState]); + }, [dispatchToaster, reportersState]); useEffect(() => { fetchReporters(); - }, []); + }, [fetchReporters]); return { ...reportersState, fetchReporters }; }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_get_tags.tsx b/x-pack/plugins/siem/public/cases/containers/use_get_tags.tsx index 14f5e35bc4976e..2470b91bef5877 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_get_tags.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_get_tags.tsx @@ -59,7 +59,7 @@ export const useGetTags = (): UseGetTags => { }); const [, dispatchToaster] = useStateToaster(); - const callFetch = () => { + const callFetch = useCallback(() => { let didCancel = false; const abortCtrl = new AbortController(); @@ -86,9 +86,9 @@ export const useGetTags = (): UseGetTags => { abortCtrl.abort(); didCancel = true; }; - }; + }); useEffect(() => { callFetch(); - }, []); + }, [callFetch]); return { ...state, fetchTags: callFetch }; }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_post_case.tsx b/x-pack/plugins/siem/public/cases/containers/use_post_case.tsx index 13cfc2738620fc..aae0eece6b05d8 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_post_case.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_post_case.tsx @@ -59,34 +59,37 @@ export const usePostCase = (): UsePostCase => { }); const [, dispatchToaster] = useStateToaster(); - const postMyCase = useCallback(async (data: CasePostRequest) => { - let cancel = false; - const abortCtrl = new AbortController(); + const postMyCase = useCallback( + async (data: CasePostRequest) => { + let cancel = false; + const abortCtrl = new AbortController(); - try { - dispatch({ type: 'FETCH_INIT' }); - const response = await postCase(data, abortCtrl.signal); - if (!cancel) { - dispatch({ - type: 'FETCH_SUCCESS', - payload: response, - }); + try { + dispatch({ type: 'FETCH_INIT' }); + const response = await postCase(data, abortCtrl.signal); + if (!cancel) { + dispatch({ + type: 'FETCH_SUCCESS', + payload: response, + }); + } + } catch (error) { + if (!cancel) { + errorToToaster({ + title: i18n.ERROR_TITLE, + error: error.body && error.body.message ? new Error(error.body.message) : error, + dispatchToaster, + }); + dispatch({ type: 'FETCH_FAILURE' }); + } } - } catch (error) { - if (!cancel) { - errorToToaster({ - title: i18n.ERROR_TITLE, - error: error.body && error.body.message ? new Error(error.body.message) : error, - dispatchToaster, - }); - dispatch({ type: 'FETCH_FAILURE' }); - } - } - return () => { - abortCtrl.abort(); - cancel = true; - }; - }, []); + return () => { + abortCtrl.abort(); + cancel = true; + }; + }, + [dispatchToaster] + ); return { ...state, postCase: postMyCase }; }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_post_comment.tsx b/x-pack/plugins/siem/public/cases/containers/use_post_comment.tsx index 9a52eaaf0db6b3..573443a7c7074a 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_post_comment.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_post_comment.tsx @@ -79,7 +79,7 @@ export const usePostComment = (caseId: string): UsePostComment => { cancel = true; }; }, - [caseId] + [caseId, dispatchToaster] ); return { ...state, postComment: postMyComment }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_post_push_to_service.tsx b/x-pack/plugins/siem/public/cases/containers/use_post_push_to_service.tsx index 4d25ac7fbf0dbc..23eb9f4ce46f29 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_post_push_to_service.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_post_push_to_service.tsx @@ -146,7 +146,7 @@ export const usePostPushToService = (): UsePostPushToService => { abortCtrl.abort(); }; }, - [] + [dispatchToaster] ); return { ...state, postPushToService }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_update_case.tsx b/x-pack/plugins/siem/public/cases/containers/use_update_case.tsx index 77cf53165d9147..28d9ee45524ba1 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_update_case.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_update_case.tsx @@ -118,7 +118,7 @@ export const useUpdateCase = ({ caseId }: { caseId: string }): UseUpdateCase => abortCtrl.abort(); }; }, - [] + [caseId, dispatchToaster] ); return { ...state, updateCaseProperty: dispatchUpdateCaseProperty }; diff --git a/x-pack/plugins/siem/public/cases/containers/use_update_comment.tsx b/x-pack/plugins/siem/public/cases/containers/use_update_comment.tsx index 821fd5523a7519..1c4061ae8d7918 100644 --- a/x-pack/plugins/siem/public/cases/containers/use_update_comment.tsx +++ b/x-pack/plugins/siem/public/cases/containers/use_update_comment.tsx @@ -111,7 +111,7 @@ export const useUpdateComment = (): UseUpdateComment => { abortCtrl.abort(); }; }, - [] + [dispatchToaster] ); return { ...state, patchComment: dispatchUpdateComment }; diff --git a/x-pack/plugins/siem/public/common/components/alerts_viewer/index.tsx b/x-pack/plugins/siem/public/common/components/alerts_viewer/index.tsx index 29f4bdff92ad60..d514c9690598f6 100644 --- a/x-pack/plugins/siem/public/common/components/alerts_viewer/index.tsx +++ b/x-pack/plugins/siem/public/common/components/alerts_viewer/index.tsx @@ -31,7 +31,7 @@ export const AlertsView = ({ `${i18n.SHOWING}: ${numeral(totalCount).format(defaultNumberFormat)} ${i18n.UNIT( totalCount )}`, - [] + [defaultNumberFormat] ); const alertsHistogramConfigs: MatrixHisrogramConfigs = useMemo( () => ({ diff --git a/x-pack/plugins/siem/public/common/components/charts/common.tsx b/x-pack/plugins/siem/public/common/components/charts/common.tsx index 4858af4f4f2576..00803e8f0b62bf 100644 --- a/x-pack/plugins/siem/public/common/components/charts/common.tsx +++ b/x-pack/plugins/siem/public/common/components/charts/common.tsx @@ -101,7 +101,7 @@ const theme: PartialTheme = { export const useTheme = () => { const isDarkMode = useUiSetting(DEFAULT_DARK_MODE); const defaultTheme = isDarkMode ? DARK_THEME : LIGHT_THEME; - const themeValue = useMemo(() => mergeWithDefaultTheme(theme, defaultTheme), []); + const themeValue = useMemo(() => mergeWithDefaultTheme(theme, defaultTheme), [defaultTheme]); return themeValue; }; diff --git a/x-pack/plugins/siem/public/common/components/drag_and_drop/drag_drop_context_wrapper.tsx b/x-pack/plugins/siem/public/common/components/drag_and_drop/drag_drop_context_wrapper.tsx index 3bd2a3da1c88b3..5ec534884dca53 100644 --- a/x-pack/plugins/siem/public/common/components/drag_and_drop/drag_drop_context_wrapper.tsx +++ b/x-pack/plugins/siem/public/common/components/drag_and_drop/drag_drop_context_wrapper.tsx @@ -125,7 +125,7 @@ export const DragDropContextWrapperComponent = React.memo( () => () => { unRegisterProvider(); }, - [] + [unRegisterProvider] ); const hoverContent = useMemo( diff --git a/x-pack/plugins/siem/public/common/components/events_viewer/index.tsx b/x-pack/plugins/siem/public/common/components/events_viewer/index.tsx index 8069ae312b3a81..a960ab9313f2d5 100644 --- a/x-pack/plugins/siem/public/common/components/events_viewer/index.tsx +++ b/x-pack/plugins/siem/public/common/components/events_viewer/index.tsx @@ -82,7 +82,16 @@ const StatefulEventsViewerComponent: React.FC = ({ return () => { deleteEventQuery({ id, inputId: 'global' }); }; - }, []); + }, [ + columns, + createTimeline, + deleteEventQuery, + id, + itemsPerPage, + showCheckboxes, + showRowRenderers, + sort, + ]); const onChangeItemsPerPage: OnChangeItemsPerPage = useCallback( (itemsChangedPerPage) => updateItemsPerPage({ id, itemsPerPage: itemsChangedPerPage }), diff --git a/x-pack/plugins/siem/public/common/components/generic_downloader/index.tsx b/x-pack/plugins/siem/public/common/components/generic_downloader/index.tsx index 2f68da0c18727b..98275a41748aff 100644 --- a/x-pack/plugins/siem/public/common/components/generic_downloader/index.tsx +++ b/x-pack/plugins/siem/public/common/components/generic_downloader/index.tsx @@ -95,7 +95,7 @@ export const GenericDownloaderComponent = ({ isSubscribed = false; abortCtrl.abort(); }; - }, [ids]); + }, [dispatchToaster, exportSelectedData, filename, ids, onExportFailure, onExportSuccess]); return ; }; diff --git a/x-pack/plugins/siem/public/common/components/header_page/editable_title.tsx b/x-pack/plugins/siem/public/common/components/header_page/editable_title.tsx index 0c6f7258d09dc7..ee1217c3d74d9b 100644 --- a/x-pack/plugins/siem/public/common/components/header_page/editable_title.tsx +++ b/x-pack/plugins/siem/public/common/components/header_page/editable_title.tsx @@ -57,7 +57,7 @@ const EditableTitleComponent: React.FC = ({ onSubmit(changedTitle); } setEditMode(false); - }, [changedTitle, title]); + }, [changedTitle, onSubmit, title]); const handleOnChange = useCallback( (e: ChangeEvent) => onTitleChange(e.target.value), diff --git a/x-pack/plugins/siem/public/common/components/help_menu/index.tsx b/x-pack/plugins/siem/public/common/components/help_menu/index.tsx index a219dca595cda4..76d757feafe257 100644 --- a/x-pack/plugins/siem/public/common/components/help_menu/index.tsx +++ b/x-pack/plugins/siem/public/common/components/help_menu/index.tsx @@ -45,7 +45,7 @@ export const HelpMenu = React.memo(() => { }, ], }); - }, []); + }, [chrome, docLinks.ELASTIC_WEBSITE_URL, docLinks.links.siem.guide]); return null; }); diff --git a/x-pack/plugins/siem/public/common/components/import_data_modal/index.tsx b/x-pack/plugins/siem/public/common/components/import_data_modal/index.tsx index c4e0a0de5ae81f..6cf07978282e89 100644 --- a/x-pack/plugins/siem/public/common/components/import_data_modal/index.tsx +++ b/x-pack/plugins/siem/public/common/components/import_data_modal/index.tsx @@ -109,7 +109,17 @@ export const ImportDataModalComponent = ({ errorToToaster({ title: errorMessage, error, dispatchToaster }); } } - }, [selectedFiles, overwrite]); + }, [ + selectedFiles, + importData, + overwrite, + importComplete, + cleanupAndCloseModal, + successMessage, + dispatchToaster, + errorMessage, + failedDetailed, + ]); const handleCloseModal = useCallback(() => { setSelectedFiles(null); diff --git a/x-pack/plugins/siem/public/common/components/links/index.tsx b/x-pack/plugins/siem/public/common/components/links/index.tsx index 8a41d4c36edbbc..6839a0d61de3d1 100644 --- a/x-pack/plugins/siem/public/common/components/links/index.tsx +++ b/x-pack/plugins/siem/public/common/components/links/index.tsx @@ -242,7 +242,7 @@ const ReputationLinkComponent: React.FC<{ name: isDefaultReputationLink(name) ? defaultNameMapping[name] : name, url_template: url_template.replace(`{{ip}}`, encodeURIComponent(domain)), })), - [ipReputationLinksSetting, domain, defaultNameMapping, allItemsLimit] + [ipReputationLinksSetting, domain, allItemsLimit] ); return ipReputationLinks?.length > 0 ? ( diff --git a/x-pack/plugins/siem/public/common/components/markdown_editor/index.tsx b/x-pack/plugins/siem/public/common/components/markdown_editor/index.tsx index b0df2b6b5b60f5..b31a99ce6b684d 100644 --- a/x-pack/plugins/siem/public/common/components/markdown_editor/index.tsx +++ b/x-pack/plugins/siem/public/common/components/markdown_editor/index.tsx @@ -135,7 +135,7 @@ export const MarkdownEditor = React.memo<{ ), }, ], - [content, isDisabled, placeholder] + [content, handleOnChange, isDisabled, onClickTimeline, placeholder, setCursorPosition] ); return ( diff --git a/x-pack/plugins/siem/public/common/components/matrix_histogram/index.tsx b/x-pack/plugins/siem/public/common/components/matrix_histogram/index.tsx index 08edae208fefac..8814db9c7ab24c 100644 --- a/x-pack/plugins/siem/public/common/components/matrix_histogram/index.tsx +++ b/x-pack/plugins/siem/public/common/components/matrix_histogram/index.tsx @@ -130,9 +130,10 @@ export const MatrixHistogramComponent: React.FC< startDate, legendPosition, endDate, - dispatchSetAbsoluteRangeDatePicker, yTickFormatter, showLegend, + dispatchSetAbsoluteRangeDatePicker, + setAbsoluteRangeDatePickerTarget, ] ); const [isInitialLoading, setIsInitialLoading] = useState(true); @@ -145,7 +146,7 @@ export const MatrixHistogramComponent: React.FC< stackByOptions.find((co) => co.value === event.target.value) ?? defaultStackByOption ); }, - [] + [defaultStackByOption, stackByOptions] ); const { data, loading, inspect, totalCount, refetch = noop } = useQuery<{}, HistogramAggregation>( diff --git a/x-pack/plugins/siem/public/common/components/ml/anomaly/use_anomalies_table_data.ts b/x-pack/plugins/siem/public/common/components/ml/anomaly/use_anomalies_table_data.ts index a76c4c850b8d93..1f01ce008f1624 100644 --- a/x-pack/plugins/siem/public/common/components/ml/anomaly/use_anomalies_table_data.ts +++ b/x-pack/plugins/siem/public/common/components/ml/anomaly/use_anomalies_table_data.ts @@ -122,13 +122,17 @@ export const useAnomaliesTableData = ({ abortCtrl.abort(); }; }, [ - influencersOrCriteriaToString(influencers), - influencersOrCriteriaToString(criteriaFields), startDate, endDate, skip, userPermissions, - siemJobIds.sort().join(), + influencers, + criteriaFields, + siemJobIds, + anomalyScore, + threshold, + timeZone, + dispatchToaster, ]); return [loading, tableData]; diff --git a/x-pack/plugins/siem/public/common/components/ml/permissions/ml_capabilities_provider.tsx b/x-pack/plugins/siem/public/common/components/ml/permissions/ml_capabilities_provider.tsx index 1d5c1b36e22af2..deefa597d48947 100644 --- a/x-pack/plugins/siem/public/common/components/ml/permissions/ml_capabilities_provider.tsx +++ b/x-pack/plugins/siem/public/common/components/ml/permissions/ml_capabilities_provider.tsx @@ -60,7 +60,7 @@ export const MlCapabilitiesProvider = React.memo<{ children: JSX.Element }>(({ c isSubscribed = false; abortCtrl.abort(); }; - }, []); + }, [dispatchToaster]); return ( {children} diff --git a/x-pack/plugins/siem/public/common/components/ml_popover/hooks/use_siem_jobs.tsx b/x-pack/plugins/siem/public/common/components/ml_popover/hooks/use_siem_jobs.tsx index a84d88782926c3..e4b94d06022b0a 100644 --- a/x-pack/plugins/siem/public/common/components/ml_popover/hooks/use_siem_jobs.tsx +++ b/x-pack/plugins/siem/public/common/components/ml_popover/hooks/use_siem_jobs.tsx @@ -74,7 +74,7 @@ export const useSiemJobs = (refetchData: boolean): Return => { isSubscribed = false; abortCtrl.abort(); }; - }, [refetchData, userPermissions]); + }, [dispatchToaster, refetchData, siemDefaultIndex, userPermissions]); return [loading, siemJobs]; }; diff --git a/x-pack/plugins/siem/public/common/components/ml_popover/jobs_table/filters/groups_filter_popover.tsx b/x-pack/plugins/siem/public/common/components/ml_popover/jobs_table/filters/groups_filter_popover.tsx index dd6e2d3f471100..6bf3c2c49d2646 100644 --- a/x-pack/plugins/siem/public/common/components/ml_popover/jobs_table/filters/groups_filter_popover.tsx +++ b/x-pack/plugins/siem/public/common/components/ml_popover/jobs_table/filters/groups_filter_popover.tsx @@ -46,7 +46,7 @@ export const GroupsFilterPopoverComponent = ({ useEffect(() => { onSelectedGroupsChanged(selectedGroups); - }, [selectedGroups.sort().join()]); + }, [onSelectedGroupsChanged, selectedGroups]); return ( ( window.setTimeout(() => updateSearch(updateSearchBar), 0); }, - [id, end, filterQuery, fromStr, queries, start, toStr] + [id, toStr, end, fromStr, start, filterManager, filterQuery, queries, updateSearch] ); const onRefresh = useCallback( @@ -153,14 +153,14 @@ const SearchBarComponent = memo( queries.forEach((q) => q.refetch && (q.refetch as inputsModel.Refetch)()); } }, - [id, queries, filterManager] + [updateSearch, id, filterManager, queries] ); const onSaved = useCallback( (newSavedQuery: SavedQuery) => { setSavedQuery({ id, savedQuery: newSavedQuery }); }, - [id] + [id, setSavedQuery] ); const onSavedQueryUpdated = useCallback( @@ -196,7 +196,7 @@ const SearchBarComponent = memo( updateSearch(updateSearchBar); }, - [id, end, fromStr, start, toStr] + [id, toStr, end, fromStr, start, filterManager, updateSearch] ); const onClearSavedQuery = useCallback(() => { @@ -218,7 +218,7 @@ const SearchBarComponent = memo( filterManager, }); } - }, [id, end, filterManager, fromStr, start, toStr, savedQuery]); + }, [savedQuery, updateSearch, id, toStr, end, fromStr, start, filterManager]); useEffect(() => { let isSubscribed = true; @@ -241,7 +241,7 @@ const SearchBarComponent = memo( isSubscribed = false; subscriptions.unsubscribe(); }; - }, []); + }, [filterManager, id, setSearchBarFilter]); const indexPatterns = useMemo(() => [indexPattern], [indexPattern]); return ( diff --git a/x-pack/plugins/siem/public/common/components/stat_items/index.tsx b/x-pack/plugins/siem/public/common/components/stat_items/index.tsx index ec9cfc62ebadaa..06a5bbbcc16ed5 100644 --- a/x-pack/plugins/siem/public/common/components/stat_items/index.tsx +++ b/x-pack/plugins/siem/public/common/components/stat_items/index.tsx @@ -183,7 +183,7 @@ export const useKpiMatrixStatus = ( }; }) ); - }, [data]); + }, [data, from, id, mappings, narrowDateRange, to]); return statItemsProps; }; diff --git a/x-pack/plugins/siem/public/common/components/super_date_picker/index.tsx b/x-pack/plugins/siem/public/common/components/super_date_picker/index.tsx index 6b979df653eb4c..31b23d16911803 100644 --- a/x-pack/plugins/siem/public/common/components/super_date_picker/index.tsx +++ b/x-pack/plugins/siem/public/common/components/super_date_picker/index.tsx @@ -117,7 +117,7 @@ export const SuperDatePickerComponent = React.memo( refetchQuery(queries); } }, - [end, id, isQuickSelection, kqlQuery, start, timelineId] + [end, id, isQuickSelection, kqlQuery, queries, start, timelineId, updateReduxTime] ); const onRefreshChange = useCallback( @@ -136,7 +136,17 @@ export const SuperDatePickerComponent = React.memo( refetchQuery(queries); } }, - [id, isQuickSelection, duration, policy, toStr] + [ + duration, + policy, + isQuickSelection, + toStr, + setDuration, + id, + stopAutoReload, + startAutoReload, + queries, + ] ); const refetchQuery = (newQueries: inputsModel.GlobalGraphqlQuery[]) => { @@ -175,7 +185,7 @@ export const SuperDatePickerComponent = React.memo( setIsQuickSelection(newIsQuickSelection); } }, - [recentlyUsedRanges, kqlQuery] + [updateReduxTime, id, kqlQuery, timelineId, recentlyUsedRanges] ); const endDate = kind === 'relative' ? toStr : new Date(end).toISOString(); diff --git a/x-pack/plugins/siem/public/common/components/toasters/index.test.tsx b/x-pack/plugins/siem/public/common/components/toasters/index.test.tsx index 944e8f6d1fb399..5353a5deeaf5a3 100644 --- a/x-pack/plugins/siem/public/common/components/toasters/index.test.tsx +++ b/x-pack/plugins/siem/public/common/components/toasters/index.test.tsx @@ -69,7 +69,7 @@ describe('Toaster', () => { if (toasts.length === 0) { dispatch({ type: 'addToaster', toast: mockToast }); } - }, []); + }, [dispatch, toasts.length]); return ( <>