Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fleet] added fleet setup before installing integration #121379

Merged
merged 3 commits into from
Dec 17, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ import {
useCapabilities,
useGetPackageInstallStatus,
useInstallPackage,
useStartServices,
} from '../../../../../hooks';

import { sendPostFleetSetup } from '../../../../../../../hooks/use_request/setup';
import { toMountPoint } from '../../../../../../../../../../../src/plugins/kibana_react/public';

import { ConfirmPackageInstall } from './confirm_package_install';

type InstallationButtonProps = Pick<PackageInfo, 'name' | 'title' | 'version'> & {
Expand All @@ -35,17 +39,42 @@ export function InstallButton(props: InstallationButtonProps) {
const getPackageInstallStatus = useGetPackageInstallStatus();
const { status: installationStatus } = getPackageInstallStatus(name);

const isInstalling = installationStatus === InstallStatus.installing;
const [isFleetSetupInProgress, setFleetSetupInProgress] = useState<boolean>(false);

const isInstalling = installationStatus === InstallStatus.installing || isFleetSetupInProgress;
const [isInstallModalVisible, setIsInstallModalVisible] = useState<boolean>(false);

const toggleInstallModal = useCallback(() => {
setIsInstallModalVisible(!isInstallModalVisible);
}, [isInstallModalVisible]);

const handleClickInstall = useCallback(() => {
installPackage({ name, version, title });
const { notifications } = useStartServices();

const handleClickInstall = useCallback(async () => {
setFleetSetupInProgress(true);
toggleInstallModal();
}, [installPackage, name, title, toggleInstallModal, version]);
const res = await sendPostFleetSetup({ forceRecreate: false });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a little nitpick but I would put this in a try catch to avoid uncaught exception here.

try {
const res = await sendPostFleetSetup({ forceRecreate: false });
if (res.error) {
 throw res.error;
}
} catch (e) {
 // show toast
}

if (res.error) {
notifications.toasts.addWarning({
title: toMountPoint(
<FormattedMessage
id="xpack.fleet.integrations.fleetSetupErrorTitle"
defaultMessage="Failed to setup Fleet"
values={{ title }}
/>
),
text: toMountPoint(
<FormattedMessage
id="xpack.fleet.integrations.fleetSetupErrorDescription"
defaultMessage="Something went wrong while trying to setup Fleet. Please try again by navigating to Fleet tab."
/>
),
iconType: 'alert',
});
}
setFleetSetupInProgress(false);
installPackage({ name, version, title });
}, [installPackage, name, title, toggleInstallModal, version, notifications.toasts]);

const installModal = (
<ConfirmPackageInstall
Expand Down