Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Issue 510 fix clearing date callback - #511

Merged
alexcjohnson merged 3 commits into
plotly:masterfrom
derekclee:issue-510-fix-clearing-date-callback
Apr 5, 2019
Merged

alexcjohnson merged 3 commits into
plotly:masterfrom
derekclee:issue-510-fix-clearing-date-callback

Conversation

@derekclee

Copy link
Copy Markdown
Contributor

Fixes a problem with <DatePickerSingle /> where the callback setProps was not called when a date was cleared.

if (setProps && date !== null) {
setProps({date: date.format('YYYY-MM-DD')});
if (setProps) {
setProps({date: date ? date.format('YYYY-MM-DD') : null });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This looks good to me. I'm a bit concerned about backward compatibility though, as it's been this way for as long as these components have existed and users may depend on null never arriving in their callbacks. @chriddyp thoughts? Do we need to make this behavior opt-in?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

OK, we discussed this internally, the consensus is we're happy to call the old behavior a bug, this PR a fix, so no need for opt-in 🎉

@alexcjohnson

Copy link
Copy Markdown
Collaborator

Thanks @derekclee! Really appreciate seeing the PR come with tests already in place 🏆 Aside from the question about backward compatibility that I'm not immediately sure how I feel about (if we were starting from scratch I'd much prefer to keep it simple like you have here), the only issue I see is linting - we use prettier, you can run it with npm run format to automagically fix the issues.

  - When clearing a date, `date` is set to `null` but `setProps`
    was not called.
  - Made sure to always call `setProps` on any date change.
@derekclee
derekclee force-pushed the issue-510-fix-clearing-date-callback branch from b745c51 to b29653d Compare April 4, 2019 14:19
@derekclee

Copy link
Copy Markdown
Contributor Author

@alexcjohnson I ran prettier on the files and fixed up the commit.

Our use case of the clearing is that we initially have a blank date filter on a visualization. The date may not always be present in the data thus having the filter optional is important. A user is able to filter by a date. If the date was not clearable, the user would have to do a full refresh of the application to get it back to the original state. I can add an opt in prop if needed.

On an unrelated note, I originally tried to use the DatePickerRange but that would no accept null starting dates. The fix for that is a lot harder as the error seems to be in <DayPicker /> from https://github.com/airbnb/react-dates and this library is using an older version.

@alexcjohnson alexcjohnson mentioned this pull request Apr 4, 2019

@alexcjohnson alexcjohnson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

💃

Comment thread test/test_integration.py

self.startServer(app=app)

self.wait_for_element_by_css_selector('#tabs-content')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

There was a percy diff - the image produced in this PR prior to this commit was actually the right one, dunno how the incorrect one got approved... but to make that more robust I added this wait for the correct element to be on the page.

@alexcjohnson
alexcjohnson merged commit 6c9cb71 into plotly:master Apr 5, 2019
@derekclee

Copy link
Copy Markdown
Contributor Author

Thanks @alexcjohnson !

alexcjohnson added a commit that referenced this pull request Apr 6, 2019
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.

2 participants