Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert #21356(able to sort bar on the bar chart V2) #21481

Merged
merged 1 commit into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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