Skip to content

Commit

Permalink
feat(native-filters): add sort metric to select (#14590)
Browse files Browse the repository at this point in the history
(cherry picked from commit f1c32b9)
  • Loading branch information
villebro authored and amitmiran137 committed May 13, 2021
1 parent 69e24bb commit 09e871e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
59 changes: 59 additions & 0 deletions superset-frontend/src/filters/components/Select/buildQuery.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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 buildQuery from './buildQuery';

describe('Select buildQuery', () => {
const formData = {
datasource: '5__table',
groupby: ['my_col'],
viz_type: 'filter_select',
sortAscending: false,
sortMetric: undefined,
filters: undefined,
enableEmptyFilter: false,
inverseSelection: false,
multiSelect: false,
defaultToFirstItem: false,
height: 100,
width: 100,
};

it('should build a default query', () => {
const queryContext = buildQuery(formData);
expect(queryContext.queries.length).toEqual(1);
const [query] = queryContext.queries;
expect(query.groupby).toEqual(['my_col']);
expect(query.metrics).toEqual([]);
expect(query.apply_fetch_values_predicate).toEqual(true);
expect(query.orderby).toEqual([]);
});

it('should handle sort metric correctly', () => {
const queryContext = buildQuery({
...formData,
sortMetric: 'my_metric',
sortAscending: false,
});
expect(queryContext.queries.length).toEqual(1);
const [query] = queryContext.queries;
expect(query.groupby).toEqual(['my_col']);
expect(query.metrics).toEqual(['my_metric']);
expect(query.orderby).toEqual([['my_metric', false]]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function buildQuery(formData: PluginFilterSelectQueryFormData) {
...baseQueryObject,
apply_fetch_values_predicate: true,
groupby: columns,
metrics: sortMetric ? [sortMetric] : [],
filters: filters.concat(
columns.map(column => ({ col: column, op: 'IS NOT NULL' })),
),
Expand Down

0 comments on commit 09e871e

Please sign in to comment.