Skip to content

Commit

Permalink
Add back min zero value, add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang committed Jun 30, 2021
1 parent 5bb9691 commit df3bc47
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ export const agentPolicyFormValidation = (
errors.namespace = [namespaceValidation.error];
}

if (agentPolicy.unenroll_timeout && agentPolicy.unenroll_timeout < 0) {
errors.unenroll_timeout = [
<FormattedMessage
id="xpack.fleet.agentPolicyForm.unenrollTimeoutMinValueErrorMessage"
defaultMessage="Timeout must be greater than zero."
/>,
];
}

return errors;
};

Expand Down Expand Up @@ -314,11 +323,20 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
/>
}
>
<EuiFormRow fullWidth>
<EuiFormRow
fullWidth
error={
touchedFields.unenroll_timeout && validation.unenroll_timeout
? validation.unenroll_timeout
: null
}
isInvalid={Boolean(touchedFields.unenroll_timeout && validation.unenroll_timeout)}
>
<EuiFieldNumber
fullWidth
disabled={agentPolicy.is_managed === true}
value={agentPolicy.unenroll_timeout || ''}
min={0}
onChange={(e) => {
updateAgentPolicy({
unenroll_timeout: e.target.value ? Number(e.target.value) : 0,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const AgentPolicyBaseSchema = {
namespace: NamespaceSchema,
description: schema.maybe(schema.string()),
is_managed: schema.maybe(schema.boolean()),
unenroll_timeout: schema.maybe(schema.number()),
unenroll_timeout: schema.maybe(schema.number({ min: 0 })),
monitoring_enabled: schema.maybe(
schema.arrayOf(
schema.oneOf([schema.literal(dataTypes.Logs), schema.literal(dataTypes.Metrics)])
Expand Down

0 comments on commit df3bc47

Please sign in to comment.