Skip to content

Commit 782e0bd

Browse files
committed
pr feedback: refactor logic for rendering form fields
1 parent 72eab3c commit 782e0bd

File tree

1 file changed

+52
-35
lines changed
  • x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions

1 file changed

+52
-35
lines changed

x-pack/plugins/security_solution/public/detections/components/rules/step_rule_actions/index.tsx

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -142,45 +142,62 @@ const StepRuleActionsComponent: FC<StepRuleActionsProps> = ({
142142
[isLoading, throttleOptions]
143143
);
144144

145-
return isReadOnlyView ? (
146-
<StepContentWrapper addPadding={addPadding}>
147-
<StepRuleDescription schema={schema} data={initialState} columns="single" />
148-
</StepContentWrapper>
145+
if (isReadOnlyView) {
146+
return (
147+
<StepContentWrapper addPadding={addPadding}>
148+
<StepRuleDescription schema={schema} data={initialState} columns="single" />
149+
</StepContentWrapper>
150+
);
151+
}
152+
153+
const displayActionsOptions =
154+
throttle !== stepActionsDefaultValue.throttle ? (
155+
<>
156+
<EuiSpacer />
157+
<UseField
158+
path="actions"
159+
component={RuleActionsField}
160+
componentProps={{
161+
messageVariables: actionMessageParams,
162+
}}
163+
/>
164+
</>
165+
) : (
166+
<UseField path="actions" component={GhostFormField} />
167+
);
168+
169+
// only display the actions dropdown if the user has "read" privileges for actions
170+
const displayActionsDropDown = application.capabilities.actions.show ? (
171+
<>
172+
<UseField
173+
path="throttle"
174+
component={ThrottleSelectField}
175+
componentProps={throttleFieldComponentProps}
176+
/>
177+
{displayActionsOptions}
178+
<UseField path="kibanaSiemAppUrl" component={GhostFormField} />
179+
<UseField path="enabled" component={GhostFormField} />
180+
</>
149181
) : (
182+
<>
183+
<EuiText>{I18n.NO_ACTIONS_READ_PERMISSIONS}</EuiText>
184+
<UseField
185+
path="throttle"
186+
componentProps={throttleFieldComponentProps}
187+
component={GhostFormField}
188+
/>
189+
<UseField path="actions" component={GhostFormField} />
190+
<UseField path="kibanaSiemAppUrl" component={GhostFormField} />
191+
<UseField path="enabled" component={GhostFormField} />
192+
</>
193+
);
194+
195+
return (
150196
<>
151197
<StepContentWrapper addPadding={!isUpdateView}>
152-
<Form
153-
form={form}
154-
style={{ display: application.capabilities.actions.show ? 'block' : 'none' }}
155-
data-test-subj="stepRuleActions"
156-
>
157-
<EuiForm>
158-
<UseField
159-
path="throttle"
160-
component={ThrottleSelectField}
161-
componentProps={throttleFieldComponentProps}
162-
/>
163-
{throttle !== stepActionsDefaultValue.throttle ? (
164-
<>
165-
<EuiSpacer />
166-
<UseField
167-
path="actions"
168-
component={RuleActionsField}
169-
componentProps={{
170-
messageVariables: actionMessageParams,
171-
}}
172-
/>
173-
</>
174-
) : (
175-
<UseField path="actions" component={GhostFormField} />
176-
)}
177-
<UseField path="kibanaSiemAppUrl" component={GhostFormField} />
178-
<UseField path="enabled" component={GhostFormField} />
179-
</EuiForm>
198+
<Form form={form} data-test-subj="stepRuleActions">
199+
<EuiForm>{displayActionsDropDown}</EuiForm>
180200
</Form>
181-
{!application.capabilities.actions.show && (
182-
<EuiText>{I18n.NO_ACTIONS_READ_PERMISSIONS}</EuiText>
183-
)}
184201
</StepContentWrapper>
185202

186203
{!isUpdateView && (

0 commit comments

Comments
 (0)