Skip to content

Commit

Permalink
[8.x] Revert "[ECO][Inventory v2] Ad hoc data view: Add get enti…
Browse files Browse the repository at this point in the history
…ties definition endpoint using sources (#203424) (#204012) (#204025)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Revert "[ECO][Inventory v2] Ad hoc data view: Add get entities
definition endpoint using sources (#203424)
(#204012)](#204012)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"jennypavlova","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-12T13:42:47Z","message":"Revert
\"[ECO][Inventory v2] Ad hoc data view: Add get entities definition
endpoint using sources (#203424) (#204012)\n\nThis reverts commit
5bacf1f.\r\n\r\nReverting because it's
blocked
by\r\nhttps://github.com//issues/202296","sha":"fe67c9536bb1a65b5aa0c9dbc8d5169728d9310e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-infra_services"],"title":"Revert
\"[ECO][Inventory v2] Ad hoc data view: Add get entities definition
endpoint using sources
(#203424)","number":204012,"url":"https://github.com/elastic/kibana/pull/204012","mergeCommit":{"message":"Revert
\"[ECO][Inventory v2] Ad hoc data view: Add get entities definition
endpoint using sources (#203424) (#204012)\n\nThis reverts commit
5bacf1f.\r\n\r\nReverting because it's
blocked
by\r\nhttps://github.com//issues/202296","sha":"fe67c9536bb1a65b5aa0c9dbc8d5169728d9310e"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204012","number":204012,"mergeCommit":{"message":"Revert
\"[ECO][Inventory v2] Ad hoc data view: Add get entities definition
endpoint using sources (#203424) (#204012)\n\nThis reverts commit
5bacf1f.\r\n\r\nReverting because it's
blocked
by\r\nhttps://github.com//issues/202296","sha":"fe67c9536bb1a65b5aa0c9dbc8d5169728d9310e"}}]}]
BACKPORT-->

Co-authored-by: jennypavlova <[email protected]>
Co-authored-by: Irene Blanco <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2024
1 parent 7559d03 commit 4e7bca8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,17 @@ export const EntityActions = ({ entity, setShowActions }: Props) => {
? `inventoryEntityActionsButton-${entity.entityDisplayName}`
: 'inventoryEntityActionsButton';

const { getDiscoverEntitiesRedirectUrl, isEntityDefinitionIndexPatternsLoading } =
useDiscoverRedirect(entity);
const { getDiscoverEntitiesRedirectUrl, isEntityDefinitionLoading } = useDiscoverRedirect(entity);
const discoverUrl = getDiscoverEntitiesRedirectUrl();

const actions: React.ReactElement[] = [];

if (!discoverUrl && !isEntityDefinitionIndexPatternsLoading) {
if (!discoverUrl && !isEntityDefinitionLoading) {
setShowActions(false);
return null;
}

if (!isEntityDefinitionIndexPatternsLoading) {
if (!isEntityDefinitionLoading) {
actions.push(
<EuiContextMenuItem
data-test-subj="inventoryEntityActionExploreInDiscover"
Expand Down Expand Up @@ -66,7 +65,7 @@ export const EntityActions = ({ entity, setShowActions }: Props) => {
iconType="boxesHorizontal"
color="text"
onClick={togglePopover}
isLoading={isEntityDefinitionIndexPatternsLoading}
isLoading={isEntityDefinitionLoading}
/>
}
closePopover={closePopover}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
import { useCallback, useMemo } from 'react';
import type { InventoryEntity } from '../../common/entities';
import { useAdHocDataView } from './use_adhoc_data_view';
import { useFetchEntityDefinitionIndexPattern } from './use_fetch_entity_definition_index_patterns';
import { useFetchEntityDefinition } from './use_fetch_entity_definition';
import { useKibana } from './use_kibana';

export const useDiscoverRedirect = (entity: InventoryEntity) => {
const {
services: { share, application, entityManager },
} = useKibana();
const { entityDefinitionIndexPatterns, isEntityDefinitionIndexPatternsLoading } =
useFetchEntityDefinitionIndexPattern(entity.entityType);
const { entityDefinitions, isEntityDefinitionLoading } = useFetchEntityDefinition(
entity.entityDefinitionId
);

const title = useMemo(
() =>
!isEntityDefinitionIndexPatternsLoading && (entityDefinitionIndexPatterns ?? []).length > 0
? entityDefinitionIndexPatterns[0].join()
!isEntityDefinitionLoading && entityDefinitions && entityDefinitions?.length > 0
? entityDefinitions[0]?.indexPatterns?.join(',')
: '',
[entityDefinitionIndexPatterns, isEntityDefinitionIndexPatternsLoading]
[entityDefinitions, isEntityDefinitionLoading]
);

const { dataView } = useAdHocDataView(title);
Expand Down Expand Up @@ -53,5 +54,5 @@ export const useDiscoverRedirect = (entity: InventoryEntity) => {
entityManager.entityClient,
]);

return { getDiscoverEntitiesRedirectUrl, isEntityDefinitionIndexPatternsLoading };
return { getDiscoverEntitiesRedirectUrl, isEntityDefinitionLoading };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 { useAbortableAsync } from '@kbn/observability-utils-browser/hooks/use_abortable_async';
import { useKibana } from './use_kibana';

export const useFetchEntityDefinition = (id: string) => {
const {
services: { entityManager },
} = useKibana();

const { value, loading } = useAbortableAsync(
({ signal }) => {
return entityManager.entityClient.getEntityDefinition(id);
},
[entityManager.entityClient, id]
);

return {
entityDefinitions: value?.definitions,
isEntityDefinitionLoading: loading,
};
};

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
*/

import { entitiesRoutes } from './entities/route';
import { entityDefinitionsRoutes } from './entity_definition/get_entity_definitions';
import { hasDataRoutes } from './has_data/route';

export function getGlobalInventoryServerRouteRepository() {
return {
...entitiesRoutes,
...entityDefinitionsRoutes,
...hasDataRoutes,
};
}
Expand Down

0 comments on commit 4e7bca8

Please sign in to comment.