Skip to content

Commit

Permalink
[Fleet] Fix EuiComboBox in agent upgrade modal to disallow clear (#13…
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Jun 3, 2022
1 parent 71652fb commit 4b273d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import type { EuiComboBoxOptionOption } from '@elastic/eui';

import semverCoerce from 'semver/functions/coerce';
import semverGt from 'semver/functions/gt';
import semverValid from 'semver/functions/valid';

import { getMinVersion } from '../../../../../../../common/services/get_min_max_version';
import type { Agent } from '../../../../types';
Expand Down Expand Up @@ -199,6 +200,10 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<AgentUpgradeAgentMo
}

const onCreateOption = (searchValue: string) => {
if (!semverValid(searchValue)) {
return;
}

const agentVersionNumber = semverCoerce(searchValue);
if (
agentVersionNumber?.version &&
Expand Down Expand Up @@ -297,8 +302,12 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<AgentUpgradeAgentMo
fullWidth
singleSelection={{ asPlainText: true }}
options={versionOptions}
isClearable={false}
selectedOptions={selectedVersion}
onChange={(selected: Array<EuiComboBoxOptionOption<string>>) => {
if (!selected.length) {
return;
}
setSelectedVersion(selected);
}}
onCreateOption={onCreateOption}
Expand Down Expand Up @@ -369,10 +378,14 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<AgentUpgradeAgentMo
<EuiComboBox
data-test-subj="agentUpgradeModal.MaintainanceCombobox"
fullWidth
isClearable={false}
singleSelection={{ asPlainText: true }}
options={maintainanceOptions}
selectedOptions={selectedMantainanceWindow}
onChange={(selected: Array<EuiComboBoxOptionOption<number>>) => {
if (!selected.length) {
return;
}
setSelectedMantainanceWindow(selected);
}}
/>
Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/fleet/server/types/rest_spec/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { schema } from '@kbn/config-schema';
import moment from 'moment';
import semverIsValid from 'semver/functions/valid';

import { NewAgentActionSchema } from '../models';

Expand Down Expand Up @@ -61,13 +62,21 @@ export const PostBulkAgentUnenrollRequestSchema = {
}),
};

function validateVersion(s: string) {
if (!semverIsValid(s)) {
return 'not a valid semver';
}
}

export const PostAgentUpgradeRequestSchema = {
params: schema.object({
agentId: schema.string(),
}),
body: schema.object({
source_uri: schema.maybe(schema.string()),
version: schema.string(),
version: schema.string({
validate: validateVersion,
}),
force: schema.maybe(schema.boolean()),
}),
};
Expand All @@ -76,7 +85,7 @@ export const PostBulkAgentUpgradeRequestSchema = {
body: schema.object({
agents: schema.oneOf([schema.arrayOf(schema.string()), schema.string()]),
source_uri: schema.maybe(schema.string()),
version: schema.string(),
version: schema.string({ validate: validateVersion }),
force: schema.maybe(schema.boolean()),
rollout_duration_seconds: schema.maybe(schema.number({ min: 600 })),
start_time: schema.maybe(
Expand Down

0 comments on commit 4b273d5

Please sign in to comment.