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: pivot v2 charts created before GENERIC_CHART_AXES is enabled #23731

Merged
merged 6 commits into from
Apr 26, 2023
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 @@ -42,7 +42,11 @@ export default function buildQuery(formData: PivotTableQueryFormData) {
isPhysicalColumn(col) &&
formData.time_grain_sqla &&
hasGenericChartAxes &&
formData?.temporal_columns_lookup?.[col]
/* Charts created before `GENERIC_CHART_AXES` is enabled have a different
* form data, with `granularity_sqla` set instead.
*/
(formData?.temporal_columns_lookup?.[col] ||
formData.granularity_sqla === col)
) {
return {
timeGrain: formData.time_grain_sqla,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ interface PivotTableCustomizeProps {
filters?: ContextMenuFilters,
) => void;
timeGrainSqla?: TimeGranularity;
time_grain_sqla?: TimeGranularity;
granularity_sqla?: string;
}

export type PivotTableQueryFormData = QueryFormData &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

import { TimeGranularity } from '@superset-ui/core';
import * as supersetCoreModule from '@superset-ui/core';
import buildQuery from '../../src/plugin/buildQuery';
import { PivotTableQueryFormData } from '../../src/types';

Expand Down Expand Up @@ -55,4 +57,29 @@ describe('PivotTableChart buildQuery', () => {
const [query] = queryContext.queries;
expect(query.columns).toEqual(['col1', 'col2', 'row1', 'row2']);
});

it('should work with old charts after GENERIC_CHART_AXES is enabled', () => {
Object.defineProperty(supersetCoreModule, 'hasGenericChartAxes', {
value: true,
});
const modifiedFormData = {
...formData,
time_grain_sqla: TimeGranularity.MONTH,
granularity_sqla: 'col1',
};
const queryContext = buildQuery(modifiedFormData);
const [query] = queryContext.queries;
expect(query.columns).toEqual([
{
timeGrain: 'P1M',
columnType: 'BASE_AXIS',
sqlExpression: 'col1',
label: 'col1',
expressionType: 'SQL',
},
'col2',
'row1',
'row2',
]);
});
});