-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Allow to install Kibana assets in multiple spaces #186620
Changes from 18 commits
00d685b
901424e
80320de
7dfbc24
168704c
8ff55eb
9eb9135
a30de0a
8223489
e944f52
b74f13e
587c9f9
3ac768f
2cd5196
09c6abe
b7fcb9b
e86f532
50632d7
a6b5c18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ import { Redirect } from 'react-router-dom'; | |
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { EuiFlexGroup, EuiFlexItem, EuiLink, EuiSpacer, EuiTitle, EuiCallOut } from '@elastic/eui'; | ||
|
||
import { ExperimentalFeaturesService } from '../../../../../../../services'; | ||
|
||
import type { | ||
EsAssetReference, | ||
AssetSOObject, | ||
|
@@ -31,12 +33,11 @@ import { | |
useAuthz, | ||
useFleetStatus, | ||
} from '../../../../../hooks'; | ||
|
||
import { sendGetBulkAssets } from '../../../../../hooks'; | ||
|
||
import { DeferredAssetsSection } from './deferred_assets_accordion'; | ||
|
||
import { AssetsAccordion } from './assets_accordion'; | ||
import { InstallKibanaAssetsButton } from './install_kibana_assets_button'; | ||
|
||
interface AssetsPanelProps { | ||
packageInfo: PackageInfo; | ||
|
@@ -50,6 +51,8 @@ export const AssetsPage = ({ packageInfo, refetchPackageInfo }: AssetsPanelProps | |
const { docLinks } = useStartServices(); | ||
const { spaceId } = useFleetStatus(); | ||
|
||
const { useSpaceAwareness } = ExperimentalFeaturesService.get(); | ||
|
||
const customAssetsExtension = useUIExtension(packageInfo.name, 'package-detail-assets'); | ||
|
||
const canReadPackageSettings = useAuthz().integrations.readPackageInfo; | ||
|
@@ -62,23 +65,30 @@ export const AssetsPage = ({ packageInfo, refetchPackageInfo }: AssetsPanelProps | |
'installationInfo' in packageInfo ? packageInfo.installationInfo : undefined; | ||
|
||
const installedSpaceId = pkgInstallationInfo?.installed_kibana_space_id; | ||
const assetsInstalledInCurrentSpace = !installedSpaceId || installedSpaceId === spaceId; | ||
|
||
const assetsInstalledInCurrentSpace = | ||
!installedSpaceId || | ||
installedSpaceId === spaceId || | ||
pkgInstallationInfo?.additional_spaces_installed_kibana?.[spaceId || 'default']; | ||
const [assetSavedObjectsByType, setAssetsSavedObjectsByType] = useState< | ||
Record<string, Record<string, SimpleSOAssetType & { appLink?: string }>> | ||
>({}); | ||
const [deferredInstallations, setDeferredInstallations] = useState<EsAssetReference[]>(); | ||
|
||
const kibanaAssets = useMemo(() => { | ||
return !installedSpaceId || installedSpaceId === spaceId | ||
? pkgInstallationInfo?.installed_kibana || [] | ||
: pkgInstallationInfo?.additional_spaces_installed_kibana?.[spaceId || 'default'] || []; | ||
}, [ | ||
installedSpaceId, | ||
spaceId, | ||
pkgInstallationInfo?.installed_kibana, | ||
pkgInstallationInfo?.additional_spaces_installed_kibana, | ||
]); | ||
const pkgAssets = useMemo( | ||
() => [ | ||
...(assetsInstalledInCurrentSpace ? pkgInstallationInfo?.installed_kibana || [] : []), | ||
...(pkgInstallationInfo?.installed_es || []), | ||
], | ||
[ | ||
assetsInstalledInCurrentSpace, | ||
pkgInstallationInfo?.installed_es, | ||
pkgInstallationInfo?.installed_kibana, | ||
] | ||
() => [...kibanaAssets, ...(pkgInstallationInfo?.installed_es || [])], | ||
[kibanaAssets, pkgInstallationInfo?.installed_es] | ||
); | ||
|
||
const pkgAssetsByType = useMemo( | ||
() => | ||
pkgAssets.reduce((acc, asset) => { | ||
|
@@ -231,6 +241,13 @@ export const AssetsPage = ({ packageInfo, refetchPackageInfo }: AssetsPanelProps | |
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there already a docs issue to update https://www.elastic.co/guide/en/fleet/current/install-uninstall-integration-assets.html once this feature is enabled by default? if not, let's go ahead and create a placeholder issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No there is not, I will create one for the whole space awareness project as there is probably more than this to document. |
||
/> | ||
</p> | ||
{useSpaceAwareness ? ( | ||
<InstallKibanaAssetsButton | ||
installInfo={pkgInstallationInfo} | ||
title={packageInfo.title} | ||
onSuccess={forceRefreshAssets} | ||
/> | ||
) : null} | ||
</EuiCallOut> | ||
|
||
<EuiSpacer size="m" /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiButton } from '@elastic/eui'; | ||
import React, { useCallback } from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import type { InstallationInfo } from '../../../../../../../../common/types'; | ||
import { useAuthz, useInstallKibanaAssetsMutation, useStartServices } from '../../../../../hooks'; | ||
|
||
interface InstallKibanaAssetsButtonProps { | ||
title: string; | ||
installInfo: InstallationInfo; | ||
onSuccess?: () => void; | ||
} | ||
|
||
export function InstallKibanaAssetsButton({ | ||
installInfo, | ||
title, | ||
onSuccess, | ||
}: InstallKibanaAssetsButtonProps) { | ||
const { notifications } = useStartServices(); | ||
const { name, version } = installInfo; | ||
const canInstallPackages = useAuthz().integrations.installPackages; | ||
const { mutateAsync, isLoading } = useInstallKibanaAssetsMutation(); | ||
|
||
const handleClickInstall = useCallback(async () => { | ||
try { | ||
await mutateAsync({ | ||
pkgName: name, | ||
pkgVersion: version, | ||
}); | ||
if (onSuccess) { | ||
await onSuccess(); | ||
} | ||
} catch (err) { | ||
notifications.toasts.addError(err, { | ||
title: i18n.translate('xpack.fleet.fleetServerSetup.kibanaInstallAssetsErrorTitle', { | ||
defaultMessage: 'Error installing kibana assets', | ||
nchaulet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}), | ||
}); | ||
} | ||
}, [mutateAsync, onSuccess, name, version, notifications.toasts]); | ||
|
||
return ( | ||
<EuiButton | ||
disabled={!canInstallPackages} | ||
iconType="importAction" | ||
isLoading={isLoading} | ||
onClick={handleClickInstall} | ||
> | ||
{isLoading ? ( | ||
<FormattedMessage | ||
id="xpack.fleet.integrations.installPackage.kibanaAssetsInstallingButtonLabel" | ||
defaultMessage="Installing {title} kibana assets in current space" | ||
values={{ | ||
title, | ||
}} | ||
/> | ||
) : ( | ||
<FormattedMessage | ||
id="xpack.fleet.integrations.installPackage.kibanaAssetsInstallButtonLabel" | ||
defaultMessage="Install {title} kibana assets in current space" | ||
nchaulet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
values={{ | ||
title, | ||
}} | ||
/> | ||
)} | ||
</EuiButton> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really related to that feature, but it allow to add some type safety to
allowedExperimentalValues
, and fix the autocompletion that was bothering me