Skip to content

Commit

Permalink
Add externalIncidentUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme committed Sep 24, 2024
1 parent cd32aff commit 68fb35e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/kbn-investigation-shared/src/rest_specs/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const createInvestigationParamsSchema = z.object({
}),
origin: z.union([alertOriginSchema, blankOriginSchema]),
tags: z.array(z.string()),
externalIncidentUrl: z.string().nullable(),
}),
});

Expand Down
1 change: 1 addition & 0 deletions packages/kbn-investigation-shared/src/rest_specs/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const updateInvestigationParamsSchema = z.object({
timeRange: z.object({ from: z.number(), to: z.number() }),
}),
tags: z.array(z.string()),
externalIncidentUrl: z.string().nullable(),
})
.partial(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const investigationSchema = z.object({
tags: z.array(z.string()),
notes: z.array(investigationNoteSchema),
items: z.array(investigationItemSchema),
externalIncidentUrl: z.string().nullable(),
});

type Status = z.infer<typeof statusSchema>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ import { InvestigationResponse } from '@kbn/investigation-shared';
import { pick } from 'lodash';
import React from 'react';
import { Controller, FormProvider, useForm } from 'react-hook-form';
import { v4 as uuidv4 } from 'uuid';
import { paths } from '../../../common/paths';
import { useCreateInvestigation } from '../../hooks/use_create_investigation';
import { useFetchInvestigation } from '../../hooks/use_fetch_investigation';
import { useKibana } from '../../hooks/use_kibana';
import { useUpdateInvestigation } from '../../hooks/use_update_investigation';
import { InvestigationNotFound } from '../investigation_not_found/investigation_not_found';
import { ExternalIncidentField } from './fields/external_incident_field';
import { StatusField } from './fields/status_field';
import { TagsField } from './fields/tags_field';
import { toCreateInvestigationParams, toUpdateInvestigationParams } from './form_helper';

export interface InvestigationForm {
title: string;
status: InvestigationResponse['status'];
tags: string[];
externalIncidentUrl: string | null;
}

interface Props {
Expand All @@ -64,8 +66,15 @@ export function InvestigationEditForm({ investigationId, onClose }: Props) {
const { mutateAsync: createInvestigation } = useCreateInvestigation();

const methods = useForm<InvestigationForm>({
defaultValues: { title: 'New investigation', status: 'triage', tags: [] },
values: investigation ? pick(investigation, ['title', 'status', 'tags']) : undefined,
defaultValues: {
title: 'New investigation',
status: 'triage',
tags: [],
externalIncidentUrl: null,
},
values: investigation
? pick(investigation, ['title', 'status', 'tags', 'externalIncidentUrl'])
: undefined,
mode: 'all',
});

Expand All @@ -81,24 +90,11 @@ export function InvestigationEditForm({ investigationId, onClose }: Props) {
if (isEditing) {
await updateInvestigation({
investigationId: investigationId!,
payload: { title: data.title, status: data.status, tags: data.tags },
payload: toUpdateInvestigationParams(data),
});
onClose();
} else {
const resp = await createInvestigation({
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',
},
});
const resp = await createInvestigation(toCreateInvestigationParams(data));
navigateToUrl(basePath.prepend(paths.investigationDetails(resp.id)));
}
};
Expand Down Expand Up @@ -157,6 +153,9 @@ export function InvestigationEditForm({ investigationId, onClose }: Props) {
<EuiFlexItem grow>
<TagsField />
</EuiFlexItem>
<EuiFlexItem grow>
<ExternalIncidentField />
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlyoutBody>
<EuiFlyoutFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ export function investigationRepositoryFactory({
logger: Logger;
}): InvestigationRepository {
function toInvestigation(stored: StoredInvestigation): Investigation | undefined {
const result = investigationSchema.safeParse({
...stored,
});
const result = investigationSchema.safeParse(stored);

if (!result.success) {
logger.error(`Invalid stored Investigation with id [${stored.id}]`);
Expand Down

0 comments on commit 68fb35e

Please sign in to comment.