Skip to content

Commit

Permalink
Add callout in modal for 400 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
criamico committed May 19, 2022
1 parent 8d35d71 commit 7f36bec
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
EuiIcon,
EuiFlexGroup,
EuiFlexItem,
EuiCallOut
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';

Expand Down Expand Up @@ -43,6 +44,8 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
}) => {
const { notifications } = useStartServices();
const [isSubmitting, setIsSubmitting] = useState(false);
const [errors, setErrors] = useState<string | undefined>();

const isSingleAgent = Array.isArray(agents) && agents.length === 1;
const isSmallBatch = Array.isArray(agents) && agents.length > 1 && agents.length <= 10;
const isAllAgents = agents === '';
Expand Down Expand Up @@ -97,6 +100,9 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
...rolloutOptions,
});
if (error) {
if (error?.statusCode === 400) {
setErrors(error?.message);
}
throw error;
}

Expand Down Expand Up @@ -128,7 +134,6 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
isAllAgents,
},
});
// remove toasts
if (counts.success === counts.total) {
notifications.toasts.addSuccess(successMessage);
} else if (counts.error === counts.total) {
Expand Down Expand Up @@ -231,6 +236,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
fullWidth
>
<EuiComboBox
data-test-subj="agentUpgradeModal.VersionCombobox"
fullWidth
singleSelection={{ asPlainText: true }}
options={fallbackVersions}
Expand Down Expand Up @@ -270,6 +276,7 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
fullWidth
>
<EuiComboBox
data-test-subj="agentUpgradeModal.MaintainanceCombobox"
fullWidth
singleSelection={{ asPlainText: true }}
options={maintainanceOptions}
Expand All @@ -280,6 +287,25 @@ export const AgentUpgradeAgentModal: React.FunctionComponent<Props> = ({
/>
</EuiFormRow>
) : null}
{ errors ?
<>
<EuiCallOut
color="danger"
title={
i18n.translate('xpack.fleet.upgradeAgents.warningCallout', {
defaultMessage:
'Error upgrading the selected {count, plural, one {agent} other {{count} agents}}',
values: { count: isSingleAgent },
})
}
>
<FormattedMessage
id="xpack.fleet.deleteAgentPolicy.confirmModal.affectedAgentsMessage"
defaultMessage={errors}
/>
</EuiCallOut>
</> : null
}
</EuiConfirmModal>
);
};
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -13073,8 +13073,6 @@
"xpack.fleet.upgradeAgents.cancelButtonLabel": "Annuler",
"xpack.fleet.upgradeAgents.confirmMultipleButtonLabel": "Mettre à niveau {count, plural, one {l'agent} other {{count} agents} =true {tous les agents sélectionnés}}",
"xpack.fleet.upgradeAgents.confirmSingleButtonLabel": "Mettre à niveau l'agent",
"xpack.fleet.upgradeAgents.experimentalLabel": "Expérimental",
"xpack.fleet.upgradeAgents.experimentalLabelTooltip": "Une modification ou une suppression de la mise à niveau de l'agent peut intervenir dans une version ultérieure. La mise à niveau n'est pas soumise à l'accord de niveau de service du support technique.",
"xpack.fleet.upgradeAgents.fatalErrorNotificationTitle": "Erreur lors de la mise à niveau de {count, plural, one {l'agent} other {{count} agents} =true {tous les agents sélectionnés}}",
"xpack.fleet.upgradeAgents.successMultiNotificationTitle": "{isMixed, select, true {{success} agents sur {total}} other {{isAllAgents, select, true {Tous les agents sélectionnés} other {{success}} }}} mis à niveau",
"xpack.fleet.upgradeAgents.successSingleNotificationTitle": "{count} agent mis à niveau",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -13190,8 +13190,6 @@
"xpack.fleet.upgradeAgents.cancelButtonLabel": "キャンセル",
"xpack.fleet.upgradeAgents.confirmMultipleButtonLabel": "{count, plural, other {{count}個のエージェント} =true {すべての選択されたエージェント}}をアップグレード",
"xpack.fleet.upgradeAgents.confirmSingleButtonLabel": "エージェントをアップグレード",
"xpack.fleet.upgradeAgents.experimentalLabel": "実験的",
"xpack.fleet.upgradeAgents.experimentalLabelTooltip": "アップグレードエージェントは今後のリリースで変更または削除される可能性があり、SLA のサポート対象になりません。",
"xpack.fleet.upgradeAgents.fatalErrorNotificationTitle": "{count, plural, other {{count}個のエージェント} =true {すべての選択されたエージェント}}のアップグレードエラー",
"xpack.fleet.upgradeAgents.successMultiNotificationTitle": "{isMixed, select, true {{success}/{total}個の} other {{isAllAgents, select, true {すべての選択された} other {{success}} }}}エージェントをアップグレードしました",
"xpack.fleet.upgradeAgents.successSingleNotificationTitle": "{count}個のエージェントをアップグレードしました",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -13214,8 +13214,6 @@
"xpack.fleet.upgradeAgents.cancelButtonLabel": "取消",
"xpack.fleet.upgradeAgents.confirmMultipleButtonLabel": "升级{count, plural, one {代理} other { {count} 个代理} =true {所有选定代理}}",
"xpack.fleet.upgradeAgents.confirmSingleButtonLabel": "升级代理",
"xpack.fleet.upgradeAgents.experimentalLabel": "实验性",
"xpack.fleet.upgradeAgents.experimentalLabelTooltip": "在未来的版本中可能会更改或移除升级代理,其不受支持 SLA 的约束。",
"xpack.fleet.upgradeAgents.fatalErrorNotificationTitle": "升级{count, plural, one {代理} other { {count} 个代理} =true {所有选定代理}}时出错",
"xpack.fleet.upgradeAgents.successMultiNotificationTitle": "已升级{isMixed, select, true { {success} 个(共 {total} 个)} other {{isAllAgents, select, true {所有选定} other { {success} 个} }}}代理",
"xpack.fleet.upgradeAgents.successSingleNotificationTitle": "已升级 {count} 个代理",
Expand Down

0 comments on commit 7f36bec

Please sign in to comment.