Skip to content

Commit

Permalink
Revert "feat(plugin-chart-echarts): able to sort bar on the bar chart…
Browse files Browse the repository at this point in the history
… V2 (#21356)"

This reverts commit 59437ea.
  • Loading branch information
stephenLYZ committed Sep 15, 2022
1 parent 4fcc1d9 commit b490123
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
prophetOperator,
timeComparePivotOperator,
flattenOperator,
sortOperator,
} from '@superset-ui/chart-controls';

export default function buildQuery(formData: QueryFormData) {
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit b490123

Please sign in to comment.