Skip to content

Commit

Permalink
[Fleet] Tell users when assets are installed in a different space (el…
Browse files Browse the repository at this point in the history
…astic#125278)

* Show new message when assets installed in separate space

* move variable into useEffect
  • Loading branch information
hop-dev authored Feb 11, 2022
1 parent 13d566c commit a81b11e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -47,13 +48,26 @@ 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);

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;
Expand Down Expand Up @@ -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
Expand All @@ -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>
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/public/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
12 changes: 12 additions & 0 deletions x-pack/plugins/fleet/public/types/start_plugins.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit a81b11e

Please sign in to comment.