From ca51e9c4a71c312d6d3b5defa0143ffeda07c26d Mon Sep 17 00:00:00 2001 From: Kevin Delemme Date: Tue, 24 Sep 2024 16:02:16 -0400 Subject: [PATCH] Add external incident link to header --- .../fields/external_incident_field.tsx | 45 +++++++++++++++++++ .../investigation_edit_form/form_helper.ts | 43 ++++++++++++++++++ .../external_incident_button.tsx | 35 +++++++++++++++ .../investigation_header.tsx | 9 +++- 4 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/observability_solution/investigate_app/public/components/investigation_edit_form/fields/external_incident_field.tsx create mode 100644 x-pack/plugins/observability_solution/investigate_app/public/components/investigation_edit_form/form_helper.ts create mode 100644 x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/investigation_header/external_incident_button.tsx diff --git a/x-pack/plugins/observability_solution/investigate_app/public/components/investigation_edit_form/fields/external_incident_field.tsx b/x-pack/plugins/observability_solution/investigate_app/public/components/investigation_edit_form/fields/external_incident_field.tsx new file mode 100644 index 0000000000000..faeebb34ccb9c --- /dev/null +++ b/x-pack/plugins/observability_solution/investigate_app/public/components/investigation_edit_form/fields/external_incident_field.tsx @@ -0,0 +1,45 @@ +/* + * 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 { EuiFormRow, EuiFieldText } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import React from 'react'; +import { Controller, useFormContext } from 'react-hook-form'; +import { InvestigationForm } from '../investigation_edit_form'; + +const I18N_LABEL = i18n.translate( + 'xpack.investigateApp.investigationEditForm.externalIncidentUrlLabel', + { defaultMessage: 'External incident URL' } +); + +export function ExternalIncidentField() { + const { control, getFieldState } = useFormContext(); + + return ( + + ( + + )} + /> + + ); +} diff --git a/x-pack/plugins/observability_solution/investigate_app/public/components/investigation_edit_form/form_helper.ts b/x-pack/plugins/observability_solution/investigate_app/public/components/investigation_edit_form/form_helper.ts new file mode 100644 index 0000000000000..102b6d81d67b6 --- /dev/null +++ b/x-pack/plugins/observability_solution/investigate_app/public/components/investigation_edit_form/form_helper.ts @@ -0,0 +1,43 @@ +/* + * 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 { CreateInvestigationParams, UpdateInvestigationParams } from '@kbn/investigation-shared'; +import { v4 as uuidv4 } from 'uuid'; +import type { InvestigationForm } from './investigation_edit_form'; + +export function toCreateInvestigationParams(data: InvestigationForm): CreateInvestigationParams { + return { + id: uuidv4(), + title: data.title, + params: { + timeRange: { + from: new Date(new Date().getTime() - 30 * 60 * 1000).getTime(), + to: new Date().getTime(), + }, + }, + tags: data.tags, + origin: { + type: 'blank', + }, + externalIncidentUrl: + data.externalIncidentUrl && data.externalIncidentUrl.trim().length > 0 + ? data.externalIncidentUrl + : null, + }; +} + +export function toUpdateInvestigationParams(data: InvestigationForm): UpdateInvestigationParams { + return { + title: data.title, + status: data.status, + tags: data.tags, + externalIncidentUrl: + data.externalIncidentUrl && data.externalIncidentUrl.trim().length > 0 + ? data.externalIncidentUrl + : null, + }; +} diff --git a/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/investigation_header/external_incident_button.tsx b/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/investigation_header/external_incident_button.tsx new file mode 100644 index 0000000000000..911f4e0661fe7 --- /dev/null +++ b/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/investigation_header/external_incident_button.tsx @@ -0,0 +1,35 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import React from 'react'; +import { useInvestigation } from '../../contexts/investigation_context'; + +export function ExternalIncidentButton() { + const { investigation } = useInvestigation(); + + if (!investigation?.externalIncidentUrl) { + return null; + } + + return ( + + + {i18n.translate('xpack.investigateApp.investigationHeader.externalIncidentTextLabel', { + defaultMessage: 'External incident', + })} + + + ); +} diff --git a/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/investigation_header/investigation_header.tsx b/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/investigation_header/investigation_header.tsx index 339f2ce1be8e7..d6bfb1c496793 100644 --- a/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/investigation_header/investigation_header.tsx +++ b/x-pack/plugins/observability_solution/investigate_app/public/pages/details/components/investigation_header/investigation_header.tsx @@ -6,14 +6,15 @@ */ import { EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n-react'; // eslint-disable-next-line import/no-extraneous-dependencies import { formatDistance } from 'date-fns'; -import { FormattedMessage } from '@kbn/i18n-react'; import React from 'react'; 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'; +import { ExternalIncidentButton } from './external_incident_button'; export function InvestigationHeader() { const { investigation } = useInvestigation(); @@ -62,6 +63,12 @@ export function InvestigationHeader() { /> + + {!!investigation.externalIncidentUrl && ( + + + + )} );