-
-
Notifications
You must be signed in to change notification settings - Fork 144
Fix clearable #599
Fix clearable #599
Changes from all commits
1433805
2f02308
89c8302
9450371
8610ed3
fe941fb
9d782ac
6eb4ac8
36057de
e6ffd7c
e810da4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ export default class DatePickerRange extends Component { | |
} | ||
|
||
onDatesChange({startDate: start_date, endDate: end_date}) { | ||
const {setProps, updatemode} = this.props; | ||
const {setProps, updatemode, clearable} = this.props; | ||
|
||
const oldMomentDates = convertToMoment(this.state, [ | ||
'start_date', | ||
|
@@ -71,6 +71,16 @@ export default class DatePickerRange extends Component { | |
}); | ||
} | ||
} | ||
|
||
byronz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if ( | ||
clearable && | ||
!start_date && | ||
!end_date && | ||
(oldMomentDates.start_date !== start_date || | ||
oldMomentDates.end_date !== 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. @Marc-Andre-Rivet when you click the |
||
) { | ||
setProps({start_date: null, end_date: null}); | ||
} | ||
byronz marked this conversation as resolved.
Show resolved
Hide resolved
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. While the previous code was not optimal in terms of setProps, it would have updated the values in all cases. Now this won't update if one is unset, whether updatemode is single or both. Rather than preventing the update if one of start/end was not previously set, could instead check and add each individually if the "global" condition is met. e.g.
|
||
} | ||
|
||
isOutsideRange(date) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import itertools | ||
import pytest | ||
|
||
import dash_core_components as dcc | ||
import dash_html_components as html | ||
import dash | ||
from dash.dependencies import Input, Output | ||
import dash.testing.wait as wait | ||
|
||
DAY_SELECTOR = 'div[data-visible="true"] td.CalendarDay' | ||
|
||
|
||
@pytest.mark.DCC594 | ||
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. this is an idea I have in mind to associate the test case with issue number, could be helpful for test selection by associating the test case with the issue 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. @byronz we can keep this if it's useful, but we should do something to clear the warning it currently gives:
|
||
def test_cdpr001_date_clearable_true_works(dash_duo): | ||
|
||
app = dash.Dash(__name__) | ||
app.layout = html.Div([dcc.DatePickerRange(id="dpr", clearable=True)]) | ||
|
||
dash_duo.start_server(app) | ||
|
||
start_date = dash_duo.find_element('input[aria-label="Start Date"]') | ||
end_date = dash_duo.find_element('input[aria-label="End Date"]') | ||
|
||
start_date.click() | ||
|
||
dash_duo.find_elements(DAY_SELECTOR)[0].click() | ||
dash_duo.find_elements(DAY_SELECTOR)[-1].click() | ||
|
||
close_btn = dash_duo.wait_for_element('button[aria-label="Clear Dates"]') | ||
|
||
assert start_date.get_attribute("value") and end_date.get_attribute( | ||
"value" | ||
), "both start date and end date should get values" | ||
|
||
close_btn.click() | ||
assert not start_date.get_attribute( | ||
"value" | ||
) and not end_date.get_attribute( | ||
"value" | ||
), "both start and end dates should be cleared" | ||
|
||
|
||
def test_cdpr002_updatemodes(dash_duo): | ||
app = dash.Dash(__name__) | ||
|
||
app.layout = html.Div( | ||
[ | ||
dcc.DatePickerRange( | ||
id="date-picker-range", | ||
start_date_id="startDate", | ||
end_date_id="endDate", | ||
start_date_placeholder_text="Select a start date!", | ||
end_date_placeholder_text="Select an end date!", | ||
updatemode="bothdates", | ||
), | ||
html.Div(id="date-picker-range-output"), | ||
] | ||
) | ||
|
||
@app.callback( | ||
Output("date-picker-range-output", "children"), | ||
[ | ||
Input("date-picker-range", "start_date"), | ||
Input("date-picker-range", "end_date"), | ||
], | ||
) | ||
def update_output(start_date, end_date): | ||
return "{} - {}".format(start_date, end_date) | ||
|
||
dash_duo.start_server(app=app) | ||
|
||
start_date = dash_duo.find_element("#startDate") | ||
start_date.click() | ||
|
||
end_date = dash_duo.find_element("#endDate") | ||
end_date.click() | ||
|
||
assert ( | ||
dash_duo.find_element("#date-picker-range-output").text | ||
== "None - None" | ||
), "the output should not update when both clicked but no selection happen" | ||
|
||
start_date.click() | ||
|
||
dash_duo.find_elements(DAY_SELECTOR)[4].click() | ||
assert ( | ||
dash_duo.find_element("#date-picker-range-output").text | ||
== "None - None" | ||
), "the output should not update when only one is selected" | ||
|
||
eday = dash_duo.find_elements(DAY_SELECTOR)[-4] | ||
wait.until(lambda: eday.is_displayed() and eday.is_enabled(), timeout=2) | ||
eday.click() | ||
|
||
date_tokens = set(start_date.get_attribute("value").split("/")) | ||
date_tokens.update(end_date.get_attribute("value").split("/")) | ||
|
||
assert ( | ||
set( | ||
itertools.chain( | ||
*[ | ||
_.split("-") | ||
for _ in dash_duo.find_element( | ||
"#date-picker-range-output" | ||
).text.split(" - ") | ||
] | ||
) | ||
) | ||
== date_tokens | ||
), "date should match the callback output" |
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.
there are numerous requests on circleci community about conditional
Jobs
upon previous failure. right now, the behavior is when the previous job fails, the percy finalize job cannot be executed.a compromise for now as a percy clean up when failed