Skip to content

Commit

Permalink
[Inventory] Fix Open Explore in Discover link in a new tab (elastic#2…
Browse files Browse the repository at this point in the history
…07346)

## Summary

Closes elastic#207064

This PR fixes the Explore in Discover link to be able to open it in a
new tab using `dataViewSpec: dataView.toMinimalSpec()`.

## How to test it
1. Enable `entityCentricExperience` feature flag
2. Run some synthtrace scenario, for example `node scripts/synthtrace
infra_docker_containers`
3. Click into an entity group and select Explore in Discover in any
entity.
4. You should be redirected to the data view correctly by clicking or
opening in a new tab

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
2 people authored and viduni94 committed Jan 23, 2025
1 parent 6398dc5 commit 97ddfad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"unifiedSearch",
"data",
"ruleRegistry",
"share"
"share",
"discover"
],
"requiredBundles": ["kibanaReact"],
"optionalPlugins": ["spaces", "cloud"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
* 2.0.
*/
import { useCallback } from 'react';
import type { DiscoverAppLocatorParams } from '@kbn/discover-plugin/common/app_locator';
import { DISCOVER_APP_LOCATOR } from '@kbn/discover-plugin/common';
import type { InventoryEntity } from '../../common/entities';
import { useKibana } from './use_kibana';
import { useUnifiedSearchContext } from './use_unified_search_context';

export const useDiscoverRedirect = (entity: InventoryEntity) => {
const {
services: { share, application, entityManager },
} = useKibana();
const { discoverDataview } = useUnifiedSearchContext();
const { dataView } = discoverDataview;
const discoverLocator = share.url.locators.get('DISCOVER_APP_LOCATOR');
const discoverLocator = share.url.locators.get<DiscoverAppLocatorParams>(DISCOVER_APP_LOCATOR);

const getDiscoverEntitiesRedirectUrl = useCallback(() => {
const entityKqlFilter = entity
Expand All @@ -24,9 +25,9 @@ export const useDiscoverRedirect = (entity: InventoryEntity) => {
})
: '';

return application.capabilities.discover?.show || !dataView
return application.capabilities.discover?.show
? discoverLocator?.getRedirectUrl({
dataViewId: dataView?.id ?? '',
dataViewSpec: dataView?.toMinimalSpec?.(),
query: { query: entityKqlFilter, language: 'kuery' },
})
: undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
"@kbn/kibana-utils-plugin",
"@kbn/dataset-quality-plugin",
"@kbn/observability-utils-common",
"@kbn/discover-plugin",
]
}

0 comments on commit 97ddfad

Please sign in to comment.