Skip to content

Commit 6f5ced9

Browse files
[Response Ops][Cases] Fetch alerts within observability (#123883) (#125347)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> (cherry picked from commit 30ed7bb) Co-authored-by: Jonathan Buttner <56361221+jonathan-buttner@users.noreply.github.com>
1 parent 7a65488 commit 6f5ced9

16 files changed

Lines changed: 493 additions & 72 deletions

File tree

x-pack/plugins/cases/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Arguments:
7474
| userCanCrud | `boolean;` user permissions to crud |
7575
| owner | `string[];` owner ids of the cases |
7676
| basePath | `string;` path to mount the Cases router on top of |
77-
| useFetchAlertData | `(alertIds: string[]) => [boolean, Record<string, Ecs>];` fetch alerts |
77+
| useFetchAlertData | `(alertIds: string[]) => [boolean, Record<string, unknown>];` fetch alerts |
7878
| disableAlerts? | `boolean` (default: false) flag to not show alerts information |
7979
| actionsNavigation? | <code>CasesNavigation<string, 'configurable'></code> |
8080
| ruleDetailsNavigation? | <code>CasesNavigation<string &vert; null &vert; undefined, 'configurable'></code> |

x-pack/plugins/cases/common/ui/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,5 @@ export interface Ecs {
253253
}
254254

255255
export type CaseActionConnector = ActionConnector;
256+
257+
export type UseFetchAlertData = (alertIds: string[]) => [boolean, Record<string, unknown>];

x-pack/plugins/cases/public/components/app/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import { MutableRefObject } from 'react';
9-
import { Ecs, CaseViewRefreshPropInterface } from '../../../common/ui/types';
9+
import { CaseViewRefreshPropInterface, UseFetchAlertData } from '../../../common/ui/types';
1010
import { CasesNavigation } from '../links';
1111
import { CasesTimelineIntegration } from '../timeline_context';
1212

@@ -15,7 +15,7 @@ export interface CasesRoutesProps {
1515
actionsNavigation?: CasesNavigation<string, 'configurable'>;
1616
ruleDetailsNavigation?: CasesNavigation<string | null | undefined, 'configurable'>;
1717
showAlertDetails?: (alertId: string, index: string) => void;
18-
useFetchAlertData: (alertIds: string[]) => [boolean, Record<string, Ecs>];
18+
useFetchAlertData: UseFetchAlertData;
1919
/**
2020
* A React `Ref` that Exposes data refresh callbacks.
2121
* **NOTE**: Do not hold on to the `.current` object, as it could become stale

x-pack/plugins/cases/public/components/case_view/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
import { MutableRefObject } from 'react';
88
import { CasesTimelineIntegration } from '../timeline_context';
99
import { CasesNavigation } from '../links';
10-
import { CaseViewRefreshPropInterface, Ecs, Case } from '../../../common';
10+
import { CaseViewRefreshPropInterface, Case } from '../../../common';
1111
import { UseGetCase } from '../../containers/use_get_case';
12+
import { UseFetchAlertData } from '../../../common/ui';
1213

1314
export interface CaseViewBaseProps {
1415
onComponentInitialized?: () => void;
1516
actionsNavigation?: CasesNavigation<string, 'configurable'>;
1617
ruleDetailsNavigation?: CasesNavigation<string | null | undefined, 'configurable'>;
1718
showAlertDetails?: (alertId: string, index: string) => void;
18-
useFetchAlertData: (alertIds: string[]) => [boolean, Record<string, Ecs>];
19+
useFetchAlertData: UseFetchAlertData;
1920
/**
2021
* A React `Ref` that Exposes data refresh callbacks.
2122
* **NOTE**: Do not hold on to the `.current` object, as it could become stale

x-pack/plugins/cases/public/components/user_actions/comment/alert.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { UserActionUsernameWithAvatar } from '../avatar_username';
1818
import { AlertCommentEvent } from './alert_event';
1919
import { UserActionCopyLink } from '../copy_link';
2020
import { UserActionShowAlert } from './show_alert';
21-
import { Ecs } from '../../../containers/types';
2221

2322
type BuilderArgs = Pick<
2423
UserActionBuilderArgs,
@@ -49,7 +48,7 @@ export const createAlertAttachmentUserActionBuilder = ({
4948
return [];
5049
}
5150

52-
const alertField: Ecs | undefined = alertData[alertId];
51+
const alertField: unknown | undefined = alertData[alertId];
5352
const ruleId = getRuleId(comment, alertField);
5453
const ruleName = getRuleName(comment, alertField);
5554

@@ -101,15 +100,15 @@ const getFirstItem = (items?: string | string[] | null): string | null => {
101100
return Array.isArray(items) ? items[0] : items ?? null;
102101
};
103102

104-
export const getRuleId = (comment: BuilderArgs['comment'], alertData?: Ecs): string | null =>
103+
export const getRuleId = (comment: BuilderArgs['comment'], alertData?: unknown): string | null =>
105104
getRuleField({
106105
commentRuleField: comment?.rule?.id,
107106
alertData,
108107
signalRuleFieldPath: 'signal.rule.id',
109108
kibanaAlertFieldPath: ALERT_RULE_UUID,
110109
});
111110

112-
export const getRuleName = (comment: BuilderArgs['comment'], alertData?: Ecs): string | null =>
111+
export const getRuleName = (comment: BuilderArgs['comment'], alertData?: unknown): string | null =>
113112
getRuleField({
114113
commentRuleField: comment?.rule?.name,
115114
alertData,
@@ -124,7 +123,7 @@ const getRuleField = ({
124123
kibanaAlertFieldPath,
125124
}: {
126125
commentRuleField: string | string[] | null | undefined;
127-
alertData: Ecs | undefined;
126+
alertData: unknown | undefined;
128127
signalRuleFieldPath: string;
129128
kibanaAlertFieldPath: string;
130129
}): string | null => {

x-pack/plugins/cases/public/components/user_actions/index.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
} from '../../containers/mock';
2323
import { UserActions } from '.';
2424
import { TestProviders } from '../../common/mock';
25-
import { Ecs } from '../../../common/ui/types';
2625
import { Actions } from '../../../common/api';
2726

2827
const fetchUserActions = jest.fn();
@@ -46,7 +45,7 @@ const defaultProps = {
4645
statusActionButton: null,
4746
updateCase,
4847
userCanCrud: true,
49-
useFetchAlertData: (): [boolean, Record<string, Ecs>] => [
48+
useFetchAlertData: (): [boolean, Record<string, unknown>] => [
5049
false,
5150
{ 'some-id': { _id: 'some-id' } },
5251
],

x-pack/plugins/cases/public/components/user_actions/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,13 @@ export const UserActions = React.memo(
9898
const [initLoading, setInitLoading] = useState(true);
9999
const currentUser = useCurrentUser();
100100

101-
const [loadingAlertData, manualAlertsData] = useFetchAlertData(
102-
getManualAlertIdsWithNoRuleId(caseData.comments)
101+
const alertIdsWithoutRuleInfo = useMemo(
102+
() => getManualAlertIdsWithNoRuleId(caseData.comments),
103+
[caseData.comments]
103104
);
104105

106+
const [loadingAlertData, manualAlertsData] = useFetchAlertData(alertIdsWithoutRuleInfo);
107+
105108
const {
106109
loadingCommentIds,
107110
commentRefs,

x-pack/plugins/cases/public/components/user_actions/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { EuiCommentProps } from '@elastic/eui';
99
import { SnakeToCamelCase } from '../../../common/types';
1010
import { ActionTypes, UserActionWithResponse } from '../../../common/api';
11-
import { Case, CaseUserActions, Ecs, Comment } from '../../containers/types';
11+
import { Case, CaseUserActions, Comment, UseFetchAlertData } from '../../containers/types';
1212
import { CaseServices } from '../../containers/use_get_case_user_actions';
1313
import { AddCommentRefObject } from '../add_comment';
1414
import { UserActionMarkdownRefObject } from './markdown_form';
@@ -31,7 +31,7 @@ export interface UserActionTreeProps {
3131
renderInvestigateInTimelineActionComponent?: (alertIds: string[]) => JSX.Element;
3232
statusActionButton: JSX.Element | null;
3333
updateCase: (newCase: Case) => void;
34-
useFetchAlertData: (alertIds: string[]) => [boolean, Record<string, Ecs>];
34+
useFetchAlertData: UseFetchAlertData;
3535
userCanCrud: boolean;
3636
}
3737

@@ -52,7 +52,7 @@ export interface UserActionBuilderArgs {
5252
selectedOutlineCommentId: string;
5353
loadingCommentIds: string[];
5454
loadingAlertData: boolean;
55-
alertData: Record<string, Ecs>;
55+
alertData: Record<string, unknown>;
5656
handleOutlineComment: (id: string) => void;
5757
handleManageMarkdownEditId: (id: string) => void;
5858
handleSaveComment: ({ id, version }: { id: string; version: string }, content: string) => void;

x-pack/plugins/observability/public/pages/cases/cases.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
import React, { Suspense, useCallback, useState } from 'react';
99

1010
import { useKibana } from '../../utils/kibana_react';
11-
import { useFetchAlertData, useFetchAlertDetail } from './helpers';
1211
import { CASES_OWNER, CASES_PATH } from './constants';
1312
import { usePluginContext } from '../../hooks/use_plugin_context';
1413
import { LazyAlertsFlyout } from '../..';
14+
import { useFetchAlertDetail } from './use_fetch_alert_detail';
15+
import { useFetchAlertData } from './use_fetch_alert_data';
1516

1617
interface CasesProps {
1718
userCanCrud: boolean;

x-pack/plugins/observability/public/pages/cases/helpers.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)