Skip to content

Commit

Permalink
[Security Solution, Timelines] Replace more legacy elasticsearch types (
Browse files Browse the repository at this point in the history
#108087)

* Replace more legacy elasticsearch types

* Handle possibly undefined response fields

These are both number | undefined, so we default to 0 if we need a
value. Fixes the type errors resulting from the previous type changes.
  • Loading branch information
rylnd committed Aug 11, 2021
1 parent def97bd commit 9476571
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import { useEffect, useState } from 'react';
import { SearchResponse } from 'elasticsearch';
import type { estypes } from '@elastic/elasticsearch';
import { isEmpty } from 'lodash';

import {
Expand Down Expand Up @@ -37,18 +37,18 @@ export const useFetchEcsAlertsData = ({
try {
setIsLoading(true);
const alertResponse = await KibanaServices.get().http.fetch<
SearchResponse<{ '@timestamp': string; [key: string]: unknown }>
estypes.SearchResponse<{ '@timestamp': string; [key: string]: unknown }>
>(DETECTION_ENGINE_QUERY_SIGNALS_URL, {
method: 'POST',
body: JSON.stringify(buildAlertsQuery(alertIds ?? [])),
});

setAlertEcsData(
alertResponse?.hits.hits.reduce<Ecs[]>(
(acc, { _id, _index, _source }) => [
(acc, { _id, _index, _source = {} }) => [
...acc,
{
...formatAlertToEcsSignal(_source as {}),
...formatAlertToEcsSignal(_source),
_id,
_index,
timestamp: _source['@timestamp'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import { UpdateDocumentByQueryResponse } from 'elasticsearch';
import type { estypes } from '@elastic/elasticsearch';

import { useKibana } from '../../../../../src/plugins/kibana_react/public';
import { AlertStatus } from '../../../timelines/common';

Expand All @@ -24,7 +25,7 @@ export const useUpdateAlertsStatus = (): {
updateAlertStatus: (params: {
query: object;
status: AlertStatus;
}) => Promise<UpdateDocumentByQueryResponse>;
}) => Promise<estypes.UpdateByQueryResponse>;
} => {
const { http } = useKibana().services;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export const useStatusBulkActionItems = ({
// TODO: Only delete those that were successfully updated from updatedRules
setEventsDeleted({ eventIds, isDeleted: true });

if (response.version_conflicts > 0 && eventIds.length === 1) {
if (response.version_conflicts && eventIds.length === 1) {
throw new Error(i18n.BULK_ACTION_FAILED_SINGLE_ALERT);
}

onUpdateSuccess(response.updated, response.version_conflicts, status);
onUpdateSuccess(response.updated ?? 0, response.version_conflicts ?? 0, status);
} catch (error) {
onUpdateFailure(status, error);
} finally {
Expand Down

0 comments on commit 9476571

Please sign in to comment.