mirror of
https://github.com/apache/superset.git
synced 2024-09-06 05:47:43 -04:00
fix: show TIME COLUMN options in dashboard (#11210)
* fix: show TIME COLUMN options in dashboard * add unit test
This commit is contained in:
parent
4f4367edf3
commit
88af85ac53
@ -17,9 +17,10 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { shallow } from 'enzyme';
|
import { shallow, mount } from 'enzyme';
|
||||||
|
|
||||||
import FilterBox from 'src/visualizations/FilterBox/FilterBox';
|
import FilterBox from 'src/visualizations/FilterBox/FilterBox';
|
||||||
|
import SelectControl from 'src/explore/components/controls/SelectControl';
|
||||||
|
|
||||||
describe('FilterBox', () => {
|
describe('FilterBox', () => {
|
||||||
it('should only add defined non-predefined options to filtersChoices', () => {
|
it('should only add defined non-predefined options to filtersChoices', () => {
|
||||||
@ -58,4 +59,30 @@ describe('FilterBox', () => {
|
|||||||
inst.setState({ selectedValues: { name: 'James' } });
|
inst.setState({ selectedValues: { name: 'James' } });
|
||||||
expect(inst.props.filtersChoices.name.length).toEqual(3);
|
expect(inst.props.filtersChoices.name.length).toEqual(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should support granularity_sqla options', () => {
|
||||||
|
const wrapper = mount(
|
||||||
|
<FilterBox
|
||||||
|
chartId={1001}
|
||||||
|
datasource={{
|
||||||
|
id: 1,
|
||||||
|
columns: [],
|
||||||
|
databases: {},
|
||||||
|
granularity_sqla: [
|
||||||
|
['created_on', 'created_on'],
|
||||||
|
['changed_on', 'changed_on'],
|
||||||
|
],
|
||||||
|
}}
|
||||||
|
showSqlaTimeColumn
|
||||||
|
instantFiltering
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(wrapper.find(SelectControl).props().choices).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
['created_on', 'created_on'],
|
||||||
|
['changed_on', 'changed_on'],
|
||||||
|
]),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -316,12 +316,12 @@ export const controls = {
|
|||||||
mapStateToProps: state => {
|
mapStateToProps: state => {
|
||||||
const props = {};
|
const props = {};
|
||||||
if (state.datasource) {
|
if (state.datasource) {
|
||||||
props.options = state.datasource.columns.filter(c => c.is_dttm);
|
props.choices = state.datasource.granularity_sqla;
|
||||||
props.default = null;
|
props.default = null;
|
||||||
if (state.datasource.main_dttm_col) {
|
if (state.datasource.main_dttm_col) {
|
||||||
props.default = state.datasource.main_dttm_col;
|
props.default = state.datasource.main_dttm_col;
|
||||||
} else if (props.options && props.options.length > 0) {
|
} else if (props.choices && props.choices.length > 0) {
|
||||||
props.default = props.options[0].column_name;
|
props.default = props.choices[0].column_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return props;
|
return props;
|
||||||
|
@ -406,7 +406,7 @@ class FilterBox extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
renderFilters() {
|
renderFilters() {
|
||||||
const { filtersFields, chartId } = this.props;
|
const { filtersFields = [], chartId } = this.props;
|
||||||
return filtersFields.map(filterConfig => {
|
return filtersFields.map(filterConfig => {
|
||||||
const { label, key } = filterConfig;
|
const { label, key } = filterConfig;
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user