mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
[fix] dashboard filter indicator no showing single number value (#9401)
This commit is contained in:
@@ -85,4 +85,25 @@ describe('FilterIndicatorsContainer', () => {
|
||||
const wrapper = setup({ dashboardFilters: overwriteDashboardFilters });
|
||||
expect(wrapper.find(FilterIndicator)).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('should show single number type value', () => {
|
||||
const overwriteDashboardFilters = {
|
||||
...dashboardFilters,
|
||||
[filterId]: {
|
||||
...dashboardFilters[filterId],
|
||||
columns: {
|
||||
testField: 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
const wrapper = setup({ dashboardFilters: overwriteDashboardFilters });
|
||||
expect(wrapper.find(FilterIndicator)).toHaveLength(1);
|
||||
|
||||
const indicatorProps = wrapper
|
||||
.find(FilterIndicator)
|
||||
.first()
|
||||
.props().indicator;
|
||||
expect(indicatorProps.label).toEqual('testField');
|
||||
expect(indicatorProps.values).toEqual([0]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { isEmpty, isNil } from 'lodash';
|
||||
|
||||
import FilterIndicator from './FilterIndicator';
|
||||
import FilterIndicatorGroup from './FilterIndicatorGroup';
|
||||
@@ -101,6 +101,15 @@ export default class FilterIndicatorsContainer extends React.PureComponent {
|
||||
chartId,
|
||||
column: name,
|
||||
});
|
||||
|
||||
// filter values could be single value or array of values
|
||||
const values =
|
||||
isNil(columns[name]) ||
|
||||
(isDateFilter && columns[name] === 'No filter') ||
|
||||
(Array.isArray(columns[name]) && columns[name].length === 0)
|
||||
? []
|
||||
: [].concat(columns[name]);
|
||||
|
||||
const indicator = {
|
||||
chartId,
|
||||
colorCode: dashboardFiltersColorMap[colorMapKey],
|
||||
@@ -110,11 +119,7 @@ export default class FilterIndicatorsContainer extends React.PureComponent {
|
||||
isInstantFilter,
|
||||
name,
|
||||
label: labels[name] || name,
|
||||
values:
|
||||
isEmpty(columns[name]) ||
|
||||
(isDateFilter && columns[name] === 'No filter')
|
||||
? []
|
||||
: [].concat(columns[name]),
|
||||
values,
|
||||
isFilterFieldActive:
|
||||
chartId === filterFieldOnFocus.chartId &&
|
||||
name === filterFieldOnFocus.column,
|
||||
|
||||
Reference in New Issue
Block a user