Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SIEM] Restore rules of hooks #67878

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const AddItem = ({
inputsRef.current[haveBeenKeyboardDeleted].focus();
setHaveBeenKeyboardDeleted(-1);
}
}, [haveBeenKeyboardDeleted, inputsRef.current]);
}, [haveBeenKeyboardDeleted]);

const values = field.value as string[];
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -49,7 +49,7 @@ export const PickTimeline = ({
field.setValue({ id, title });
}
},
[field]
[field, timelineId, timelineTitle]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const QueryBarDefineRule = ({
isSubscribed = false;
subscriptions.unsubscribe();
};
}, [field.value]);
}, [field, field.value, filterManager]);

useEffect(() => {
let isSubscribed = true;
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -179,7 +179,7 @@ export const QueryBarDefineRule = ({
}
}
},
[field.value]
[field]
);

const onCloseTimelineModal = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -71,7 +71,7 @@ export const RuleActionsField: ThrottleSelectField = ({ field, messageVariables
updatedActions[index].params[key] = value;
field.setValue(updatedActions);
},
[field.setValue, actions]
[actions, field]
);

useEffect(() => {
Expand All @@ -82,7 +82,7 @@ export const RuleActionsField: ThrottleSelectField = ({ field, messageVariables
);
setSupportedActionTypes(supportedTypes);
})();
}, []);
}, [http]);

useEffect(() => {
if (field.form.isSubmitting || !field.errors.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const RuleActionsOverflowComponent = ({
</EuiContextMenuItem>,
]
: [],
[rule, userHasNoPermissions]
[dispatchToaster, onRuleDeletedCallback, rule, userHasNoPermissions]
);

const handlePopoverOpen = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<EuiFlexGroup alignItems="center" justifyContent="spaceAround">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const ScheduleItem = ({
setTimeType(e.target.value);
field.setValue(`${timeVal}${e.target.value}`);
},
[timeVal]
[field, timeVal]
);

const onChangeTimeVal = useCallback(
Expand All @@ -87,7 +87,7 @@ export const ScheduleItem = ({
setTimeVal(sanitizedValue);
field.setValue(`${sanitizedValue}${timeType}`);
},
[timeType]
[field, timeType]
);

useEffect(() => {
Expand All @@ -111,7 +111,7 @@ export const ScheduleItem = ({
setTimeType(filterTimeType[0]);
}
}
}, [field.value]);
}, [field.value, timeType, timeVal]);

// EUI missing some props
const rest = { disabled: isDisabled };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const StepAboutRuleComponent: FC<StepAboutRuleProps> = ({
setMyStepData({ ...data, isNew: false } as AboutStepRule);
}
}
}, [form]);
}, [form, setStepData]);

useEffect(() => {
const { isNew, ...initDefaultValue } = myStepData;
Expand All @@ -113,13 +113,13 @@ const StepAboutRuleComponent: FC<StepAboutRuleProps> = ({
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 ? (
<StepContentWrapper data-test-subj="aboutStep" addPadding={addPadding}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const StepDefineRuleComponent: FC<StepDefineRuleProps> = ({
setMyStepData({ ...data, isNew: false } as DefineStepRule);
}
}
}, [form]);
}, [form, setStepData]);

useEffect(() => {
const { isNew, ...values } = myStepData;
Expand All @@ -132,13 +132,13 @@ const StepDefineRuleComponent: FC<StepDefineRuleProps> = ({
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const StepRuleActionsComponent: FC<StepRuleActionsProps> = ({
}
}
},
[form]
[form, setStepData]
);

useEffect(() => {
Expand All @@ -112,13 +112,13 @@ const StepRuleActionsComponent: FC<StepRuleActionsProps> = ({
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,
Expand All @@ -142,7 +142,7 @@ const StepRuleActionsComponent: FC<StepRuleActionsProps> = ({
options: throttleOptions,
},
}),
[isLoading, updateThrottle]
[isLoading, throttleOptions, updateThrottle]
);

return isReadOnlyView && myStepData != null ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const StepScheduleRuleComponent: FC<StepScheduleRuleProps> = ({
setMyStepData({ ...data, isNew: false } as ScheduleStepRule);
}
}
}, [form]);
}, [form, setStepData]);

useEffect(() => {
const { isNew, ...initDefaultValue } = myStepData;
Expand All @@ -74,13 +74,13 @@ const StepScheduleRuleComponent: FC<StepScheduleRuleProps> = ({
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 ? (
<StepContentWrapper addPadding={addPadding}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SelectField {...props} euiFieldProps={newEuiFieldProps} />;
Expand Down
15 changes: 12 additions & 3 deletions x-pack/plugins/siem/public/alerts/components/signals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ export const SignalsTableComponent: React.FC<SignalsTableComponentProps> = ({
});
}
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(
Expand All @@ -136,14 +145,14 @@ export const SignalsTableComponent: React.FC<SignalsTableComponentProps> = ({
({ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,17 @@ export const SignalsHistogramPanel = memo<SignalsHistogramPanelProps>(
totalSignalsObj.value,
totalSignalsObj.relation === 'gte' ? '>' : totalSignalsObj.relation === 'lte' ? '<' : ''
),
[totalSignalsObj]
[defaultNumberFormat, totalSignalsObj.relation, totalSignalsObj.value]
);

const setSelectedOptionCallback = useCallback((event: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedStackByOption(
stackByOptions?.find((co) => co.value === event.target.value) ?? defaultStackByOption
);
}, []);
const setSelectedOptionCallback = useCallback(
(event: React.ChangeEvent<HTMLSelectElement>) => {
setSelectedStackByOption(
stackByOptions?.find((co) => co.value === event.target.value) ?? defaultStackByOption
);
},
[defaultStackByOption, stackByOptions]
);

const formattedSignalsData = useMemo(() => formatSignalsData(signalsData), [signalsData]);

Expand Down Expand Up @@ -175,7 +178,7 @@ export const SignalsHistogramPanel = memo<SignalsHistogramPanelProps>(
deleteQuery({ id: uniqueQueryId });
}
};
}, []);
}, [deleteQuery, uniqueQueryId]);

useEffect(() => {
if (refetch != null && setQuery != null) {
Expand All @@ -189,7 +192,7 @@ export const SignalsHistogramPanel = memo<SignalsHistogramPanelProps>(
refetch,
});
}
}, [setQuery, isLoadingSignals, signalsData, response, request, refetch]);
}, [setQuery, isLoadingSignals, signalsData, response, request, refetch, uniqueQueryId]);

useEffect(() => {
setTotalSignalsObj(
Expand Down Expand Up @@ -219,7 +222,15 @@ export const SignalsHistogramPanel = memo<SignalsHistogramPanelProps>(
!isEmpty(converted) ? [converted] : []
)
);
}, [selectedStackByOption.value, from, to, query, filters]);
}, [
selectedStackByOption.value,
from,
to,
query,
filters,
kibana.services.uiSettings,
setSignalsQuery,
]);

const linkButton = useMemo(() => {
if (showLinkToSignals) {
Expand Down
Loading