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

[APM] UI filters: Change transaction type selector from dropdown to radio buttons #75625

Merged
merged 7 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -4,25 +4,23 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import {
fireEvent,
getByText,
queryByLabelText,
render,
getByText,
getByDisplayValue,
queryByDisplayValue,
fireEvent,
} from '@testing-library/react';
import { omit } from 'lodash';
import { history } from '../../../../utils/history';
import React from 'react';
import { Router } from 'react-router-dom';
import { TransactionOverview } from '..';
import { MockApmPluginContextWrapper } from '../../../../context/ApmPluginContext/MockApmPluginContext';
import { UrlParamsProvider } from '../../../../context/UrlParamsContext';
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
import * as useServiceTransactionTypesHook from '../../../../hooks/useServiceTransactionTypes';
import * as useFetcherHook from '../../../../hooks/useFetcher';
import * as useServiceTransactionTypesHook from '../../../../hooks/useServiceTransactionTypes';
import { history } from '../../../../utils/history';
import { fromQuery } from '../../../shared/Links/url_helpers';
import { Router } from 'react-router-dom';
import { UrlParamsProvider } from '../../../../context/UrlParamsContext';
import { MockApmPluginContextWrapper } from '../../../../context/ApmPluginContext/MockApmPluginContext';

jest.spyOn(history, 'push');
jest.spyOn(history, 'replace');
Expand Down Expand Up @@ -85,7 +83,7 @@ describe('TransactionOverview', () => {
const FILTER_BY_TYPE_LABEL = 'Transaction type';

describe('when transactionType is selected and multiple transaction types are given', () => {
it('should render dropdown with transaction types', () => {
it('should render radio group with transaction types', () => {
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
const { container } = setup({
serviceTransactionTypes: ['firstType', 'secondType'],
urlParams: {
Expand All @@ -94,9 +92,8 @@ describe('TransactionOverview', () => {
},
});

// secondType is selected in the dropdown
expect(queryByDisplayValue(container, 'secondType')).not.toBeNull();
expect(queryByDisplayValue(container, 'firstType')).toBeNull();
expect(getByText(container, 'firstType')).toBeInTheDocument();
expect(getByText(container, 'secondType')).toBeInTheDocument();

expect(getByText(container, 'firstType')).not.toBeNull();
});
Expand All @@ -110,22 +107,19 @@ describe('TransactionOverview', () => {
},
});

expect(queryByDisplayValue(container, 'firstType')).toBeNull();
expect(history.location.search).toEqual('?transactionType=secondType');
expect(getByText(container, 'firstType')).toBeInTheDocument();
expect(getByText(container, 'secondType')).toBeInTheDocument();

fireEvent.change(getByDisplayValue(container, 'secondType'), {
target: { value: 'firstType' },
});
fireEvent.click(getByText(container, 'firstType'));

expect(history.push).toHaveBeenCalled();

getByDisplayValue(container, 'firstType');

expect(queryByDisplayValue(container, 'firstType')).not.toBeNull();
expect(history.location.search).toEqual('?transactionType=firstType');
});
});

describe('when a transaction type is selected, and there are no other transaction types', () => {
it('should not render a dropdown with transaction types', () => {
it('should not render radio group with transaction types', () => {
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
const { container } = setup({
serviceTransactionTypes: ['firstType'],
urlParams: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
EuiTitle,
EuiHorizontalRule,
EuiSpacer,
EuiSelect,
EuiRadioGroup,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useUrlParams } from '../../../../hooks/useUrlParams';
Expand All @@ -26,8 +26,8 @@ function TransactionTypeFilter({ transactionTypes }: Props) {
} = useUrlParams();

const options = transactionTypes.map((type) => ({
text: type,
value: type,
id: type,
label: type,
}));

return (
Expand All @@ -42,16 +42,15 @@ function TransactionTypeFilter({ transactionTypes }: Props) {
<EuiSpacer size="s" />
<EuiHorizontalRule margin="none" />
<EuiSpacer size="s" />
<EuiSelect
<EuiRadioGroup
options={options}
value={transactionType}
compressed={true}
onChange={(event) => {
idSelected={transactionType}
onChange={(selectedTransactionType) => {
const newLocation = {
...history.location,
search: fromQuery({
...toQuery(history.location.search),
transactionType: event.target.value,
transactionType: selectedTransactionType,
}),
};
history.push(newLocation);
Expand Down