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

fix(native-filters): Range filter max/min default display value #21680

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -18,7 +18,7 @@
*/
import { AppSection, GenericDataType } from '@superset-ui/core';
import React from 'react';
import { render } from 'spec/helpers/testing-library';
import { render, screen } from 'spec/helpers/testing-library';
import RangeFilterPlugin from './RangeFilterPlugin';
import { SingleValueType } from './SingleValueType';
import transformProps from './transformProps';
Expand Down Expand Up @@ -121,41 +121,49 @@ describe('RangeFilterPlugin', () => {
});

it('should call setDataMask with correct greater than filter', () => {
getWrapper({ enableSingleValue: SingleValueType.Minimum });
getWrapper({
enableSingleValue: SingleValueType.Minimum,
defaultValue: [20, 60],
});
expect(setDataMask).toHaveBeenCalledWith({
extraFormData: {
filters: [
{
col: 'SP_POP_TOTL',
op: '>=',
val: 70,
val: 20,
},
],
},
filterState: {
label: 'x ≥ 70',
value: [70, 100],
label: 'x ≥ 20',
value: [20, 100],
},
});
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuenow', '20');
});

it('should call setDataMask with correct less than filter', () => {
getWrapper({ enableSingleValue: SingleValueType.Maximum });
getWrapper({
enableSingleValue: SingleValueType.Maximum,
defaultValue: [20, 60],
});
expect(setDataMask).toHaveBeenCalledWith({
extraFormData: {
filters: [
{
col: 'SP_POP_TOTL',
op: '<=',
val: 70,
val: 60,
},
],
},
filterState: {
label: 'x ≤ 70',
value: [10, 70],
label: 'x ≤ 60',
value: [10, 60],
},
});
expect(screen.getByRole('slider')).toHaveAttribute('aria-valuenow', '60');
});

it('should call setDataMask with correct exact filter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ export default function RangeFilterPlugin(props: PluginFilterRangeProps) {

useEffect(() => {
if (enableSingleMaxValue) {
handleAfterChange([min, minMax[minIndex]]);
handleAfterChange([min, minMax[maxIndex]]);
}
}, [enableSingleMaxValue]);

useEffect(() => {
if (enableSingleMinValue) {
handleAfterChange([minMax[maxIndex], max]);
handleAfterChange([minMax[minIndex], max]);
}
}, [enableSingleMinValue]);

Expand Down