hughhhh commented on code in PR #24665:
URL: https://github.com/apache/superset/pull/24665#discussion_r1260004141
##########
superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/buildQuery.ts:
##########
@@ -30,7 +30,10 @@ import {
import { PivotTableQueryFormData } from '../types';
export default function buildQuery(formData: PivotTableQueryFormData) {
- const { groupbyColumns = [], groupbyRows = [] } = formData;
+ const { groupbyColumns = [], groupbyRows = [], extra_form_data } = formData;
Review Comment:
can we write a small unit test to for buildQuery to verify the grains are
being properly set?
```
import buildQuery from './path-to-your-file';
describe('buildQuery', () => {
it('should build query with expected columns', () => {
const formData = {
groupbyColumns: ['column1', 'column2'],
groupbyRows: ['row1', 'row2'],
extra_form_data: {
time_grain_sqla: 'monthly'
},
time_grain_sqla: 'weekly',
temporal_columns_lookup: { column1: true },
granularity_sqla: 'column1'
};
const result = buildQuery(formData as any);
// Define your expected output here.
const expected = [
// Fill in with expected transformed columns
];
expect(result).toEqual(expected);
});
it('should prefer extra_form_data.time_grain_sqla over
formData.time_grain_sqla', () => {
const formData = {
groupbyColumns: ['column1'],
groupbyRows: [],
extra_form_data: {
time_grain_sqla: 'monthly'
},
time_grain_sqla: 'weekly',
temporal_columns_lookup: { column1: true },
granularity_sqla: 'column1'
};
const result = buildQuery(formData as any);
// Assuming that the time_grain_sqla is reflected in the 'timeGrain'
property of the result
const timeGrain = result[0]?.timeGrain;
expect(timeGrain).toEqual('monthly');
});
it('should fallback to formData.time_grain_sqla if
extra_form_data.time_grain_sqla is not set', () => {
const formData = {
groupbyColumns: ['column1'],
groupbyRows: [],
extra_form_data: {},
time_grain_sqla: 'weekly',
temporal_columns_lookup: { column1: true },
granularity_sqla: 'column1'
};
const result = buildQuery(formData as any);
// Assuming that the time_grain_sqla is reflected in the 'timeGrain'
property of the result
const timeGrain = result[0]?.timeGrain;
expect(timeGrain).toEqual('weekly');
});
});
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]