Skip to content

Commit

Permalink
[8.x] feat(rca): add header details (#193600) (#193620)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [feat(rca): add header details
(#193600)](#193600)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kevin
Delemme","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-20T16:34:23Z","message":"feat(rca):
add header details
(#193600)","sha":"0b1bf2727b565c5dc1b824c9b076e6bc0514f2a9","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-management","v8.16.0"],"title":"feat(rca):
add header
details","number":193600,"url":"https://github.com/elastic/kibana/pull/193600","mergeCommit":{"message":"feat(rca):
add header details
(#193600)","sha":"0b1bf2727b565c5dc1b824c9b076e6bc0514f2a9"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193600","number":193600,"mergeCommit":{"message":"feat(rca):
add header details
(#193600)","sha":"0b1bf2727b565c5dc1b824c9b076e6bc0514f2a9"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Kevin Delemme <[email protected]>
  • Loading branch information
kibanamachine and kdelemme authored Sep 20, 2024
1 parent 9c641cb commit 6b4524f
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { EuiFlexItem, EuiBadge } from '@elastic/eui';
import React from 'react';

interface Props {
tag: string;
}

export function InvestigationTag({ tag }: Props) {
return (
<EuiFlexItem grow={false}>
<EuiBadge color="hollow">{tag}</EuiBadge>
</EuiFlexItem>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { EuiButtonEmpty, EuiText } from '@elastic/eui';
import { alertOriginSchema } from '@kbn/investigation-shared';
import { ALERT_RULE_CATEGORY } from '@kbn/rule-registry-plugin/common/technical_rule_data_field_names';
import React from 'react';
import { useKibana } from '../../../../hooks/use_kibana';
import { useInvestigation } from '../../contexts/investigation_context';
import { useFetchAlert } from '../../hooks/use_fetch_alert';

export function AlertDetailsButton() {
const {
core: {
http: { basePath },
},
} = useKibana();
const { investigation } = useInvestigation();

const alertOriginInvestigation = alertOriginSchema.safeParse(investigation?.origin);
const alertId = alertOriginInvestigation.success ? alertOriginInvestigation.data.id : undefined;
const { data: alertDetails } = useFetchAlert({ id: alertId });

if (!alertDetails) {
return null;
}
return (
<EuiButtonEmpty
data-test-subj="investigationDetailsAlertLink"
iconType="arrowLeft"
size="xs"
href={basePath.prepend(`/app/observability/alerts/${alertId}`)}
>
<EuiText size="s">{`[Alert] ${alertDetails?.[ALERT_RULE_CATEGORY]} breached`}</EuiText>
</EuiButtonEmpty>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,64 @@
* 2.0.
*/

import { EuiButtonEmpty, EuiText } from '@elastic/eui';
import { alertOriginSchema } from '@kbn/investigation-shared';
import { ALERT_RULE_CATEGORY } from '@kbn/rule-registry-plugin/common/technical_rule_data_field_names';
import { EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';
// eslint-disable-next-line import/no-extraneous-dependencies
import { formatDistance } from 'date-fns';
import { FormattedMessage } from '@kbn/i18n-react';
import React from 'react';
import { useFetchAlert } from '../../../../hooks/use_get_alert_details';
import { useKibana } from '../../../../hooks/use_kibana';
import { InvestigationStatusBadge } from '../../../../components/investigation_status_badge/investigation_status_badge';
import { InvestigationTag } from '../../../../components/investigation_tag/investigation_tag';
import { useInvestigation } from '../../contexts/investigation_context';
import { AlertDetailsButton } from './alert_details_button';

export function InvestigationHeader() {
const {
core: {
http: { basePath },
},
} = useKibana();

const { investigation } = useInvestigation();

const alertOriginInvestigation = alertOriginSchema.safeParse(investigation?.origin);
const alertId = alertOriginInvestigation.success ? alertOriginInvestigation.data.id : undefined;
const { data: alertDetails } = useFetchAlert({ id: alertId });
if (!investigation) {
return null;
}

return (
<>
{alertDetails && (
<EuiButtonEmpty
data-test-subj="investigationDetailsAlertLink"
iconType="arrowLeft"
size="xs"
href={basePath.prepend(`/app/observability/alerts/${alertId}`)}
>
<EuiText size="s">{`[Alert] ${alertDetails?.[ALERT_RULE_CATEGORY]} breached`}</EuiText>
</EuiButtonEmpty>
)}
{investigation && <div>{investigation.title}</div>}
</>
<EuiFlexGroup direction="column" gutterSize="m" alignItems="flexStart">
<EuiFlexItem>
<AlertDetailsButton />
</EuiFlexItem>

<EuiFlexItem>{investigation.title}</EuiFlexItem>

<EuiFlexGroup direction="row" gutterSize="m" alignItems="center" wrap responsive={false}>
<EuiFlexItem grow={false}>
<InvestigationStatusBadge status={investigation.status} />
</EuiFlexItem>

{investigation.tags.length > 0 && (
<EuiFlexItem grow={false}>
<EuiFlexGroup responsive={false} wrap gutterSize="s">
{investigation.tags.map((tag) => (
<InvestigationTag key={tag} tag={tag} />
))}
</EuiFlexGroup>
</EuiFlexItem>
)}

<EuiFlexItem grow={false}>
<EuiText size="s">
<FormattedMessage
id="xpack.investigateApp.investigationHeader.startedLabel"
defaultMessage="Started: {timeAgo}"
values={{
timeAgo: (
<strong>
{formatDistance(new Date(investigation.createdAt), new Date(), {
addSuffix: true,
})}
</strong>
),
}}
/>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexGroup>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { useQuery } from '@tanstack/react-query';
import { BASE_RAC_ALERTS_API_PATH, EcsFieldsResponse } from '@kbn/rule-registry-plugin/common';
import { useKibana } from './use_kibana';
import { useKibana } from '../../../hooks/use_kibana';

export interface AlertParams {
id?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import {
Criteria,
EuiAvatar,
EuiBadge,
EuiBasicTable,
EuiBasicTableColumn,
EuiFlexGroup,
EuiFlexItem,
EuiLink,
EuiLoadingSpinner,
EuiText,
Expand All @@ -22,6 +20,7 @@ import moment from 'moment';
import React, { useState } from 'react';
import { paths } from '../../../../common/paths';
import { InvestigationStatusBadge } from '../../../components/investigation_status_badge/investigation_status_badge';
import { InvestigationTag } from '../../../components/investigation_tag/investigation_tag';
import { useFetchInvestigationList } from '../../../hooks/use_fetch_investigation_list';
import { useFetchUserProfiles } from '../../../hooks/use_fetch_user_profiles';
import { useKibana } from '../../../hooks/use_kibana';
Expand Down Expand Up @@ -114,9 +113,7 @@ export function InvestigationList() {
return (
<EuiFlexGroup wrap gutterSize="xs">
{value.map((tag) => (
<EuiFlexItem key={tag} grow={false}>
<EuiBadge color="hollow">{tag}</EuiBadge>
</EuiFlexItem>
<InvestigationTag key={tag} tag={tag} />
))}
</EuiFlexGroup>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export async function deleteInvestigationItem(
const investigation = await repository.findById(investigationId);
const item = investigation.items.find((currItem) => currItem.id === itemId);
if (!item) {
throw new Error('Note not found');
throw new Error('Item not found');
}

if (item.createdBy !== user.profile_uid) {
throw new Error('User does not have permission to delete note');
throw new Error('User does not have permission to delete item');
}

investigation.items = investigation.items.filter((currItem) => currItem.id !== itemId);
Expand Down

0 comments on commit 6b4524f

Please sign in to comment.