|
| 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, { memo, useMemo } from 'react'; |
| 9 | +import { EuiBadge, EuiTextColor } from '@elastic/eui'; |
| 10 | +import { FormattedMessage } from '@kbn/i18n/react'; |
| 11 | + |
| 12 | +export interface EndpointHostIsolationStatusProps { |
| 13 | + isIsolated: boolean; |
| 14 | + /** the count of pending isolate actions */ |
| 15 | + pendingIsolate?: number; |
| 16 | + /** the count of pending unisoalte actions */ |
| 17 | + pendingUnIsolate?: number; |
| 18 | +} |
| 19 | + |
| 20 | +/** |
| 21 | + * Component will display a host isoaltion status based on whether it is currently isolated or there are |
| 22 | + * isolate/unisolate actions pending. If none of these are applicable, no UI component will be rendered |
| 23 | + * (`null` is returned) |
| 24 | + */ |
| 25 | +export const EndpointHostIsolationStatus = memo<EndpointHostIsolationStatusProps>( |
| 26 | + ({ isIsolated, pendingIsolate = 0, pendingUnIsolate = 0 }) => { |
| 27 | + return useMemo(() => { |
| 28 | + // If nothing is pending and host is not currently isolated, then render nothing |
| 29 | + if (!isIsolated && !pendingIsolate && !pendingUnIsolate) { |
| 30 | + return null; |
| 31 | + } |
| 32 | + |
| 33 | + // If nothing is pending, but host is isolated, then show isolation badge |
| 34 | + if (!pendingIsolate && !pendingUnIsolate) { |
| 35 | + return ( |
| 36 | + <EuiBadge color="hollow"> |
| 37 | + <FormattedMessage |
| 38 | + id="xpack.securitySolution.endpoint.hostIsolationStatus.isolated" |
| 39 | + defaultMessage="Isolated" |
| 40 | + /> |
| 41 | + </EuiBadge> |
| 42 | + ); |
| 43 | + } |
| 44 | + |
| 45 | + // If there are multiple types of pending isolation actions, then show count of actions with tooltip that displays breakdown |
| 46 | + // TODO:PT implement edge case |
| 47 | + // if () { |
| 48 | + // |
| 49 | + // } |
| 50 | + |
| 51 | + // Show 'pending [un]isolate' depending on what's pending |
| 52 | + return ( |
| 53 | + <EuiBadge color="hollow"> |
| 54 | + <EuiTextColor color="subdued"> |
| 55 | + {pendingIsolate ? ( |
| 56 | + <FormattedMessage |
| 57 | + id="xpack.securitySolution.endpoint.hostIsolationStatus.isIsolating" |
| 58 | + defaultMessage="Isolating pending" |
| 59 | + /> |
| 60 | + ) : ( |
| 61 | + <FormattedMessage |
| 62 | + id="xpack.securitySolution.endpoint.hostIsolationStatus.isUnIsolating" |
| 63 | + defaultMessage="Unisolating pending" |
| 64 | + /> |
| 65 | + )} |
| 66 | + </EuiTextColor> |
| 67 | + </EuiBadge> |
| 68 | + ); |
| 69 | + }, [isIsolated, pendingIsolate, pendingUnIsolate]); |
| 70 | + } |
| 71 | +); |
| 72 | + |
| 73 | +EndpointHostIsolationStatus.displayName = 'EndpointHostIsolationStatus'; |
0 commit comments