From 8444d693ae7972891e6a92e3c6454e906c0ca228 Mon Sep 17 00:00:00 2001 From: Jenny Date: Tue, 18 Jul 2023 13:14:37 +0200 Subject: [PATCH] Add tooltip with documentation link in metadata summary --- .../tabs/overview/metadata_summary.tsx | 122 ++++++++++++------ 1 file changed, 82 insertions(+), 40 deletions(-) diff --git a/x-pack/plugins/infra/public/components/asset_details/tabs/overview/metadata_summary.tsx b/x-pack/plugins/infra/public/components/asset_details/tabs/overview/metadata_summary.tsx index 1ab7cd8fb5361..c8be7c111e603 100644 --- a/x-pack/plugins/infra/public/components/asset_details/tabs/overview/metadata_summary.tsx +++ b/x-pack/plugins/infra/public/components/asset_details/tabs/overview/metadata_summary.tsx @@ -12,12 +12,16 @@ import { EuiFlexItem, EuiDescriptionList, EuiDescriptionListDescription, + EuiIcon, + EuiLink, EuiLoadingSpinner, + EuiPopover, } from '@elastic/eui'; import { css } from '@emotion/react'; import { i18n } from '@kbn/i18n'; import React from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; +import { useBoolean } from '../../../../hooks/use_boolean'; import type { InfraMetadata } from '../../../../../common/http_api'; import { NOT_AVAILABLE_LABEL } from '../../translations'; import { useTabSwitcherContext } from '../../hooks/use_tab_switcher'; @@ -42,6 +46,8 @@ const metadataData = (metadataInfo: InfraMetadata['info']) => [ { field: 'hostIp', value: metadataInfo?.host?.ip, + tooltipLinkLabel: 'host.ip', + tooltipLink: 'https://www.elastic.co/guide/en/ecs/current/ecs-host.html#field-host-ip', }, { field: 'hostOsVersion', @@ -55,6 +61,7 @@ interface MetadataSummaryProps { } export const MetadataSummary = ({ metadata, metadataLoading }: MetadataSummaryProps) => { + const [isPopoverOpen, { off: closePopover, toggle: togglePopover }] = useBoolean(false); const { showTab } = useTabSwitcherContext(); const onClick = () => { @@ -62,46 +69,81 @@ export const MetadataSummary = ({ metadata, metadataLoading }: MetadataSummaryPr }; return ( - <> - - - {metadataData(metadata?.info).map((metadataValue) => ( - - - - {columnTitles[metadataValue.field as MetadataFields]} - - - {metadataLoading ? ( - - ) : ( - - )} - - - - ))} - - - - - - + + + {metadataData(metadata?.info).map((metadataValue) => ( + + + + + + {columnTitles[metadataValue.field as MetadataFields]} + + + {metadataValue.tooltipLink && ( + + } + isOpen={isPopoverOpen} + closePopover={closePopover} + repositionOnScroll + anchorPosition="upCenter" + > + + {metadataValue.tooltipLinkLabel} + + ), + }} + /> + + )} + + + + + {metadataLoading ? ( + + ) : ( + + )} + + + + ))} - + + + + + + ); };