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(dashboard filters): add "previous quarter" as option #30506

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

personofnorank
Copy link

@personofnorank personofnorank commented Oct 3, 2024

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

  • Has associated issue: [SIP-116] Simplifying time period filtering for users  #26651
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@dosubot dosubot bot added change:frontend Requires changing the frontend explore:time Related to the time filters in Explore labels Oct 3, 2024
@personofnorank
Copy link
Author

@sfirke as per Slack discussion, thank you!

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on making your first PR and thank you for contributing to Superset! 🎉 ❤️

We hope to see you in our Slack community too! Not signed up? Use our Slack App to self-register.

@personofnorank personofnorank changed the title Previous quarter option for custom date filter fix(dashboard filters): add "previous quarter" as option Oct 3, 2024
@pull-request-size pull-request-size bot added size/S and removed size/XS labels Oct 3, 2024
@@ -78,6 +78,11 @@ export const parseDttmToDate = (
now.setMonth(now.getMonth() - 1);
}
return now;
case 'previous calendar quarter': {
Copy link
Member

@michael-s-molina michael-s-molina Oct 3, 2024

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

Copy link
Member

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'));
});

Copy link
Author

@personofnorank personofnorank Oct 4, 2024

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.

Copy link

codecov bot commented Oct 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.92%. Comparing base (76d897e) to head (8bab026).
Report is 866 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master   #30506       +/-   ##
===========================================
+ Coverage   60.48%   83.92%   +23.43%     
===========================================
  Files        1931      533     -1398     
  Lines       76236    38612    -37624     
  Branches     8568        0     -8568     
===========================================
- Hits        46114    32404    -13710     
+ Misses      28017     6208    -21809     
+ Partials     2105        0     -2105     
Flag Coverage Δ
hive 48.96% <0.00%> (-0.21%) ⬇️
javascript ?
mysql 76.76% <50.00%> (?)
postgres 76.86% <50.00%> (?)
presto 53.44% <50.00%> (-0.37%) ⬇️
python 83.92% <100.00%> (+20.43%) ⬆️
sqlite 76.31% <50.00%> (?)
unit 60.93% <100.00%> (+3.30%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pull-request-size pull-request-size bot added size/M and removed size/S labels Oct 4, 2024
@sfirke
Copy link
Member

sfirke commented Oct 4, 2024

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 ?

@rusackas
Copy link
Member

rusackas commented Oct 4, 2024

Re-running CI :D

@personofnorank
Copy link
Author

@justinpark I think this is pending your review - please let me know if anything needed from my side, with apologies for any oversight as I'm new to the process.

@sfirke
Copy link
Member

sfirke commented Oct 11, 2024

Looks like there is a failing Python test: https://github.com/apache/superset/actions/runs/11278958608/job/31368926066?pr=30506

@personofnorank
Copy link
Author

Fixed a typo in the test script

@sfirke
Copy link
Member

sfirke commented Oct 17, 2024

Looks like tests are failing with a function getting too many arguments

@personofnorank
Copy link
Author

In the last run the code seemed to be working but test was expecting wrong thing... maybe this time :)

@sfirke
Copy link
Member

sfirke commented Oct 21, 2024

It's getting closer to passing tests 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change:frontend Requires changing the frontend explore:time Related to the time filters in Explore packages size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants