Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,12 @@ export const useSourcererDataView = (
() => ({
browserFields: browserFields(),
dataViewId: sourcererDataView.id,
indexPattern: {
fields: Object.values(sourcererDataView.fields || {}),
title: selectedPatterns.join(','),
getName: () => selectedPatterns.join(','),
},
indicesExist,
loading: loading || sourcererDataView.loading,
// all active & inactive patterns in DATA_VIEW
patternList: sourcererDataView.title.split(','),
// selected patterns in DATA_VIEW including filter
selectedPatterns,
// if we have to do an update to data view, tell us which patterns are active
...(legacyPatterns.length > 0 ? { activePatterns: sourcererDataView.patternList } : {}),
sourcererDataView: sourcererDataView.dataView,
}),
[
browserFields,
sourcererDataView,
selectedPatterns,
indicesExist,
loading,
legacyPatterns.length,
]
[browserFields, sourcererDataView, selectedPatterns, indicesExist, loading]
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ export const FieldTypesContext = createContext<FieldTypesContextValue | undefine
* Exposes mapped field types for threat intel shared use
*/
export const FieldTypesProvider: FC<PropsWithChildren<unknown>> = ({ children }) => {
const { indexPattern } = useSourcererDataView();
const {
sourcererDataView: { fields = {} },
} = useSourcererDataView();

// field name to field type map to allow the cell_renderer to format dates
const fieldTypes: FieldTypesContextValue = useMemo(
() =>
indexPattern.fields.reduce((acc, field) => {
Object.values(fields).reduce((acc, field) => {
acc[field.name] = field.type;
return acc;
}, {} as FieldTypesContextValue),
[indexPattern.fields]
[fields]
);

return <FieldTypesContext.Provider value={fieldTypes}>{children}</FieldTypesContext.Provider>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,10 @@

import React from 'react';
import { Story } from '@storybook/react';
import { DataView, DataViewField } from '@kbn/data-views-plugin/common';
import { EuiComboBoxOptionOption } from '@elastic/eui';
import { RawIndicatorFieldId } from '../../../../../common/types/indicator';
import { IndicatorsFieldSelector } from './field_selector';

const mockIndexPattern: DataView = {
fields: [
{
name: '@timestamp',
type: 'date',
} as DataViewField,
{
name: 'threat.feed.name',
type: 'string',
} as DataViewField,
],
} as DataView;

export default {
component: IndicatorsFieldSelector,
title: 'IndicatorsFieldSelector',
Expand All @@ -33,7 +19,6 @@ export default {
export const Default: Story<void> = () => {
return (
<IndicatorsFieldSelector
indexPattern={mockIndexPattern}
valueChange={({ label }: EuiComboBoxOptionOption<string>) =>
window.alert(`${label} selected`)
}
Expand All @@ -44,7 +29,6 @@ export const Default: Story<void> = () => {
export const WithDefaultValue: Story<void> = () => {
return (
<IndicatorsFieldSelector
indexPattern={mockIndexPattern}
valueChange={({ label }: EuiComboBoxOptionOption<string>) =>
window.alert(`${label} selected`)
}
Expand All @@ -54,5 +38,5 @@ export const WithDefaultValue: Story<void> = () => {
};

export const NoData: Story<void> = () => {
return <IndicatorsFieldSelector indexPattern={{ fields: [] } as any} valueChange={() => {}} />;
return <IndicatorsFieldSelector valueChange={() => {}} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,16 @@

import React from 'react';
import { render } from '@testing-library/react';
import { DataView, DataViewField } from '@kbn/data-views-plugin/common';
import { TestProvidersComponent } from '../../../../mocks/test_providers';
import { IndicatorsFieldSelector } from './field_selector';
import { EuiComboBoxOptionOption } from '@elastic/eui';
import { DROPDOWN_TEST_ID } from './test_ids';

const mockIndexPattern: DataView = {
fields: [
{
name: '@timestamp',
type: 'date',
} as DataViewField,
{
name: 'threat.feed.name',
type: 'string',
} as DataViewField,
],
} as DataView;

describe('<IndicatorsFieldSelector />', () => {
it('should handle empty array of indexPatterns', () => {
const { getByTestId } = render(
<TestProvidersComponent>
<IndicatorsFieldSelector
indexPattern={{ fields: [] } as any}
// eslint-disable-next-line no-console
valueChange={(value: EuiComboBoxOptionOption<string>) => console.log(value)}
/>
Expand All @@ -45,7 +30,6 @@ describe('<IndicatorsFieldSelector />', () => {
const { getByTestId } = render(
<TestProvidersComponent>
<IndicatorsFieldSelector
indexPattern={mockIndexPattern}
// eslint-disable-next-line no-console
valueChange={(value: EuiComboBoxOptionOption<string>) => console.log(value)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@

import React, { memo, useCallback, useMemo, useState } from 'react';
import { EuiComboBox } from '@elastic/eui';
import { DataViewField } from '@kbn/data-views-plugin/common';
import { FieldSpec } from '@kbn/data-views-plugin/common';
import { EuiComboBoxOptionOption } from '@elastic/eui/src/components/combo_box/types';
import { SecuritySolutionDataViewBase } from '../../../../types';
import { RawIndicatorFieldId } from '../../../../../common/types/indicator';
import { useStyles } from './styles';
import { DROPDOWN_TEST_ID } from './test_ids';
import { COMBOBOX_PREPEND_LABEL } from './translations';
import { useCurrentDataViewFields } from '../../hooks/use_current_data_view_fields';

export interface IndicatorsFieldSelectorProps {
indexPattern: SecuritySolutionDataViewBase;
valueChange: (value: EuiComboBoxOptionOption<string>) => void;
defaultStackByValue?: RawIndicatorFieldId;
}
Expand All @@ -25,10 +24,12 @@ const DEFAULT_STACK_BY_VALUE = RawIndicatorFieldId.Feed;
const COMBOBOX_SINGLE_SELECTION = { asPlainText: true };

export const IndicatorsFieldSelector = memo<IndicatorsFieldSelectorProps>(
({ indexPattern, valueChange, defaultStackByValue = DEFAULT_STACK_BY_VALUE }) => {
({ valueChange, defaultStackByValue = DEFAULT_STACK_BY_VALUE }) => {
const rawFields = useCurrentDataViewFields();

const styles = useStyles();
const defaultStackByValueInfo = indexPattern.fields.find(
(f: DataViewField) => f.name === defaultStackByValue
const defaultStackByValueInfo = rawFields.find(
(f: FieldSpec) => f.name === defaultStackByValue
);
const [selectedField, setSelectedField] = useState<Array<EuiComboBoxOptionOption<string>>>([
{
Expand All @@ -38,13 +39,11 @@ export const IndicatorsFieldSelector = memo<IndicatorsFieldSelectorProps>(
]);
const fields: Array<EuiComboBoxOptionOption<string>> = useMemo(
() =>
indexPattern
? indexPattern.fields.map((f: DataViewField) => ({
label: f.name,
value: f.type,
}))
: [],
[indexPattern]
rawFields.map((f: FieldSpec) => ({
label: f.name,
value: f.type,
})),
[rawFields]
);

const selectedFieldChange = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { of } from 'rxjs';
import { Story } from '@storybook/react';
import { DataView, DataViewField } from '@kbn/data-views-plugin/common';
import { TimeRange } from '@kbn/es-query';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { IUiSettingsClient } from '@kbn/core/public';
Expand All @@ -28,19 +27,6 @@ export default {

const mockTimeRange: TimeRange = { from: '', to: '' };

const mockIndexPattern: DataView = {
fields: [
{
name: '@timestamp',
type: 'date',
} as DataViewField,
{
name: 'threat.feed.name',
type: 'string',
} as DataViewField,
],
} as DataView;

const validDate: string = '1 Jan 2022 00:00:00 GMT';
const numberOfDays: number = 1;
const aggregation1: Aggregation = {
Expand Down Expand Up @@ -135,7 +121,6 @@ export const Default: Story<void> = () => {
<IndicatorsBarChartWrapper
dateRange={{ min: moment(), max: moment() }}
timeRange={mockTimeRange}
indexPattern={mockIndexPattern}
series={[]}
field={mockField}
onFieldChange={mockOnFieldChange}
Expand All @@ -159,7 +144,6 @@ export const InitialLoad: Story<void> = () => {
<IndicatorsBarChartWrapper
dateRange={{ min: moment(), max: moment() }}
timeRange={mockTimeRange}
indexPattern={mockIndexPattern}
series={[]}
isLoading={true}
isFetching={false}
Expand Down Expand Up @@ -208,7 +192,6 @@ export const UpdatingData: Story<void> = () => {
<IndicatorsBarChartWrapper
dateRange={{ min: moment(), max: moment() }}
timeRange={mockTimeRange}
indexPattern={mockIndexPattern}
series={mockIndicators}
isLoading={false}
isFetching={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import React from 'react';
import { render } from '@testing-library/react';
import { TimeRange } from '@kbn/es-query';
import { DataView, DataViewField } from '@kbn/data-views-plugin/common';
import { TestProvidersComponent } from '../../../../mocks/test_providers';
import { IndicatorsBarChartWrapper } from './wrapper';
import {
Expand All @@ -21,19 +20,6 @@ import { DROPDOWN_TEST_ID } from './test_ids';

jest.mock('../../../query_bar/hooks/use_filters');

const mockIndexPattern: DataView = {
fields: [
{
name: '@timestamp',
type: 'date',
} as DataViewField,
{
name: 'threat.feed.name',
type: 'string',
} as DataViewField,
],
} as DataView;

const mockTimeRange: TimeRange = { from: '', to: '' };
const mockField = { label: 'host.name', value: 'string' };

Expand All @@ -47,7 +33,6 @@ describe('<IndicatorsBarChartWrapper />', () => {
series={[]}
field={mockField}
onFieldChange={jest.fn()}
indexPattern={mockIndexPattern}
timeRange={mockTimeRange}
isFetching={false}
isLoading={false}
Expand All @@ -70,7 +55,6 @@ describe('<IndicatorsBarChartWrapper />', () => {
series={[]}
field={mockField}
onFieldChange={jest.fn()}
indexPattern={mockIndexPattern}
timeRange={mockTimeRange}
isFetching={false}
isLoading={true}
Expand All @@ -92,7 +76,6 @@ describe('<IndicatorsBarChartWrapper />', () => {
series={[]}
field={mockField}
onFieldChange={jest.fn()}
indexPattern={mockIndexPattern}
timeRange={mockTimeRange}
isFetching={true}
isLoading={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
import { FormattedMessage } from '@kbn/i18n-react';
import { TimeRange } from '@kbn/es-query';
import { TimeRangeBounds } from '@kbn/data-plugin/common';
import { SecuritySolutionDataViewBase } from '../../../../types';
import { RawIndicatorFieldId } from '../../../../../common/types/indicator';
import { IndicatorsFieldSelector } from './field_selector';
import { IndicatorsBarChart } from './barchart';
Expand All @@ -36,10 +35,6 @@ export interface IndicatorsBarChartWrapperProps {
* From and to values received from the KQL bar and passed down to the hook to query data.
*/
timeRange?: TimeRange;
/**
* List of fields coming from the Security Solution sourcerer data view, passed down to the {@link IndicatorsFieldSelector} to populate the dropdown.
*/
indexPattern: SecuritySolutionDataViewBase;

series: ChartSeries[];

Expand All @@ -61,7 +56,7 @@ export interface IndicatorsBarChartWrapperProps {
* and handles retrieving aggregated indicator data.
*/
export const IndicatorsBarChartWrapper = memo<IndicatorsBarChartWrapperProps>(
({ timeRange, indexPattern, isLoading, isFetching, series, dateRange, field, onFieldChange }) => {
({ timeRange, isLoading, isFetching, series, dateRange, field, onFieldChange }) => {
if (isLoading) {
return (
<EuiFlexGroup justifyContent="spaceAround">
Expand Down Expand Up @@ -89,7 +84,6 @@ export const IndicatorsBarChartWrapper = memo<IndicatorsBarChartWrapperProps>(
</EuiFlexItem>
<EuiFlexItem grow={false}>
<IndicatorsFieldSelector
indexPattern={indexPattern}
defaultStackByValue={DEFAULT_FIELD}
valueChange={onFieldChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import React from 'react';
import { DataView } from '@kbn/data-views-plugin/common';
import { mockIndicatorsFiltersContext } from '../../../../mocks/mock_indicators_filters_context';
import { StoryProvidersComponent } from '../../../../mocks/story_providers';
import { generateMockIndicator, Indicator } from '../../../../../common/types/indicator';
Expand All @@ -19,8 +18,6 @@ export default {
title: 'IndicatorsTable',
};

const mockIndexPattern: DataView = undefined as unknown as DataView;

const stub = () => void 0;

const columnSettings = {
Expand Down Expand Up @@ -54,7 +51,6 @@ export function IndicatorsFullyLoaded() {
onChangePage={stub}
onChangeItemsPerPage={stub}
indicatorCount={indicatorsFixture.length * 2}
indexPattern={mockIndexPattern}
columnSettings={columnSettings}
/>
</IndicatorsFiltersContext.Provider>
Expand All @@ -77,7 +73,6 @@ export function FirstLoad() {
onChangeItemsPerPage={stub}
indicatorCount={0}
isLoading={true}
indexPattern={mockIndexPattern}
columnSettings={columnSettings}
/>
</StoryProvidersComponent>
Expand All @@ -103,7 +98,6 @@ export function DataUpdateInProgress() {
onChangePage={stub}
onChangeItemsPerPage={stub}
indicatorCount={indicatorsFixture.length * 2}
indexPattern={mockIndexPattern}
columnSettings={columnSettings}
/>
</IndicatorsFiltersContext.Provider>
Expand All @@ -126,7 +120,6 @@ export function WithNoIndicators() {
onChangeItemsPerPage={stub}
indicatorCount={0}
isLoading={false}
indexPattern={mockIndexPattern}
columnSettings={columnSettings}
/>
</StoryProvidersComponent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { IndicatorsTable, IndicatorsTableProps } from './table';
import { TestProvidersComponent } from '../../../../mocks/test_providers';
import { generateMockIndicator, Indicator } from '../../../../../common/types/indicator';
import { BUTTON_TEST_ID, TABLE_UPDATE_PROGRESS_TEST_ID } from './test_ids';
import { SecuritySolutionDataViewBase } from '../../../../types';
import { INDICATORS_FLYOUT_TITLE_TEST_ID } from '../flyout/test_ids';

const stub = () => {};
Expand All @@ -24,7 +23,6 @@ const tableProps: IndicatorsTableProps = {
indicatorCount: 0,
isLoading: false,
browserFields: {},
indexPattern: { fields: [], title: '' } as SecuritySolutionDataViewBase,
columnSettings: {
columnVisibility: {
visibleColumns: [],
Expand Down
Loading