[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
This commit is contained in:
Mark Hopkin 2022-02-11 13:41:19 +00:00 committed by GitHub
parent 13d566cec3
commit a81b11e0fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 4 deletions

View file

@ -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<StartPlugins>().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<boolean>(true);
const [assetSavedObjects, setAssetsSavedObjects] = useState<undefined | AssetSavedObject[]>();
const [fetchError, setFetchError] = useState<undefined | Error>();
const [isLoading, setIsLoading] = useState<boolean>(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 = (
<EuiTitle>
<h2>
<FormattedMessage
id="xpack.fleet.epm.packageDetails.assets.assetsNotAvailableInCurrentSpace"
defaultMessage="This integration is installed, but no assets are available in this space"
/>
</h2>
</EuiTitle>
);
} 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 = (
<ExtensionWrapper>

View file

@ -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';

View file

@ -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;
}