-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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: Dashboard time grain in Pivot Table #24665
fix: Dashboard time grain in Pivot Table #24665
Conversation
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we write a small unit test to for buildQuery to verify the grains are being properly set?
I ran this thru chat gpt, but it would be good to have this to make sure that queries are being built properly
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');
});
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the references @hughhhh. I added the tests with modifications.
One tip: you can ask Chat GPT to avoid using describe
and it
blocks to generate tests that conform to our best practices 😉
Codecov Report
@@ Coverage Diff @@
## master #24665 +/- ##
==========================================
+ Coverage 68.97% 69.05% +0.07%
==========================================
Files 1907 1908 +1
Lines 74153 74174 +21
Branches 8182 8179 -3
==========================================
+ Hits 51148 51220 +72
+ Misses 20882 20833 -49
+ Partials 2123 2121 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 9 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
/testenv up |
@kgabryje Ephemeral environment spinning up at http://34.217.82.78:8080. Credentials are |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Ephemeral environment shutdown and build artifacts deleted. |
Thanks for the fix @michael-s-molina ! I didn't get a chance to check on the ephemeral before the merge, but I believe this was broken for tables as well and it looks like this fix was only for pivot tables, is that right? |
Yes, it was only for pivot tables. I'll check the table too and submit a fix if it's broken. |
Hi @michael-s-molina I also found the same behavior occurs on table too. |
Thank you for the details @unnyns-307. I'll fix it. |
(cherry picked from commit 6e59f11)
SUMMARY
Fixes #24460.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Before: Check the original issue.
After: The time grain is correctly applied
Screen.Recording.2023-07-11.at.11.20.33.mov
TESTING INSTRUCTIONS
Check the original issue for instructions.
ADDITIONAL INFORMATION