This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 144
PersistenceTransforms for date in datePickerRange and datePickerSingle #854
Merged
Merged
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d2d0f1a
add persistenceTransforms for datePickerSingle to strip time
harryturr 4d18af3
add persistenceTransforms for datePickerRange to strip time
harryturr 1c61fa4
circleci pointing to dash branch
harryturr de4647a
noise
harryturr cc69b07
noise
harryturr f4b82d1
add tests for persistence in date picker single and range
harryturr abc13ec
Merge branch 'dev' into hg-700-persistence
harryturr c66bb74
rm obsolete import
harryturr 2745855
noise
harryturr 24db1fe
noise
harryturr 57e5019
use ramda isNil
harryturr c2668a2
simplify dps test
harryturr 778f8ca
Merge branch 'dev' into hg-700-persistence
harryturr c76c973
noise
harryturr 605594c
simplify tests for dps and dpr using dash_dcc functions
harryturr 4ba16c8
change function names and add comment
harryturr cc121c6
removing comma
harryturr 32852c0
add DatePickerPersistence for shared logic between dps and dpr
harryturr d80a500
noise
harryturr e733726
Merge branch 'dev' into hg-700-persistence
harryturr 6df0230
remove dash branch to test against new dash dev in ci
harryturr c0f98b4
change transformDate prop assignment
harryturr 0519d89
update CHANGELOG.md
harryturr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,8 +1,11 @@ | ||||||
import PropTypes from 'prop-types'; | ||||||
import React, {Component, lazy, Suspense} from 'react'; | ||||||
import datePickerRange from '../utils/LazyLoader/datePickerRange'; | ||||||
import transformDate from '../utils/DatePickerPersistence'; | ||||||
|
||||||
const RealDatePickerRange = lazy(datePickerRange); | ||||||
const end_date = transformDate; | ||||||
const start_date = transformDate; | ||||||
|
||||||
/** | ||||||
* DatePickerRange is a tailor made component designed for selecting | ||||||
|
@@ -263,6 +266,11 @@ DatePickerRange.propTypes = { | |||||
persistence_type: PropTypes.oneOf(['local', 'session', 'memory']), | ||||||
}; | ||||||
|
||||||
DatePickerRange.persistenceTransforms = { | ||||||
end_date, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
start_date, | ||||||
}; | ||||||
|
||||||
DatePickerRange.defaultProps = { | ||||||
calendar_orientation: 'horizontal', | ||||||
is_RTL: false, | ||||||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import moment from 'moment'; | ||
import {isNil} from 'ramda'; | ||
|
||
export default { | ||
extract: propValue => { | ||
if (!isNil(propValue)) { | ||
return moment(propValue) | ||
.startOf('day') | ||
.format('YYYY-MM-DD'); | ||
} | ||
return propValue; | ||
}, | ||
apply: storedValue => storedValue, | ||
}; |
87 changes: 87 additions & 0 deletions
87
tests/integration/calendar/test_date_picker_persistence.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from datetime import datetime | ||
|
||
import dash | ||
import dash_html_components as html | ||
import dash_core_components as dcc | ||
from dash.dependencies import Input, Output | ||
|
||
|
||
def test_rdpr001_persisted_dps(dash_dcc): | ||
app = dash.Dash(__name__) | ||
app.layout = html.Div( | ||
[ | ||
html.Button("fire callback", id="btn", n_clicks=1), | ||
html.Div(children=[html.Div(id="container"), html.P("dps", id="dps-p")]), | ||
] | ||
) | ||
|
||
# changing value of date with each callback to verify | ||
# persistenceTransforms is stripping the time-part from the date-time | ||
@app.callback(Output("container", "children"), [Input("btn", "n_clicks")]) | ||
def update_output(value): | ||
return dcc.DatePickerSingle( | ||
id="dps", | ||
min_date_allowed=datetime(2020, 1, 1), | ||
max_date_allowed=datetime(2020, 1, 7), | ||
date=datetime(2020, 1, 3, 1, 1, 1, value), | ||
persistence=True, | ||
persistence_type="session", | ||
) | ||
|
||
@app.callback(Output("dps-p", "children"), [Input("dps", "date")]) | ||
def display_dps(value): | ||
return value | ||
|
||
dash_dcc.start_server(app) | ||
|
||
dash_dcc.select_date_single("dps", day="2") | ||
dash_dcc.wait_for_text_to_equal("#dps-p", "2020-01-02") | ||
dash_dcc.find_element("#btn").click() | ||
dash_dcc.wait_for_text_to_equal("#dps-p", "2020-01-02") | ||
|
||
|
||
def test_rdpr002_persisted_dpr(dash_dcc): | ||
app = dash.Dash(__name__) | ||
app.layout = html.Div( | ||
[ | ||
html.Button("fire callback", id="btn", n_clicks=1), | ||
html.Div( | ||
children=[ | ||
html.Div(id="container"), | ||
html.P("dpr", id="dpr-p-start"), | ||
html.P("dpr", id="dpr-p-end"), | ||
] | ||
), | ||
] | ||
) | ||
|
||
# changing value of start_date and end_date with each callback to verify | ||
# persistenceTransforms is stripping the time-part from the date-time | ||
@app.callback(Output("container", "children"), [Input("btn", "n_clicks")]) | ||
def update_output(value): | ||
return dcc.DatePickerRange( | ||
id="dpr", | ||
min_date_allowed=datetime(2020, 1, 1), | ||
max_date_allowed=datetime(2020, 1, 7), | ||
start_date=datetime(2020, 1, 3, 1, 1, 1, value), | ||
end_date=datetime(2020, 1, 4, 1, 1, 1, value), | ||
persistence=True, | ||
persistence_type="session", | ||
) | ||
|
||
@app.callback(Output("dpr-p-start", "children"), [Input("dpr", "start_date")]) | ||
def display_dpr_start(value): | ||
return value | ||
|
||
@app.callback(Output("dpr-p-end", "children"), [Input("dpr", "end_date")]) | ||
def display_dpr_end(value): | ||
return value | ||
|
||
dash_dcc.start_server(app) | ||
|
||
dash_dcc.select_date_range("dpr", (2, 5)) | ||
dash_dcc.wait_for_text_to_equal("#dpr-p-start", "2020-01-02") | ||
dash_dcc.wait_for_text_to_equal("#dpr-p-end", "2020-01-05") | ||
dash_dcc.find_element("#btn").click() | ||
dash_dcc.wait_for_text_to_equal("#dpr-p-start", "2020-01-02") | ||
dash_dcc.wait_for_text_to_equal("#dpr-p-end", "2020-01-05") |
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.
There was a problem hiding this comment.
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 🔪
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6df0230