Skip to content

Commit

Permalink
Prevent users from changing an existing Rule's type
Browse files Browse the repository at this point in the history
  • Loading branch information
rylnd committed Mar 19, 2020
1 parent a2a0d0c commit 9341e06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import { isMlRule } from '../../helpers';

interface SelectRuleTypeProps {
field: FieldHook;
isReadOnly: boolean;
}

export const SelectRuleType: React.FC<SelectRuleTypeProps> = ({ field }) => {
export const SelectRuleType: React.FC<SelectRuleTypeProps> = ({ field, isReadOnly = false }) => {
const ruleType = field.value as RuleType;
const setType = useCallback(
(type: RuleType) => {
Expand All @@ -37,6 +38,7 @@ export const SelectRuleType: React.FC<SelectRuleTypeProps> = ({ field }) => {
description={i18n.QUERY_TYPE_DESCRIPTION}
icon={<EuiIcon size="l" type="search" />}
selectable={{
isDisabled: isReadOnly,
onClick: setQuery,
isSelected: !isMlRule(ruleType),
}}
Expand All @@ -49,6 +51,7 @@ export const SelectRuleType: React.FC<SelectRuleTypeProps> = ({ field }) => {
isDisabled={!license}
icon={<EuiIcon size="l" type="machineLearningApp" />}
selectable={{
isDisabled: isReadOnly,
onClick: setMl,
isSelected: isMlRule(ruleType),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,13 @@ const StepDefineRuleComponent: FC<StepDefineRuleProps> = ({
<>
<StepContentWrapper addPadding={!isUpdateView}>
<Form form={form} data-test-subj="stepDefineRule">
<UseField path="ruleType" component={SelectRuleType} />
<UseField
path="ruleType"
component={SelectRuleType}
componentProps={{
isReadOnly: isUpdateView,
}}
/>
<EuiFormRow fullWidth style={{ display: localIsMlRule ? 'none' : 'flex' }}>
<>
<CommonUseField
Expand Down

0 comments on commit 9341e06

Please sign in to comment.