Skip to content

Commit

Permalink
Allow zero (0) to unset unenroll_timeout field (#103790) (#103897)
Browse files Browse the repository at this point in the history
  • Loading branch information
jen-huang authored Jun 30, 2021
1 parent dc0cf92 commit 9796817
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
</EuiFormRow>
);
});
const unenrollmentTimeoutText = i18n.translate(
'xpack.fleet.agentPolicyForm.unenrollmentTimeoutLabel',
{ defaultMessage: 'Unenrollment timeout' }
);

const advancedOptionsContent = (
<>
Expand Down Expand Up @@ -303,7 +299,14 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
/>
</EuiDescribedFormGroup>
<EuiDescribedFormGroup
title={<h4>{unenrollmentTimeoutText}</h4>}
title={
<h4>
<FormattedMessage
id="xpack.fleet.agentPolicyForm.unenrollmentTimeoutLabel"
defaultMessage="Unenrollment timeout"
/>
</h4>
}
description={
<FormattedMessage
id="xpack.fleet.agentPolicyForm.unenrollmentTimeoutDescription"
Expand All @@ -315,12 +318,14 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
<EuiFieldNumber
fullWidth
disabled={agentPolicy.is_managed === true}
value={agentPolicy.unenroll_timeout}
min={1}
onChange={(e) => updateAgentPolicy({ unenroll_timeout: Number(e.target.value) })}
value={agentPolicy.unenroll_timeout || ''}
onChange={(e) => {
updateAgentPolicy({
unenroll_timeout: e.target.value ? Number(e.target.value) : 0,
});
}}
isInvalid={Boolean(touchedFields.unenroll_timeout && validation.unenroll_timeout)}
onBlur={() => setTouchedFields({ ...touchedFields, unenroll_timeout: true })}
placeholder={unenrollmentTimeoutText}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
import React, { memo, useState } from 'react';
import { useHistory } from 'react-router-dom';
import styled from 'styled-components';
import { EuiBottomBar, EuiFlexGroup, EuiFlexItem, EuiButtonEmpty, EuiButton } from '@elastic/eui';
import {
EuiBottomBar,
EuiFlexGroup,
EuiFlexItem,
EuiButtonEmpty,
EuiButton,
EuiSpacer,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

Expand Down Expand Up @@ -145,58 +152,62 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>(
/>

{hasChanges ? (
<EuiBottomBar>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem>
<FormattedMessage
id="xpack.fleet.editAgentPolicy.unsavedChangesText"
defaultMessage="You have unsaved changes"
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup gutterSize="s" justifyContent="flexEnd">
<EuiFlexItem grow={false}>
<EuiButtonEmpty
color="ghost"
onClick={() => {
setAgentPolicy({ ...originalAgentPolicy });
setHasChanges(false);
}}
>
<FormattedMessage
id="xpack.fleet.editAgentPolicy.cancelButtonText"
defaultMessage="Cancel"
/>
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
onClick={onSubmit}
isLoading={isLoading}
isDisabled={
!hasWriteCapabilites || isLoading || Object.keys(validation).length > 0
}
iconType="save"
color="primary"
fill
>
{isLoading ? (
<FormattedMessage
id="xpack.fleet.editAgentPolicy.savingButtonText"
defaultMessage="Saving…"
/>
) : (
<>
<EuiSpacer size="xl" />
<EuiSpacer size="xl" />
<EuiBottomBar>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem>
<FormattedMessage
id="xpack.fleet.editAgentPolicy.unsavedChangesText"
defaultMessage="You have unsaved changes"
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup gutterSize="s" justifyContent="flexEnd">
<EuiFlexItem grow={false}>
<EuiButtonEmpty
color="ghost"
onClick={() => {
setAgentPolicy({ ...originalAgentPolicy });
setHasChanges(false);
}}
>
<FormattedMessage
id="xpack.fleet.editAgentPolicy.saveButtonText"
defaultMessage="Save changes"
id="xpack.fleet.editAgentPolicy.cancelButtonText"
defaultMessage="Cancel"
/>
)}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
</EuiBottomBar>
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
onClick={onSubmit}
isLoading={isLoading}
isDisabled={
!hasWriteCapabilites || isLoading || Object.keys(validation).length > 0
}
iconType="save"
color="primary"
fill
>
{isLoading ? (
<FormattedMessage
id="xpack.fleet.editAgentPolicy.savingButtonText"
defaultMessage="Saving…"
/>
) : (
<FormattedMessage
id="xpack.fleet.editAgentPolicy.saveButtonText"
defaultMessage="Save changes"
/>
)}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
</EuiBottomBar>
</>
) : null}
</FormWrapper>
);
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,12 @@ class AgentPolicyService {
data: (fullPolicy as unknown) as FleetServerPolicy['data'],
policy_id: fullPolicy.id,
default_fleet_server: policy.is_default_fleet_server === true,
unenroll_timeout: policy.unenroll_timeout,
};

if (policy.unenroll_timeout) {
fleetServerPolicy.unenroll_timeout = policy.unenroll_timeout;
}

await esClient.create({
index: AGENT_POLICY_INDEX,
body: fleetServerPolicy,
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({ min: 1 })),
unenroll_timeout: schema.maybe(schema.number()),
monitoring_enabled: schema.maybe(
schema.arrayOf(
schema.oneOf([schema.literal(dataTypes.Logs), schema.literal(dataTypes.Metrics)])
Expand Down

0 comments on commit 9796817

Please sign in to comment.