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: Null values on Explore filter #19341

Merged
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
18 changes: 11 additions & 7 deletions superset-frontend/src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import Icons from 'src/components/Icons';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { SLOW_DEBOUNCE } from 'src/constants';
import { rankedSearchCompare } from 'src/utils/rankedSearchCompare';
import { getValue, hasOption } from './utils';
import { getValue, hasOption, isObject } from './utils';

const { Option } = AntdSelect;

Expand Down Expand Up @@ -385,18 +385,20 @@ const Select = (

const hasCustomLabels = fullSelectOptions.some(opt => !!opt?.customLabel);

const handleOnSelect = (selectedItem: string | number | AntdLabeledValue) => {
const handleOnSelect = (
selectedItem: string | number | AntdLabeledValue | undefined,
) => {
if (isSingleMode) {
setSelectValue(selectedItem);
} else {
setSelectValue(previousState => {
const array = ensureIsArray(previousState);
const isObject = typeof selectedItem === 'object';
const value = isObject ? selectedItem.value : selectedItem;
const isLabeledValue = isObject(selectedItem);
const value = isLabeledValue ? selectedItem.value : selectedItem;
// Tokenized values can contain duplicated values
if (!hasOption(value, array)) {
const result = [...array, selectedItem];
return isObject
return isLabeledValue
? (result as AntdLabeledValue[])
: (result as (string | number)[]);
}
Expand All @@ -406,9 +408,11 @@ const Select = (
setInputValue('');
};

const handleOnDeselect = (value: string | number | AntdLabeledValue) => {
const handleOnDeselect = (
value: string | number | AntdLabeledValue | undefined,
) => {
if (Array.isArray(selectValue)) {
if (typeof value === 'number' || typeof value === 'string') {
if (typeof value === 'number' || typeof value === 'string' || !value) {
const array = selectValue as (string | number)[];
setSelectValue(array.filter(element => element !== value));
} else {
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/components/Select/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
GroupedOptionsType,
} from 'react-select';

function isObject(value: unknown): value is Record<string, unknown> {
export function isObject(value: unknown): value is Record<string, unknown> {
return (
value !== null &&
typeof value === 'object' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,15 @@ const AdhocFilterEditPopoverSimpleTabContent: React.FC<Props> = props => {
{...operatorSelectProps}
/>
{MULTI_OPERATORS.has(operatorId) || suggestions.length > 0 ? (
<SelectWithLabel
labelText={labelText}
options={suggestions}
{...comparatorSelectProps}
/>
// We need to delay rendering the select because we can't pass a primitive value without options
// We can't pass value = [null] and options=[]
comparatorSelectProps.value && suggestions.length === 0 ? null : (
<SelectWithLabel
labelText={labelText}
options={suggestions}
{...comparatorSelectProps}
/>
)
) : (
<StyledInput
data-test="adhoc-filter-simple-value"
Expand Down