Skip to content

Commit

Permalink
[EDR Workflows][Osquery] Prevent pack creation on shards field error (e…
Browse files Browse the repository at this point in the history
…lastic#191186)

It was observed that even though we display an error on Shard policy
field if the field is left empty we still proceed with displaying
confirmation modal which does nothing on selecting "Save and deploy
changes".



https://github.com/user-attachments/assets/0506894d-9e93-4233-8ac3-442968b6f848



With this change form behaves as expected, with a field error it won't
proceed with form submission.


https://github.com/user-attachments/assets/0168ccf7-4137-43d4-8005-589be3ae0e35
  • Loading branch information
szwarckonrad authored Aug 27, 2024
1 parent 9372027 commit b386e1c
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ const ShardsPolicyFieldComponent = ({
}: ShardsPolicyFieldComponent) => {
const { data: { agentPoliciesById } = {} } = useAgentPolicies();

const missingValueError = i18n.translate(
'xpack.osquery.pack.form.shardsPolicyFieldMissingErrorMessage',
{
defaultMessage: 'Policy is a required field',
}
);

const policyFieldValidator = useCallback(
(policy: { key: string; label: string }) =>
!policy
? i18n.translate('xpack.osquery.pack.form.shardsPolicyFieldMissingErrorMessage', {
defaultMessage: 'Policy is a required field',
})
: undefined,
(policy: { key: string; label: string }) => (!policy ? missingValueError : undefined),

[]
[missingValueError]
);

const {
Expand All @@ -47,6 +49,7 @@ const ShardsPolicyFieldComponent = ({
name: `shardsArray.${index}.policy`,
rules: {
validate: policyFieldValidator,
required: missingValueError,
},
});

Expand Down

0 comments on commit b386e1c

Please sign in to comment.