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

New props, functionalities and behaviour #18

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

Serg4554
Copy link

@Serg4554 Serg4554 commented Aug 20, 2018

Hello!
I needed some extra functionalities for my project and I thought that it could be useful for others, so here is the pull request :)

  • minutesStep property (number)
    Allows to choose the steps between minutes, so for instance, if you need to allow times only each 5 minutes, just set minutesStep={5}
  • cancelOnClose property (bool)
    Allows to decide if the time is cancelled or saved when background is clicked
  • inputClasses property (object)
    Allows to apply classes to input form (only TimePicker was supported)
  • Calling onChange when time changes
    The time is updated (onChange is called) whenever the time is changed and return the init date when is cancelled

I hope you find it useful 😃👍

@@ -78,7 +78,6 @@ describe('<TimePicker />', () => {
.simulate('click', testUtils.stubClickEvent(190, 230)) // click on 25
.simulate('mouseup', testUtils.stubClickEvent(190, 230)) // click on 25

expect(changeHandler).toBeCalled()
Copy link
Author

Choose a reason for hiding this comment

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

Removed by mistake, amended in the next commit

@@ -260,7 +259,6 @@ describe('<TimePicker />', () => {
.simulate('click', testUtils.stubClickEvent(190, 230)) // click on 25
.simulate('mouseup', testUtils.stubClickEvent(190, 230)) // click on 25

expect(changeHandler).toBeCalled()
Copy link
Author

Choose a reason for hiding this comment

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

Removed by mistake, amended in the next commit

@@ -141,7 +141,6 @@ describe('<TimeInput />', () => {
tree.find(Button).at(0).simulate('click')

expect(getValue(tree)).toBe('13:37') // unchanged
expect(changeHandler).not.toHaveBeenCalled()
Copy link
Author

Choose a reason for hiding this comment

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

Now is called in every date change and restored when canceled

Copy link
Member

Choose a reason for hiding this comment

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

Why? There is no reason to call the change handler when the date isn't changed.

Copy link
Author

Choose a reason for hiding this comment

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

I did that change because I needed the time text field (and some other components) to be updated when the user changes the hour in real time, so every time the user moves the clock hands, changeHandler is called.

Copy link
Member

@leMaik leMaik Sep 13, 2018

Choose a reason for hiding this comment

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

I see, that's a good point. 🤔 We should make that optional and turn it off by default. Maybe call that prop updateImmediately?

Copy link
Author

Choose a reason for hiding this comment

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

In fact, I think that's the best option, thus maintaining the same behavior (avoiding some developers from going crazy when updating 🙃) and providing that functionality, which in my case is very useful

Copy link
Member

Choose a reason for hiding this comment

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

That was my intention. 👍 Adding your use case while keeping this a minor update (i.e. no breaking changes).

@Serg4554 Serg4554 changed the title Added minutesSteps, cancelOnClose and calling onChange when time changes New props, functionalities and behaviour Aug 20, 2018
@coveralls
Copy link

coveralls commented Aug 20, 2018

Coverage Status

Coverage decreased (-2.9%) to 93.286% when pulling bb09972 on Serg4554:minutes-steps-and-onchange-update into 79b29df on TeamWertarbyte:master.

@leMaik
Copy link
Member

leMaik commented Sep 13, 2018

@Serg4554 I'm sorry I didn't see this earlier! This is an awesome first contribution, thank you so much! 🎉

I'd rename cancelOnClose to selectOnClose. 🤔 What do you think?

@Serg4554
Copy link
Author

Thanks to you for this awesome component!
About the property rename, yes, no problem, I agree 👍

Copy link
Member

@leMaik leMaik left a comment

Choose a reason for hiding this comment

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

Thanks again for this great PR! ❤️ Some nit-picky things (don't worry about them too much 😉).

I don't like the idea of calling onChange even if there are no changes. Is there an actual use case where this behavior is needed? 🤔

Regarding test coverage: While I aim at 💯 %, the -1,2% is fine. 👍

this.setState({ minutes: value }, () => {
this.propagateChange()
})
} else if (value % (this.props.minutesStep || 1) === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

The default step should better be set in the default props.

@@ -186,6 +184,7 @@ class TimePicker extends React.Component {
value={clockMode === 'minutes' ? minutes : hours}
onMouseUp={this.handleClockChangeDone}
onTouchEnd={this.handleClockChangeDone}
minutesStep={this.props.minutesStep || 1}
Copy link
Member

Choose a reason for hiding this comment

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

See above.

src/Clock.js Outdated
className={classNames(
classes.number,
{ selected: value === digit.display || (digit.display === 60 && value === 0) },
{ disabled: digit.display % (this.props.minutesStep || 1) })}
Copy link
Member

Choose a reason for hiding this comment

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

These two objects can be merged.

src/Clock.js Outdated
value: PropTypes.number.isRequired
value: PropTypes.number.isRequired,
/** Steps between minutes. */
minutesStep: PropTypes.number
Copy link
Member

Choose a reason for hiding this comment

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

The propTypes were sorted alphabetically before. 😉

src/TimeInput.js Outdated
@@ -80,19 +89,21 @@ class TimeInput extends React.Component {
value={formattedValue}
readOnly
key='TimeInput-input'
classes={inputClasses || {}}
Copy link
Member

Choose a reason for hiding this comment

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

No reason to set this to an empty object. Also, instead of introducing a new prop, this could as well be classes.input (just add input: {} to the styles object above, the user will then be able to customize it with classes={{ input: 'the-users-input-class' }}, a common Material-UI pattern).

src/TimeInput.js Outdated
onChange={this.handleChange}
onMinutesSelected={autoOk ? this.handleOk : null}
classes={{ header: classes.header, body: classes.body }}
minutesStep={minutesStep || 1}
Copy link
Member

Choose a reason for hiding this comment

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

minutesStep has a default value set below, so || 1 can be dropped here

src/TimeInput.js Outdated
@@ -117,14 +128,22 @@ TimeInput.propTypes = {
/** Callback that is called with the new date (as Date instance) when the value is changed. */
onChange: PropTypes.func,
/** The value of the time picker, for use in controlled mode. */
value: PropTypes.instanceOf(Date)
value: PropTypes.instanceOf(Date),
Copy link
Member

Choose a reason for hiding this comment

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

These used to be sorted alphabetically. 😅

}

TimeInput.defaultProps = {
autoOk: false,
cancelLabel: 'Cancel',
mode: '12h',
okLabel: 'Ok'
okLabel: 'Ok',
Copy link
Member

Choose a reason for hiding this comment

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

…these, too

value: PropTypes.instanceOf(Date)
value: PropTypes.instanceOf(Date),
/** Steps between minutes. */
minutesStep: PropTypes.number
Copy link
Member

Choose a reason for hiding this comment

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

see above

@Serg4554
Copy link
Author

Than you very much for taking the time to review all changes. Right now I'm developing a project against the clock 😅, but as soon as I finish I will try to leave it perfect 👌

@leMaik
Copy link
Member

leMaik commented Sep 13, 2018

@Serg4554 No problem, I'm happy that you'll take the time to get this PR ready to merge. :)

@leMaik
Copy link
Member

leMaik commented Sep 24, 2018

@Serg4554 Do you still have time to finish this PR? Don't worry, I'll update it for you otherwise. 👍

@Serg4554
Copy link
Author

@leMaik I will finish the current project that I'm working on in a month aprox. but we have very tight time, so if you could update it, I would appreciate it! Otherwise I will do it, you have my words

@Serg4554
Copy link
Author

@leMaik All changes we discussed are done, I hope you find them fine and useful! But the coverage has decreased a little bit, I will thank you if you could help me with that :)

@leMaik
Copy link
Member

leMaik commented Oct 29, 2018

@Serg4554 Awesome! 🎉 I've got this on my radar, I'll look into the tests soon (TM).

@leMaik
Copy link
Member

leMaik commented Nov 3, 2018

@Serg4554 Would you mind rebasing this on top of master? I'm a bit confused by all the changes right now…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants