mirror of https://github.com/apache/superset.git
fix: revert #21356(able to sort bar on the bar chart V2) (#21481)
This commit is contained in:
parent
4fcc1d952f
commit
1c0bff3dfb
|
@ -17,30 +17,24 @@
|
|||
* specific language governing permissions and limitationsxw
|
||||
* under the License.
|
||||
*/
|
||||
import {
|
||||
ensureIsArray,
|
||||
getColumnLabel,
|
||||
getMetricLabel,
|
||||
PostProcessingSort,
|
||||
} from '@superset-ui/core';
|
||||
import { DTTM_ALIAS, PostProcessingSort, RollingType } from '@superset-ui/core';
|
||||
import { PostProcessingFactory } from './types';
|
||||
|
||||
export const sortOperator: PostProcessingFactory<PostProcessingSort> = (
|
||||
formData,
|
||||
queryObject,
|
||||
) => {
|
||||
const { columns, metrics, timeseries_limit_metric, order_desc } = queryObject;
|
||||
const metricLabels = ensureIsArray(metrics).map(getMetricLabel);
|
||||
const columnLabels = ensureIsArray(columns).map(getColumnLabel);
|
||||
const column: string[] = ensureIsArray(timeseries_limit_metric).map(
|
||||
getMetricLabel,
|
||||
);
|
||||
if (metricLabels.includes(column[0]) || columnLabels.includes(column[0])) {
|
||||
const { x_axis: xAxis } = formData;
|
||||
if (
|
||||
(xAxis || queryObject.is_timeseries) &&
|
||||
Object.values(RollingType).includes(formData.rolling_type)
|
||||
) {
|
||||
const index = xAxis || DTTM_ALIAS;
|
||||
return {
|
||||
operation: 'sort',
|
||||
options: {
|
||||
columns: {
|
||||
[column[0]]: !order_desc,
|
||||
[index]: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -34,7 +34,6 @@ const queryObject: QueryObject = {
|
|||
'count(*)',
|
||||
{ label: 'sum(val)', expressionType: 'SQL', sqlExpression: 'sum(val)' },
|
||||
],
|
||||
columns: ['state'],
|
||||
time_range: '2015 : 2016',
|
||||
granularity: 'month',
|
||||
post_processing: [
|
||||
|
@ -56,89 +55,88 @@ const queryObject: QueryObject = {
|
|||
test('skip sort', () => {
|
||||
expect(sortOperator(formData, queryObject)).toEqual(undefined);
|
||||
expect(
|
||||
sortOperator(formData, { ...queryObject, timeseries_limit_metric: 'bar' }),
|
||||
sortOperator(formData, { ...queryObject, is_timeseries: false }),
|
||||
).toEqual(undefined);
|
||||
expect(
|
||||
sortOperator(
|
||||
{ ...formData, rolling_type: 'xxxx' },
|
||||
{ ...queryObject, is_timeseries: true },
|
||||
),
|
||||
).toEqual(undefined);
|
||||
expect(
|
||||
sortOperator(formData, { ...queryObject, is_timeseries: true }),
|
||||
).toEqual(undefined);
|
||||
});
|
||||
|
||||
test('sort by metric', () => {
|
||||
test('sort by __timestamp', () => {
|
||||
expect(
|
||||
sortOperator(formData, {
|
||||
...queryObject,
|
||||
timeseries_limit_metric: 'count(*)',
|
||||
}),
|
||||
sortOperator(
|
||||
{ ...formData, rolling_type: 'cumsum' },
|
||||
{ ...queryObject, is_timeseries: true },
|
||||
),
|
||||
).toEqual({
|
||||
operation: 'sort',
|
||||
options: {
|
||||
columns: {
|
||||
'count(*)': true,
|
||||
__timestamp: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
sortOperator(formData, {
|
||||
...queryObject,
|
||||
timeseries_limit_metric: 'count(*)',
|
||||
order_desc: true,
|
||||
}),
|
||||
sortOperator(
|
||||
{ ...formData, rolling_type: 'sum' },
|
||||
{ ...queryObject, is_timeseries: true },
|
||||
),
|
||||
).toEqual({
|
||||
operation: 'sort',
|
||||
options: {
|
||||
columns: {
|
||||
'count(*)': false,
|
||||
__timestamp: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
sortOperator(formData, {
|
||||
...queryObject,
|
||||
timeseries_limit_metric: {
|
||||
label: 'sum(val)',
|
||||
expressionType: 'SQL',
|
||||
sqlExpression: 'sum(val)',
|
||||
},
|
||||
}),
|
||||
sortOperator(
|
||||
{ ...formData, rolling_type: 'mean' },
|
||||
{ ...queryObject, is_timeseries: true },
|
||||
),
|
||||
).toEqual({
|
||||
operation: 'sort',
|
||||
options: {
|
||||
columns: {
|
||||
'sum(val)': true,
|
||||
__timestamp: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
sortOperator(formData, {
|
||||
...queryObject,
|
||||
timeseries_limit_metric: {
|
||||
label: 'sum(val)',
|
||||
expressionType: 'SQL',
|
||||
sqlExpression: 'sum(val)',
|
||||
},
|
||||
order_desc: false,
|
||||
}),
|
||||
sortOperator(
|
||||
{ ...formData, rolling_type: 'std' },
|
||||
{ ...queryObject, is_timeseries: true },
|
||||
),
|
||||
).toEqual({
|
||||
operation: 'sort',
|
||||
options: {
|
||||
columns: {
|
||||
'sum(val)': true,
|
||||
__timestamp: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test('sort by column', () => {
|
||||
test('sort by named x-axis', () => {
|
||||
expect(
|
||||
sortOperator(formData, {
|
||||
...queryObject,
|
||||
timeseries_limit_metric: 'state',
|
||||
}),
|
||||
sortOperator(
|
||||
{ ...formData, x_axis: 'ds', rolling_type: 'cumsum' },
|
||||
{ ...queryObject },
|
||||
),
|
||||
).toEqual({
|
||||
operation: 'sort',
|
||||
options: {
|
||||
columns: {
|
||||
state: true,
|
||||
ds: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
|
|
@ -35,7 +35,6 @@ import {
|
|||
prophetOperator,
|
||||
timeComparePivotOperator,
|
||||
flattenOperator,
|
||||
sortOperator,
|
||||
} from '@superset-ui/chart-controls';
|
||||
|
||||
export default function buildQuery(formData: QueryFormData) {
|
||||
|
@ -98,7 +97,6 @@ export default function buildQuery(formData: QueryFormData) {
|
|||
is_timeseries,
|
||||
}),
|
||||
contributionOperator(formData, baseQueryObject),
|
||||
sortOperator(formData, baseQueryObject),
|
||||
flattenOperator(formData, baseQueryObject),
|
||||
// todo: move prophet before flatten
|
||||
prophetOperator(formData, baseQueryObject),
|
||||
|
|
Loading…
Reference in New Issue