Skip to content
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

Redo TimeInput #151

Merged
merged 14 commits into from
Dec 5, 2018
Merged

Redo TimeInput #151

merged 14 commits into from
Dec 5, 2018

Conversation

dferber90
Copy link
Contributor

@dferber90 dferber90 commented Oct 8, 2018

Recreates TimeInput without flatpickr.

Advantages of new TimeInput

timeinput

UX:

  • shows time depending on locale
  • allows user to enter time using the keyboard
  • it is possible to enter time in the 24h format or 12h format

Code improvements:

  • does not use flatpicker anymore, so it’s A LOT cheaper to initialize (I dropped all optimizations we made, where initialized it on click only, and not at all on mobile)
  • renamed isInvalid to hasError as we use that for all inputs
  • added isAutofocussed
  • removed unused mode prop
  • removed unused timeZone prop
  • value can now always be converted to 24h format using TimeInput.to24h(value)
  • added name for easier use with Formik

Problems of old TimeInput

old-timeinput

It has the UX limitations that:

  • it is not possible to enter any value with the keyboard
  • no matter the locale, the value is always entered and shown in 12hr format (AM/PM)
  • The documentation was wrong
  • users can only adjust the time by a specificity of 5 minutes
  • users can not specify time more precise than minutes even though the API supports precision up to milliseconds

Technically it had the problems that:

  • It had support for props that had no effect on it or even broke it when unsupported props were passed
  • it is really heavy to initialize so we had to defer initialization for Modified Products where many TimeInput fields can be present at the same time

@dferber90 dferber90 added 💅 Type: Enhancement Improves existing code 🙏Status: Dev Review 👨‍🎨 Status: UI/UX Review Requires review from design team labels Oct 8, 2018
@dferber90
Copy link
Contributor Author

Tests are failing on CI because of something related to locale apparently. The tests are succeeding on my machine. I'm investigating.

@dferber90 dferber90 force-pushed the df-redo-time-input branch 2 times, most recently from 39d99cd to 28a8d0c Compare October 8, 2018 14:01
@dferber90
Copy link
Contributor Author

Fixed the failing test. Ready for review now :)

@dferber90
Copy link
Contributor Author

Ok, that wasn't very long until a new requirement surfaced.

The input should support a higher precision than currently shown. It should support up to 14:00:00.000, as the API supports the same precision.

I'll add this before putting the component into review again.

@dferber90 dferber90 added 🙏Status: Dev Review 👨‍🎨 Status: UI/UX Review Requires review from design team and removed 👨‍🎨 Status: UI/UX Review Requires review from design team labels Oct 8, 2018
@dferber90
Copy link
Contributor Author

The TimeInput now supports high precision times as well. It will only show the high-precision time (eg 14:00:05.895) when seconds or milliseconds are entered. Otherwise it will show the basic time (eg 14:00).

@dferber90 dferber90 requested a review from lufego October 9, 2018 08:33
@dferber90
Copy link
Contributor Author

high-precision-time

High precision timing for ya'll

@montezume
Copy link
Contributor

@dferber90 so much precision, so much wow 😮 👍

@dferber90 dferber90 requested a review from antonboyko October 9, 2018 09:52
Copy link

@antonboyko antonboyko left a comment

Choose a reason for hiding this comment

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

@dferber90 good job!

Copy link
Contributor

@tdeekens tdeekens left a comment

Choose a reason for hiding this comment

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

Super nice too see so much dependency cruft gone. Thanks a lot! Just left some thoughts.


export const ClearSection = props => (
<div
onClick={props.isDisabled ? undefined : props.onClear}
Copy link
Contributor

Choose a reason for hiding this comment

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

I've seen null being passed in that case. I don't mind but was wondering if there is a specific reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not aware of a difference and don't have any arguments for either side. I usually use undefined though.

If the target component was a custom component (not a "native" one like a div), then passing null would lead to the default prop not overwriting it if I'm not mistaken. Hence, I usually use undefined. In this case it does not matter though.


it('should have focus automatically when isAutofocussed is passed', () => {
const { container } = render(<TimeInput {...baseProps} isAutofocussed />);
expect(container.querySelector('input')).toHaveFocus();
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Copy link
Contributor Author

@dferber90 dferber90 left a comment

Choose a reason for hiding this comment

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

Noticed some things myself

@dferber90
Copy link
Contributor Author

dferber90 commented Oct 10, 2018

This was approved by @coolmilo as well, so we're good to go!

I'm thinking of waiting with the merge though, so that DateInput, DateTimeInput and TimeInput can be released at once.

hours: Number(hours) + (amPm === 'pm' ? 12 : 0),
minutes: Number(minutes),
seconds: Number(seconds),
milliseconds: Number(milliseconds),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The parsing of milliseconds is actually wrong. When a user enters 00:00:00.75 we parse 75 milliseconds, but it should be 750. We need to use right-pad to fill up to 3 digits with 0s before parsing the number.

The bug isn't noticeable because we use rightPad before displaying the data in format24hr, but the parseTime function itself is broken.

@dferber90 dferber90 force-pushed the df-redo-time-input branch 2 times, most recently from d861157 to e01cead Compare October 17, 2018 14:06
@dferber90 dferber90 removed the request for review from lufego October 22, 2018 13:09
@emmenko
Copy link
Member

emmenko commented Oct 25, 2018

@dferber90 anything else blocking this? Can you give us a status update on how to proceed here?

@dferber90
Copy link
Contributor Author

See the last comment:

I'm thinking of waiting with the merge though, so that DateInput, DateTimeInput and TimeInput can be released at once.

I want to merge this along with #166 so that they can be released at the same time. That's also why the "Awaiting release" label is on this PR. Otherwise consumers would have to do the migration in two steps if we release in between because of a bugfix or something alike.

#166 is still missing the implementation of the new designs, but I've started that yesterday.

@emmenko
Copy link
Member

emmenko commented Oct 26, 2018

Ok thanks for the update 👌

@dferber90 dferber90 merged commit 4d0205e into master Dec 5, 2018
@dferber90 dferber90 deleted the df-redo-time-input branch December 5, 2018 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💅 Type: Enhancement Improves existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants