Skip to content

Commit 9796817

Browse files
authored
Allow zero (0) to unset unenroll_timeout field (#103790) (#103897)
1 parent dc0cf92 commit 9796817

File tree

4 files changed

+81
-62
lines changed

4 files changed

+81
-62
lines changed

x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_form.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
159159
</EuiFormRow>
160160
);
161161
});
162-
const unenrollmentTimeoutText = i18n.translate(
163-
'xpack.fleet.agentPolicyForm.unenrollmentTimeoutLabel',
164-
{ defaultMessage: 'Unenrollment timeout' }
165-
);
166162

167163
const advancedOptionsContent = (
168164
<>
@@ -303,7 +299,14 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
303299
/>
304300
</EuiDescribedFormGroup>
305301
<EuiDescribedFormGroup
306-
title={<h4>{unenrollmentTimeoutText}</h4>}
302+
title={
303+
<h4>
304+
<FormattedMessage
305+
id="xpack.fleet.agentPolicyForm.unenrollmentTimeoutLabel"
306+
defaultMessage="Unenrollment timeout"
307+
/>
308+
</h4>
309+
}
307310
description={
308311
<FormattedMessage
309312
id="xpack.fleet.agentPolicyForm.unenrollmentTimeoutDescription"
@@ -315,12 +318,14 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
315318
<EuiFieldNumber
316319
fullWidth
317320
disabled={agentPolicy.is_managed === true}
318-
value={agentPolicy.unenroll_timeout}
319-
min={1}
320-
onChange={(e) => updateAgentPolicy({ unenroll_timeout: Number(e.target.value) })}
321+
value={agentPolicy.unenroll_timeout || ''}
322+
onChange={(e) => {
323+
updateAgentPolicy({
324+
unenroll_timeout: e.target.value ? Number(e.target.value) : 0,
325+
});
326+
}}
321327
isInvalid={Boolean(touchedFields.unenroll_timeout && validation.unenroll_timeout)}
322328
onBlur={() => setTouchedFields({ ...touchedFields, unenroll_timeout: true })}
323-
placeholder={unenrollmentTimeoutText}
324329
/>
325330
</EuiFormRow>
326331
</EuiDescribedFormGroup>

x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/details_page/components/settings/index.tsx

Lines changed: 62 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@
88
import React, { memo, useState } from 'react';
99
import { useHistory } from 'react-router-dom';
1010
import styled from 'styled-components';
11-
import { EuiBottomBar, EuiFlexGroup, EuiFlexItem, EuiButtonEmpty, EuiButton } from '@elastic/eui';
11+
import {
12+
EuiBottomBar,
13+
EuiFlexGroup,
14+
EuiFlexItem,
15+
EuiButtonEmpty,
16+
EuiButton,
17+
EuiSpacer,
18+
} from '@elastic/eui';
1219
import { i18n } from '@kbn/i18n';
1320
import { FormattedMessage } from '@kbn/i18n/react';
1421

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

147154
{hasChanges ? (
148-
<EuiBottomBar>
149-
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
150-
<EuiFlexItem>
151-
<FormattedMessage
152-
id="xpack.fleet.editAgentPolicy.unsavedChangesText"
153-
defaultMessage="You have unsaved changes"
154-
/>
155-
</EuiFlexItem>
156-
<EuiFlexItem>
157-
<EuiFlexGroup gutterSize="s" justifyContent="flexEnd">
158-
<EuiFlexItem grow={false}>
159-
<EuiButtonEmpty
160-
color="ghost"
161-
onClick={() => {
162-
setAgentPolicy({ ...originalAgentPolicy });
163-
setHasChanges(false);
164-
}}
165-
>
166-
<FormattedMessage
167-
id="xpack.fleet.editAgentPolicy.cancelButtonText"
168-
defaultMessage="Cancel"
169-
/>
170-
</EuiButtonEmpty>
171-
</EuiFlexItem>
172-
<EuiFlexItem grow={false}>
173-
<EuiButton
174-
onClick={onSubmit}
175-
isLoading={isLoading}
176-
isDisabled={
177-
!hasWriteCapabilites || isLoading || Object.keys(validation).length > 0
178-
}
179-
iconType="save"
180-
color="primary"
181-
fill
182-
>
183-
{isLoading ? (
184-
<FormattedMessage
185-
id="xpack.fleet.editAgentPolicy.savingButtonText"
186-
defaultMessage="Saving…"
187-
/>
188-
) : (
155+
<>
156+
<EuiSpacer size="xl" />
157+
<EuiSpacer size="xl" />
158+
<EuiBottomBar>
159+
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
160+
<EuiFlexItem>
161+
<FormattedMessage
162+
id="xpack.fleet.editAgentPolicy.unsavedChangesText"
163+
defaultMessage="You have unsaved changes"
164+
/>
165+
</EuiFlexItem>
166+
<EuiFlexItem>
167+
<EuiFlexGroup gutterSize="s" justifyContent="flexEnd">
168+
<EuiFlexItem grow={false}>
169+
<EuiButtonEmpty
170+
color="ghost"
171+
onClick={() => {
172+
setAgentPolicy({ ...originalAgentPolicy });
173+
setHasChanges(false);
174+
}}
175+
>
189176
<FormattedMessage
190-
id="xpack.fleet.editAgentPolicy.saveButtonText"
191-
defaultMessage="Save changes"
177+
id="xpack.fleet.editAgentPolicy.cancelButtonText"
178+
defaultMessage="Cancel"
192179
/>
193-
)}
194-
</EuiButton>
195-
</EuiFlexItem>
196-
</EuiFlexGroup>
197-
</EuiFlexItem>
198-
</EuiFlexGroup>
199-
</EuiBottomBar>
180+
</EuiButtonEmpty>
181+
</EuiFlexItem>
182+
<EuiFlexItem grow={false}>
183+
<EuiButton
184+
onClick={onSubmit}
185+
isLoading={isLoading}
186+
isDisabled={
187+
!hasWriteCapabilites || isLoading || Object.keys(validation).length > 0
188+
}
189+
iconType="save"
190+
color="primary"
191+
fill
192+
>
193+
{isLoading ? (
194+
<FormattedMessage
195+
id="xpack.fleet.editAgentPolicy.savingButtonText"
196+
defaultMessage="Saving…"
197+
/>
198+
) : (
199+
<FormattedMessage
200+
id="xpack.fleet.editAgentPolicy.saveButtonText"
201+
defaultMessage="Save changes"
202+
/>
203+
)}
204+
</EuiButton>
205+
</EuiFlexItem>
206+
</EuiFlexGroup>
207+
</EuiFlexItem>
208+
</EuiFlexGroup>
209+
</EuiBottomBar>
210+
</>
200211
) : null}
201212
</FormWrapper>
202213
);

x-pack/plugins/fleet/server/services/agent_policy.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,12 @@ class AgentPolicyService {
642642
data: (fullPolicy as unknown) as FleetServerPolicy['data'],
643643
policy_id: fullPolicy.id,
644644
default_fleet_server: policy.is_default_fleet_server === true,
645-
unenroll_timeout: policy.unenroll_timeout,
646645
};
647646

647+
if (policy.unenroll_timeout) {
648+
fleetServerPolicy.unenroll_timeout = policy.unenroll_timeout;
649+
}
650+
648651
await esClient.create({
649652
index: AGENT_POLICY_INDEX,
650653
body: fleetServerPolicy,

x-pack/plugins/fleet/server/types/models/agent_policy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const AgentPolicyBaseSchema = {
1616
namespace: NamespaceSchema,
1717
description: schema.maybe(schema.string()),
1818
is_managed: schema.maybe(schema.boolean()),
19-
unenroll_timeout: schema.maybe(schema.number({ min: 1 })),
19+
unenroll_timeout: schema.maybe(schema.number()),
2020
monitoring_enabled: schema.maybe(
2121
schema.arrayOf(
2222
schema.oneOf([schema.literal(dataTypes.Logs), schema.literal(dataTypes.Metrics)])

0 commit comments

Comments
 (0)