diff --git a/x-pack/plugins/fleet/common/types/rest_spec/agent.ts b/x-pack/plugins/fleet/common/types/rest_spec/agent.ts index 82d5a779c2ed43..886730d38f8314 100644 --- a/x-pack/plugins/fleet/common/types/rest_spec/agent.ts +++ b/x-pack/plugins/fleet/common/types/rest_spec/agent.ts @@ -89,7 +89,7 @@ export interface PostBulkAgentUpgradeRequest { agents: string[] | string; source_uri?: string; version: string; - rollout_duration_seconds?: number + rollout_duration_seconds?: number; }; } diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx index abdd6552742f1e..b5d8cd8f4d72d6 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/constants.tsx @@ -10,31 +10,23 @@ // in the event that the updated versions cannot be retrieved from the endpoint export const FALLBACK_VERSIONS = [ - '8.2.0', - '8.1.3', - '8.1.2', - '8.1.1', - '8.1.0', - '8.0.1', - '8.0.0', - '7.9.3', - '7.9.2', - '7.9.1', - '7.9.0', - '7.8.1', - '7.8.0', - '7.17.3', - '7.17.2', - '7.17.1', - '7.17.0' + '8.2.0', + '8.1.3', + '8.1.2', + '8.1.1', + '8.1.0', + '8.0.1', + '8.0.0', + '7.9.3', + '7.9.2', + '7.9.1', + '7.9.0', + '7.8.1', + '7.8.0', + '7.17.3', + '7.17.2', + '7.17.1', + '7.17.0', ]; -export const MAINTAINANCE_VALUES = [ - 1, - 2, - 4, - 8, - 12, - 24, - 48 -]; +export const MAINTAINANCE_VALUES = [1, 2, 4, 8, 12, 24, 48]; diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx index 696a2a729d7d07..34cf9085d78a55 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agents/components/agent_upgrade_modal/index.tsx @@ -27,6 +27,7 @@ import { sendPostBulkAgentUpgrade, useStartServices, } from '../../../../hooks'; + import { FALLBACK_VERSIONS, MAINTAINANCE_VALUES } from './constants'; interface Props { @@ -43,38 +44,46 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ const { notifications } = useStartServices(); const [isSubmitting, setIsSubmitting] = useState(false); const isSingleAgent = Array.isArray(agents) && agents.length === 1; - const isSmallBatch = Array.isArray(agents) && agents.length > 1 && agents.length <= 10; + const isSmallBatch = Array.isArray(agents) && agents.length > 1 && agents.length <= 10; const isAllAgents = agents === ''; - const fallbackVersions: Array> = FALLBACK_VERSIONS.map((option) => ({ - label: option, - value: option, - })); + const fallbackVersions: Array> = FALLBACK_VERSIONS.map( + (option) => ({ + label: option, + value: option, + }) + ); const maintainanceWindows = isSmallBatch ? [0].concat(MAINTAINANCE_VALUES) : MAINTAINANCE_VALUES; - const maintainanceOptions: Array> = maintainanceWindows.map((option) => ({ - label: option === 0 ? i18n.translate( - 'xpack.fleet.upgradeAgents.noMaintainanceWindowOption', - { - defaultMessage: 'Immediately', - } - ) : i18n.translate('xpack.fleet.upgradeAgents.hourLabel', { - defaultMessage: - '{option} {count, plural, one {hour} other {hours}}', - values: { option, count: option === 1 }, - }), - value: option === 0 ? 0 : option * 3600 - })); + const maintainanceOptions: Array> = maintainanceWindows.map( + (option) => ({ + label: + option === 0 + ? i18n.translate('xpack.fleet.upgradeAgents.noMaintainanceWindowOption', { + defaultMessage: 'Immediately', + }) + : i18n.translate('xpack.fleet.upgradeAgents.hourLabel', { + defaultMessage: '{option} {count, plural, one {hour} other {hours}}', + values: { option, count: option === 1 }, + }), + value: option === 0 ? 0 : option * 3600, + }) + ); const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[0]]); - const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([maintainanceOptions[0]]); + const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([ + maintainanceOptions[0], + ]); - - const getVersion = (version: EuiComboBoxOptionOption[]) => version[0].value as string; + const getVersion = (version: Array>) => + version[0].value as string; async function onSubmit() { const version = getVersion(selectedVersion); - const rolloutOptions = selectedMantainanceWindow.length > 0 && selectedMantainanceWindow[0]?.value as number > 0 ? { - rollout_duration_seconds: selectedMantainanceWindow[0].value - } : {}; + const rolloutOptions = + selectedMantainanceWindow.length > 0 && (selectedMantainanceWindow[0]?.value as number) > 0 + ? { + rollout_duration_seconds: selectedMantainanceWindow[0].value, + } + : {}; try { setIsSubmitting(true); @@ -82,11 +91,11 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ ? await sendPostAgentUpgrade((agents[0] as Agent).id, { version, }) - : await sendPostBulkAgentUpgrade({ + : await sendPostBulkAgentUpgrade({ version, agents: Array.isArray(agents) ? agents.map((agent) => agent.id) : agents, - ...rolloutOptions - }) + ...rolloutOptions, + }); if (error) { throw error; }