Skip to content

Commit

Permalink
Revert "[ECO][Inventory v2] Ad hoc data view: Add get entities defini…
Browse files Browse the repository at this point in the history
…tion endpoint using sources (#203424) (#204012)

This reverts commit 5bacf1f.

Reverting because it's blocked by
#202296
  • Loading branch information
jennypavlova authored Dec 12, 2024
1 parent 8d5cd4f commit fe67c95
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 fe67c95

Please sign in to comment.