Skip to content

Commit

Permalink
some more type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
semd committed Aug 13, 2021
1 parent 8138fb6 commit 23e77f3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* 2.0.
*/
import Boom from '@hapi/boom';
import { estypes } from '@elastic/elasticsearch';
import { PublicMethodsOf } from '@kbn/utility-types';
import { Filter, buildEsQuery, EsQueryConfig } from '@kbn/es-query';
import { decodeVersion, encodeHitVersion } from '@kbn/securitysolution-es-utils';
Expand Down Expand Up @@ -50,12 +51,12 @@ const mapConsumerToIndexName: typeof mapConsumerToIndexNameTyped = mapConsumerTo
// TODO: Fix typings https://github.com/elastic/kibana/issues/101776
type NonNullableProps<Obj extends {}, Props extends keyof Obj> = Omit<Obj, Props> &
{ [K in Props]-?: NonNullable<Obj[K]> };
type AlertType = NonNullableProps<
type AlertType = { _index: string; _id: string } & NonNullableProps<
ParsedTechnicalFields,
typeof ALERT_RULE_TYPE_ID | typeof ALERT_RULE_CONSUMER | typeof SPACE_IDS
>;

const isValidAlert = (source?: any): source is AlertType => {
const isValidAlert = (source?: estypes.SearchHit<any>): source is AlertType => {
return (
(source?._source?.[ALERT_RULE_TYPE_ID] != null &&
source?._source?.[ALERT_RULE_CONSUMER] != null &&
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/timelines/public/components/t_grid/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type { Filter, EsQueryConfig, Query } from '@kbn/es-query';
import { FilterStateStore } from '@kbn/es-query';
import { isEmpty, get } from 'lodash/fp';
import memoizeOne from 'memoize-one';
import { ALERT_WORKFLOW_STATUS } from '@kbn/rule-data-utils';
Expand All @@ -16,7 +17,7 @@ import {
handleSkipFocus,
stopPropagationAndPreventDefault,
} from '../../../common';
import { esFilters, IIndexPattern } from '../../../../../../src/plugins/data/public';
import { IIndexPattern } from '../../../../../../src/plugins/data/public';
import type { BrowserFields } from '../../../common/search_strategy/index_fields';
import { DataProviderType, EXISTS_OPERATOR } from '../../../common/types/timeline';
import type { DataProvider, DataProvidersAnd } from '../../../common/types/timeline';
Expand Down Expand Up @@ -218,7 +219,7 @@ export const buildTimeRangeFilter = (from: string, to: string): Filter =>
},
},
$state: {
store: esFilters.FilterStateStore.APP_STATE,
store: FilterStateStore.APP_STATE,
},
} as Filter);

Expand Down
13 changes: 7 additions & 6 deletions x-pack/plugins/timelines/public/container/use_update_alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import type { estypes } from '@elastic/elasticsearch';
import { CoreStart } from '../../../../../src/core/public';

import { useKibana } from '../../../../../src/plugins/kibana_react/public';
import { AlertStatus } from '../../../timelines/common';
Expand All @@ -15,9 +16,10 @@ export const RAC_ALERTS_BULK_UPDATE_URL = '/internal/rac/alerts/bulk_update';
/**
* Update alert status by query
*
* @param query of alerts to update
* @param status to update to('open' / 'closed' / 'in-progress')
* @param signal AbortSignal for cancelling request
* @param status to update to('open' / 'closed' / 'acknowledged')
* @param index index to be updated
* @param query optional query object to update alerts by query.
* @param ids optional array of alert ids to update. Ignored if query passed.
*
* @throws An error if response is not OK
*/
Expand All @@ -29,11 +31,10 @@ export const useUpdateAlertsStatus = (): {
query?: object;
}) => Promise<estypes.UpdateByQueryResponse>;
} => {
const { http } = useKibana().services;
const { http } = useKibana<CoreStart>().services;
return {
updateAlertStatus: async ({ status, index, ids, query }) => {
const { body } = await http!.fetch(RAC_ALERTS_BULK_UPDATE_URL, {
method: 'POST',
const { body } = await http.post(RAC_ALERTS_BULK_UPDATE_URL, {
body: JSON.stringify({ index, status, ...(query ? { query } : { ids }) }),
});
return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,4 @@
"kibana.space_ids": ["space2"]
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export default ({ getService }: FtrProviderContext) => {
const APM_ALERT_INDEX = '.alerts-observability-apm';
const SECURITY_SOLUTION_ALERT_ID = '020202';
const SECURITY_SOLUTION_ALERT_INDEX = '.alerts-security.alerts';
// const ALERT_VERSION = Buffer.from(JSON.stringify([0, 1]), 'utf8').toString('base64'); // required for optimistic concurrency control

const getAPMIndexName = async (user: User) => {
const {
Expand Down

0 comments on commit 23e77f3

Please sign in to comment.