From e68c4a37b42276ed8b53e223c176c41f19fca693 Mon Sep 17 00:00:00 2001 From: Mark Hopkin Date: Fri, 11 Feb 2022 13:41:19 +0000 Subject: [PATCH] [Fleet] Tell users when assets are installed in a different space (#125278) * Show new message when assets installed in separate space * move variable into useEffect (cherry picked from commit a81b11e0fb1df208b1997a294bb22ff0a1b1cc24) --- .../epm/screens/detail/assets/assets.tsx | 33 ++++++++++++++++--- x-pack/plugins/fleet/public/types/index.ts | 1 + .../fleet/public/types/start_plugins.ts | 12 +++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 x-pack/plugins/fleet/public/types/start_plugins.ts diff --git a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/assets/assets.tsx b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/assets/assets.tsx index dc931f835b043..6dae7920fa692 100644 --- a/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/assets/assets.tsx +++ b/x-pack/plugins/fleet/public/applications/integrations/sections/epm/screens/detail/assets/assets.tsx @@ -13,9 +13,10 @@ import { groupBy } from 'lodash'; import type { ResolvedSimpleSavedObject } from 'src/core/public'; +import { useKibana } from '../../../../../../../../../../../src/plugins/kibana_react/public'; import { Loading, Error, ExtensionWrapper } from '../../../../../components'; -import type { PackageInfo } from '../../../../../types'; +import type { PackageInfo, StartPlugins } from '../../../../../types'; import { InstallStatus } from '../../../../../types'; import { @@ -36,8 +37,8 @@ interface AssetsPanelProps { export const AssetsPage = ({ packageInfo }: AssetsPanelProps) => { const { name, version } = packageInfo; + const { spaces } = useKibana().services; const pkgkey = `${name}-${version}`; - const { savedObjects: { client: savedObjectsClient }, } = useStartServices(); @@ -47,6 +48,8 @@ export const AssetsPage = ({ packageInfo }: AssetsPanelProps) => { const getPackageInstallStatus = useGetPackageInstallStatus(); const packageInstallStatus = getPackageInstallStatus(packageInfo.name); + // assume assets are installed in this space until we find otherwise + const [assetsInstalledInCurrentSpace, setAssetsInstalledInCurrentSpace] = useState(true); const [assetSavedObjects, setAssetsSavedObjects] = useState(); const [fetchError, setFetchError] = useState(); const [isLoading, setIsLoading] = useState(true); @@ -54,6 +57,17 @@ export const AssetsPage = ({ packageInfo }: AssetsPanelProps) => { useEffect(() => { const fetchAssetSavedObjects = async () => { if ('savedObject' in packageInfo) { + if (spaces) { + const { id: spaceId } = await spaces.getActiveSpace(); + const assetInstallSpaceId = packageInfo.savedObject.attributes.installed_kibana_space_id; + // if assets are installed in a different space no need to attempt to load them. + if (assetInstallSpaceId && assetInstallSpaceId !== spaceId) { + setAssetsInstalledInCurrentSpace(false); + setIsLoading(false); + return; + } + } + const { savedObject: { attributes: packageAttributes }, } = packageInfo; @@ -114,7 +128,7 @@ export const AssetsPage = ({ packageInfo }: AssetsPanelProps) => { } }; fetchAssetSavedObjects(); - }, [savedObjectsClient, packageInfo]); + }, [savedObjectsClient, packageInfo, spaces]); // if they arrive at this page and the package is not installed, send them to overview // this happens if they arrive with a direct url or they uninstall while on this tab @@ -137,9 +151,20 @@ export const AssetsPage = ({ packageInfo }: AssetsPanelProps) => { error={fetchError} /> ); + } else if (!assetsInstalledInCurrentSpace) { + content = ( + +

+ +

+
+ ); } else if (assetSavedObjects === undefined || assetSavedObjects.length === 0) { if (customAssetsExtension) { - // If a UI extension for custom asset entries is defined, render the custom component here depisite + // If a UI extension for custom asset entries is defined, render the custom component here despite // there being no saved objects found content = ( diff --git a/x-pack/plugins/fleet/public/types/index.ts b/x-pack/plugins/fleet/public/types/index.ts index ead44a798cfc7..6fbe645c9bea3 100644 --- a/x-pack/plugins/fleet/public/types/index.ts +++ b/x-pack/plugins/fleet/public/types/index.ts @@ -121,3 +121,4 @@ export { entries, ElasticsearchAssetType, KibanaAssetType, InstallStatus } from export * from './intra_app_route_state'; export * from './ui_extensions'; export * from './in_memory_package_policy'; +export * from './start_plugins'; diff --git a/x-pack/plugins/fleet/public/types/start_plugins.ts b/x-pack/plugins/fleet/public/types/start_plugins.ts new file mode 100644 index 0000000000000..8fcad821f2ccb --- /dev/null +++ b/x-pack/plugins/fleet/public/types/start_plugins.ts @@ -0,0 +1,12 @@ +/* + * 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 type { SpacesPluginStart } from '../../../spaces/public'; + +export interface StartPlugins { + spaces?: SpacesPluginStart; +}