Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -0,0 +1,41 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import getEffectiveExtraFilters from 'src/dashboard/util/charts/getEffectiveExtraFilters';

describe('getEffectiveExtraFilters', () => {
it('should create IN operator for arrays', () => {
const result = getEffectiveExtraFilters({
gender: ['girl'],
name: null,
__time_range: ' : 2020-07-17T00:00:00',
});
expect(result).toMatchObject([
{
col: 'gender',
op: 'IN',
val: ['girl'],
},
{
col: '__time_range',
op: '=',
val: ' : 2020-07-17T00:00:00',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import { DataRecordFilters } from '@superset-ui/chart';

export default function getEffectiveExtraFilters(filters: DataRecordFilters) {
return Object.entries(filters).map(([column, values]) => ({
col: column,
op: 'in',
val: values,
}));
return Object.entries(filters)
.map(([column, values]) => ({
col: column,
op: Array.isArray(values) ? 'IN' : '=',
val: values,
}))
.filter(filter => filter.val !== null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

when user clear out a filter, it's value will be null, and we need to send out this to backend.

@villebro villebro Jul 21, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@graceguo-supercat when the filter is cleared, the filter will be removed, thus triggering a filter event (tested that it works properly on both legacy and new charts). Having an undefined value for a binary or set filter is also invalid according to the type declarations on superset-ui, so if this is the case we probably need to make changes there. See https://github.com/apache-superset/superset-ui/blob/97e7ba99d0efc363805a415f5f1a646f781ba1fb/packages/superset-ui-query/src/types/Query.ts#L8-L22

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

agree!

}
2 changes: 1 addition & 1 deletion superset/charts/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ class ChartDataQueryObjectSchema(Schema):
fields.Dict(),
description="HAVING filters to be added to legacy Druid datasource queries. "
"This field is deprecated and should be passed to `extras` "
"as `filters_druid`.",
"as `having_druid`.",
deprecated=True,
)

Expand Down