fix: filterbox apply single value (#14841)

* fix: filterbox apply single value

* fix ci

* fix e2e
This commit is contained in:
Yongjie Zhao 2021-05-27 07:00:48 +01:00 committed by GitHub
parent bd2c087f78
commit 9f54231af1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 12 deletions

View File

@ -70,8 +70,8 @@ describe('Dashboard filter', () => {
} }
expect(requestFilter).deep.eq({ expect(requestFilter).deep.eq({
col: 'region', col: 'region',
op: '==', op: 'IN',
val: 'South Asia', val: ['South Asia'],
}); });
}); });
}); });

View File

@ -121,8 +121,8 @@ describe('Dashboard tabs', () => {
const requestParams = JSON.parse(requestBody.form_data as string); const requestParams = JSON.parse(requestBody.form_data as string);
expect(requestParams.extra_filters[0]).deep.eq({ expect(requestParams.extra_filters[0]).deep.eq({
col: 'region', col: 'region',
op: '==', op: 'IN',
val: 'South Asia', val: ['South Asia'],
}); });
}); });
}); });
@ -136,8 +136,8 @@ describe('Dashboard tabs', () => {
const requestParams = JSON.parse(requestBody.form_data as string); const requestParams = JSON.parse(requestBody.form_data as string);
expect(requestParams.extra_filters[0]).deep.eq({ expect(requestParams.extra_filters[0]).deep.eq({
col: 'region', col: 'region',
op: '==', op: 'IN',
val: 'South Asia', val: ['South Asia'],
}); });
expect(requestParams.viz_type).eq(LINE_CHART.viz); expect(requestParams.viz_type).eq(LINE_CHART.viz);
}); });
@ -150,8 +150,8 @@ describe('Dashboard tabs', () => {
cy.wait('@v1ChartData').then(({ request }) => { cy.wait('@v1ChartData').then(({ request }) => {
expect(request.body.queries[0].filters[0]).deep.eq({ expect(request.body.queries[0].filters[0]).deep.eq({
col: 'region', col: 'region',
op: '==', op: 'IN',
val: 'South Asia', val: ['South Asia'],
}); });
}); });

View File

@ -22,7 +22,7 @@ import { debounce } from 'lodash';
import { max as d3Max } from 'd3-array'; import { max as d3Max } from 'd3-array';
import { AsyncCreatableSelect, CreatableSelect } from 'src/components/Select'; import { AsyncCreatableSelect, CreatableSelect } from 'src/components/Select';
import Button from 'src/components/Button'; import Button from 'src/components/Button';
import { t, SupersetClient } from '@superset-ui/core'; import { t, SupersetClient, ensureIsArray } from '@superset-ui/core';
import { import {
BOOL_FALSE_DISPLAY, BOOL_FALSE_DISPLAY,
@ -158,10 +158,9 @@ class FilterBox extends React.PureComponent {
if (options !== null) { if (options !== null) {
if (Array.isArray(options)) { if (Array.isArray(options)) {
vals = options.map(opt => (typeof opt === 'string' ? opt : opt.value)); vals = options.map(opt => (typeof opt === 'string' ? opt : opt.value));
} else if (options.value) {
vals = options.value;
} else { } else {
vals = options; // must use array member for legacy extra_filters's value
vals = ensureIsArray(options.value ?? options);
} }
} }