[8.6] Invalidate cache for rules, after add shared exception (#146979) (#147074)

# Backport

This will backport the following commits from `main` to `8.6`:
- [Invalidate cache for rules, after add shared exception
(#146979)](https://github.com/elastic/kibana/pull/146979)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Khristinin
Nikita","email":"nikita.khristinin@elastic.co"},"sourceCommit":{"committedDate":"2022-12-06T09:37:46Z","message":"Invalidate
cache for rules, after add shared exception (#146979)\n\n## Invalidate
cache for rules, after adding shared
exception\r\n\r\nRelated:\r\nhttps://github.com/elastic/kibana/issues/146962\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"ab8993679fbd199dfaf80c2ea96d480ba306a82a","branchLabelMapping":{"^v8.7.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","backport:prev-minor","ci:cloud-deploy","v8.7.0"],"number":146979,"url":"https://github.com/elastic/kibana/pull/146979","mergeCommit":{"message":"Invalidate
cache for rules, after add shared exception (#146979)\n\n## Invalidate
cache for rules, after adding shared
exception\r\n\r\nRelated:\r\nhttps://github.com/elastic/kibana/issues/146962\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"ab8993679fbd199dfaf80c2ea96d480ba306a82a"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.7.0","labelRegex":"^v8.7.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/146979","number":146979,"mergeCommit":{"message":"Invalidate
cache for rules, after add shared exception (#146979)\n\n## Invalidate
cache for rules, after adding shared
exception\r\n\r\nRelated:\r\nhttps://github.com/elastic/kibana/issues/146962\r\n\r\nCo-authored-by:
Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"ab8993679fbd199dfaf80c2ea96d480ba306a82a"}}]}]
BACKPORT-->

Co-authored-by: Khristinin Nikita <nikita.khristinin@elastic.co>
This commit is contained in:
Kibana Machine 2022-12-06 06:09:49 -05:00 committed by GitHub
parent 3ff918f201
commit 33c8b50323
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View file

@ -49,6 +49,7 @@ jest.mock('@kbn/securitysolution-hook-utils', () => ({
jest.mock('../../../rule_management/logic/use_rule');
jest.mock('@kbn/lists-plugin/public');
jest.mock('../../../rule_management/logic/use_find_rules');
jest.mock('../../../rule_management/api/hooks/use_fetch_rule_by_id_query');
const mockGetExceptionBuilderComponentLazy = getExceptionBuilderComponentLazy as jest.Mock<
ReturnType<typeof getExceptionBuilderComponentLazy>

View file

@ -53,6 +53,7 @@ import { useAddNewExceptionItems } from './use_add_new_exceptions';
import { enrichNewExceptionItems } from '../flyout_components/utils';
import { useCloseAlertsFromExceptions } from '../../logic/use_close_alerts';
import { ruleTypesThatAllowLargeValueLists } from '../../utils/constants';
import { useInvalidateFetchRuleByIdQuery } from '../../../rule_management/api/hooks/use_fetch_rule_by_id_query';
const SectionHeader = styled(EuiTitle)`
${() => css`
@ -116,6 +117,7 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({
const { isLoading, indexPatterns } = useFetchIndexPatterns(rules);
const [isSubmitting, submitNewExceptionItems] = useAddNewExceptionItems();
const [isClosingAlerts, closeAlerts] = useCloseAlertsFromExceptions();
const invalidateFetchRuleByIdQuery = useInvalidateFetchRuleByIdQuery();
const allowLargeValueLists = useMemo((): boolean => {
if (rules != null && rules.length === 1) {
// We'll only block this when we know what rule we're dealing with.
@ -362,6 +364,7 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({
await closeAlerts(ruleStaticIds, addedItems, alertIdToClose, bulkCloseIndex);
}
invalidateFetchRuleByIdQuery();
// Rule only would have been updated if we had to create a rule default list
// to attach to it, all shared lists would already be referenced on the rule
onConfirm(true, closeSingleAlert, bulkCloseAlerts);
@ -387,6 +390,7 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({
onConfirm,
bulkCloseIndex,
setErrorSubmitting,
invalidateFetchRuleByIdQuery,
]);
const isSubmitButtonDisabled = useMemo(

View file

@ -28,6 +28,7 @@ import {
} from '../../api';
import { checkIfListCannotBeEdited, isAnExceptionListItem } from '../../utils/list.utils';
import * as i18n from '../../translations';
import { useInvalidateFetchRuleByIdQuery } from '../../../detection_engine/rule_management/api/hooks/use_fetch_rule_by_id_query';
interface ReferenceModalState {
contentText: string;
@ -74,6 +75,7 @@ export const useListDetailsView = () => {
);
const [disableManageButton, setDisableManageButton] = useState(true);
const [refreshExceptions, setRefreshExceptions] = useState(false);
const invalidateFetchRuleByIdQuery = useInvalidateFetchRuleByIdQuery();
const headerBackOptions: BackOptions = useMemo(
() => ({
@ -310,7 +312,8 @@ export const useListDetailsView = () => {
setRefreshExceptions(true);
resetManageRulesAfterSaving();
})
.then(() => setRefreshExceptions(false));
.then(() => setRefreshExceptions(false))
.then(() => invalidateFetchRuleByIdQuery());
} catch (err) {
handleErrorStatus(err);
}
@ -321,6 +324,7 @@ export const useListDetailsView = () => {
exceptionListId,
resetManageRulesAfterSaving,
handleErrorStatus,
invalidateFetchRuleByIdQuery,
]);
const onCancelManageRules = useCallback(() => {
setShowManageRulesFlyout(false);