mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix(native-filters): handle descending sorting correctly (#15112)
This commit is contained in:
parent
3456dd571c
commit
5e825cf063
@ -25,7 +25,7 @@ describe('Select buildQuery', () => {
|
||||
datasource: '5__table',
|
||||
groupby: ['my_col'],
|
||||
viz_type: 'filter_select',
|
||||
sortAscending: false,
|
||||
sortAscending: undefined,
|
||||
sortMetric: undefined,
|
||||
filters: undefined,
|
||||
enableEmptyFilter: false,
|
||||
@ -47,7 +47,7 @@ describe('Select buildQuery', () => {
|
||||
expect(query.orderby).toEqual([]);
|
||||
});
|
||||
|
||||
it('should handle sort metric correctly', () => {
|
||||
it('should sort descending by metric', () => {
|
||||
const queryContext = buildQuery({
|
||||
...formData,
|
||||
sortMetric: 'my_metric',
|
||||
@ -60,6 +60,43 @@ describe('Select buildQuery', () => {
|
||||
expect(query.orderby).toEqual([['my_metric', false]]);
|
||||
});
|
||||
|
||||
it('should sort ascending by metric', () => {
|
||||
const queryContext = buildQuery({
|
||||
...formData,
|
||||
sortMetric: 'my_metric',
|
||||
sortAscending: true,
|
||||
});
|
||||
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', true]]);
|
||||
});
|
||||
|
||||
it('should sort ascending by column', () => {
|
||||
const queryContext = buildQuery({
|
||||
...formData,
|
||||
sortAscending: true,
|
||||
});
|
||||
expect(queryContext.queries.length).toEqual(1);
|
||||
const [query] = queryContext.queries;
|
||||
expect(query.groupby).toEqual(['my_col']);
|
||||
expect(query.metrics).toEqual([]);
|
||||
expect(query.orderby).toEqual([['my_col', true]]);
|
||||
});
|
||||
|
||||
it('should sort descending by column', () => {
|
||||
const queryContext = buildQuery({
|
||||
...formData,
|
||||
sortAscending: false,
|
||||
});
|
||||
expect(queryContext.queries.length).toEqual(1);
|
||||
const [query] = queryContext.queries;
|
||||
expect(query.groupby).toEqual(['my_col']);
|
||||
expect(query.metrics).toEqual([]);
|
||||
expect(query.orderby).toEqual([['my_col', false]]);
|
||||
});
|
||||
|
||||
it('should add text search parameter to query filter', () => {
|
||||
const queryContext = buildQuery(formData, {
|
||||
ownState: {
|
||||
|
@ -65,8 +65,8 @@ const buildQuery: BuildQuery<PluginFilterSelectQueryFormData> = (
|
||||
metrics: sortMetric ? [sortMetric] : [],
|
||||
filters: filters.concat(extra_filters),
|
||||
orderby:
|
||||
sortMetric || sortAscending
|
||||
? sortColumns.map(column => [column, sortAscending])
|
||||
sortMetric || sortAscending !== undefined
|
||||
? sortColumns.map(column => [column, !!sortAscending])
|
||||
: [],
|
||||
},
|
||||
];
|
||||
|
@ -39,7 +39,7 @@ interface PluginFilterSelectCustomizeProps {
|
||||
defaultToFirstItem: boolean;
|
||||
inputRef?: RefObject<HTMLInputElement>;
|
||||
searchAllOptions: boolean;
|
||||
sortAscending: boolean;
|
||||
sortAscending?: boolean;
|
||||
sortMetric?: string;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user