Skip to content

Commit

Permalink
Index pattern management - typescript components (#56987)
Browse files Browse the repository at this point in the history
* Index pattern management - typescript components
  • Loading branch information
mattkime authored Feb 18, 2020
1 parent f6dc674 commit 911981d
Show file tree
Hide file tree
Showing 64 changed files with 509 additions and 312 deletions.
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 @@ -33,7 +33,17 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

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

export const Header: React.FC<HeaderProps> = ({
isInputInvalid,
errors,
characterList,
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

0 comments on commit 911981d

Please sign in to comment.