Skip to content
This repository has been archived by the owner on Jan 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #104 from Terralego/fix-filter-panel-content-hoc
Browse files Browse the repository at this point in the history
Fix connect HOC on FilterPanelContent
  • Loading branch information
Sébastien Corbin authored Sep 16, 2019
2 parents 8745e75 + 937a85c commit a129116
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/modules/Forms/Controls/RangeNumeric.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class RangeNumeric extends RangeComponent {
onNumericInputChange = pos => bound => {
const { onChange, min, max } = this.props;
const { range } = this.state;
if (Number.isNaN(+bound)) return; // Sanity check that allows typing '-'
range[pos] = bound;
this.setState({ range });

Expand Down
9 changes: 8 additions & 1 deletion src/modules/Forms/Controls/RangeNumeric.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock('@blueprintjs/core', () => ({
Intent: { DANGER: 'danger' },
}));

it('should handle numeric change', async () => {
it('should handle numeric change', () => {
const onChange = jest.fn();
const wrapper = mount(<RangeNumeric onChange={onChange} />);
expect(wrapper.find('NumericInput').last().prop('value')).toBe(100);
Expand All @@ -18,6 +18,13 @@ it('should handle numeric change', async () => {
expect(onChange).toHaveBeenCalled();
});

it('should allow typing minus', () => {
const instance = new RangeNumeric({});
instance.setState = jest.fn();
instance.onNumericInputChange(0)('-');
expect(instance.setState).not.toHaveBeenCalled();
});

it('should update range numeric if props are changed', () => {
const wrapper = mount(<RangeNumeric max={1000} />);
expect(wrapper.state().range).toEqual([0, 1000]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ import FiltersPanelContent from './FiltersPanelContent';

import { connectLayersTree } from '../../../LayersTreeProvider/context';

export default connectLayersTree('translate', ({ getLayerState }, { layer, layer: { exclusive, layers } }) => {
export default connectLayersTree((
{ getLayerState, translate }, // context
{ layer, layer: { exclusive, layers } }, // props
) => {
const activeLayer = exclusive
? layers.find(l => getLayerState({ layer: l }).active) || layer
: layer;

return {
filtersValues: getLayerState({ layer: activeLayer }).filters || {},
activeLayer,
translate,
};
})(FiltersPanelContent);

0 comments on commit a129116

Please sign in to comment.