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