Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Add functionality to select multiple indices
Browse files Browse the repository at this point in the history
  • Loading branch information
ohltyler committed Apr 6, 2020
1 parent 9b706c8 commit 5bf4dc5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import {
EuiPagination,
} from '@elastic/eui';
import React from 'react';
import { ALL_DETECTOR_STATES, ALL_INDICES } from '../../utils/constants';
import { ALL_DETECTOR_STATES } from '../../utils/constants';
import { getDetectorStateOptions } from '../../utils/helpers';

interface ListControlsProps {
activePage: number;
pageCount: number;
search: string;
selectedDetectorState: string;
selectedIndex: string;
selectedIndices: string[];
indexOptions: EuiComboBoxOptionProps[];
onDetectorStateChange: (options: EuiComboBoxOptionProps[]) => void;
onIndexChange: (options: EuiComboBoxOptionProps[]) => void;
Expand All @@ -40,7 +40,7 @@ interface ListControlsProps {
}
export const ListControls = (props: ListControlsProps) => (
<EuiFlexGroup>
<EuiFlexItem grow={false} style={{ width: '50%' }}>
<EuiFlexItem grow={false} style={{ width: '40%' }}>
<EuiFieldSearch
fullWidth={true}
value={props.search}
Expand Down Expand Up @@ -69,15 +69,15 @@ export const ListControls = (props: ListControlsProps) => (
<EuiComboBox
id="selectedIndices"
placeholder="All indices"
singleSelection={true}
singleSelection={false}
async
options={props.indexOptions}
onChange={props.onIndexChange}
onSearchChange={props.onSearchIndexChange}
selectedOptions={
props.selectedIndex == ALL_INDICES
? []
: [{ label: props.selectedIndex }]
props.selectedIndices.length > 0
? props.selectedIndices.map(index => ({ label: index }))
: []
}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { fireEvent, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { ALL_DETECTOR_STATES, ALL_INDICES } from '../../../utils/constants';
import { ALL_DETECTOR_STATES } from '../../../utils/constants';
import { ListControls } from '../ListControls';

describe('<ListControls /> spec', () => {
Expand All @@ -25,7 +25,7 @@ describe('<ListControls /> spec', () => {
pageCount: 10,
search: '',
selectedDetectorState: ALL_DETECTOR_STATES,
selectedIndex: ALL_INDICES,
selectedIndices: [],
detectorStateOptions: [],
indexOptions: [],
onDetectorStateChange: jest.fn(),
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('<ListControls /> spec', () => {
const updatedProps = {
...defaultProps,
selectedDetectorState: 'test_state',
selectedIndex: 'test_index',
selectedIndices: ['test_index'],
};
const { getByText } = render(<ListControls {...updatedProps} />);
expect(getByText('test_state')).toBeInTheDocument();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`<ListControls /> spec Empty results renders component with empty messag
>
<div
class="euiFlexItem euiFlexItem--flexGrowZero"
style="width: 50%;"
style="width: 40%;"
>
<div
class="euiFormControlLayout euiFormControlLayout--fullWidth"
Expand Down Expand Up @@ -144,7 +144,7 @@ exports[`<ListControls /> spec Empty results renders component with empty messag
class="euiFormControlLayout__childrenWrapper"
>
<div
class="euiComboBox__inputWrap euiComboBox__inputWrap--noWrap euiComboBox__inputWrap-isClearable"
class="euiComboBox__inputWrap euiComboBox__inputWrap-isClearable"
data-test-subj="comboBoxInput"
tabindex="-1"
>
Expand Down
25 changes: 15 additions & 10 deletions public/pages/DetectorsList/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ import { EmptyDetectorMessage } from '../Components/EmptyMessage/EmptyMessage';
import { ListControls } from '../Components/ListControls/ListControls';
import {
ALL_DETECTOR_STATES,
ALL_INDICES,
MAX_DETECTORS,
MAX_DISPLAY_LEN,
MAX_SELECTED_INDICES,
} from '../utils/constants';
import { getURLQueryParams } from '../utils/helpers';
import { staticColumn } from '../utils/tableUtils';
Expand All @@ -68,7 +68,7 @@ interface ListState {
page: number;
queryParams: GetDetectorsQueryParams;
selectedDetectorState: string;
selectedIndex: string;
selectedIndices: string[];
}

export const DetectorList = (props: ListProps) => {
Expand Down Expand Up @@ -105,7 +105,7 @@ export const DetectorList = (props: ListProps) => {
page: 0,
queryParams: getURLQueryParams(props.location),
selectedDetectorState: ALL_DETECTOR_STATES,
selectedIndex: ALL_INDICES,
selectedIndices: [],
});

// Remove breadcrumbs on page initialization
Expand All @@ -118,7 +118,7 @@ export const DetectorList = (props: ListProps) => {
const { history, location } = props;
const updatedParams = {
...state.queryParams,
indices: state.selectedIndex,
indices: state.selectedIndices.join(' '),
from: state.page * state.queryParams.size,
};
dispatch(getDetectorList(updatedParams));
Expand All @@ -136,7 +136,7 @@ export const DetectorList = (props: ListProps) => {
state.queryParams.sortDirection,
state.queryParams.sortField,
state.selectedDetectorState,
state.selectedIndex,
state.selectedIndices,
]);

const handlePageChange = (pageNumber: number) => {
Expand Down Expand Up @@ -193,10 +193,15 @@ export const DetectorList = (props: ListProps) => {

// Refresh data if user is selecting an index filter
const handleIndexChange = (options: EuiComboBoxOptionProps[]): void => {
const newIndex = options.length > 0 ? options[0].label : ALL_INDICES;
let indices: string[];
indices = options.length > 0 ? [] : options.map(option => option.label);
if (options.length > 0) {
indices = options.map(option => option.label);
}

setState({
...state,
selectedIndex: newIndex,
selectedIndices: indices.slice(0, MAX_SELECTED_INDICES),
});
};

Expand All @@ -206,10 +211,10 @@ export const DetectorList = (props: ListProps) => {
queryParams: {
...state.queryParams,
search: '',
indices: ALL_INDICES,
indices: '',
},
selectedDetectorState: ALL_DETECTOR_STATES,
selectedIndex: ALL_INDICES,
selectedIndices: [],
}));
};

Expand Down Expand Up @@ -247,7 +252,7 @@ export const DetectorList = (props: ListProps) => {
pageCount={Math.ceil(totalDetectors / state.queryParams.size) || 1}
search={state.queryParams.search}
selectedDetectorState={state.selectedDetectorState}
selectedIndex={state.selectedIndex}
selectedIndices={state.selectedIndices}
indexOptions={indexOptions}
onDetectorStateChange={handleDetectorStateChange}
onIndexChange={handleIndexChange}
Expand Down
2 changes: 1 addition & 1 deletion public/pages/DetectorsList/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import { SORT_DIRECTION } from '../../../../server/utils/constants';

export const ALL_DETECTOR_STATES = '';
export const ALL_INDICES = '';
export const MAX_DETECTORS = 1000;
export const MAX_DISPLAY_LEN = 20;
export const MAX_SELECTED_INDICES = 10;

// TODO: finish when we know all possible detector states
export enum DETECTOR_STATES {
Expand Down
2 changes: 1 addition & 1 deletion server/routes/ad.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ const getDetectors = async (
mustQueries.push({
query_string: {
fields: ['indices'],
default_operator: 'AND',
default_operator: 'OR',
query: `*${indices
.trim()
.split(' ')
Expand Down

0 comments on commit 5bf4dc5

Please sign in to comment.