<div className="display-flex-center">
{!isFileComponent && metric && (
<>
- <div>{translate('component_measures.view_as')}</div>
+ <div id="measures-view-selection-label">
+ {translate('component_measures.view_as')}
+ </div>
<MeasureViewSelect
className="measure-view-select spacer-left big-spacer-right"
handleViewChange={this.updateView}
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import * as React from 'react';
-import SelectLegacy from '../../../components/controls/SelectLegacy';
+import { components, OptionProps, SingleValueProps } from 'react-select';
+import Select from '../../../components/controls/Select';
import ListIcon from '../../../components/icons/ListIcon';
import TreeIcon from '../../../components/icons/TreeIcon';
import TreemapIcon from '../../../components/icons/TreemapIcon';
view: MeasurePageView;
}
+interface ViewOption {
+ icon: JSX.Element;
+ label: string;
+ value: string;
+}
+
export default class MeasureViewSelect extends React.PureComponent<Props> {
getOptions = () => {
const { metric } = this.props;
- const options = [];
+ const options: ViewOption[] = [];
if (hasTree(metric.key)) {
options.push({
icon: <TreeIcon />,
return options;
};
- handleChange = (option: { value: string }) => {
+ handleChange = (option: ViewOption) => {
return this.props.handleViewChange(option.value as MeasurePageView);
};
- renderOption = (option: { icon: JSX.Element; label: string }) => {
- return (
- <>
- {option.icon}
- <span className="little-spacer-left">{option.label}</span>
- </>
- );
- };
+ renderOption = (props: OptionProps<ViewOption, false>) => (
+ <components.Option {...props} className="display-flex-center">
+ {props.data.icon}
+ <span className="little-spacer-left">{props.data.label}</span>
+ </components.Option>
+ );
+
+ renderValue = (props: SingleValueProps<ViewOption>) => (
+ <components.SingleValue {...props} className="display-flex-center">
+ {props.data.icon}
+ <span className="little-spacer-left">{props.data.label}</span>
+ </components.SingleValue>
+ );
render() {
+ const { className, view } = this.props;
+ const options = this.getOptions();
+
return (
- <SelectLegacy
+ <Select
+ aria-labelledby="measures-view-selection-label"
autoBlur={true}
- className={this.props.className}
- clearable={false}
+ className={className}
onChange={this.handleChange}
- optionRenderer={this.renderOption}
- options={this.getOptions()}
- searchable={false}
- value={this.props.view}
- valueRenderer={this.renderOption}
+ components={{
+ Option: this.renderOption,
+ SingleValue: this.renderValue
+ }}
+ options={options}
+ isSearchable={false}
+ value={options.find(o => o.value === view)}
/>
);
}
*/
import { shallow } from 'enzyme';
import * as React from 'react';
+import ListIcon from '../../../../components/icons/ListIcon';
import { mockMetric } from '../../../../helpers/testMocks';
import { MetricKey } from '../../../../types/metrics';
import MeasureViewSelect from '../MeasureViewSelect';
it('should correctly trigger a selection change', () => {
const handleViewChange = jest.fn();
const wrapper = shallowRender({ handleViewChange });
- wrapper.instance().handleChange({ value: 'list' });
+ wrapper.instance().handleChange({ icon: <ListIcon />, label: 'List View', value: 'list' });
expect(handleViewChange).toBeCalledWith('list');
});
className="display-flex-center"
>
<React.Fragment>
- <div>
+ <div
+ id="measures-view-selection-label"
+ >
component_measures.view_as
</div>
<MeasureViewSelect
className="display-flex-center"
>
<React.Fragment>
- <div>
+ <div
+ id="measures-view-selection-label"
+ >
component_measures.view_as
</div>
<MeasureViewSelect
className="display-flex-center"
>
<React.Fragment>
- <div>
+ <div
+ id="measures-view-selection-label"
+ >
component_measures.view_as
</div>
<MeasureViewSelect
className="display-flex-center"
>
<React.Fragment>
- <div>
+ <div
+ id="measures-view-selection-label"
+ >
component_measures.view_as
</div>
<MeasureViewSelect
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`should render correctly: has no list 1`] = `
-<SelectLegacy
+<Select
+ aria-labelledby="measures-view-selection-label"
autoBlur={true}
- clearable={false}
+ components={
+ Object {
+ "Option": [Function],
+ "SingleValue": [Function],
+ }
+ }
+ isSearchable={false}
onChange={[Function]}
- optionRenderer={[Function]}
options={
Array [
Object {
},
]
}
- searchable={false}
- value="list"
- valueRenderer={[Function]}
/>
`;
exports[`should render correctly: has no tree 1`] = `
-<SelectLegacy
+<Select
+ aria-labelledby="measures-view-selection-label"
autoBlur={true}
- clearable={false}
+ components={
+ Object {
+ "Option": [Function],
+ "SingleValue": [Function],
+ }
+ }
+ isSearchable={false}
onChange={[Function]}
- optionRenderer={[Function]}
options={
Array [
Object {
},
]
}
- searchable={false}
- value="list"
- valueRenderer={[Function]}
+ value={
+ Object {
+ "icon": <ListIcon />,
+ "label": "component_measures.tab.list",
+ "value": "list",
+ }
+ }
/>
`;
exports[`should render correctly: has no treemap 1`] = `
-<SelectLegacy
+<Select
+ aria-labelledby="measures-view-selection-label"
autoBlur={true}
- clearable={false}
+ components={
+ Object {
+ "Option": [Function],
+ "SingleValue": [Function],
+ }
+ }
+ isSearchable={false}
onChange={[Function]}
- optionRenderer={[Function]}
options={
Array [
Object {
},
]
}
- searchable={false}
- value="list"
- valueRenderer={[Function]}
+ value={
+ Object {
+ "icon": <ListIcon />,
+ "label": "component_measures.tab.list",
+ "value": "list",
+ }
+ }
/>
`;
}
}
-.measure-view-select {
- width: 102px;
-}
-
-.measure-view-select .Select-menu-outer {
- width: 100px;
- border-top-right-radius: 4px;
-}
-
.measure-content-header {
display: flex;
align-items: center;
}
+.measure-content-header .measure-view-select {
+ width: 102px;
+}
+
.measure-content-header-left {
flex: 1;
min-width: 0;