fix: [filter_box] fix 2 issues in single value filter_box (#9829)

* fix: [filter_box] fix 2 issues in single value filter_box

* add unit test

* add fix per comments
This commit is contained in:
Grace Guo
2020-05-18 21:25:10 -07:00
committed by GitHub
parent e121e090c7
commit d96bb874f2
5 changed files with 121 additions and 12 deletions

View File

@@ -31,7 +31,10 @@ import OnPasteSelect from '../../components/OnPasteSelect';
import VirtualizedRendererWrap from '../../components/VirtualizedRendererWrap';
import { getDashboardFilterKey } from '../../dashboard/util/getDashboardFilterKey';
import { getFilterColorMap } from '../../dashboard/util/dashboardFiltersColorMap';
import { TIME_FILTER_LABELS } from '../../explore/constants';
import {
FILTER_CONFIG_ATTRIBUTES,
TIME_FILTER_LABELS,
} from '../../explore/constants';
import FilterBadgeIcon from '../../components/FilterBadgeIcon';
import './FilterBox.less';
@@ -259,19 +262,22 @@ class FilterBox extends React.Component {
let value = selectedValues[key] || null;
// Assign default value if required
if (!value && filterConfig.defaultValue) {
if (filterConfig.multiple) {
if (
value === undefined &&
filterConfig[FILTER_CONFIG_ATTRIBUTES.DEFAULT_VALUE]
) {
if (filterConfig[FILTER_CONFIG_ATTRIBUTES.MULTIPLE]) {
// Support for semicolon-delimited multiple values
value = filterConfig.defaultValue.split(';');
value = filterConfig[FILTER_CONFIG_ATTRIBUTES.DEFAULT_VALUE].split(';');
} else {
value = filterConfig.defaultValue;
value = filterConfig[FILTER_CONFIG_ATTRIBUTES.DEFAULT_VALUE];
}
}
return (
<OnPasteSelect
placeholder={t('Select [%s]', label)}
key={key}
multi={filterConfig.multiple}
multi={filterConfig[FILTER_CONFIG_ATTRIBUTES.MULTIPLE]}
clearable={filterConfig.clearable}
value={value}
options={data.map(opt => {