New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flatpickr #9509
Flatpickr #9509
Conversation
As an aside I have realized half the issue is that our handing of date values (by forcing them to be datetimes) is half the problem(s). It did not help that is what pikaday expected. But Flatpick can handle actual date values with no no time, e.g. "2019-12-06", so I cam going to fix our |
7fb3001
to
22a13dc
Compare
@mattpap I'm not actually seeing what JS tests fail:
Is there something I need to do or does this need a separate issue? |
Test failures are currently showed only inline. We already discussed this, though there may not be an issue for this, and I'm going to improve reporting as time permits. If you don't see any errors inline and tests fail, then report a new issue. |
3aefe8b
to
c0c04e1
Compare
@mattpap @philippjfr this is still WIP but I would like some feedback. First, things to do:
Both of those will be fairly easy/straightforward. I'd like some input on the properties changes. The current code around serializing dates and datetimes is a mess, so the current changes are also a mess, and that is what I would like input on. I think ideally what should happen is for scalar Currently this is not quite true -- series/arrays transform as timestamps but plain lists of dates become iso strings:
I think the list case can be made consistent, though. |
Well, I was wrong about this, but I think we just document it and live with it. |
@philippjfr can you test this with HV/Panel when you get a chance? |
@mattpap @philippjfr OK I think everything except plumbing to hook up whatever set of flatpickr features we want, is done. I hope to have this PR done done by tomorrow night. I think the Date/Datetime property situation is generally better. To summarize:
One weird but anavoidable corner case: lists of Weird stuff I noticed but did not touch: timedeltas and pandas Period values are serialized as datetimes. I think this is not the right thing to do, in general. |
This pull request introduces 1 alert when merging c3471d9 into 16a7acd - view on LGTM.com new alerts:
|
else if (isArray(item) && item.length == 2) | ||
result.push({from: item[0], to: item[1]}) | ||
} | ||
return result |
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.
type DatesList = (string | string[])[]
Based on the above code the type should be (string | [string, string])[]
. The second condition is unnecessary. The return type should be (string | DateLimit<string>)[]
.
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.
It would be very meaningful to type DateType = string
, primarily for readability, even if that doesn't change anything from static typing perspective (TypeScript doesn't have nominal types unfortunately).
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.
type DateType = string
Actually, I will introduce that later, because there's an opportunity here to introduce pseudo nominal types.
private _picker: Pikaday | ||
private _picker: flatpickr.Instance | ||
|
||
private _set(key: string, value: any): void { |
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.
key: keyof Options
, then you won't need the cast below.
// toISOString() returns the wrong day (IE on day earlier) #7048 | ||
// XXX: this should be handled by the serializer | ||
this.model.value = date.toDateString() | ||
_on_change(_selected_dates: any, date_string: string, _instance: flatpickr.Instance): void { |
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.
https://github.com/flatpickr/flatpickr/blob/master/src/types/options.ts#L11 to get rid of the any
type.
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.
@mattpap the only way I can get those types to import is to do
import {Options as FlatpickrOptions, DateLimit} from "flatpickr/dist/types/options"
which does seem safe/good (importing from dist). Tried installing @types/flatpickr
but trying to import that also yields an error. The only thing exported from standard flatpickr
seems to be the flatpickr
instance.
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.
This is a common mistake that library author make, i.e. not exporting publicly enough type information. Let's leave it for now.
This pull request introduces 1 alert when merging ec557b6 into 87ca243 - view on LGTM.com new alerts:
|
this.connect(this.model.change, () => this.render()) | ||
|
||
const {value, min_date, max_date, disabled_dates, enabled_dates, position, inline} = this.model.properties | ||
this.connect(value.change, () => this._set("defaultDate", value.value())) |
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.
@bryevdv This sets only the initial date. The current date will not be changed. See the report at https://discourse.bokeh.org/t/datepicker-ui-not-updating-in-bokeh-2-0/5021
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.
@p-himik OK we should get a fix in for 2.0.1 (with a test) can you make an issue and I will take a look tomorrow.
Replace the current date picker with Flatpickr and also make the
Date
property more strict.