[filter_box] dashboard should carry defaultValue in filter_box (#8812)

This commit is contained in:
Grace Guo 2019-12-12 11:01:18 -08:00 committed by GitHub
parent ed54f6ec8d
commit 1d3c93ccb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View File

@ -20,6 +20,16 @@ import getFilterConfigsFromFormdata from '../../../../src/dashboard/util/getFilt
describe('getFilterConfigsFromFormdata', () => { describe('getFilterConfigsFromFormdata', () => {
const testFormdata = { const testFormdata = {
filter_configs: [
{
asc: true,
clearable: true,
column: 'state',
defaultValue: 'CA',
key: 'fvwncPjUf',
multiple: true,
},
],
date_filter: true, date_filter: true,
granularity_sqla: '__time', granularity_sqla: '__time',
time_grain_sqla: 'P1M', time_grain_sqla: 'P1M',
@ -45,4 +55,14 @@ describe('getFilterConfigsFromFormdata', () => {
__time_col: testFormdata.granularity_sqla, __time_col: testFormdata.granularity_sqla,
}); });
}); });
it('should use default value from form_data', () => {
const result = getFilterConfigsFromFormdata({
...testFormdata,
show_sqla_time_column: true,
});
expect(result.columns).toMatchObject({
state: 'CA',
});
});
}); });

View File

@ -33,7 +33,7 @@ export default function getFilterConfigsFromFormdata(form_data = {}) {
({ columns, labels }, config) => { ({ columns, labels }, config) => {
const updatedColumns = { const updatedColumns = {
...columns, ...columns,
[config.column]: config.vals, [config.column]: config.vals || config.defaultValue,
}; };
const updatedLabels = { const updatedLabels = {
...labels, ...labels,