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

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

Merged
merged 1 commit into from
Dec 6, 2022
Merged
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
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