-
Notifications
You must be signed in to change notification settings - Fork 13.6k
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 filters): add "previous quarter" as option #30506
base: master
Are you sure you want to change the base?
Conversation
@sfirke as per Slack discussion, thank you! |
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! This repository requires PR titles to follow Conventional Commit format (I think it's called). For this one it could be: fix(dashboard filters): add "previous quarter" as option That will cause CI failure until fixed. I'm off work today but maybe someone else will review, otherwise I'll look when I'm back. |
superset-frontend/src/explore/components/controls/DateFilterControl/types.ts
Outdated
Show resolved
Hide resolved
superset-frontend/packages/superset-ui-core/src/time-comparison/getTimeOffset.ts
Outdated
Show resolved
Hide resolved
@@ -78,6 +78,11 @@ export const parseDttmToDate = ( | |||
now.setMonth(now.getMonth() - 1); | |||
} | |||
return now; | |||
case 'previous calendar quarter': { |
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.
@personofnorank You can add tests to the getTimeOffset.test.ts
file.
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.
Done :)
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.
Hi @personofnorank. There are problems with this logic as it can result in an invalid month value (e.g., -3, -2, -1) when the current quarter is the first quarter of the year.
I suggest adding some tests like these:
test('should return the first day of the previous calendar quarter when current date is in Q4', () => {
const result = getTimeOffset('previous calendar quarter', false, now);
expect(result).toEqual(new Date('2023-07-01T00:00:00Z'));
});
test('should return the first day of the previous calendar quarter when current date is in Q3', () => {
now = new Date('2023-08-15T00:00:00Z');
const result = getTimeOffset('previous calendar quarter', false, now);
expect(result).toEqual(new Date('2023-04-01T00:00:00Z'));
});
test('should return the first day of the previous calendar quarter when current date is in Q2', () => {
now = new Date('2023-05-15T00:00:00Z');
const result = getTimeOffset('previous calendar quarter', false, now);
expect(result).toEqual(new Date('2023-01-01T00:00:00Z'));
});
test('should return the first day of the previous calendar quarter when current date is in Q1', () => {
now = new Date('2023-02-15T00:00:00Z');
const result = getTimeOffset('previous calendar quarter', false, now);
expect(result).toEqual(new Date('2022-10-01T00:00:00Z'));
});
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.
It should work because Date allows a negative month.
new Date(2016, -1) gives you December 2015.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #30506 +/- ##
===========================================
+ Coverage 60.48% 77.34% +16.85%
===========================================
Files 1931 533 -1398
Lines 76236 38538 -37698
Branches 8568 0 -8568
===========================================
- Hits 46114 29806 -16308
+ Misses 28017 8732 -19285
+ Partials 2105 0 -2105
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Looks like there is a pre-commit linting check failing, it says to delete two spaces I think. And then a test failing. Can you investigate the CI failures when you get a chance, @personofnorank ? |
Re-running CI :D |
SUMMARY
The custom date range filter should include previous quarter along with previous calendar week, month or year
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION