Skip to content

Commit

Permalink
[WIP] Index pattern management UI -> TypeScript (source_filters_table)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed Apr 8, 2020
1 parent 267f22c commit 5da482a
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 164 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,30 @@
*/

import React from 'react';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
import { shallow } from 'enzyme';

import { AddFilter } from '../add_filter';
import { AddFilter } from './add_filter';

describe('AddFilter', () => {
it('should render normally', async () => {
const component = shallowWithI18nProvider(<AddFilter onAddFilter={() => {}} />);
test('should render normally', () => {
const component = shallow(<AddFilter onAddFilter={() => {}} />);

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

it('should allow adding a filter', async () => {
test('should allow adding a filter', async () => {
const onAddFilter = jest.fn();
const component = shallowWithI18nProvider(<AddFilter onAddFilter={onAddFilter} />);
const component = shallow(<AddFilter onAddFilter={onAddFilter} />);

// Set a value in the input field
component.setState({ filter: 'tim*' });

// Click the button
component.find('EuiFieldText').simulate('change', { target: { value: 'tim*' } });
component.find('EuiButton').simulate('click');
component.update();

expect(onAddFilter).toBeCalledWith('tim*');
});

it('should ignore strings with just spaces', async () => {
const component = shallowWithI18nProvider(<AddFilter onAddFilter={() => {}} />);
test('should ignore strings with just spaces', () => {
const component = shallow(<AddFilter onAddFilter={() => {}} />);

// Set a value in the input field
component.find('EuiFieldText').simulate('keypress', ' ');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React, { useState, useCallback } from 'react';
import PropTypes from 'prop-types';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiFlexGroup, EuiFlexItem, EuiFieldText, EuiButton } from '@elastic/eui';

interface AddFilterProps {
onAddFilter: (filter: string) => void;
}

const sourcePlaceholder = i18n.translate('kbn.management.editIndexPattern.sourcePlaceholder', {
defaultMessage:
"source filter, accepts wildcards (e.g., `user*` to filter fields starting with 'user')",
});

export const AddFilter = ({ onAddFilter }: AddFilterProps) => {
const [filter, setFilter] = useState<string>('');

const onAddButtonClick = useCallback(() => {
onAddFilter(filter);
setFilter('');
}, [filter, onAddFilter]);

return (
<EuiFlexGroup>
<EuiFlexItem grow={10}>
<EuiFieldText
fullWidth
value={filter}
onChange={e => setFilter(e.target.value.trim())}
placeholder={sourcePlaceholder}
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiButton isDisabled={filter.length === 0} onClick={onAddButtonClick}>
<FormattedMessage
id="kbn.management.editIndexPattern.source.addButtonLabel"
defaultMessage="Add"
/>
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
);
};

AddFilter.propTypes = {
onAddFilter: PropTypes.func.isRequired,
};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { shallow } from 'enzyme';
import { Header } from '../header';

describe('Header', () => {
it('should render normally', async () => {
test('should render normally', () => {
const component = shallow(<Header />);

expect(component).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
import React from 'react';

import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n/react';

export const Header = () => (
<div>
<>
<EuiTitle size="s">
<h3>
<FormattedMessage
Expand Down Expand Up @@ -52,5 +51,5 @@ export const Header = () => (
</p>
</EuiText>
<EuiSpacer size="s" />
</div>
</>
);
Loading

0 comments on commit 5da482a

Please sign in to comment.