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

[Management] Highlight query in results for index pattern creation wizard #16529

Merged
merged 3 commits into from
Feb 8, 2018
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 @@ -59,6 +59,7 @@ exports[`StepIndexPattern should disable the next step if the index pattern exis
},
]
}
query="k*"
/>
</EuiPanel>
`;
Expand Down Expand Up @@ -122,6 +123,7 @@ exports[`StepIndexPattern should properly fetch indices for the initial query 1`
},
]
}
query="k*"
/>
</EuiPanel>
`;
Expand All @@ -134,11 +136,7 @@ exports[`StepIndexPattern should render normally 1`] = `
>
<Header
characterList="\\\\, /, ?, \\", <, >, |"
errors={
Array [
"Your input contains invalid characters or spaces. Please omit: \\\\, /, ?, \\", <, >, |",
]
}
errors={Array []}
goToNextStep={[Function]}
isInputInvalid={false}
isNextStepDisabled={true}
Expand Down Expand Up @@ -187,6 +185,7 @@ exports[`StepIndexPattern should render normally 1`] = `
},
]
}
query=""
/>
</EuiPanel>
`;
Expand Down Expand Up @@ -250,6 +249,7 @@ exports[`StepIndexPattern should render some indices 1`] = `
},
]
}
query="k*"
/>
</EuiPanel>
`;
Expand Down Expand Up @@ -342,6 +342,7 @@ exports[`StepIndexPattern should show errors 1`] = `
},
]
}
query="?"
/>
</EuiPanel>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,111 @@ exports[`IndicesList should change per page 1`] = `
</div>
`;

exports[`IndicesList should highlight the query in the matches 1`] = `
<div>
<EuiTable>
<EuiTableBody>
<EuiTableRow
key="0"
>
<EuiTableRowCell
align="left"
textOnly={true}
>
<span>
<strong>
ki
</strong>
bana
</span>
</EuiTableRowCell>
</EuiTableRow>
<EuiTableRow
key="1"
>
<EuiTableRowCell
align="left"
textOnly={true}
>
es
</EuiTableRowCell>
</EuiTableRow>
</EuiTableBody>
</EuiTable>
<EuiSpacer
size="m"
/>
<EuiFlexGroup
alignItems="center"
component="div"
gutterSize="l"
justifyContent="spaceBetween"
responsive={true}
wrap={false}
>
<EuiFlexItem
component="div"
grow={false}
>
<EuiPopover
anchorPosition="downCenter"
button={
<EuiButtonEmpty
color="text"
iconSide="right"
iconType="arrowDown"
onClick={[Function]}
size="s"
type="button"
>
Rows per page:
10
</EuiButtonEmpty>
}
closePopover={[Function]}
id="customizablePagination"
isOpen={false}
ownFocus={false}
panelPaddingSize="none"
withTitle={true}
>
<EuiContextMenuPanel
hasFocus={true}
items={
Array [
<EuiContextMenuItem
icon="empty"
onClick={[Function]}
>
5
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="empty"
onClick={[Function]}
>
10
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="empty"
onClick={[Function]}
>
20
</EuiContextMenuItem>,
<EuiContextMenuItem
icon="empty"
onClick={[Function]}
>
50
</EuiContextMenuItem>,
]
}
/>
</EuiPopover>
</EuiFlexItem>
</EuiFlexGroup>
</div>
`;

exports[`IndicesList should render normally 1`] = `
<div>
<EuiTable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ const indices = [
describe('IndicesList', () => {
it('should render normally', () => {
const component = shallow(
<IndicesList indices={indices}/>
<IndicesList indices={indices} query=""/>
);

expect(component).toMatchSnapshot();
});

it('should change pages', () => {
const component = shallow(
<IndicesList indices={indices}/>
<IndicesList indices={indices} query=""/>
);

const instance = component.instance();
Expand All @@ -32,7 +32,7 @@ describe('IndicesList', () => {

it('should change per page', () => {
const component = shallow(
<IndicesList indices={indices}/>
<IndicesList indices={indices} query="" />
);

const instance = component.instance();
Expand All @@ -42,10 +42,18 @@ describe('IndicesList', () => {
expect(component).toMatchSnapshot();
});

it('should highlight the query in the matches', () => {
const component = shallow(
<IndicesList indices={indices} query="ki" />
);

expect(component).toMatchSnapshot();
});

describe('updating props', () => {
it('should render all new indices', () => {
const component = shallow(
<IndicesList indices={indices}/>
<IndicesList indices={indices} query=""/>
);

const moreIndices = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
export class IndicesList extends Component {
static propTypes = {
indices: PropTypes.array.isRequired,
query: PropTypes.string.isRequired,
}

constructor(props) {
Expand Down Expand Up @@ -129,15 +130,35 @@ export class IndicesList extends Component {
);
}

highlightIndexName(indexName, query) {
const queryIdx = indexName.indexOf(query);
if (!query || queryIdx === -1) {
return indexName;
}

const preStr = indexName.substr(0, queryIdx);
const postStr = indexName.substr(queryIdx + query.length);

return (
<span>
{preStr}
<strong>{query}</strong>
{postStr}
</span>
);
}

render() {
const { indices } = this.props;
const { indices, query } = this.props;

const queryWithoutWildcard = query.endsWith('*') ? query.substr(0, query.length - 1) : query;

const paginatedIndices = indices.slice(this.pager.firstItemIndex, this.pager.lastItemIndex + 1);
const rows = paginatedIndices.map((index, key) => {
return (
<EuiTableRow key={key}>
<EuiTableRowCell>
{index.name}
{this.highlightIndexName(index.name, queryWithoutWildcard)}
</EuiTableRowCell>
</EuiTableRow>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { ILLEGAL_CHARACTERS, MAX_SEARCH_SIZE } from '../../constants';
import {
getIndices,
isIndexPatternQueryValid,
containsInvalidCharacters,
getMatchedIndices,
canAppendWildcard,
createReasonableWait
Expand Down Expand Up @@ -139,6 +139,7 @@ export class StepIndexPattern extends Component {

return (
<IndicesList
query={query}
indices={indicesToList}
/>
);
Expand Down Expand Up @@ -170,12 +171,16 @@ export class StepIndexPattern extends Component {
const errors = [];
const characterList = ILLEGAL_CHARACTERS.slice(0, ILLEGAL_CHARACTERS.length - 1).join(', ');

if (!isIndexPatternQueryValid(query, ILLEGAL_CHARACTERS)) {
if (!query || !query.length || query === '.' || query === '..') {
// This is an error scenario but do not report an error
containsErrors = true;
}
else if (!containsInvalidCharacters(query, ILLEGAL_CHARACTERS)) {
errors.push(`Your input contains invalid characters or spaces. Please omit: ${characterList}`);
containsErrors = true;
}

const isInputInvalid = showingIndexPatternQueryErrors && containsErrors;
const isInputInvalid = showingIndexPatternQueryErrors && containsErrors && errors.length > 0;
const isNextStepDisabled = containsErrors || indices.length === 0 || indexPatternExists;

return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { containsInvalidCharacters } from '../contains_invalid_characters';

describe('containsInvalidCharacters', () => {
it('should fail with illegal characters', () => {
const valid = containsInvalidCharacters('abc', ['a']);
expect(valid).toBeFalsy();
});

it('should pass with no illegal characters', () => {
const valid = containsInvalidCharacters('abc', ['%']);
expect(valid).toBeTruthy();
});
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function containsInvalidCharacters(pattern, illegalCharacters) {
return !illegalCharacters.some(char => pattern.includes(char));
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ export { getIndices } from './get_indices';

export { getMatchedIndices } from './get_matched_indices';

export { isIndexPatternQueryValid } from './is_index_pattern_query_valid';
export { containsInvalidCharacters } from './contains_invalid_characters';

export { extractTimeFields } from './extract_time_fields';

This file was deleted.