Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

PersistenceTransforms for date in datePickerRange and datePickerSingle #854

Merged
merged 23 commits into from
Sep 4, 2020

Conversation

harryturr
Copy link
Contributor

@harryturr harryturr commented Aug 25, 2020

In conjunction with plotly/dash#1376, fixes #700.

The persistence logic in DatePickerRange and DatePickerSingle have been modified to extract/apply just the date portion of the date-time. This will provide stability to date pickers (eg defined in callbacks) for the entire day they are defined.

@harryturr harryturr changed the title Hg 700 persistence PersistenceTransforms for date in datePickerRange and datePickerSingle Aug 25, 2020
@harryturr harryturr marked this pull request as ready for review August 25, 2020 17:02
DatePickerRange.persistenceTransforms = {
end_date: {
extract: propValue => {
if (!(propValue === null || propValue === undefined)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This check is fine but can be simplified by using https://ramdajs.com/docs/#isNil instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}
return propValue;
},
apply: storedValue => storedValue,
Copy link
Contributor

Choose a reason for hiding this comment

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

The implementation for end_date and start_date extract and apply are identical (same for DatePickerSingle date) -- DRY by defining a functions that you can share between the 3 cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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


dash_dcc.start_server(app)
dpr1 = dash_dcc.find_element("div#dpr1 div div div div .DateInput_input")
dpr2 = dash_dcc.find_element("div#dpr2 div div div div .DateInput_input")
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it work with only div#dpr2 .DateInput_input ? This find_element seems to be very dependent on the implementation details of the underlying third-party component

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See 605594c . Now we use only the dash_dcc functions for interacting with date pickers, and are testing the behaviour DatePickerSingle and Range defined in callbacks, with the date, start/end_date props changing value each time the callback is fired.

@@ -80,7 +80,7 @@ jobs:
command: |
. venv/bin/activate && mkdir packages
# build main dash
git clone --depth 1 https://github.com/plotly/dash.git dash-main
git clone -b persistence-hg --depth 1 https://github.com/plotly/dash.git dash-main
Copy link
Contributor

Choose a reason for hiding this comment

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

With plotly/dash#1376 now merged, this can be 🔪

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -263,6 +266,11 @@ DatePickerRange.propTypes = {
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']),
};

DatePickerRange.persistenceTransforms = {
end_date,
Copy link
Contributor

Choose a reason for hiding this comment

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

Assign the value to the prop instead of assigning to a value that matches the prop for shortcut assignation

Suggested change
end_date,
end_date: transformDate,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet left a comment

Choose a reason for hiding this comment

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

  • now needs to be run against dash dev
  • needs a changelog entry

Copy link
Contributor

@Marc-Andre-Rivet Marc-Andre-Rivet left a comment

Choose a reason for hiding this comment

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

💃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dcc.DatePickerSingle() persistence not working
2 participants