Add dateRange to core/user store
See original GitHub issueFeature Description
In preparation for refactoring date range select boxes to use the datastore, we need to first add dateRange state and functionality to the core/user datastore.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- There should be a new
assets/js/googlesitekit/datastore/user/date-range.jsdatastore module which is combined into thecore/userstore in its index with the following components:selectors.getDateRange- returns the current date range slugactions.setDateRange( slug )sets the current date range by itsslug
- The initial dateRange should be
last-28-daysfor now although in the future this may be persisted from a previous choice - There should be a new
assets/js/googlesitekit/datastore/user/date-range.test.jsadding test coverage to the new components - There should be a new utility function (not in datastore)
getAvailableDateRanges()that returns an array of objects like:{ slug: 'last-28-days', label: sprintf( __( 'Last %d days', 'google-site-kit' ), 28 ), }
Implementation Brief
- Add a
getDateRange()selector that returns the currently-selected date range slug, eg:'last-7-days' - Add a
setDateRange( slug )action that sets the active date range using asluglike"last-28-days". - The state’s defaults should be what would be set by
setDateRange( 'last-28-days' ) - Add a utility function (
getAvailableDateRanges()) that returns an object where the key is the date rangeslug, and the value is an object with the date range slug and its translation (I think that’s[ 'last-7-days', 'last-14-days', 'last-28-days', 'last-90-days' ], but check existing code to make sure I’m not missing anything). It would have the shape:{'last-7-days': {slug: 'last-7-days', label: _n( 'Last %s day', 'Last %s days', 28, 'google-site-kit' ) }}
QA Brief
Changelog entry
- Add
getDateRange()selector andsetDateRange( slug )action to thecore/userstore.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Date range on invoices - CORE Help Center
So, it depends on the date range you select here. If you un-check this option, the invoice displays the range of billing dates...
Read more >Setting a date range - Pega Documentation
On the Presentation tab, in the Editable settings section, enter the date range from which users can choose in the yyyy-mm-dd format.
Read more >php - I have Date Range I try to insert date range but it store 0000-00 ...
This is right way to store like this 'bilty_date_range' => date('y-m-d',strtotime($bilty_date_range)),. This is Date picker function
Read more >Solved: Consecutive date range into collection
Is there a way to store each day in a collection? ... Add two Date picker controls on the same screen, say Date...
Read more >core user guide - Johnson Financial Group
business gateway® core user guide | johnsonbank.com ... Select the Add User button on the right to create users. ... then enter a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Returning an object here makes sense, since it allows for quick lookup by slug. QA ✅
Mostly SGTM, but a few points of feedback:
getActiveDateRangeshould begetDateRange.getAvailableDateRangesthat could include localized values, potentially even functions to transform tostartDateandendDateor something like that. I think we should removegetAllDateRangesas a selector and instead have a decoupled utility function.slugapproach to something more sophisticated should either not happen at this point, or we should take the time to think it all the way through. I’m not sure anumber+dateUnitapproach satisfies the needs in a future-proof way. From that POV, theslugis actually better because it doesn’t restrict us to any convention (but clearly has other trade-offs). A good idea here is to look at the additional date ranges that some parts of the AdSense module support and from there determine how we can abstract it into something more structured than a slug.