-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
169 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/lens/public/shared_components/value_labels_settings.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallowWithIntl as shallow } from '@kbn/test/jest'; | ||
import { ValueLabelsSettings, VisualOptionsProps } from './value_labels_settings'; | ||
|
||
describe('Value labels Settings', () => { | ||
let props: VisualOptionsProps; | ||
beforeEach(() => { | ||
props = { | ||
onValueLabelChange: jest.fn(), | ||
}; | ||
}); | ||
|
||
it('should not render the component if not enabled', () => { | ||
const component = shallow(<ValueLabelsSettings {...props} isVisible={false} />); | ||
expect(component.find('[data-test-subj="lens-value-labels-visibility-btn"]').length).toEqual(0); | ||
}); | ||
|
||
it('should set hide as default value', () => { | ||
const component = shallow(<ValueLabelsSettings {...props} />); | ||
expect( | ||
component.find('[data-test-subj="lens-value-labels-visibility-btn"]').prop('idSelected') | ||
).toEqual(`value_labels_hide`); | ||
}); | ||
|
||
it('should have called onValueLabelChange function on ButtonGroup change', () => { | ||
const component = shallow(<ValueLabelsSettings {...props} />); | ||
component | ||
.find('[data-test-subj="lens-value-labels-visibility-btn"]') | ||
.simulate('change', 'value_labels_inside'); | ||
expect(props.onValueLabelChange).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should render the passed value if given', () => { | ||
const component = shallow(<ValueLabelsSettings {...props} valueLabels="inside" />); | ||
expect( | ||
component.find('[data-test-subj="lens-value-labels-visibility-btn"]').prop('idSelected') | ||
).toEqual(`value_labels_inside`); | ||
}); | ||
}); |
75 changes: 75 additions & 0 deletions
75
x-pack/plugins/lens/public/shared_components/value_labels_settings.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { FC } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiButtonGroup, EuiFormRow } from '@elastic/eui'; | ||
import { ValueLabelConfig } from '../../common/types'; | ||
|
||
const valueLabelsOptions: Array<{ | ||
id: string; | ||
value: ValueLabelConfig; | ||
label: string; | ||
'data-test-subj': string; | ||
}> = [ | ||
{ | ||
id: `value_labels_hide`, | ||
value: 'hide', | ||
label: i18n.translate('xpack.lens.shared.valueLabelsVisibility.auto', { | ||
defaultMessage: 'Hide', | ||
}), | ||
'data-test-subj': 'lns_valueLabels_hide', | ||
}, | ||
{ | ||
id: `value_labels_inside`, | ||
value: 'inside', | ||
label: i18n.translate('xpack.lens.shared.valueLabelsVisibility.inside', { | ||
defaultMessage: 'Show', | ||
}), | ||
'data-test-subj': 'lns_valueLabels_inside', | ||
}, | ||
]; | ||
|
||
export interface VisualOptionsProps { | ||
isVisible?: boolean; | ||
valueLabels?: ValueLabelConfig; | ||
onValueLabelChange: (newMode: ValueLabelConfig) => void; | ||
} | ||
|
||
export const ValueLabelsSettings: FC<VisualOptionsProps> = ({ | ||
isVisible = true, | ||
valueLabels = 'hide', | ||
onValueLabelChange, | ||
}) => { | ||
if (!isVisible) { | ||
return null; | ||
} | ||
const label = i18n.translate('xpack.lens.shared.chartValueLabelVisibilityLabel', { | ||
defaultMessage: 'Labels', | ||
}); | ||
const isSelected = | ||
valueLabelsOptions.find(({ value }) => value === valueLabels)?.id || 'value_labels_hide'; | ||
return ( | ||
<EuiFormRow display="columnCompressed" label={<span>{label}</span>}> | ||
<EuiButtonGroup | ||
isFullWidth | ||
legend={label} | ||
data-test-subj="lens-value-labels-visibility-btn" | ||
name="valueLabelsDisplay" | ||
buttonSize="compressed" | ||
options={valueLabelsOptions} | ||
idSelected={isSelected} | ||
onChange={(modeId) => { | ||
const newMode = valueLabelsOptions.find(({ id }) => id === modeId); | ||
if (newMode) { | ||
onValueLabelChange(newMode.value); | ||
} | ||
}} | ||
/> | ||
</EuiFormRow> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.