|
| 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 | +import React, { memo, useMemo } from 'react'; |
| 7 | +import { |
| 8 | + EuiFlexGroup, |
| 9 | + EuiFlexItem, |
| 10 | + EuiLink, |
| 11 | + EuiAccordion, |
| 12 | + EuiTitle, |
| 13 | + EuiPanel, |
| 14 | + EuiButtonIcon, |
| 15 | + EuiBasicTable, |
| 16 | +} from '@elastic/eui'; |
| 17 | +import { i18n } from '@kbn/i18n'; |
| 18 | +import styled from 'styled-components'; |
| 19 | +import { Agent, AgentPolicy, PackagePolicy, PackagePolicyInput } from '../../../../../types'; |
| 20 | +import { useLink } from '../../../../../hooks'; |
| 21 | +import { PackageIcon } from '../../../../../components'; |
| 22 | +import { displayInputType, getLogsQueryByInputType } from './input_type_utils'; |
| 23 | + |
| 24 | +const StyledCollapsablePanel = styled(EuiPanel).attrs((props) => ({ |
| 25 | + paddingSize: 'none', |
| 26 | +}))` |
| 27 | + .euiAccordion__triggerWrapper { |
| 28 | + border-bottom: 1px solid ${(props) => props.theme.eui.euiColorLightShade}; |
| 29 | + padding: ${(props) => props.theme.eui.paddingSizes.m} |
| 30 | + ${(props) => props.theme.eui.paddingSizes.m}; |
| 31 | + } |
| 32 | + .euiAccordion__childWrapper { |
| 33 | + overflow: visible; |
| 34 | + } |
| 35 | +`; |
| 36 | + |
| 37 | +const CollapsablePanel: React.FC<{ title: React.ReactNode }> = ({ title, children }) => { |
| 38 | + return ( |
| 39 | + <StyledCollapsablePanel paddingSize="none"> |
| 40 | + <EuiAccordion id="accordion-1" arrowDisplay="right" buttonContent={title}> |
| 41 | + {children} |
| 42 | + </EuiAccordion> |
| 43 | + </StyledCollapsablePanel> |
| 44 | + ); |
| 45 | +}; |
| 46 | + |
| 47 | +export const AgentDetailsIntegration: React.FunctionComponent<{ |
| 48 | + agent: Agent; |
| 49 | + agentPolicy: AgentPolicy; |
| 50 | + packagePolicy: PackagePolicy; |
| 51 | +}> = memo(({ agent, agentPolicy, packagePolicy }) => { |
| 52 | + const { getHref } = useLink(); |
| 53 | + |
| 54 | + const inputs = useMemo(() => { |
| 55 | + return packagePolicy.inputs.filter((input) => input.enabled); |
| 56 | + }, [packagePolicy.inputs]); |
| 57 | + |
| 58 | + const columns = [ |
| 59 | + { |
| 60 | + field: 'type', |
| 61 | + width: '100%', |
| 62 | + name: i18n.translate('xpack.fleet.agentDetailsIntegrations.inputTypeLabel', { |
| 63 | + defaultMessage: 'Input', |
| 64 | + }), |
| 65 | + render: (inputType: string) => { |
| 66 | + return displayInputType(inputType); |
| 67 | + }, |
| 68 | + }, |
| 69 | + { |
| 70 | + name: i18n.translate('xpack.fleet.agentDetailsIntegrations.actionsLabel', { |
| 71 | + defaultMessage: 'Actions', |
| 72 | + }), |
| 73 | + field: 'type', |
| 74 | + width: 'auto', |
| 75 | + render: (inputType: string) => { |
| 76 | + return ( |
| 77 | + <EuiButtonIcon |
| 78 | + href={`${getHref('fleet_agent_details', { |
| 79 | + agentId: agent.id, |
| 80 | + tabId: 'logs', |
| 81 | + })}?${getLogsQueryByInputType(inputType)}`} |
| 82 | + iconType="editorAlignLeft" |
| 83 | + title={i18n.translate('xpack.fleet.agentDetailsIntegrations.viewLogsButton', { |
| 84 | + defaultMessage: 'View logs', |
| 85 | + })} |
| 86 | + /> |
| 87 | + ); |
| 88 | + }, |
| 89 | + }, |
| 90 | + ]; |
| 91 | + |
| 92 | + return ( |
| 93 | + <CollapsablePanel |
| 94 | + title={ |
| 95 | + <EuiTitle size="xs"> |
| 96 | + <h3> |
| 97 | + <EuiFlexGroup gutterSize="s"> |
| 98 | + <EuiFlexItem grow={false}> |
| 99 | + {packagePolicy.package ? ( |
| 100 | + <PackageIcon |
| 101 | + packageName={packagePolicy.package.name} |
| 102 | + version={packagePolicy.package.version} |
| 103 | + size="l" |
| 104 | + tryApi={true} |
| 105 | + /> |
| 106 | + ) : ( |
| 107 | + <PackageIcon size="l" packageName="default" version="0" /> |
| 108 | + )} |
| 109 | + </EuiFlexItem> |
| 110 | + <EuiFlexItem grow={false}> |
| 111 | + <EuiLink |
| 112 | + href={getHref('edit_integration', { |
| 113 | + policyId: agentPolicy.id, |
| 114 | + packagePolicyId: packagePolicy.id, |
| 115 | + })} |
| 116 | + > |
| 117 | + {packagePolicy.name} |
| 118 | + </EuiLink> |
| 119 | + </EuiFlexItem> |
| 120 | + </EuiFlexGroup> |
| 121 | + </h3> |
| 122 | + </EuiTitle> |
| 123 | + } |
| 124 | + > |
| 125 | + <EuiBasicTable<PackagePolicyInput> tableLayout="auto" items={inputs} columns={columns} /> |
| 126 | + </CollapsablePanel> |
| 127 | + ); |
| 128 | +}); |
| 129 | + |
| 130 | +export const AgentDetailsIntegrationsSection: React.FunctionComponent<{ |
| 131 | + agent: Agent; |
| 132 | + agentPolicy?: AgentPolicy; |
| 133 | +}> = memo(({ agent, agentPolicy }) => { |
| 134 | + if (!agentPolicy || !agentPolicy.package_policies) { |
| 135 | + return null; |
| 136 | + } |
| 137 | + |
| 138 | + return ( |
| 139 | + <EuiFlexGroup direction="column"> |
| 140 | + {(agentPolicy.package_policies as PackagePolicy[]).map((packagePolicy) => { |
| 141 | + return ( |
| 142 | + <EuiFlexItem grow={false} key={packagePolicy.id}> |
| 143 | + <AgentDetailsIntegration |
| 144 | + agent={agent} |
| 145 | + agentPolicy={agentPolicy} |
| 146 | + packagePolicy={packagePolicy} |
| 147 | + /> |
| 148 | + </EuiFlexItem> |
| 149 | + ); |
| 150 | + })} |
| 151 | + </EuiFlexGroup> |
| 152 | + ); |
| 153 | +}); |
0 commit comments