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

Index pattern management - typescript components #56987

Merged
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c7fca74
partial progress
mattkime Feb 6, 2020
b86c950
Merge branch 'master' into create_index_pattern_components_to_ts
elasticmachine Feb 6, 2020
60bab32
Merge branch 'master' into create_index_pattern_components_to_ts
mattkime Feb 6, 2020
3fd3e42
partial progress
mattkime Feb 6, 2020
c9b40dc
fix hybrid index patterns
mattkime Feb 6, 2020
8e814d5
Merge branch 'create_index_pattern_components_to_ts' of github.com:ma…
mattkime Feb 6, 2020
1581a0f
Merge branch 'master' into create_index_pattern_components_to_ts
elasticmachine Feb 7, 2020
83ad444
typescript fixes
mattkime Feb 7, 2020
a8b9872
Merge branch 'create_index_pattern_components_to_ts' of github.com:ma…
mattkime Feb 7, 2020
2663c78
update snäpshöt
mattkime Feb 7, 2020
69fd992
update snäpshöt
mattkime Feb 7, 2020
74f2626
partial progress
mattkime Feb 7, 2020
0fa2ed1
Merge branch 'master' into create_index_pattern_components_to_ts
elasticmachine Feb 7, 2020
3dd8c5e
fix types in test
mattkime Feb 8, 2020
6a83c49
Merge branch 'create_index_pattern_components_to_ts' of github.com:ma…
mattkime Feb 8, 2020
73e3989
Merge branch 'master' into create_index_pattern_components_to_ts
mattkime Feb 10, 2020
c0ba90c
fix index pattern w/o time field selected
mattkime Feb 10, 2020
580fad2
remove unused snapshot
mattkime Feb 10, 2020
ff85afe
Merge branch 'master' into create_index_pattern_components_to_ts
elasticmachine Feb 11, 2020
a112ca3
small ts fixes
mattkime Feb 11, 2020
25a5504
Merge branch 'create_index_pattern_components_to_ts' of github.com:ma…
mattkime Feb 11, 2020
27b1ff1
Merge branch 'master' into create_index_pattern_components_to_ts
mattkime Feb 11, 2020
b97a998
typescript step_index_pattern
mattkime Feb 12, 2020
3d5b806
fix test, add todos
mattkime Feb 13, 2020
de168bb
add more type info
mattkime Feb 15, 2020
528e640
fix index pattern api call, also lets not have components and types w…
mattkime Feb 16, 2020
ef390f5
Merge branch 'master' into create_index_pattern_components_to_ts
mattkime Feb 16, 2020
a3084b3
fix step_time_field test
mattkime Feb 16, 2020
044d713
remove debugging info
mattkime Feb 16, 2020
35d70d9
update snäpshöts
mattkime Feb 17, 2020
312562d
one less any
mattkime Feb 17, 2020
05aeed3
Merge branch 'master' into create_index_pattern_components_to_ts
elasticmachine Feb 18, 2020
b1c2d9a
type refactor
mattkime Feb 18, 2020
366f942
Merge branch 'create_index_pattern_components_to_ts' of github.com:ma…
mattkime Feb 18, 2020
ac65d8f
revert removal of ts-ignore
mattkime Feb 18, 2020
44a4dd1
revert removal of ts-ignore
mattkime Feb 18, 2020
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 @@ -24,9 +24,7 @@ import sinon from 'sinon';

describe('EmptyState', () => {
it('should render normally', () => {
const component = shallow(
<EmptyState loadingDataDocUrl="http://www.elastic.co" onRefresh={() => {}} />
);
const component = shallow(<EmptyState onRefresh={() => {}} />);

expect(component).toMatchSnapshot();
});
Expand All @@ -36,9 +34,7 @@ describe('EmptyState', () => {
it('is called when refresh button is clicked', () => {
const onRefreshHandler = sinon.stub();

const component = shallow(
<EmptyState loadingDataDocUrl="http://www.elastic.co" onRefresh={onRefreshHandler} />
);
const component = shallow(<EmptyState onRefresh={onRefreshHandler} />);

component.find('[data-test-subj="refreshIndicesButton"]').simulate('click');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
*/

import React from 'react';
import PropTypes from 'prop-types';

import { EuiCallOut, EuiTextColor, EuiLink, EuiButton } from '@elastic/eui';

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

export const EmptyState = ({ onRefresh }) => (
export const EmptyState = ({ onRefresh }: { onRefresh: () => void }) => (
<div>
<EuiCallOut
color="warning"
Expand Down Expand Up @@ -82,7 +81,3 @@ export const EmptyState = ({ onRefresh }) => (
</EuiCallOut>
</div>
);

EmptyState.propTypes = {
onRefresh: 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 @@ -22,17 +22,26 @@ import { Header } from '../header';
import { shallowWithI18nProvider } from 'test_utils/enzyme_helpers';

describe('Header', () => {
const indexPatternName = 'test index pattern';
it('should render normally', () => {
const component = shallowWithI18nProvider(
<Header isIncludingSystemIndices={true} onChangeIncludingSystemIndices={() => {}} />
<Header
indexPatternName={indexPatternName}
isIncludingSystemIndices={true}
onChangeIncludingSystemIndices={() => {}}
/>
);

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

it('should render without including system indices', () => {
const component = shallowWithI18nProvider(
<Header isIncludingSystemIndices={false} onChangeIncludingSystemIndices={() => {}} />
<Header
indexPatternName={indexPatternName}
isIncludingSystemIndices={false}
onChangeIncludingSystemIndices={() => {}}
/>
);

expect(component).toMatchSnapshot();
Expand All @@ -44,7 +53,7 @@ describe('Header', () => {
isIncludingSystemIndices={false}
onChangeIncludingSystemIndices={() => {}}
prompt={<div>Test prompt</div>}
indexPatternName="test index pattern"
indexPatternName={indexPatternName}
isBeta={true}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ import { FormattedMessage } from '@kbn/i18n/react';
export const Header = ({
prompt,
indexPatternName,
showSystemIndices,
showSystemIndices = false,
isIncludingSystemIndices,
onChangeIncludingSystemIndices,
isBeta,
isBeta = false,
}: {
prompt?: React.ReactNode;
indexPatternName: string;
showSystemIndices?: boolean;
isIncludingSystemIndices: boolean;
onChangeIncludingSystemIndices: () => void;
isBeta?: boolean;
}) => (
<div>
<EuiTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('Header', () => {
<Header
isInputInvalid={false}
errors={[]}
characterList={['%']}
characterList={'%'}
query={'k'}
onQueryChanged={() => {}}
goToNextStep={() => {}}
Expand All @@ -43,7 +43,7 @@ describe('Header', () => {
<Header
isInputInvalid={true}
errors={['Input is invalid']}
characterList={['%']}
characterList={'%'}
query={'%'}
onQueryChanged={() => {}}
goToNextStep={() => {}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ export const Header = ({
goToNextStep,
isNextStepDisabled,
...rest
}: {
isInputInvalid: boolean;
errors: any;
characterList: string;
query: string;
onQueryChanged: (e: React.ChangeEvent<HTMLInputElement>) => void;
goToNextStep: (query: string) => void;
isNextStepDisabled: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of inlining a type here, type this function as a React component?

interface Props {
  isInputInvalid: boolean;
  errors: any;
  characterList: string;
  query: string;
  onQueryChanged: (e: React.ChangeEvent<HTMLInputElement>) => void;
  goToNextStep: (query: string) => void;
  isNextStepDisabled: boolean;
}

const Header: React.FC<Props> = 

}) => (
<div {...rest}>
<EuiTitle size="s">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('IndicesList', () => {
it('should change pages', () => {
const component = shallow(<IndicesList indices={indices} query="" />);

const instance = component.instance();
const instance = component.instance() as IndicesList;

component.setState({ perPage: 1 });
instance.onChangePage(1);
Expand All @@ -48,7 +48,7 @@ describe('IndicesList', () => {
it('should change per page', () => {
const component = shallow(<IndicesList indices={indices} query="" />);

const instance = component.instance();
const instance = component.instance() as IndicesList;
instance.onChangePerPage(1);
component.update();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
* under the License.
*/

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { PER_PAGE_INCREMENTS } from '../../../../constants';
import React from 'react';

import {
EuiBadge,
Expand All @@ -37,17 +35,26 @@ import {
EuiPopover,
} from '@elastic/eui';

import { Pager } from '@elastic/eui/lib/services';
import { Pager } from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n/react';
import { PER_PAGE_INCREMENTS } from '../../../../constants';
import { MatchedIndex, Tag } from '../../../../types';

export class IndicesList extends Component {
static propTypes = {
indices: PropTypes.array.isRequired,
query: PropTypes.string.isRequired,
};
interface IndicesListProps {
indices: MatchedIndex[];
query: string;
}

interface IndicesListState {
page: number;
perPage: number;
isPerPageControlOpen: boolean;
}

constructor(props) {
export class IndicesList extends React.Component<IndicesListProps, IndicesListState> {
pager: Pager;
constructor(props: IndicesListProps) {
super(props);

this.state = {
Expand All @@ -59,7 +66,7 @@ export class IndicesList extends Component {
this.pager = new Pager(props.indices.length, this.state.perPage, this.state.page);
}

UNSAFE_componentWillReceiveProps(nextProps) {
UNSAFE_componentWillReceiveProps(nextProps: IndicesListProps) {
if (nextProps.indices.length !== this.props.indices.length) {
this.pager.setTotalItems(nextProps.indices.length);
this.resetPageTo0();
Expand All @@ -68,12 +75,12 @@ export class IndicesList extends Component {

resetPageTo0 = () => this.onChangePage(0);

onChangePage = page => {
onChangePage = (page: number) => {
this.pager.goToPageIndex(page);
this.setState({ page });
};

onChangePerPage = perPage => {
onChangePerPage = (perPage: number) => {
this.pager.setItemsPerPage(perPage);
this.setState({ perPage });
this.resetPageTo0();
Expand Down Expand Up @@ -147,7 +154,7 @@ export class IndicesList extends Component {
);
}

highlightIndexName(indexName, query) {
highlightIndexName(indexName: string, query: string) {
const queryIdx = indexName.indexOf(query);
if (!query || queryIdx === -1) {
return indexName;
Expand Down Expand Up @@ -178,7 +185,7 @@ export class IndicesList extends Component {
{this.highlightIndexName(index.name, queryWithoutWildcard)}
</EuiTableRowCell>
<EuiTableRowCell>
{index.tags.map(tag => {
{index.tags.map((tag: Tag) => {
return (
<EuiBadge key={`index_${key}_tag_${tag.key}`} color="primary">
{tag.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,60 @@ import React from 'react';
import { StatusMessage } from '../status_message';
import { shallow } from 'enzyme';

const tagsPartial = {
tags: [],
};

const matchedIndices = {
allIndices: [{ name: 'kibana' }, { name: 'es' }],
allIndices: [
{ name: 'kibana', ...tagsPartial },
{ name: 'es', ...tagsPartial },
],
exactMatchedIndices: [],
partialMatchedIndices: [{ name: 'kibana' }],
partialMatchedIndices: [{ name: 'kibana', ...tagsPartial }],
};

describe('StatusMessage', () => {
it('should render without a query', () => {
const component = shallow(<StatusMessage matchedIndices={matchedIndices} query={''} />);
const component = shallow(
<StatusMessage
matchedIndices={matchedIndices}
query={''}
isIncludingSystemIndices={false}
showSystemIndices={false}
/>
);

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

it('should render with exact matches', () => {
const localMatchedIndices = {
...matchedIndices,
exactMatchedIndices: [{ name: 'kibana' }],
exactMatchedIndices: [{ name: 'kibana', ...tagsPartial }],
};

const component = shallow(<StatusMessage matchedIndices={localMatchedIndices} query={'k*'} />);
const component = shallow(
<StatusMessage
matchedIndices={localMatchedIndices}
query={'k*'}
isIncludingSystemIndices={false}
showSystemIndices={false}
/>
);

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

it('should render with partial matches', () => {
const component = shallow(<StatusMessage matchedIndices={matchedIndices} query={'k'} />);
const component = shallow(
<StatusMessage
matchedIndices={matchedIndices}
query={'k'}
isIncludingSystemIndices={false}
showSystemIndices={false}
/>
);

expect(component).toMatchSnapshot();
});
Expand All @@ -57,22 +85,47 @@ describe('StatusMessage', () => {
partialMatchedIndices: [],
};

const component = shallow(<StatusMessage matchedIndices={localMatchedIndices} query={'k'} />);
const component = shallow(
<StatusMessage
matchedIndices={localMatchedIndices}
query={'k'}
isIncludingSystemIndices={false}
showSystemIndices={false}
/>
);

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

it('should show that system indices exist', () => {
const component = shallow(
<StatusMessage matchedIndices={[]} isIncludingSystemIndices={false} query={''} />
<StatusMessage
matchedIndices={{
allIndices: [],
exactMatchedIndices: [],
partialMatchedIndices: [],
}}
isIncludingSystemIndices={false}
query={''}
showSystemIndices={false}
/>
);

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

it('should show that no indices exist', () => {
const component = shallow(
<StatusMessage matchedIndices={[]} isIncludingSystemIndices={true} query={''} />
<StatusMessage
matchedIndices={{
allIndices: [],
exactMatchedIndices: [],
partialMatchedIndices: [],
}}
isIncludingSystemIndices={true}
query={''}
showSystemIndices={false}
/>
);

expect(component).toMatchSnapshot();
Expand Down
Loading