Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security Solution] getDataViewStateFromIndexFields was using wrong type as part of a cast #158594

Merged
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useDispatch } from 'react-redux';
import memoizeOne from 'memoize-one';
import type { BrowserField } from '@kbn/timelines-plugin/common';
import { getCategory } from '@kbn/triggers-actions-ui-plugin/public';
import type { DataViewFieldBase } from '@kbn/es-query';
import type { DataView } from '@kbn/data-views-plugin/public';

import { useKibana } from '../../lib/kibana';
import { sourcererActions } from '../../store/sourcerer';
Expand Down Expand Up @@ -48,11 +48,7 @@ interface DataViewInfo {
* VERY mutatious on purpose to improve the performance of the transform.
*/
export const getDataViewStateFromIndexFields = memoizeOne(
(
_title: string,
fields: DataViewFieldBase[],
_includeUnmapped: boolean = false
): DataViewInfo => {
(_title: string, fields: DataView['fields'], _includeUnmapped: boolean = false): DataViewInfo => {
// Adds two dangerous casts to allow for mutations within this function
type DangerCastForMutation = Record<string, {}>;

Expand All @@ -66,7 +62,7 @@ export const getDataViewStateFromIndexFields = memoizeOne(
if (acc.browserFields[category].fields == null) {
acc.browserFields[category].fields = {};
}
acc.browserFields[category].fields[field.name] = field as unknown as BrowserField;
acc.browserFields[category].fields[field.name] = field.spec as BrowserField;

return acc;
},
Expand Down