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 d0348f87eadf8..a7cf312e9f929 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 edebdefe8af0d..7e50b1e7e8151 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 @@ -1,4 +1,3 @@ - /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License @@ -11,31 +10,23 @@ // in the event that the updated versions cannot be retrieved from the endpoint export const FALLBACK_VERSIONS = [ - "7.17.0", - "7.17.1", - "7.17.2", - "7.17.3", - "7.8.0", - "7.8.1", - "7.9.0", - "7.9.1", - "7.9.2", - "7.9.3", - "8.0.0", - "8.0.1", - "8.1.0", - "8.1.1", - "8.1.2", - "8.1.3", - "8.2.0", + '7.17.0', + '7.17.1', + '7.17.2', + '7.17.3', + '7.8.0', + '7.8.1', + '7.9.0', + '7.9.1', + '7.9.2', + '7.9.3', + '8.0.0', + '8.0.1', + '8.1.0', + '8.1.1', + '8.1.2', + '8.1.3', + '8.2.0', ]; -export const MAINTAINANCE_WINDOWS = [ - 1, - 2, - 4, - 8, - 12, - 24, - 48 -]; +export const MAINTAINANCE_WINDOWS = [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 73c6eebf57375..6fe07aac78624 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 @@ -7,16 +7,27 @@ import React, { useState } from 'react'; import { i18n } from '@kbn/i18n'; -import { EuiConfirmModal, EuiComboBox, EuiFormRow, EuiSpacer, EuiToolTip, EuiIcon, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { + EuiConfirmModal, + EuiComboBox, + EuiFormRow, + EuiSpacer, + EuiToolTip, + EuiIcon, + EuiFlexGroup, + EuiFlexItem, +} from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import type { EuiComboBoxOptionOption } from '@elastic/eui'; + import type { Agent } from '../../../../types'; import { sendPostAgentUpgrade, sendPostBulkAgentUpgrade, useStartServices, } from '../../../../hooks'; + import { FALLBACK_VERSIONS, MAINTAINANCE_WINDOWS } from './constants'; interface Props { @@ -32,21 +43,29 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ }) => { const { notifications } = useStartServices(); const [isSubmitting, setIsSubmitting] = useState(false); - const fallbackVersions: Array> = FALLBACK_VERSIONS.map((option) => ({ - label: option, - value: option, - })); - const maintainanceOptions: Array> = MAINTAINANCE_WINDOWS.map((option) => ({ - label: option === 1 ? `${option} hour` : `${option} hours`, - value: `${option * 3600}` - })); + const fallbackVersions: Array> = FALLBACK_VERSIONS.map( + (option) => ({ + label: option, + value: option, + }) + ); + const maintainanceOptions: Array> = MAINTAINANCE_WINDOWS.map( + (option) => ({ + label: option === 1 ? `${option} hour` : `${option} hours`, + value: `${option * 3600}`, + }) + ); const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[0]]); - const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([maintainanceOptions[0]]); + const [selectedMantainanceWindow, setSelectedMantainanceWindow] = useState([ + maintainanceOptions[0], + ]); const isSingleAgent = Array.isArray(agents) && agents.length === 1; const isAllAgents = agents === ''; - const getVersion = (selectedVersion: EuiComboBoxOptionOption[]) => selectedVersion[0].value as string; - const getRolloutDuration = (selectedMantainanceWindow: EuiComboBoxOptionOption[]) => Number(selectedMantainanceWindow[0].value) + const getVersion = (selectedVersion: Array>) => + selectedVersion[0].value as string; + const getRolloutDuration = (selectedMantainanceWindow: Array>) => + Number(selectedMantainanceWindow[0].value); async function onSubmit() { const version = getVersion(selectedVersion); @@ -59,7 +78,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ : await sendPostBulkAgentUpgrade({ agents: Array.isArray(agents) ? agents.map((agent) => agent.id) : agents, version, - rollout_duration_seconds: getRolloutDuration(selectedMantainanceWindow) + rollout_duration_seconds: getRolloutDuration(selectedMantainanceWindow), }); if (error) { throw error; @@ -169,7 +188,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent = ({ ) } > -

+

{isSingleAgent ? ( = ({

= ({ /> - { !isSingleAgent ? + {!isSingleAgent ? ( - {i18n.translate( - 'xpack.fleet.upgradeAgents.maintainanceAvailableLabel', - { - defaultMessage: 'Maintainance window available', - } - )} + {i18n.translate('xpack.fleet.upgradeAgents.maintainanceAvailableLabel', { + defaultMessage: 'Maintainance window available', + })} - + - - } + + } fullWidth > = ({ }} /> - : null - } - + ) : null} ); };