-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Fix success bulk edit toast message (#144497)
**Resolves:** #139897 ## Summary Fixes bulk edit success toast's message. Displays `You've successfully updated X rules. If you did not select to apply changes to rules using Kibana data views, those rules were not updated and will continue using data views.` when rule's index patterns were edited and `You've successfully updated X rules.` in the other cases. *Before:* https://user-images.githubusercontent.com/3775283/199676233-d3287d97-8e66-4938-bc80-7c643ca0e0ad.mov *After:* https://user-images.githubusercontent.com/3775283/199676250-0814ea26-a9bb-4402-a8db-8c2f0e394563.mov ### Checklist - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
Showing
12 changed files
with
215 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
...ion/public/detection_engine/rule_management/logic/bulk_actions/show_bulk_success_toast.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...public/detection_engine/rule_management/logic/bulk_actions/use_download_exported_rules.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useCallback } from 'react'; | ||
import { BulkActionType } from '../../../../../common/detection_engine/rule_management/api/rules/bulk_actions/request_schema'; | ||
import { downloadBlob } from '../../../../common/utils/download_blob'; | ||
import * as i18n from '../../../../detections/pages/detection_engine/rules/translations'; | ||
import { getExportedRulesCounts } from '../../../rule_management_ui/components/rules_table/helpers'; | ||
import { useShowBulkErrorToast } from './use_show_bulk_error_toast'; | ||
import { useShowBulkSuccessToast } from './use_show_bulk_success_toast'; | ||
|
||
const DEFAULT_EXPORT_FILENAME = `${i18n.EXPORT_FILENAME}.ndjson`; | ||
|
||
/** | ||
* downloads exported rules, received from export action | ||
*/ | ||
export function useDownloadExportedRules() { | ||
const showBulkSuccessToast = useShowBulkSuccessToast(); | ||
const showBulkErrorToast = useShowBulkErrorToast(); | ||
|
||
return useCallback( | ||
async (response: Blob) => { | ||
try { | ||
downloadBlob(response, DEFAULT_EXPORT_FILENAME); | ||
showBulkSuccessToast({ | ||
actionType: BulkActionType.export, | ||
summary: await getExportedRulesCounts(response), | ||
}); | ||
} catch (error) { | ||
showBulkErrorToast({ actionType: BulkActionType.export, error }); | ||
} | ||
}, | ||
[showBulkSuccessToast, showBulkErrorToast] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...public/detection_engine/rule_management/logic/bulk_actions/use_show_bulk_success_toast.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { useCallback } from 'react'; | ||
import type { BulkActionSummary } from '..'; | ||
import { useAppToasts } from '../../../../common/hooks/use_app_toasts'; | ||
import type { BulkActionEditPayload } from '../../../../../common/detection_engine/rule_management/api/rules/bulk_actions/request_schema'; | ||
import { BulkActionType } from '../../../../../common/detection_engine/rule_management/api/rules/bulk_actions/request_schema'; | ||
import { explainBulkEditSuccess, explainBulkSuccess, summarizeBulkSuccess } from './translations'; | ||
|
||
interface ShowBulkSuccessToastProps { | ||
actionType: BulkActionType; | ||
summary: BulkActionSummary; | ||
editPayload?: BulkActionEditPayload[]; | ||
} | ||
|
||
export function useShowBulkSuccessToast() { | ||
const toasts = useAppToasts(); | ||
|
||
return useCallback( | ||
({ actionType, summary, editPayload }: ShowBulkSuccessToastProps) => { | ||
const text = | ||
actionType === BulkActionType.edit | ||
? explainBulkEditSuccess(editPayload ?? [], summary) | ||
: explainBulkSuccess(actionType, summary); | ||
|
||
toasts.addSuccess({ | ||
title: summarizeBulkSuccess(actionType), | ||
text, | ||
}); | ||
}, | ||
[toasts] | ||
); | ||
} |
Oops, something went wrong.