Skip to content

Commit

Permalink
Update the onSubmit logic and handle case with single agent
Browse files Browse the repository at this point in the history
  • Loading branch information
criamico committed May 18, 2022
1 parent 669d749 commit f442fa9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 46 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/rest_spec/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface PostBulkAgentUpgradeRequest {
agents: string[] | string;
source_uri?: string;
version: string;
rollout_duration_seconds: number
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export const AgentDetailsActionMenu: React.FunctionComponent<{
<AgentUpgradeAgentModal
agents={[agent]}
agentCount={1}
version={kibanaVersion}
onClose={() => {
setIsUpgradeModalOpen(false);
refreshAgent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
setAgentToUpgrade(undefined);
fetchData();
}}
version={kibanaVersion}
/>
</EuiPortal>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ export const FALLBACK_VERSIONS = [
];

export const MAINTAINANCE_WINDOWS = [
'1 hour',
'2 hours',
'4 hours',
'8 hours',
'12 hours',
'24 hours',
'48 hours',
1,
2,
4,
8,
12,
24,
48
];
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
value: option,
}));
const maintainanceOptions: Array<EuiComboBoxOptionOption<string>> = MAINTAINANCE_WINDOWS.map((option) => ({
label: option,
value: option,
label: option === 1 ? `${option} hour` : `${option} hours`,
value: `${option * 3600}`
}));
const [selectedVersion, setSelectedVersion] = useState([fallbackVersions[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)

async function onSubmit() {
const version = getVersion(selectedVersion);
Expand All @@ -58,6 +59,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)
});
if (error) {
throw error;
Expand Down Expand Up @@ -206,42 +208,45 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
/>
</EuiFormRow>
<EuiSpacer size="m" />
<EuiFormRow
label= {
<EuiFlexGroup gutterSize="s">
<EuiFlexItem grow={false}>
{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.',
}
)}>
<EuiIcon type="iInCircle" title="TooltipIcon" />
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
}
fullWidth
>
<EuiComboBox
{ !isSingleAgent ?
<EuiFormRow
label= {
<EuiFlexGroup gutterSize="s">
<EuiFlexItem grow={false}>
{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.',
}
)}>
<EuiIcon type="iInCircle" title="TooltipIcon" />
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
}
fullWidth
singleSelection={{ asPlainText: true }}
options={maintainanceOptions}
selectedOptions={selectedMantainanceWindow}
onChange={(selectedMantainanceWindow: Array<EuiComboBoxOptionOption<string>>) => {
setSelectedMantainanceWindow(selectedMantainanceWindow);
}}
/>
</EuiFormRow>
>
<EuiComboBox
fullWidth
singleSelection={{ asPlainText: true }}
options={maintainanceOptions}
selectedOptions={selectedMantainanceWindow}
onChange={(selectedMantainanceWindow: Array<EuiComboBoxOptionOption<string>>) => {
setSelectedMantainanceWindow(selectedMantainanceWindow);
}}
/>
</EuiFormRow>
: null
}

</EuiConfirmModal>
);
Expand Down

0 comments on commit f442fa9

Please sign in to comment.