Skip to content

Commit

Permalink
[Fleet] disable reinstall with tooltip for uploaded packages (#150535)
Browse files Browse the repository at this point in the history
## Summary

Disable Reinstall button and added tooltip to prevent clicking Reinstall
for uploaded packages.

Related to
#148599 (comment)

<img width="731" alt="image"
src="https://user-images.githubusercontent.com/90178898/217497440-e36bad4d-d4dc-4d1c-b434-b17f0a4ead0a.png">



### Checklist


- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
  • Loading branch information
juliaElastic authored Feb 8, 2023
1 parent 031f67b commit 84003d2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,74 @@
* 2.0.
*/

import { EuiButton } from '@elastic/eui';
import { EuiButton, EuiToolTip } from '@elastic/eui';
import React, { Fragment, useCallback } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';

import type { PackageInfo } from '../../../../../types';
import { InstallStatus } from '../../../../../types';
import { useAuthz, useGetPackageInstallStatus, useInstallPackage } from '../../../../../hooks';

type ReinstallationButtonProps = Pick<PackageInfo, 'name' | 'title' | 'version'>;
type ReinstallationButtonProps = Pick<PackageInfo, 'name' | 'title' | 'version'> & {
installSource: string;
};
export function ReinstallButton(props: ReinstallationButtonProps) {
const { name, title, version } = props;
const { name, title, version, installSource } = props;
const canInstallPackages = useAuthz().integrations.installPackages;
const installPackage = useInstallPackage();
const getPackageInstallStatus = useGetPackageInstallStatus();
const { status: installationStatus } = getPackageInstallStatus(name);

const isReinstalling = installationStatus === InstallStatus.reinstalling;
const isUploadedPackage = installSource === 'upload';

const handleClickReinstall = useCallback(() => {
installPackage({ name, version, title, isReinstall: true });
}, [installPackage, name, title, version]);

const reinstallButton = (
<EuiButton
iconType="refresh"
isLoading={isReinstalling}
onClick={handleClickReinstall}
disabled={isUploadedPackage}
>
{isReinstalling ? (
<FormattedMessage
id="xpack.fleet.integrations.installPackage.reinstallingPackageButtonLabel"
defaultMessage="Reinstalling {title}"
values={{
title,
}}
/>
) : (
<FormattedMessage
id="xpack.fleet.integrations.installPackage.reinstallPackageButtonLabel"
defaultMessage="Reinstall {title}"
values={{
title,
}}
/>
)}
</EuiButton>
);

return canInstallPackages ? (
<Fragment>
<EuiButton iconType="refresh" isLoading={isReinstalling} onClick={handleClickReinstall}>
{isReinstalling ? (
<FormattedMessage
id="xpack.fleet.integrations.installPackage.reinstallingPackageButtonLabel"
defaultMessage="Reinstalling {title}"
values={{
title,
}}
/>
) : (
<FormattedMessage
id="xpack.fleet.integrations.installPackage.reinstallPackageButtonLabel"
defaultMessage="Reinstall {title}"
values={{
title,
}}
/>
)}
</EuiButton>
{isUploadedPackage ? (
<EuiToolTip
content={
<FormattedMessage
id="xpack.fleet.integrations.installPackage.uploadedTooltip"
defaultMessage="This integration was installed by upload and cannot be automatically reinstalled. Please upload it again to reinstall."
/>
}
>
{reinstallButton}
</EuiToolTip>
) : (
reinstallButton
)}
</Fragment>
) : null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,14 @@ export const SettingsPage: React.FC<Props> = memo(({ packageInfo, theme$ }: Prop
</EuiFlexItem>
<EuiFlexItem grow={false}>
<div>
<ReinstallButton {...packageInfo} />
<ReinstallButton
{...packageInfo}
installSource={
'savedObject' in packageInfo
? packageInfo.savedObject.attributes.install_source
: ''
}
/>
</div>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down

0 comments on commit 84003d2

Please sign in to comment.