|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License; |
| 4 | + * you may not use this file except in compliance with the Elastic License. |
| 5 | + */ |
| 6 | + |
| 7 | +import { EuiTabbedContent } from '@elastic/eui'; |
| 8 | +import { FormattedMessage } from '@kbn/i18n/react'; |
| 9 | +import { EuiPanel } from '@elastic/eui'; |
| 10 | +import React, { CSSProperties, useMemo } from 'react'; |
| 11 | +import { EuiText } from '@elastic/eui'; |
| 12 | +import { EuiFlexGroup, EuiFlexItem, EuiButtonEmpty } from '@elastic/eui'; |
| 13 | +import { euiStyled } from '../../../../../../../observability/public'; |
| 14 | +import { InfraWaffleMapNode, InfraWaffleMapOptions } from '../../../../../lib/lib'; |
| 15 | +import { InventoryItemType } from '../../../../../../common/inventory_models/types'; |
| 16 | +import { MetricsTab } from './tabs/metrics'; |
| 17 | +import { LogsTab } from './tabs/logs'; |
| 18 | +import { ProcessesTab } from './tabs/processes'; |
| 19 | +import { PropertiesTab } from './tabs/properties'; |
| 20 | + |
| 21 | +interface Props { |
| 22 | + isOpen: boolean; |
| 23 | + onClose(): void; |
| 24 | + options: InfraWaffleMapOptions; |
| 25 | + currentTime: number; |
| 26 | + node: InfraWaffleMapNode; |
| 27 | + nodeType: InventoryItemType; |
| 28 | +} |
| 29 | +export const NodeContextPopover = ({ |
| 30 | + isOpen, |
| 31 | + node, |
| 32 | + nodeType, |
| 33 | + currentTime, |
| 34 | + options, |
| 35 | + onClose, |
| 36 | +}: Props) => { |
| 37 | + const tabConfigs = [MetricsTab, LogsTab, ProcessesTab, PropertiesTab]; |
| 38 | + |
| 39 | + const tabs = useMemo(() => { |
| 40 | + return tabConfigs.map((m) => { |
| 41 | + const TabContent = m.content; |
| 42 | + return { |
| 43 | + ...m, |
| 44 | + content: ( |
| 45 | + <TabContent node={node} nodeType={nodeType} currentTime={currentTime} options={options} /> |
| 46 | + ), |
| 47 | + }; |
| 48 | + }); |
| 49 | + }, [tabConfigs, node, nodeType, currentTime, options]); |
| 50 | + |
| 51 | + if (!isOpen) { |
| 52 | + return null; |
| 53 | + } |
| 54 | + |
| 55 | + return ( |
| 56 | + <EuiPanel hasShadow={true} paddingSize={'none'} style={panelStyle}> |
| 57 | + <OverlayHeader> |
| 58 | + <EuiFlexGroup alignItems={'center'}> |
| 59 | + <EuiFlexItem grow={true}> |
| 60 | + <EuiText> |
| 61 | + <h4>{node.name}</h4> |
| 62 | + </EuiText> |
| 63 | + </EuiFlexItem> |
| 64 | + <EuiFlexItem grow={false}> |
| 65 | + <EuiButtonEmpty onClick={onClose} iconType={'cross'}> |
| 66 | + <FormattedMessage id="xpack.infra.infra.nodeDetails.close" defaultMessage="Close" /> |
| 67 | + </EuiButtonEmpty> |
| 68 | + </EuiFlexItem> |
| 69 | + </EuiFlexGroup> |
| 70 | + </OverlayHeader> |
| 71 | + <EuiTabbedContent tabs={tabs} /> |
| 72 | + </EuiPanel> |
| 73 | + ); |
| 74 | +}; |
| 75 | + |
| 76 | +const OverlayHeader = euiStyled.div` |
| 77 | + border-color: ${(props) => props.theme.eui.euiBorderColor}; |
| 78 | + border-bottom-width: ${(props) => props.theme.eui.euiBorderWidthThick}; |
| 79 | + padding: ${(props) => props.theme.eui.euiSizeS}; |
| 80 | + padding-bottom: 0; |
| 81 | + overflow: hidden; |
| 82 | +`; |
| 83 | + |
| 84 | +const panelStyle: CSSProperties = { |
| 85 | + position: 'absolute', |
| 86 | + right: 10, |
| 87 | + top: -100, |
| 88 | + width: '50%', |
| 89 | + maxWidth: 600, |
| 90 | + zIndex: 2, |
| 91 | + height: '50vh', |
| 92 | + overflow: 'hidden', |
| 93 | +}; |
0 commit comments