Skip to content

fix(datetime) update columns and validate value on change - #17562

Closed
KillerCodeMonkey wants to merge 14 commits into
ionic-team:masterfrom
KillerCodeMonkey:fix/datetime-update-columns-on-change
Closed

KillerCodeMonkey wants to merge 14 commits into
ionic-team:masterfrom
KillerCodeMonkey:fix/datetime-update-columns-on-change

Conversation

@KillerCodeMonkey

@KillerCodeMonkey KillerCodeMonkey commented Feb 21, 2019 •

Copy link
Copy Markdown
Contributor

Short description of what this resolves:

Dynamic datetime validation depending on current selection

Changes proposed in this pull request:

  • Extends Picker and PickerColumn to trigger events, when the selection changes.
  • Datetime listens on the new event and:
    • sets new value
    • recalculates columns
    • validates the new value

For correct Month days validation checkout #17558

Ionic Version:
4.0.2

Fixes: many of #16630

@ionitron-bot ionitron-bot Bot added the package: core @ionic/core package label Feb 21, 2019
@KillerCodeMonkey

KillerCodeMonkey commented Feb 21, 2019 •

Copy link
Copy Markdown
Contributor Author

@liamdebeasi here is a little bit help needed. There is the problem that after validation render is not triggered again. So the calculation works and columns are created and disabled and the validated dateTime is used, but you need to do a haptic change so the correct day column gets selected.

bildschirmfoto 2019-02-21 um 16 17 43

But in general i think this will improve the current datetime anyways :)

@KillerCodeMonkey KillerCodeMonkey changed the title WIP: fix(datetime) update columns and value on change WIP: fix(datetime) update columns and validate value on change Feb 21, 2019
@KillerCodeMonkey KillerCodeMonkey changed the title WIP: fix(datetime) update columns and validate value on change fix(datetime) update columns and validate value on change Feb 21, 2019

@liamdebeasi liamdebeasi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There seem to be a few issues when using the datetime component:

  1. For February 2019, sometimes the "day" column shows up to 28 days, sometimes it shows up to 31 days (days 29-31 appear and disappear as I drag the "day" column)
  2. When going from January 31, 2019 to Feburary, 2019 the "day" column disappears entirely.
  3. When going from a day like January 30 to Feburary 28, it shows the correct number of days, but I would expect that the "day" column would default to the closest day and scroll that into view. So since I had January 30 selected, but the closest day in February is February 28, I would expect that the "28" would become selected.

Let me know if you need me to clarify any of those or provide examples. Thanks for opening this PR. We really appreciate all the hard work you've put into this so far!

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi yeah here i need a little bit help from you.

i select the correct nearest date and it is correct in the datetime component, but the change of the selected columns in the picker is not updating correctly. And i do not know why?

Maybe you can help here a little bit.

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi i think i can get it!... one last thing :)

@KillerCodeMonkey

KillerCodeMonkey commented Feb 27, 2019 •

Copy link
Copy Markdown
Contributor Author

@liamdebeasi after a long time hacking around. i am at a point where is only one little thing left.

Know everything is updated correctly, but i call this.refresh() after a picker column changes.

But i have to call this in a timeout so everything works like in the componentDidLoad hook.
So you see the 31th day of a month dislocated for 250ms.
if i remove the timeout around the refresh-function the added days are dislocated all the time.

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi so i knocked it down to simply have a timeout of 0, but there is a little flickering left.
but maybe this is enough in the first step to get the datetime picker work like you would expect it.
I am open for hints how to refresh the the cols without a timeout.

@liamdebeasi

Copy link
Copy Markdown
Contributor

Ok great. Yeah apart from that flickering, everything looks good. Ideally we shouldn't have that flickering. I'll try to jump into the code and see if I can make any suggestions.

@KillerCodeMonkey

KillerCodeMonkey commented Feb 28, 2019 via email

Copy link
Copy Markdown
Contributor Author

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi but maybe we can merge this back, so the datetime component is usable and works like expected. This would make many people happy. After that we can tackle the part, how to append new column options without that little flickering?

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi i know why there is that flickering or not rendering when we remove the timeout.

the update method uses the rendered button elements. So when you add a column you need to wait for it to render :S

@KillerCodeMonkey

KillerCodeMonkey commented Mar 1, 2019 •

Copy link
Copy Markdown
Contributor Author

@liamdebeasi its doooooone... its over.... i tried my posted solution -> cols are intialized as hidden, and get visibile after first transformation.

BTW: this pr will allow to listen on column changes in a picker and will allow to change picker cols on the fly 😎

@liamdebeasi

Copy link
Copy Markdown
Contributor

This is looking a lot better! Nice work!

The one thing I'm noticing is that inertia scrolling is no longer working as it did before. Try "flinging" one of the columns and then compare it to the one in our docs: https://ionicframework.com/docs/api/datetime

It seems like it's snapping to the next item in the column a bit too aggressively. Maybe it has something to do with this? https://github.com/ionic-team/ionic/pull/17562/files#diff-c5ad26cc3f41bcf11e1dfd40af45212fR46

@KillerCodeMonkey

KillerCodeMonkey commented Mar 1, 2019 •

Copy link
Copy Markdown
Contributor Author

@liamdebeasi And it is me again 🤯. I investigated and came to this solution: i trigger the pickerColumnChange event only if the element is directly clicked (velocity === 0 in the onEnd method) or not decelerating (the case when notLockedIn is false in the decelerating function).

So this avoids emitting a flood of events and associrated refresh calls. It only refreshs if the column is locked.

Maybe now???:

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi i do not want to spam you, but maybe you want to check the latest fixes :)

@liamdebeasi liamdebeasi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking really good! Can we remove the animation when changing updating column values? If you select April 28 and then select May, you see the 31 appear and then animate down out of view.

@KillerCodeMonkey

KillerCodeMonkey commented Mar 4, 2019 via email

Copy link
Copy Markdown
Contributor Author

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi here we go again :D

@liamdebeasi

Copy link
Copy Markdown
Contributor

I think we're almost there! I'm wondering if we can do anything about the scroll cancelling occurring when changing columns.

For example, if you flick a time column and then change the month, the time column abruptly snaps to the nearest values whereas previously it would continue to scroll until it "eased" to a stop.

My guess is this is happening due to the column recalculations we're doing? Is there any easy way to determine whether or not we need to recalculate a column? For example, changing the month column should have no bearing on what the hour column is doing. Let me know if you need any clarification!

@KillerCodeMonkey

KillerCodeMonkey commented Mar 5, 2019 •

Copy link
Copy Markdown
Contributor Author

@liamdebeasi now i merge old columns with the new generated ones, so only the columns with changes get the update.

Seems like this does not cancel the flick of a column that is not affected of the previous column change.

The event i introduced is passing the column that changed, as additional data, but if you change the year - day, hour and minutes can change, because of max/min settings or like in leap years the days of feburary changes.
The same thing when you change the Month, day, hours and minutes need to be validated and generated.
For day changes only hours and minutes needs to be validated and generated.

So i think it is easier to generate all columns and merge the object together.

If this will be a performance killer we can refactor the column generation, but i trying to avoid that for now :)

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi maybe today is the day :D

- set noAninmate to true for the refresh
- reset refresh method to original params
Trigger picker column update only for columns that changed
@liamdebeasi

Copy link
Copy Markdown
Contributor

Hi @KillerCodeMonkey,

Sorry for just getting to this now. It looks like something broke -- going from March --> February no longer updates the "days" column (i.e. I can still select February 31, 2019).

I did make a few updates earlier this week to how datetime values are parsed/formatted relative to the user's timezone, but not sure that would cause issues.

Can you verify on your end if things are working as you'd expect?

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi i added
Object.assign(this.picker!.columns, columns);

to update only changed columns to avoid that #17562 (review)

this seems no longer to work... -.-"

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi seems like this is not solvable that easy (because of stenciljs immutable bindings). maybe i revert my latest changes and we merge it back and work up on this?

I think this pr gives the ionic community a mostly working datetime picker?

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi wait for it^^... i had another idea. Filtering the changes i want in the pickercolumn and only triggering refreshing if something changed!

Now my head is empty. Hope this works for you.
Nice sideeffect: Columns only update, when they really change.

Space for improvement: i simply use JSON.stringify to compare old and new col value. This works, because the cols are simple and not deep nested objects.

Update col only when it really changes. Hold the col value on an internal state and check on col prop updates, if the col really changed.
This avoids useless rerenderings and refresh of picker colums.
@KillerCodeMonkey

KillerCodeMonkey commented Mar 14, 2019 •

Copy link
Copy Markdown
Contributor Author

@liamdebeasi i remove PropWillChanged in favor of watch

@liamdebeasi

Copy link
Copy Markdown
Contributor

Hi @KillerCodeMonkey,

I would like to try and also close out this older datetime PR: #14434

As a result, I have setup a branch that has a combination of your changes and changes the other contributor made. I tested and it seems to be working well. It would be great if you could also test it and let me know if you see anything wrong.

I still need to write more automated tests, so that will have to be done before it gets merged.

Here is the branch: https://github.com/ionic-team/ionic/tree/datetime-col-change

Thanks!

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi seems to work! 👍

If you need more info for the tests. let me know. 🙃

@liamdebeasi

Copy link
Copy Markdown
Contributor

Any info you have on tests would be great! Thanks!

@KillerCodeMonkey

Copy link
Copy Markdown
Contributor Author

@liamdebeasi i only know how you write unit tests and not checked the e2e tests, yet.
what tests do you wanna add?

But there are to things to tests:

  1. the eventlistener in the datetime component, to tests that the selected value is validated and the columns are generated, e.g. changing the month should change the days from 31 to 30 or something like that.
  2. the watcher of col in picker column which should trigger refresh only if the column data changed

@liamdebeasi

Copy link
Copy Markdown
Contributor

Hi there,

This issue has been resolved by #17846. You have been added as a co-author in that commit due to your contributions here.

Thank you very much for the work you put into this PR!

@KillerCodeMonkey
KillerCodeMonkey deleted the fix/datetime-update-columns-on-change branch June 17, 2019 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants