Skip to content

Commit c604c8d

Browse files
[Security Solution][Endpoint] Adds Endpoint Host Isolation Status common component (#101782) (#101810)
* Common component for displaying Endpoint Host Isolation status Co-authored-by: Paul Tavares <56442535+paul-tavares@users.noreply.github.com>
1 parent e46640d commit c604c8d

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

x-pack/plugins/security_solution/common/endpoint/types/actions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface HostIsolationResponse {
4747
export interface PendingActionsResponse {
4848
agent_id: string;
4949
pending_actions: {
50+
/** Number of actions pending for each type. The `key` could be one of the `ISOLATION_ACTIONS` values. */
5051
[key: string]: number;
5152
};
5253
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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';

x-pack/plugins/security_solution/public/common/components/endpoint/host_isolation/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
export * from './isolate_success';
99
export * from './isolate_form';
1010
export * from './unisolate_form';
11+
export * from './endpoint_host_isolation_status';

0 commit comments

Comments
 (0)