This repository was archived by the owner on Apr 13, 2022. It is now read-only.
Preserve and display preset titles#96
Open
hheimbuerger wants to merge 9 commits intoBaremetrics:masterfrom
Open
Preserve and display preset titles#96hheimbuerger wants to merge 9 commits intoBaremetrics:masterfrom
hheimbuerger wants to merge 9 commits intoBaremetrics:masterfrom
Conversation
When selecting a preset from the preset dropdown, instead of being immediately translated into its date range representation, the preset label is now displayed inside the component. The idea is that the component consumer can now work with this preset differently, the primary use case being that e.g. "Last week" can be treated symbolic and updated when the page is reloaded on a Sunday/Monday and the date range representation of the preset has changed. The moment the user clicks on the displayed preset, it *is* turned into its date range representation and the user can set a custom date range, taking the preset's date range as the starting point.
Author
|
The biggest challenge I have is setting a prefix programmatically on the component (e.g. after depersisting a prefix from a storage system). Here's the code I'm currently using, but it's obviously not very pretty: I'd appreciate if someone could come up with a better implementation. |
Fix issue where manual date range didn't restore after preset value. Add new item 'Custom' in presets list which just opens calendar. Add possibility to set preset value as default value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
We need the ability to persist the state of the datepicker across page loads. This presents a major UX problem related to presets: if the user selects a
Todaypreset and then reloads the page on the next day, what’s the expected behavior?I don’t think there’s a single ‘right’ answer, but we decided that we wanted to go with ‘constantly updating’ presets.
Current behavior
The current behavior of datepicker is that any preset the user selects is immediately turned into a fixed daterange. So if the user selects
This monthon Jan 31, this is converted into the intervalJan 1 - Jan 31and the component immediately forgets that the prefix was ever chosen. If the user reloads the “this month” view on Feb 1, they will again see theJan 1 - Jan 31interval.Intended behavior
What we wanted to do is two-fold: First, we wanted to have the ability to actually keep the preset around and show it to the user after they’ve selected it. And second, we wanted to be able to read from the component when the user has chosen a preset as opposed to a date range, so that we can persist the specific user choice.
To continue the aforementioned example: has the user selected
This monthfrom the presets, or have they selected the interval fromJan 1toJan 31?Implementation
We introduce a new element with class
dr-date-preset, which is by default hidden, and shown instead of the threedr-date-start,dr-dates-dashanddr-date-endelements if a preset is currently selected.When a preset is selected, this element is shown and shows the title of the current preset. When that preset title is clicked, the title turns into the current date interval and the dropdown to choose another start and end date appears.
This new functionality has to be enabled by setting the new configuration flag
sticky_presetstotrue, Theoretically, if you don’t set this new configuration option, the behavior of the component should be unchanged. But I leave it to the reviewers to confirm that.The change events (
callback), now contain a new fieldpreset_labelwhich is set to the title of the preset if a preset was chosen, andnullif a date interval was selected.A new component with this configuration has been added to the test page.
Credit
This feature branch was developed in pair programming by @SergLo and @hheimbuerger. Equal credit should be given, I just happen to be the messenger.
Preview