|
| 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 | + * 2.0; you may not use this file except in compliance with the Elastic License |
| 5 | + * 2.0. |
| 6 | + */ |
| 7 | + |
| 8 | +import React, { useMemo } from 'react'; |
| 9 | +import { css } from '@emotion/react'; |
| 10 | +import type { EuiBasicTableColumn } from '@elastic/eui'; |
| 11 | +import { |
| 12 | + EuiBasicTable, |
| 13 | + EuiBadge, |
| 14 | + EuiFlexGroup, |
| 15 | + EuiFlexItem, |
| 16 | + EuiLoadingSpinner, |
| 17 | + EuiText, |
| 18 | + EuiToolTip, |
| 19 | + useEuiTheme, |
| 20 | +} from '@elastic/eui'; |
| 21 | +import { i18n } from '@kbn/i18n'; |
| 22 | +import { FormattedDate, FormattedRelative } from '@kbn/i18n-react'; |
| 23 | + |
| 24 | +import { pipelineConfigLabel } from '../../../../../../common/services/pipeline_config_label'; |
| 25 | +import type { CollectorGroup } from '../../../../../../common/types'; |
| 26 | +import { useGetCollectorGroupsQuery } from '../../../../../hooks/use_request/agents'; |
| 27 | + |
| 28 | +import { getSignalBadgeColor } from './signal_colors'; |
| 29 | + |
| 30 | +const ConfigHashTable: React.FC<{ group: CollectorGroup }> = ({ group }) => { |
| 31 | + const { euiTheme } = useEuiTheme(); |
| 32 | + |
| 33 | + const kuery = useMemo(() => { |
| 34 | + if (group.isUngrouped) { |
| 35 | + return 'NOT non_identifying_attributes.config.name:*'; |
| 36 | + } |
| 37 | + const escapedConfigName = group.group.replace(/\\/g, '\\\\').replace(/"/g, '\\"'); |
| 38 | + return `non_identifying_attributes.config.name:"${escapedConfigName}"`; |
| 39 | + }, [group.group, group.isUngrouped]); |
| 40 | + |
| 41 | + const { data, isLoading } = useGetCollectorGroupsQuery( |
| 42 | + { groupBy: 'pipeline_config', kuery, perPage: 100, showInactive: false }, |
| 43 | + { enabled: true } |
| 44 | + ); |
| 45 | + |
| 46 | + const items = data?.items ?? []; |
| 47 | + |
| 48 | + const columns: Array<EuiBasicTableColumn<CollectorGroup>> = useMemo( |
| 49 | + () => [ |
| 50 | + { |
| 51 | + field: 'group', |
| 52 | + name: i18n.translate('xpack.fleet.expandedConfigGroup.versionsColumn', { |
| 53 | + defaultMessage: 'Versions', |
| 54 | + }), |
| 55 | + width: '200px', |
| 56 | + render: (fingerprint: string) => ( |
| 57 | + <EuiToolTip content={fingerprint}> |
| 58 | + <EuiBadge color="hollow">{pipelineConfigLabel(fingerprint)}</EuiBadge> |
| 59 | + </EuiToolTip> |
| 60 | + ), |
| 61 | + }, |
| 62 | + { |
| 63 | + field: 'docCount', |
| 64 | + name: i18n.translate('xpack.fleet.expandedConfigGroup.collectorsColumn', { |
| 65 | + defaultMessage: 'Collectors', |
| 66 | + }), |
| 67 | + width: '100px', |
| 68 | + }, |
| 69 | + { |
| 70 | + field: 'signals', |
| 71 | + name: i18n.translate('xpack.fleet.expandedConfigGroup.signalsColumn', { |
| 72 | + defaultMessage: 'Signals', |
| 73 | + }), |
| 74 | + width: '190px', |
| 75 | + render: (signals: string[]) => { |
| 76 | + if (!signals?.length) return '-'; |
| 77 | + return ( |
| 78 | + <EuiFlexGroup gutterSize="xs" wrap responsive={false}> |
| 79 | + {signals.map((signal) => { |
| 80 | + const [bgColor, textColor] = getSignalBadgeColor(euiTheme.colors.vis, signal); |
| 81 | + return ( |
| 82 | + <EuiFlexItem grow={false} key={signal}> |
| 83 | + <EuiBadge |
| 84 | + color={bgColor} |
| 85 | + css={css` |
| 86 | + color: ${textColor}; |
| 87 | + `} |
| 88 | + > |
| 89 | + {signal} |
| 90 | + </EuiBadge> |
| 91 | + </EuiFlexItem> |
| 92 | + ); |
| 93 | + })} |
| 94 | + </EuiFlexGroup> |
| 95 | + ); |
| 96 | + }, |
| 97 | + }, |
| 98 | + { |
| 99 | + name: i18n.translate('xpack.fleet.expandedConfigGroup.alertsColumn', { |
| 100 | + defaultMessage: 'Alerts', |
| 101 | + }), |
| 102 | + width: '80px', |
| 103 | + render: () => '-', |
| 104 | + }, |
| 105 | + { |
| 106 | + field: 'firstSeen', |
| 107 | + name: i18n.translate('xpack.fleet.expandedConfigGroup.firstSeenColumn', { |
| 108 | + defaultMessage: 'First seen', |
| 109 | + }), |
| 110 | + width: '120px', |
| 111 | + render: (firstSeen: string | undefined) => { |
| 112 | + if (!firstSeen) return '-'; |
| 113 | + return ( |
| 114 | + <EuiToolTip |
| 115 | + content={ |
| 116 | + <FormattedDate |
| 117 | + value={firstSeen} |
| 118 | + year="numeric" |
| 119 | + month="short" |
| 120 | + day="2-digit" |
| 121 | + hour="2-digit" |
| 122 | + minute="2-digit" |
| 123 | + /> |
| 124 | + } |
| 125 | + > |
| 126 | + <EuiText size="xs"> |
| 127 | + <FormattedRelative value={firstSeen} /> |
| 128 | + </EuiText> |
| 129 | + </EuiToolTip> |
| 130 | + ); |
| 131 | + }, |
| 132 | + }, |
| 133 | + { |
| 134 | + field: 'lastSeen', |
| 135 | + name: i18n.translate('xpack.fleet.expandedConfigGroup.lastSeenColumn', { |
| 136 | + defaultMessage: 'Last seen', |
| 137 | + }), |
| 138 | + width: '120px', |
| 139 | + render: (lastSeen: string | undefined) => { |
| 140 | + if (!lastSeen) return '-'; |
| 141 | + return ( |
| 142 | + <EuiToolTip |
| 143 | + content={ |
| 144 | + <FormattedDate |
| 145 | + value={lastSeen} |
| 146 | + year="numeric" |
| 147 | + month="short" |
| 148 | + day="2-digit" |
| 149 | + hour="2-digit" |
| 150 | + minute="2-digit" |
| 151 | + /> |
| 152 | + } |
| 153 | + > |
| 154 | + <EuiText size="xs"> |
| 155 | + <FormattedRelative value={lastSeen} /> |
| 156 | + </EuiText> |
| 157 | + </EuiToolTip> |
| 158 | + ); |
| 159 | + }, |
| 160 | + }, |
| 161 | + { |
| 162 | + name: i18n.translate('xpack.fleet.expandedConfigGroup.actionsColumn', { |
| 163 | + defaultMessage: 'Actions', |
| 164 | + }), |
| 165 | + width: '70px', |
| 166 | + actions: [], |
| 167 | + }, |
| 168 | + ], |
| 169 | + [euiTheme.colors.vis] |
| 170 | + ); |
| 171 | + |
| 172 | + if (isLoading) { |
| 173 | + return ( |
| 174 | + <EuiFlexGroup justifyContent="center"> |
| 175 | + <EuiFlexItem grow={false}> |
| 176 | + <EuiLoadingSpinner size="l" /> |
| 177 | + </EuiFlexItem> |
| 178 | + </EuiFlexGroup> |
| 179 | + ); |
| 180 | + } |
| 181 | + |
| 182 | + return ( |
| 183 | + <EuiBasicTable<CollectorGroup> |
| 184 | + data-test-subj="fleetConfigHashTable" |
| 185 | + tableCaption={i18n.translate('xpack.fleet.expandedConfigGroup.tableCaption', { |
| 186 | + defaultMessage: 'Pipeline configuration versions', |
| 187 | + })} |
| 188 | + items={items} |
| 189 | + itemId="group" |
| 190 | + columns={columns} |
| 191 | + /> |
| 192 | + ); |
| 193 | +}; |
| 194 | + |
| 195 | +export const ExpandedConfigGroup: React.FC<{ group: CollectorGroup }> = ({ group }) => { |
| 196 | + return <ConfigHashTable group={group} />; |
| 197 | +}; |
0 commit comments