Skip to content

Commit

Permalink
[fix] dashboard filter indicator no showing single number value (#9401)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace Guo authored Mar 30, 2020
1 parent ce3031b commit a9ff51b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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],
Expand All @@ -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,
Expand Down

0 comments on commit a9ff51b

Please sign in to comment.