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(Explore): Pivot table V2 sort by failure with D&D enabled #18835

Merged
merged 4 commits into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -19,8 +19,11 @@

/* eslint-disable camelcase */
import {
AdhocColumn,
AdhocFilter,
PhysicalColumn,
QueryFieldAliases,
QueryFormColumn,
QueryFormData,
QueryObject,
QueryObjectFilterClause,
Expand Down Expand Up @@ -89,6 +92,14 @@ export default function buildQueryObject<T extends QueryFormData>(
...extras,
...filterFormData,
});
const isAdhocColumn = (v?: AdhocColumn | PhysicalColumn) =>
geido marked this conversation as resolved.
Show resolved Hide resolved
(v as AdhocColumn)?.sqlExpression !== undefined;
const normalizeSeriesLimitMetric = (v: QueryFormColumn | undefined) => {
if (isAdhocColumn(v) || (v as PhysicalColumn)?.length) {
geido marked this conversation as resolved.
Show resolved Hide resolved
return v;
}
return undefined;
};

let queryObject: QueryObject = {
// fallback `null` to `undefined` so they won't be sent to the backend
Expand All @@ -113,13 +124,14 @@ export default function buildQueryObject<T extends QueryFormData>(
: numericRowOffset,
series_columns,
series_limit,
series_limit_metric,
series_limit_metric: normalizeSeriesLimitMetric(series_limit_metric),
timeseries_limit: limit ? Number(limit) : 0,
timeseries_limit_metric: timeseries_limit_metric || undefined,
order_desc: typeof order_desc === 'undefined' ? true : order_desc,
url_params: url_params || undefined,
custom_params,
};

// override extra form data used by native and cross filters
queryObject = overrideExtraFormData(queryObject, overrides);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ describe('buildQueryObject', () => {
expect(query.timeseries_limit_metric).toEqual(metric);
});

it('should build series_limit_metric', () => {
const metric = 'country';
query = buildQueryObject({
datasource: '5__table',
granularity_sqla: 'ds',
viz_type: 'pivot_table_v2',
series_limit_metric: metric,
});
expect(query.series_limit_metric).toEqual(metric);
});

it('should build series_limit_metric as undefined when empty array', () => {
const metric: any = [];
query = buildQueryObject({
datasource: '5__table',
granularity_sqla: 'ds',
viz_type: 'pivot_table_v2',
series_limit_metric: metric,
});
expect(query.series_limit_metric).toEqual(undefined);
});

it('should handle null and non-numeric row_limit and row_offset', () => {
const baseQuery = {
datasource: '5__table',
Expand Down