-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[SIEM] Add license check to ML Rule form #60691
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
02ff875
Gate ML Rules behind a license check
rylnd 95ce642
Add aria-describedby for new ML input fields
rylnd 42eaba7
Add data-test-subj to new ML input fields
rylnd 004ae91
Remove unused prop
rylnd 4621085
Fix capitalization on translation id
rylnd 55df0d2
Merge branch 'master' into ml_rule_license_check
rylnd fac289c
Declare defaulted props as optional
rylnd 1b6b460
Gray out entire ML card when ML Rules are disabled
rylnd be56dc3
Merge branch 'master' into ml_rule_license_check
rylnd 41217c7
Merge branch 'master' into ml_rule_license_check
rylnd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,19 +5,58 @@ | |
*/ | ||
|
||
import React, { useCallback } from 'react'; | ||
import { EuiCard, EuiFlexGrid, EuiFlexItem, EuiIcon, EuiFormRow } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { | ||
EuiCard, | ||
EuiFlexGrid, | ||
EuiFlexItem, | ||
EuiFormRow, | ||
EuiIcon, | ||
EuiLink, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
|
||
import { FieldHook } from '../../../../../shared_imports'; | ||
import { RuleType } from '../../../../../containers/detection_engine/rules/types'; | ||
import * as i18n from './translations'; | ||
import { isMlRule } from '../../helpers'; | ||
|
||
const MlCardDescription = ({ hasValidLicense = false }: { hasValidLicense?: boolean }) => ( | ||
<EuiText size="s"> | ||
{hasValidLicense ? ( | ||
i18n.ML_TYPE_DESCRIPTION | ||
) : ( | ||
<FormattedMessage | ||
id="xpack.siem.detectionEngine.createRule.stepDefineRule.ruleTypeField.mlTypeDisabledDescription" | ||
defaultMessage="Access to ML requires a {subscriptionsLink}." | ||
values={{ | ||
subscriptionsLink: ( | ||
<EuiLink href="https://www.elastic.co/subscriptions" target="_blank"> | ||
<FormattedMessage | ||
id="xpack.siem.components.stepDefineRule.ruleTypeField.subscriptionsLink" | ||
defaultMessage="Platinum subscription" | ||
/> | ||
</EuiLink> | ||
), | ||
}} | ||
/> | ||
)} | ||
</EuiText> | ||
); | ||
|
||
interface SelectRuleTypeProps { | ||
describedByIds?: string[]; | ||
field: FieldHook; | ||
isReadOnly: boolean; | ||
hasValidLicense?: boolean; | ||
isReadOnly?: boolean; | ||
} | ||
|
||
export const SelectRuleType: React.FC<SelectRuleTypeProps> = ({ field, isReadOnly = false }) => { | ||
export const SelectRuleType: React.FC<SelectRuleTypeProps> = ({ | ||
describedByIds = [], | ||
field, | ||
hasValidLicense = false, | ||
isReadOnly = false, | ||
}) => { | ||
const ruleType = field.value as RuleType; | ||
const setType = useCallback( | ||
(type: RuleType) => { | ||
|
@@ -27,10 +66,15 @@ export const SelectRuleType: React.FC<SelectRuleTypeProps> = ({ field, isReadOnl | |
); | ||
const setMl = useCallback(() => setType('machine_learning'), [setType]); | ||
const setQuery = useCallback(() => setType('query'), [setType]); | ||
const license = true; // TODO | ||
const mlCardDisabled = isReadOnly || !hasValidLicense; | ||
|
||
return ( | ||
<EuiFormRow label={field.label} fullWidth> | ||
<EuiFormRow | ||
fullWidth | ||
data-test-subj="selectRuleType" | ||
describedByIds={describedByIds} | ||
label={field.label} | ||
> | ||
<EuiFlexGrid columns={4}> | ||
<EuiFlexItem> | ||
<EuiCard | ||
|
@@ -47,11 +91,11 @@ export const SelectRuleType: React.FC<SelectRuleTypeProps> = ({ field, isReadOnl | |
<EuiFlexItem> | ||
<EuiCard | ||
title={i18n.ML_TYPE_TITLE} | ||
description={license ? i18n.ML_TYPE_DESCRIPTION : i18n.ML_TYPE_DISABLED_DESCRIPTION} | ||
isDisabled={!license} | ||
description={<MlCardDescription hasValidLicense={hasValidLicense} />} | ||
icon={<EuiIcon size="l" type="machineLearningApp" />} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up going with the full-disabling, as it is more visually striking and a better CTA |
||
isDisabled={mlCardDisabled} | ||
selectable={{ | ||
isDisabled: isReadOnly, | ||
isDisabled: mlCardDisabled, | ||
onClick: setMl, | ||
isSelected: isMlRule(ruleType), | ||
}} | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have these two taking values when they are defaulted by the SelectRuleTypeProps shows they cannot have defaults and are required?
If they are required I would just drop the defaulting or change the types to be
?
variants where they are defaults.