-
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.
Browse files
Browse the repository at this point in the history
This PR adds the following actions to the `Rule Details` page via the `RuleActionsOverflow` component (which is permission-aware): * Duplicate * Export * Delete Additional fixes include: * Fixes duplication action (recent regression as part of status update additions) * i18n of `Duplicate` postfix when duplicating rules * Adds success toast when duplication is a success * Enabled `Edit Index Patterns` batch action * Removes unused `Run Rule Manually` action Rule Details Actions: ![image](https://user-images.githubusercontent.com/2946766/72385375-9c3a6880-36dc-11ea-8249-4ae92eb72dd1.png) Edit Index Patterns Batch Action: ![image](https://user-images.githubusercontent.com/2946766/72385468-c5f38f80-36dc-11ea-93c8-b70e4982f01a.png) Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR. - [X] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) - [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/master/packages/kbn-i18n/README.md) - [ ] ~[Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~ - [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios - [ ] ~This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~ - [ ] ~This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~ - [ ] ~This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~ Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
e0d6407
commit c076499
Showing
11 changed files
with
275 additions
and
29 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
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
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
63 changes: 63 additions & 0 deletions
63
...detection_engine/rules/components/rule_actions_overflow/__snapshots__/index.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
.../siem/public/pages/detection_engine/rules/components/rule_actions_overflow/index.test.tsx
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,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { shallow } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import { RuleActionsOverflow } from './index'; | ||
import { mockRule } from '../../all/__mocks__/mock'; | ||
|
||
jest.mock('react-router-dom', () => ({ | ||
useHistory: () => ({ | ||
push: jest.fn(), | ||
}), | ||
})); | ||
|
||
describe('RuleActionsOverflow', () => { | ||
test('renders correctly against snapshot', () => { | ||
const wrapper = shallow( | ||
<RuleActionsOverflow rule={mockRule('id')} userHasNoPermissions={false} /> | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); |
127 changes: 127 additions & 0 deletions
127
...ugins/siem/public/pages/detection_engine/rules/components/rule_actions_overflow/index.tsx
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,127 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
EuiButtonIcon, | ||
EuiContextMenuItem, | ||
EuiContextMenuPanel, | ||
EuiPopover, | ||
EuiToolTip, | ||
} from '@elastic/eui'; | ||
import React, { useCallback, useMemo, useState } from 'react'; | ||
|
||
import { noop } from 'lodash/fp'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { Rule } from '../../../../../containers/detection_engine/rules'; | ||
import * as i18n from './translations'; | ||
import * as i18nActions from '../../../rules/translations'; | ||
import { deleteRulesAction, duplicateRuleAction } from '../../all/actions'; | ||
import { displaySuccessToast, useStateToaster } from '../../../../../components/toasters'; | ||
import { RuleDownloader } from '../rule_downloader'; | ||
import { DETECTION_ENGINE_PAGE_NAME } from '../../../../../components/link_to/redirect_to_detection_engine'; | ||
|
||
interface RuleActionsOverflowComponentProps { | ||
rule: Rule | null; | ||
userHasNoPermissions: boolean; | ||
} | ||
|
||
/** | ||
* Overflow Actions for a Rule | ||
*/ | ||
const RuleActionsOverflowComponent = ({ | ||
rule, | ||
userHasNoPermissions, | ||
}: RuleActionsOverflowComponentProps) => { | ||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
const [rulesToExport, setRulesToExport] = useState<Rule[] | undefined>(undefined); | ||
const history = useHistory(); | ||
const [, dispatchToaster] = useStateToaster(); | ||
|
||
const onRuleDeletedCallback = useCallback(() => { | ||
history.push(`/${DETECTION_ENGINE_PAGE_NAME}/rules`); | ||
}, [history]); | ||
|
||
const actions = useMemo( | ||
() => | ||
rule != null | ||
? [ | ||
<EuiContextMenuItem | ||
key={i18nActions.DUPLICATE_RULE} | ||
icon="exportAction" | ||
disabled={userHasNoPermissions} | ||
onClick={async () => { | ||
setIsPopoverOpen(false); | ||
await duplicateRuleAction(rule, noop, dispatchToaster); | ||
}} | ||
> | ||
{i18nActions.DUPLICATE_RULE} | ||
</EuiContextMenuItem>, | ||
<EuiContextMenuItem | ||
key={i18nActions.EXPORT_RULE} | ||
icon="indexEdit" | ||
disabled={userHasNoPermissions || rule.immutable} | ||
onClick={async () => { | ||
setIsPopoverOpen(false); | ||
setRulesToExport([rule]); | ||
}} | ||
> | ||
{i18nActions.EXPORT_RULE} | ||
</EuiContextMenuItem>, | ||
<EuiContextMenuItem | ||
key={i18nActions.DELETE_RULE} | ||
icon="trash" | ||
disabled={userHasNoPermissions || rule.immutable} | ||
onClick={async () => { | ||
setIsPopoverOpen(false); | ||
await deleteRulesAction([rule.id], noop, dispatchToaster, onRuleDeletedCallback); | ||
}} | ||
> | ||
{i18nActions.DELETE_RULE} | ||
</EuiContextMenuItem>, | ||
] | ||
: [], | ||
[rule, userHasNoPermissions] | ||
); | ||
|
||
return ( | ||
<> | ||
<EuiPopover | ||
anchorPosition="leftCenter" | ||
button={ | ||
<EuiToolTip position="top" content={i18n.ALL_ACTIONS}> | ||
<EuiButtonIcon | ||
iconType="boxesHorizontal" | ||
aria-label={i18n.ALL_ACTIONS} | ||
isDisabled={userHasNoPermissions} | ||
onClick={() => setIsPopoverOpen(!isPopoverOpen)} | ||
/> | ||
</EuiToolTip> | ||
} | ||
closePopover={() => setIsPopoverOpen(false)} | ||
id="ruleActionsOverflow" | ||
isOpen={isPopoverOpen} | ||
ownFocus={true} | ||
panelPaddingSize="none" | ||
> | ||
<EuiContextMenuPanel items={actions} /> | ||
</EuiPopover> | ||
<RuleDownloader | ||
filename={`${i18nActions.EXPORT_FILENAME}.ndjson`} | ||
rules={rulesToExport} | ||
onExportComplete={exportCount => { | ||
displaySuccessToast( | ||
i18nActions.SUCCESSFULLY_EXPORTED_RULES(exportCount), | ||
dispatchToaster | ||
); | ||
}} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
export const RuleActionsOverflow = React.memo(RuleActionsOverflowComponent); | ||
|
||
RuleActionsOverflow.displayName = 'RuleActionsOverflow'; |
14 changes: 14 additions & 0 deletions
14
...siem/public/pages/detection_engine/rules/components/rule_actions_overflow/translations.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,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const ALL_ACTIONS = i18n.translate( | ||
'xpack.siem.detectionEngine.rules.components.ruleActionsOverflow.allActionsTitle', | ||
{ | ||
defaultMessage: 'All actions', | ||
} | ||
); |
Oops, something went wrong.