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

feat(explore): time picker enhancement #11418

Merged
merged 44 commits into from
Dec 18, 2020
Merged

Conversation

zhaoyongjie
Copy link
Member

@zhaoyongjie zhaoyongjie commented Oct 25, 2020

SUMMARY

This PR introduces the new Explore Time Picker input modal that allows quick selection of various time ranges and granularities. It is an enhancement of the existing time picker in Explore, including preservation of the current library dateutil.parse, parsedatetime and adding new libraries pyparsing, python-holidays. User now can easily set any time range by either selecting a pre-defined range(e.g. Last 24 hours, Previous Calendar Month)or creating a date range formula for more specific range definition (e.g. from HOLIDAY("Christmas", dateadd(datetime("2019"), 1, year)) to DATEADD(DATETIME("TODAY"), -13, DAY))

Miro link: https://miro.com/app/board/o9J_kiQxGIU=/

Roadmap item: apache-superset/superset-roadmap#34

Features include

  • Predefined Time Range Select - Last
  • Predefined Time Range Select - Previous
  • Relative Time Range Select
  • Specific Time Range Select
  • Advanced modal - support mini-language syntax(e.g. today, last week, last month); and advanced custom DateTime expression that returns Python DateTime object. parse DateTime expression syntax using pyparsing
  1. Datetime([string])
    DATETIME("2020-03-01 12:00:00")
    DATETIME("now")
    DATETIME("last year")
  2. Moves the given set of dates by a specified interval.
    Dateadd([datetime], [integer], [dateunit])
    dateunit = (YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND)
    DATEADD(DATETIME("TODAY"), -13, DAY)
    DATEADD(DATETIME("2020-03-01"), 2, DAY)
  3. Truncates the specified date to the accuracy specified by the date unit.
    Datetrunc([datetime], [dateunit])
  4. Get the last date by the date unit
    Lastday([datetime], [dateunit])
    dateunit = (YEAR | MONTH | WEEK)
  5. Holiday([string], , )
    Python-holidays library(https://github.com/dr-prodigy/python-holidays)
    HOLIDAY("new year")
    HOLIDAY("christmas", datetime("2019"))
    HOLIDAY("christmas", dateadd(datetime("2019"), 1, year))
    HOLIDAY("christmas", datetime("2 years ago"))
    HOLIDAY("Easter Monday", datetime("2019"), "UK")
  • Anchor time to NOW
  • Anchor time to Mid-night
  • Actual Time Range display
  • Actual Time Range validation
  • Syntax Error message

Last Modal

image

Previous Modal

image

Custom Modal

Dec-17-2020 09-03-15

Advanced Modal

  1. dateadd function

image

  1. datetrunc function

image

  1. lastday function

image

  1. holiday function

image

TEST PLAN

adding unit test for this function

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

@codecov-io
Copy link

codecov-io commented Oct 25, 2020

Codecov Report

Merging #11418 (6e82c0b) into master (92fdf54) will decrease coverage by 3.68%.
The diff coverage is 47.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11418      +/-   ##
==========================================
- Coverage   66.71%   63.02%   -3.69%     
==========================================
  Files         967      970       +3     
  Lines       47543    47937     +394     
  Branches     4650     4736      +86     
==========================================
- Hits        31716    30212    -1504     
- Misses      15706    17538    +1832     
- Partials      121      187      +66     
Flag Coverage Δ
cypress ?
javascript 62.11% <22.64%> (-0.64%) ⬇️
python 63.58% <94.15%> (-0.45%) ⬇️

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

Impacted Files Coverage Δ
superset-frontend/src/common/components/index.tsx 100.00% <ø> (ø)
...-frontend/src/explore/components/controls/index.js 100.00% <ø> (ø)
...s/controls/DateFilterControl/DateFilterControl.tsx 15.64% <15.64%> (ø)
...ore/components/controls/DateFilterControl/types.ts 80.00% <80.00%> (ø)
superset/views/api.py 70.90% <83.33%> (+6.04%) ⬆️
superset/utils/core.py 89.85% <95.58%> (+0.59%) ⬆️
...components/controls/DateFilterControl/constants.ts 100.00% <100.00%> (ø)
superset-frontend/src/explore/dateFilterUtils.ts 100.00% <100.00%> (ø)
superset-frontend/src/SqlLab/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
superset-frontend/src/explore/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
... and 166 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 92fdf54...6e82c0b. Read the comment docs.

@mistercrunch
Copy link
Member

Is this changing the behavior of the current function? We have to be mindful of the thousands of charts out there that have been built based on the current behavior.

superset/utils/core.py Outdated Show resolved Hide resolved
@junlincc
Copy link
Member

junlincc commented Dec 10, 2020

Tested it today, this feature enhancement is so AWESOME!! MANY MANY THANKS @zhaoyongjie
this is by far the best community individual collaboration!
We will update the description in a couple of days, and tune the design a bit more!

superset/charts/api.py Outdated Show resolved Hide resolved
@junlincc
Copy link
Member

many thanks to @kristw @ktmud @graceguo-supercat for reviewing this PR! 🙏🙏

Copy link
Member

@ktmud ktmud left a comment

Choose a reason for hiding this comment

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

Yeah, CI is green! Merging with the understanding that these followups have been planned:

  1. Break down control to child components
  2. Extract frontend utilities to a separate module and add unit tests
  3. Change modal to popover (potentially)
  4. Improve typescript typing
  5. Remove the validate button
  6. Extract Python helpers to a separate file

Again, thanks for the great work!

@ktmud ktmud merged commit b592cc7 into apache:master Dec 18, 2020
@ktmud
Copy link
Member

ktmud commented Dec 18, 2020

@zhaoyongjie Could you also confirm whether this new control work well with existing charts (i.e. any charts with existing custom time range filters)? I hope we have some test cases for them, but it's not obvious by just looking at the PR.

@zhaoyongjie
Copy link
Member Author

zhaoyongjie commented Dec 18, 2020

hi @ktmud, This new control is fully compatible with the original time range string. I'll test it manually right now, on every chart

@zhaoyongjie
Copy link
Member Author

@ktmud,

  1. I have tested all charts manually, all can use the new time picker without problems.
  2. tested all generated by load_examples -t command charts, no problems too.
  3. original custom time range can mapping to "time range string" split by separator, It will be parsed by the new time range control.

@mistercrunch
Copy link
Member

200 (1)

amitmiran137 pushed a commit to simcha90/incubator-superset that referenced this pull request Dec 18, 2020
* upstream/master: (55 commits)
  feat(explore): time picker enhancement (apache#11418)
  feat: update alert/report icons and column order (apache#12081)
  feat(explore): metrics and filters controls redesign (apache#12095)
  feat(alerts/reports): add refresh action (apache#12071)
  chore: add latest tag action (apache#11148)
  fix(reports): increase crontab size and alert fixes (apache#12056)
  Small typo fix in Athena connection docs (apache#12099)
  feat(queries): security perm simplification (apache#12072)
  feat(databases): security perm simplification (apache#12036)
  feat(dashboards): security permissions simplification (apache#12012)
  feat(logs): security permissions simplification (apache#12061)
  chore: Remove unused CodeModal (apache#11972)
  Fix typescript error (apache#12074)
  fix: handle context-dependent feature flags in CLI (apache#12088)
  fix: Fix "View in SQLLab" bug (apache#12086)
  feat(alert/report): add 'not null' condition option to modal (apache#12077)
  bumping superset ui to 15.18 and deckgl to 0.3.2 (apache#12078)
  fix: Python dependencies in apache#11499 (apache#12079)
  reset active tab on open (apache#12048)
  fix: improve import flow UI/UX (apache#12070)
  ...
villebro pushed a commit to preset-io/superset that referenced this pull request Jan 7, 2021
villebro pushed a commit to preset-io/superset that referenced this pull request Jan 7, 2021
@zhaoyongjie zhaoyongjie deleted the time_picker branch January 16, 2021 04:17
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.0.0 labels Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/XXL 🚢 1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.