Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] dashboard filter indicator no showing single number value #9401

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isEmpty(number) will return true, this caused indicator didn't show the selected filter value.

? []
: [].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