+
+
`;
exports[`SourceFiltersTable should update a filter 1`] = `
-
+
-
+
`;
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/__jest__/__snapshots__/add_filter.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/__snapshots__/add_filter.test.tsx.snap
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/__jest__/__snapshots__/add_filter.test.js.snap
rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/__snapshots__/add_filter.test.tsx.snap
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js
deleted file mode 100644
index 2124b76b3a915..0000000000000
--- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.js
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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, { Component } from 'react';
-import PropTypes from 'prop-types';
-
-import { EuiFlexGroup, EuiFlexItem, EuiFieldText, EuiButton } from '@elastic/eui';
-
-import { i18n } from '@kbn/i18n';
-import { FormattedMessage } from '@kbn/i18n/react';
-
-export class AddFilter extends Component {
- static propTypes = {
- onAddFilter: PropTypes.func.isRequired,
- };
-
- constructor(props) {
- super(props);
- this.state = {
- filter: '',
- };
- }
-
- onAddFilter = () => {
- this.props.onAddFilter(this.state.filter);
- this.setState({ filter: '' });
- };
-
- render() {
- const { filter } = this.state;
- const placeholder = i18n.translate('kbn.management.editIndexPattern.sourcePlaceholder', {
- defaultMessage:
- "source filter, accepts wildcards (e.g., `user*` to filter fields starting with 'user')",
- });
-
- return (
-
-
- this.setState({ filter: e.target.value.trim() })}
- placeholder={placeholder}
- />
-
-
-
-
-
-
-
- );
- }
-}
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/__jest__/add_filter.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.test.tsx
similarity index 66%
rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/__jest__/add_filter.test.js
rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.test.tsx
index 915d9490db045..1ebaa3eaf89f8 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/__jest__/add_filter.test.js
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.test.tsx
@@ -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( {}} />);
+ test('should render normally', () => {
+ const component = shallow( {}} />);
expect(component).toMatchSnapshot();
});
- it('should allow adding a filter', async () => {
+ test('should allow adding a filter', async () => {
const onAddFilter = jest.fn();
- const component = shallowWithI18nProvider();
+ const component = shallow();
- // 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( {}} />);
+ test('should ignore strings with just spaces', () => {
+ const component = shallow( {}} />);
// Set a value in the input field
component.find('EuiFieldText').simulate('keypress', ' ');
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.tsx
new file mode 100644
index 0000000000000..d0f397637de33
--- /dev/null
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/add_filter.tsx
@@ -0,0 +1,63 @@
+/*
+ * 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 { 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('');
+
+ const onAddButtonClick = useCallback(() => {
+ onAddFilter(filter);
+ setFilter('');
+ }, [filter, onAddFilter]);
+
+ return (
+
+
+ setFilter(e.target.value.trim())}
+ placeholder={sourcePlaceholder}
+ />
+
+
+
+
+
+
+
+ );
+};
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/index.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/index.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/index.js
rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/add_filter/index.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/__snapshots__/confirmation_modal.test.tsx.snap b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/__snapshots__/confirmation_modal.test.tsx.snap
new file mode 100644
index 0000000000000..62376b498d887
--- /dev/null
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/__snapshots__/confirmation_modal.test.tsx.snap
@@ -0,0 +1,37 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`Header should render normally 1`] = `
+
+
+ }
+ confirmButtonText={
+
+ }
+ defaultFocusedButton="confirm"
+ onCancel={[Function]}
+ onConfirm={[Function]}
+ title={
+
+ }
+ />
+
+`;
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/confirmation_modal.test.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/confirmation_modal.test.tsx
new file mode 100644
index 0000000000000..ac7237095e4b3
--- /dev/null
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/confirmation_modal.test.tsx
@@ -0,0 +1,37 @@
+/*
+ * 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 from 'react';
+import { shallow } from 'enzyme';
+
+import { DeleteFilterConfirmationModal } from './confirmation_modal';
+
+describe('Header', () => {
+ test('should render normally', () => {
+ const component = shallow(
+ {}}
+ onDeleteFilter={() => {}}
+ />
+ );
+
+ expect(component).toMatchSnapshot();
+ });
+});
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/confirmation_modal.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/confirmation_modal.tsx
new file mode 100644
index 0000000000000..dabfb6d8f275a
--- /dev/null
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/confirmation_modal.tsx
@@ -0,0 +1,76 @@
+/*
+ * 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 from 'react';
+import PropTypes from 'prop-types';
+
+import { FormattedMessage } from '@kbn/i18n/react';
+import { EuiOverlayMask, EuiConfirmModal, EUI_MODAL_CONFIRM_BUTTON } from '@elastic/eui';
+
+interface DeleteFilterConfirmationModalProps {
+ filterToDeleteValue: string;
+ onCancelConfirmationModal: (
+ event?: React.KeyboardEvent | React.MouseEvent
+ ) => void;
+ onDeleteFilter: (event: React.MouseEvent) => void;
+}
+
+export const DeleteFilterConfirmationModal = ({
+ filterToDeleteValue,
+ onCancelConfirmationModal,
+ onDeleteFilter,
+}: DeleteFilterConfirmationModalProps) => {
+ return (
+
+
+ }
+ onCancel={onCancelConfirmationModal}
+ onConfirm={onDeleteFilter}
+ cancelButtonText={
+
+ }
+ buttonColor="danger"
+ confirmButtonText={
+
+ }
+ defaultFocusedButton={EUI_MODAL_CONFIRM_BUTTON}
+ />
+
+ );
+};
+
+DeleteFilterConfirmationModal.propTypes = {
+ filterToDeleteValue: PropTypes.string.isRequired,
+ onCancelConfirmationModal: PropTypes.func.isRequired,
+ onDeleteFilter: PropTypes.func.isRequired,
+};
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/index.ts b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/index.ts
new file mode 100644
index 0000000000000..e48e38b7c3dcb
--- /dev/null
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/confirmation_modal/index.ts
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+export { DeleteFilterConfirmationModal } from './confirmation_modal';
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/__jest__/__snapshots__/header.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/__snapshots__/header.test.tsx.snap
similarity index 98%
rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/__jest__/__snapshots__/header.test.js.snap
rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/__snapshots__/header.test.tsx.snap
index a5be141a18c89..cde0de79caacd 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/__jest__/__snapshots__/header.test.js.snap
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/__snapshots__/header.test.tsx.snap
@@ -1,7 +1,7 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Header should render normally 1`] = `
-
+
`;
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/__jest__/header.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.test.tsx
similarity index 95%
rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/__jest__/header.test.js
rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.test.tsx
index 058bf99fe26fa..869bdeb55cf02 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/__jest__/header.test.js
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.test.tsx
@@ -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();
expect(component).toMatchSnapshot();
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.tsx
similarity index 99%
rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.js
rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.tsx
index 8822ca6236250..7b37f75043dd5 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.js
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/header.tsx
@@ -20,11 +20,10 @@
import React from 'react';
import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui';
-
import { FormattedMessage } from '@kbn/i18n/react';
export const Header = () => (
-
+ <>
(
-
+ >
);
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/index.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/index.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/index.js
rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/header/index.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/index.ts b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/index.ts
new file mode 100644
index 0000000000000..87ac13ad15f50
--- /dev/null
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/index.ts
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+export { AddFilter } from './add_filter';
+export { DeleteFilterConfirmationModal } from './confirmation_modal';
+export { Header } from './header';
+export { Table } from './table';
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__jest__/__snapshots__/table.test.js.snap b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__snapshots__/table.test.tsx.snap
similarity index 77%
rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__jest__/__snapshots__/table.test.js.snap
rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__snapshots__/table.test.tsx.snap
index a0853b8628cc9..c70d0871bb854 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__jest__/__snapshots__/table.test.js.snap
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__snapshots__/table.test.tsx.snap
@@ -3,14 +3,15 @@
exports[`Table editing should show a save button 1`] = `
@@ -18,27 +19,20 @@ exports[`Table editing should show a save button 1`] = `
`;
exports[`Table editing should show an input field 1`] = `
-
-
-
-
-
+
+ tim*
+
`;
exports[`Table editing should update the matches dynamically as input value is changed 1`] = `
-
- time, value
-
+
+
+
`;
@@ -79,6 +73,7 @@ exports[`Table should render normally 1`] = `
items={
Array [
Object {
+ "clientId": "",
"value": "tim*",
},
]
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/index.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/index.ts
similarity index 100%
rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/index.js
rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/index.ts
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__jest__/table.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.test.tsx
similarity index 69%
rename from src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__jest__/table.test.js
rename to src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.test.tsx
index 7fba1fcfe4876..4705ecd2d1685 100644
--- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/__jest__/table.test.js
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/components/table/table.test.tsx
@@ -17,25 +17,40 @@
* under the License.
*/
-import React from 'react';
-import { shallow } from 'enzyme';
-import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';
-
-import { Table } from '../table';
-import { keyCodes } from '@elastic/eui';
-
-const indexPattern = {};
-const items = [{ value: 'tim*' }];
+import React, { ReactElement } from 'react';
+import { shallow, ShallowWrapper } from 'enzyme';
+
+import { Table, TableProps, TableState } from './table';
+import { EuiTableFieldDataColumnType, keyCodes } from '@elastic/eui';
+import { IIndexPattern } from '../../../../../../../../../../../plugins/data/public';
+import { SourceFiltersTableFilter } from '../../types';
+
+const indexPattern = {} as IIndexPattern;
+const items: SourceFiltersTableFilter[] = [{ value: 'tim*', clientId: '' }];
+
+const getIndexPatternMock = (mockedFields: any = {}) => ({ ...mockedFields } as IIndexPattern);
+
+const getTableColumnRender = (
+ component: ShallowWrapper,
+ index: number = 0
+) => {
+ const columns = component.prop>>(
+ 'columns'
+ );
+ return {
+ render: columns[index].render as (...args: any) => ReactElement,
+ };
+};
describe('Table', () => {
- it('should render normally', async () => {
- const component = shallowWithI18nProvider(
+ test('should render normally', () => {
+ const component = shallow(
{
);
});
- it('should show an input field', () => {
+ test('should show an input field', () => {
// Start the editing process
+
const editingComponent = shallow(
// Wrap in a div because: https://github.com/airbnb/enzyme/issues/1213
-
);
editingComponent
.find('EuiButtonIcon')
@@ -92,19 +110,19 @@ describe('Table', () => {
// Ensure the state change propagates
component.update();
- // Ensure the table cell switches to an input
- const filterNameTableCell = shallow(
- component.prop('columns')[0].render('tim*', { clientId })
- );
+ const cell = getTableColumnRender(component).render('tim*', { clientId });
+ const filterNameTableCell = shallow(cell);
+
expect(filterNameTableCell).toMatchSnapshot();
});
- it('should show a save button', () => {
+ test('should show a save button', () => {
// Start the editing process
const editingComponent = shallow(
// Fixes: Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.
-
);
+
editingComponent
.find('EuiButtonIcon')
.at(1)
@@ -116,22 +134,20 @@ describe('Table', () => {
// Verify save button
const saveTableCell = shallow(
// Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.
-
{}}
- saveFilter={() => {}}
+ saveFilter={() => undefined}
isSaving={false}
/>
);
@@ -210,16 +230,15 @@ describe('Table', () => {
);
deleteCellComponent
.find('EuiButtonIcon')
- .at(0)
+ .at(1)
.simulate('click');
expect(deleteFilter).toBeCalled();
});
- it('should save when in edit mode and the enter key is pressed', () => {
+ test('should save when in edit mode and the enter key is pressed', () => {
const saveFilter = jest.fn();
- const clientId = 1;
- const component = shallowWithI18nProvider(
+ const component = shallow(
{
// Start the editing process
const editingComponent = shallow(
// Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.
-
);
editingComponent
.find('EuiButtonIcon')
- .at(1)
+ .at(0)
.simulate('click');
- // Ensure the state change propagates
+
component.update();
// Get the rendered input cell
const filterNameTableCell = shallow(
// Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.
-
);
// Press the enter key
@@ -253,14 +272,13 @@ describe('Table', () => {
expect(saveFilter).toBeCalled();
// It should reset
- expect(component.state('editingFilterId')).toBe(null);
+ expect(component.state('editingFilterId')).toBe('');
});
- it('should cancel when in edit mode and the esc key is pressed', () => {
+ test('should cancel when in edit mode and the esc key is pressed', () => {
const saveFilter = jest.fn();
- const clientId = 1;
- const component = shallowWithI18nProvider(
+ const component = shallow(
{
// Start the editing process
const editingComponent = shallow(
// Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.
-
);
+
editingComponent
.find('EuiButtonIcon')
- .at(1)
+ .at(0)
.simulate('click');
+
// Ensure the state change propagates
component.update();
// Get the rendered input cell
const filterNameTableCell = shallow(
// Fixes Invariant Violation: ReactShallowRenderer render(): Shallow rendering works only with custom components, but the provided element type was `symbol`.
-
+ {filterToDelete && (
+
+ )}
+ >
);
}
}
diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/types.ts b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/types.ts
new file mode 100644
index 0000000000000..ee3689f017471
--- /dev/null
+++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/edit_index_pattern/source_filters_table/types.ts
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+/** @internal **/
+export interface SourceFiltersTableFilter {
+ value: string;
+ clientId: string | number;
+}