Skip to content

Commit

Permalink
[Security Solution][Detections] fixes auto refresh issue when applyin…
Browse files Browse the repository at this point in the history
…g some of bulk actin to rules (#135208)

## Summary

Addresses: #126160

When users start to apply bulk action, rules table auto refresh will be paused and renewed after action finishes

### Before

https://user-images.githubusercontent.com/92328789/175935334-6f6dc42e-ecd5-4993-b2ce-7b0582283aa6.mov



### After

https://user-images.githubusercontent.com/92328789/175935341-e735dc18-6df1-4ac3-9ec2-3cf0de63a9dd.mov


### Release Note
- fixes issue when on applying some of bulk actions to selected rules, rules table auto refresh continues to work
  • Loading branch information
vitaliidm authored Jun 29, 2022
1 parent 8b078c3 commit cd026c2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const useBulkActions = ({
);

const {
state: { isAllSelected, rules, loadingRuleIds, selectedRuleIds },
state: { isAllSelected, rules, loadingRuleIds, selectedRuleIds, isRefreshOn },
actions: { setLoadingRules, setIsRefreshOn },
} = rulesTableContext;

Expand All @@ -103,7 +103,9 @@ export const useBulkActions = ({

const handleEnableAction = async () => {
startTransaction({ name: BULK_RULE_ACTIONS.ENABLE });
setIsRefreshOn(false);
closePopover();

const disabledRules = selectedRules.filter(({ enabled }) => !enabled);
const disabledRulesNoML = disabledRules.filter(({ type }) => !isMlRule(type));

Expand All @@ -124,11 +126,14 @@ export const useBulkActions = ({
search: isAllSelected ? { query: filterQuery } : { ids: ruleIds },
});
invalidateRules();
setIsRefreshOn(isRefreshOn);
};

const handleDisableActions = async () => {
startTransaction({ name: BULK_RULE_ACTIONS.DISABLE });
setIsRefreshOn(false);
closePopover();

const enabledIds = selectedRules.filter(({ enabled }) => enabled).map(({ id }) => id);
await executeRulesBulkAction({
visibleRuleIds: enabledIds,
Expand All @@ -138,11 +143,14 @@ export const useBulkActions = ({
search: isAllSelected ? { query: filterQuery } : { ids: enabledIds },
});
invalidateRules();
setIsRefreshOn(isRefreshOn);
};

const handleDuplicateAction = async () => {
startTransaction({ name: BULK_RULE_ACTIONS.DUPLICATE });
setIsRefreshOn(false);
closePopover();

await executeRulesBulkAction({
visibleRuleIds: selectedRuleIds,
action: BulkAction.duplicate,
Expand All @@ -151,13 +159,17 @@ export const useBulkActions = ({
search: isAllSelected ? { query: filterQuery } : { ids: selectedRuleIds },
});
invalidateRules();
setIsRefreshOn(isRefreshOn);
};

const handleDeleteAction = async () => {
setIsRefreshOn(false);
closePopover();

if (isAllSelected) {
// User has cancelled deletion
if ((await confirmDeletion()) === false) {
// User has cancelled deletion
setIsRefreshOn(isRefreshOn);
return;
}
}
Expand All @@ -171,9 +183,11 @@ export const useBulkActions = ({
search: isAllSelected ? { query: filterQuery } : { ids: selectedRuleIds },
});
invalidateRules();
setIsRefreshOn(isRefreshOn);
};

const handleExportAction = async () => {
setIsRefreshOn(false);
closePopover();

startTransaction({ name: BULK_RULE_ACTIONS.EXPORT });
Expand All @@ -184,6 +198,7 @@ export const useBulkActions = ({
toasts,
search: isAllSelected ? { query: filterQuery } : { ids: selectedRuleIds },
});
setIsRefreshOn(isRefreshOn);
};

const handleBulkEdit = (bulkEditActionType: BulkActionEditType) => async () => {
Expand All @@ -200,13 +215,13 @@ export const useBulkActions = ({

// User has cancelled edit action or there are no custom rules to proceed
if ((await confirmBulkEdit()) === false) {
setIsRefreshOn(true);
setIsRefreshOn(isRefreshOn);
return;
}

const editPayload = await completeBulkEditForm(bulkEditActionType);
if (editPayload == null) {
setIsRefreshOn(true);
setIsRefreshOn(isRefreshOn);
return;
}

Expand Down Expand Up @@ -268,6 +283,7 @@ export const useBulkActions = ({

isBulkEditFinished = true;
invalidateRules();
setIsRefreshOn(isRefreshOn);
if (getIsMounted()) {
await resolveTagsRefetch(bulkEditActionType);
}
Expand Down Expand Up @@ -439,6 +455,7 @@ export const useBulkActions = ({
filterOptions,
getIsMounted,
resolveTagsRefetch,
isRefreshOn,
]
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ export interface RulesTableActions {
setFilterOptions: (newFilter: Partial<FilterOptions>) => void;
setIsAllSelected: React.Dispatch<React.SetStateAction<boolean>>;
setIsInMemorySorting: (value: boolean) => void;
/**
* enable/disable rules table auto refresh
*
* @example
*
* setIsRefreshOn(true) // enables auto refresh
* setIsRefreshOn(false) // disables auto refresh
*/
setIsRefreshOn: React.Dispatch<React.SetStateAction<boolean>>;
setLoadingRules: React.Dispatch<React.SetStateAction<LoadingRules>>;
setPage: React.Dispatch<React.SetStateAction<number>>;
Expand Down

0 comments on commit cd026c2

Please sign in to comment.