Skip to content

Commit

Permalink
[8.6] Invalidate cache for rules, after add shared exception (elastic…
Browse files Browse the repository at this point in the history
…#146979) (elastic#147074)

# Backport

This will backport the following commits from `main` to `8.6`:
- [Invalidate cache for rules, after add shared exception
(elastic#146979)](elastic#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":"[email protected]"},"sourceCommit":{"committedDate":"2022-12-06T09:37:46Z","message":"Invalidate
cache for rules, after add shared exception (elastic#146979)\n\n## Invalidate
cache for rules, after adding shared
exception\r\n\r\nRelated:\r\nhttps://github.com/elastic/issues/146962\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","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 (elastic#146979)\n\n## Invalidate
cache for rules, after adding shared
exception\r\n\r\nRelated:\r\nhttps://github.com/elastic/issues/146962\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","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 (elastic#146979)\n\n## Invalidate
cache for rules, after adding shared
exception\r\n\r\nRelated:\r\nhttps://github.com/elastic/issues/146962\r\n\r\nCo-authored-by:
Kibana Machine
<[email protected]>","sha":"ab8993679fbd199dfaf80c2ea96d480ba306a82a"}}]}]
BACKPORT-->

Co-authored-by: Khristinin Nikita <[email protected]>
  • Loading branch information
kibanamachine and nkhristinin authored Dec 6, 2022
1 parent 3ff918f commit 33c8b50
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand All @@ -387,6 +390,7 @@ export const AddExceptionFlyout = memo(function AddExceptionFlyout({
onConfirm,
bulkCloseIndex,
setErrorSubmitting,
invalidateFetchRuleByIdQuery,
]);

const isSubmitButtonDisabled = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +75,7 @@ export const useListDetailsView = () => {
);
const [disableManageButton, setDisableManageButton] = useState(true);
const [refreshExceptions, setRefreshExceptions] = useState(false);
const invalidateFetchRuleByIdQuery = useInvalidateFetchRuleByIdQuery();

const headerBackOptions: BackOptions = useMemo(
() => ({
Expand Down Expand Up @@ -310,7 +312,8 @@ export const useListDetailsView = () => {
setRefreshExceptions(true);
resetManageRulesAfterSaving();
})
.then(() => setRefreshExceptions(false));
.then(() => setRefreshExceptions(false))
.then(() => invalidateFetchRuleByIdQuery());
} catch (err) {
handleErrorStatus(err);
}
Expand All @@ -321,6 +324,7 @@ export const useListDetailsView = () => {
exceptionListId,
resetManageRulesAfterSaving,
handleErrorStatus,
invalidateFetchRuleByIdQuery,
]);
const onCancelManageRules = useCallback(() => {
setShowManageRulesFlyout(false);
Expand Down

0 comments on commit 33c8b50

Please sign in to comment.