Skip to content

Commit

Permalink
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
Browse files Browse the repository at this point in the history
…-fix'
  • Loading branch information
kibanamachine committed May 18, 2022
1 parent 40c45d0 commit 62086a9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 67 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/rest_spec/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export interface PostBulkAgentUpgradeRequest {
agents: string[] | string;
source_uri?: string;
version: string;
rollout_duration_seconds: number
rollout_duration_seconds: number;
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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];
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -32,21 +43,29 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
}) => {
const { notifications } = useStartServices();
const [isSubmitting, setIsSubmitting] = useState(false);
const fallbackVersions: Array<EuiComboBoxOptionOption<string>> = FALLBACK_VERSIONS.map((option) => ({
label: option,
value: option,
}));
const maintainanceOptions: Array<EuiComboBoxOptionOption<string>> = MAINTAINANCE_WINDOWS.map((option) => ({
label: option === 1 ? `${option} hour` : `${option} hours`,
value: `${option * 3600}`
}));
const fallbackVersions: Array<EuiComboBoxOptionOption<string>> = FALLBACK_VERSIONS.map(
(option) => ({
label: option,
value: option,
})
);
const maintainanceOptions: Array<EuiComboBoxOptionOption<string>> = 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<string>[]) => selectedVersion[0].value as string;
const getRolloutDuration = (selectedMantainanceWindow: EuiComboBoxOptionOption<string>[]) => Number(selectedMantainanceWindow[0].value)
const getVersion = (selectedVersion: Array<EuiComboBoxOptionOption<string>>) =>
selectedVersion[0].value as string;
const getRolloutDuration = (selectedMantainanceWindow: Array<EuiComboBoxOptionOption<string>>) =>
Number(selectedMantainanceWindow[0].value);

async function onSubmit() {
const version = getVersion(selectedVersion);
Expand All @@ -59,7 +78,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
: 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;
Expand Down Expand Up @@ -169,7 +188,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
)
}
>
<p>
<p>
{isSingleAgent ? (
<FormattedMessage
id="xpack.fleet.upgradeAgents.upgradeSingleDescription"
Expand All @@ -189,12 +208,9 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
</p>
<EuiSpacer size="m" />
<EuiFormRow
label= {i18n.translate(
'xpack.fleet.upgradeAgents.chooseVersionLabel',
{
defaultMessage: 'Upgrade version',
}
)}
label={i18n.translate('xpack.fleet.upgradeAgents.chooseVersionLabel', {
defaultMessage: 'Upgrade version',
})}
fullWidth
>
<EuiComboBox
Expand All @@ -208,31 +224,32 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
/>
</EuiFormRow>
<EuiSpacer size="m" />
{ !isSingleAgent ?
{!isSingleAgent ? (
<EuiFormRow
label= {
label={
<EuiFlexGroup gutterSize="s">
<EuiFlexItem grow={false}>
{i18n.translate(
'xpack.fleet.upgradeAgents.maintainanceAvailableLabel',
{
defaultMessage: 'Maintainance window available',
}
)}
{i18n.translate('xpack.fleet.upgradeAgents.maintainanceAvailableLabel', {
defaultMessage: 'Maintainance window available',
})}
</EuiFlexItem>
<EuiSpacer size="xs" />
<EuiFlexItem grow={false}>
<EuiToolTip position="top" content={i18n.translate(
'xpack.fleet.upgradeAgents.maintainanceAvailableTooltip',
{
defaultMessage: 'Defines the duration of time available to perform the upgrade. The agent upgrades are spread uniformly across this duration in order to avoid exhausting network resources.',
}
)}>
<EuiToolTip
position="top"
content={i18n.translate(
'xpack.fleet.upgradeAgents.maintainanceAvailableTooltip',
{
defaultMessage:
'Defines the duration of time available to perform the upgrade. The agent upgrades are spread uniformly across this duration in order to avoid exhausting network resources.',
}
)}
>
<EuiIcon type="iInCircle" title="TooltipIcon" />
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
}
</EuiFlexGroup>
}
fullWidth
>
<EuiComboBox
Expand All @@ -245,9 +262,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
}}
/>
</EuiFormRow>
: null
}

) : null}
</EuiConfirmModal>
);
};

0 comments on commit 62086a9

Please sign in to comment.