Skip to content
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] Tell users when assets are installed in a different space #125278

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just swung by this PR to backport it as a patch to 8.0 and noticed this, we have useStartServices hook which encapsulates the plugin logic added by this PR so that can be use instead of traversing all the way to the kibana_react plugin:

export function useStartServices(): FleetStartServices {

I believe you'd just have to add spaces to the FleetStartServices interface. I think this would be a good candidate for a small PR 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing thanks! I'll get that done some time soon

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