-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Inventory][ECO] Show empty state when no entities are found. (#193755)
## Summary closes #193336 - Introduce route `GET /internal/inventory/has_data` that check if there are any entities for hosts, services and containers - Show empty state - Refactor a bit the button to add data to reuse it **Note**: - I used the illustration we had for the new service inventory as it had the dark version. - The callout will be shown by default. (I dismissed before starting the recording) ### without entities https://github.com/user-attachments/assets/6c5f7f38-a31c-4801-9e3d-3c91edd88f1d ### with entities https://github.com/user-attachments/assets/19de8215-1c11-4c36-bae4-00432f205855 --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
b023182
commit 476b9f5
Showing
9 changed files
with
336 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
...k/plugins/observability_solution/inventory/public/components/empty_states/empty_state.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* 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 { | ||
COLOR_MODES_STANDARD, | ||
EuiCallOut, | ||
EuiEmptyPrompt, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiHorizontalRule, | ||
EuiImage, | ||
EuiLink, | ||
EuiText, | ||
EuiTextColor, | ||
useEuiTheme, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React from 'react'; | ||
import { dashboardsLight, dashboardsDark } from '@kbn/shared-svg'; | ||
import useLocalStorage from 'react-use/lib/useLocalStorage'; | ||
import { AddData, AssociateServiceLogs } from '../shared/add_data_buttons/buttons'; | ||
import { useKibana } from '../../hooks/use_kibana'; | ||
import { InventoryAddDataParams } from '../../services/telemetry/types'; | ||
|
||
export function EmptyState() { | ||
const { services } = useKibana(); | ||
|
||
const [isDismissed, setDismissed] = useLocalStorage<boolean>( | ||
'inventory.emptyStateDismissed', | ||
false | ||
); | ||
|
||
function reportButtonClick(journey: InventoryAddDataParams['journey']) { | ||
services.telemetry.reportInventoryAddData({ | ||
view: 'empty_state', | ||
journey, | ||
}); | ||
} | ||
|
||
const { colorMode } = useEuiTheme(); | ||
|
||
return ( | ||
<EuiFlexGroup direction="column"> | ||
{!isDismissed && ( | ||
<EuiFlexItem> | ||
<EuiCallOut | ||
css={{ textAlign: 'left' }} | ||
onDismiss={() => setDismissed(true)} | ||
title={i18n.translate('xpack.inventory.noEntitiesEmptyState.callout.title', { | ||
defaultMessage: 'Trying for the first time?', | ||
})} | ||
> | ||
<p> | ||
{i18n.translate('xpack.inventory.noEntitiesEmptyState.description', { | ||
defaultMessage: | ||
'It can take a couple of minutes for your entities to show. Try refreshing in a minute or two.', | ||
})} | ||
</p> | ||
<EuiLink | ||
external | ||
target="_blank" | ||
data-test-subj="inventoryEmptyStateLink" | ||
href="https://ela.st/inventory-first-time" | ||
> | ||
{i18n.translate('xpack.inventory.noEntitiesEmptyState.learnMore.link', { | ||
defaultMessage: 'Learn more', | ||
})} | ||
</EuiLink> | ||
</EuiCallOut> | ||
</EuiFlexItem> | ||
)} | ||
<EuiFlexItem> | ||
<EuiEmptyPrompt | ||
hasShadow={false} | ||
hasBorder={false} | ||
id="inventoryEmptyState" | ||
icon={ | ||
<EuiImage | ||
size="fullWidth" | ||
src={colorMode === COLOR_MODES_STANDARD.dark ? dashboardsDark : dashboardsLight} | ||
alt="" | ||
/> | ||
} | ||
title={ | ||
<h2> | ||
{i18n.translate('xpack.inventory.noEntitiesEmptyState.title', { | ||
defaultMessage: 'No entities available', | ||
})} | ||
</h2> | ||
} | ||
layout={'horizontal'} | ||
color="plain" | ||
body={ | ||
<> | ||
<p> | ||
{i18n.translate('xpack.inventory.noEntitiesEmptyState.body.description', { | ||
defaultMessage: | ||
'See all of your observed entities in one place by collecting some data.', | ||
})} | ||
</p> | ||
<EuiHorizontalRule margin="m" /> | ||
<EuiText textAlign="left"> | ||
<h5> | ||
<EuiTextColor color="default"> | ||
{i18n.translate('xpack.inventory.noEntitiesEmptyState.actions.title', { | ||
defaultMessage: 'Start observing your entities:', | ||
})} | ||
</EuiTextColor> | ||
</h5> | ||
</EuiText> | ||
</> | ||
} | ||
actions={ | ||
<EuiFlexGroup responsive={false} wrap gutterSize="xl" direction="column"> | ||
<EuiFlexGroup direction="row" gutterSize="xs"> | ||
<AddData | ||
onClick={() => { | ||
reportButtonClick('add_data'); | ||
}} | ||
/> | ||
<AssociateServiceLogs | ||
onClick={() => { | ||
reportButtonClick('associate_existing_service_logs'); | ||
}} | ||
/> | ||
</EuiFlexGroup> | ||
</EuiFlexGroup> | ||
} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...ns/observability_solution/inventory/public/components/shared/add_data_buttons/buttons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
// Disabling it for now until the EUI team fixes it | ||
|
||
/* eslint-disable @elastic/eui/href-or-on-click */ | ||
import React from 'react'; | ||
import { | ||
OBSERVABILITY_ONBOARDING_LOCATOR, | ||
ObservabilityOnboardingLocatorParams, | ||
} from '@kbn/deeplinks-observability'; | ||
import { EuiButton } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { useKibana } from '../../../hooks/use_kibana'; | ||
|
||
export const addDataTitle = i18n.translate('xpack.inventory.addDataContextMenu.link', { | ||
defaultMessage: 'Add data', | ||
}); | ||
export const addDataItem = i18n.translate('xpack.inventory.add.apm.agent.button.', { | ||
defaultMessage: 'Add data', | ||
}); | ||
|
||
export const associateServiceLogsItem = i18n.translate( | ||
'xpack.inventory.associate.service.logs.button', | ||
{ | ||
defaultMessage: 'Associate existing service logs', | ||
} | ||
); | ||
|
||
export const ASSOCIATE_LOGS_LINK = 'https://ela.st/new-experience-associate-service-logs'; | ||
|
||
export function AssociateServiceLogs({ onClick }: { onClick?: () => void }) { | ||
return ( | ||
<EuiButton | ||
data-test-subj="associateServiceLogsButton" | ||
size="s" | ||
onClick={onClick} | ||
href={ASSOCIATE_LOGS_LINK} | ||
target="_blank" | ||
iconType="popout" | ||
iconSide="right" | ||
> | ||
{associateServiceLogsItem} | ||
</EuiButton> | ||
); | ||
} | ||
|
||
export function AddData({ onClick }: { onClick?: () => void }) { | ||
const { | ||
services: { share }, | ||
} = useKibana(); | ||
const onboardingLocator = share.url.locators.get<ObservabilityOnboardingLocatorParams>( | ||
OBSERVABILITY_ONBOARDING_LOCATOR | ||
); | ||
return ( | ||
<EuiButton | ||
iconType="plusInCircle" | ||
data-test-subj="addDataButton" | ||
size="s" | ||
onClick={onClick} | ||
color="primary" | ||
fill | ||
href={onboardingLocator?.getRedirectUrl({ category: '' })} | ||
> | ||
{addDataItem} | ||
</EuiButton> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
x-pack/plugins/observability_solution/inventory/server/routes/has_data/get_has_data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 { Logger } from '@kbn/core/server'; | ||
import { esqlResultToPlainObjects } from '@kbn/observability-utils/es/utils/esql_result_to_plain_objects'; | ||
import { type ObservabilityElasticsearchClient } from '@kbn/observability-utils/es/client/create_observability_es_client'; | ||
import { | ||
getEntityDefinitionIdWhereClause, | ||
getEntityTypesWhereClause, | ||
} from '../entities/query_helper'; | ||
import { ENTITIES_LATEST_ALIAS } from '../../../common/entities'; | ||
|
||
export async function getHasData({ | ||
inventoryEsClient, | ||
logger, | ||
}: { | ||
inventoryEsClient: ObservabilityElasticsearchClient; | ||
logger: Logger; | ||
}) { | ||
try { | ||
const esqlResults = await inventoryEsClient.esql('get_has_data', { | ||
query: `FROM ${ENTITIES_LATEST_ALIAS} | ||
| ${getEntityDefinitionIdWhereClause()} | ||
| ${getEntityTypesWhereClause()} | ||
| STATS _count = COUNT(*) | ||
| LIMIT 1`, | ||
}); | ||
|
||
const totalCount = esqlResultToPlainObjects(esqlResults)?.[0]._count ?? 0; | ||
|
||
return { hasData: totalCount > 0 }; | ||
} catch (e) { | ||
logger.error(e); | ||
return { hasData: false }; | ||
} | ||
} |
Oops, something went wrong.