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

[TimePicker] Update time state on new defaultTime prop. #3095

Merged
merged 1 commit into from
Feb 15, 2016

Conversation

rscnt
Copy link

@rscnt rscnt commented Jan 29, 2016

This pull request try to fix #3094.

If a TimePicker instance is already mounted and a new defaultTime is passed to it, the time state value doesn't update.

There was already a pull request aiming to fix this and other issues for this component at #2027, but it has been waiting for review since Nov 24, 2015.

newState.muiTheme = nextContext.muiTheme;
}
if (!Date.isEqualTime(this.state.time, nextProps.defaultTime)) {
newState.time = nextProps.defaultTime;
Copy link
Member

Choose a reason for hiding this comment

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

I think that the defaultTime should only be used during the first render, like for a regular <input />. I would add a new value property for your "controlled" use case.

Copy link
Author

Choose a reason for hiding this comment

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

@oliviertassinari of course, that would be better, the prop value is going to have precedence over defaultTime at first rendering, right?

@mbrookes
Copy link
Member

it has been waiting for review since Nov 24, 2015

Ah, technically it has been waiting for revision since then. Happens frequently. I call them drive by PRs! :D

Anyway, back to business! DatePicker has a value prop and a controlled example, you could model TimePicker off that.

@oliviertassinari oliviertassinari added the PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI label Jan 30, 2016
@rscnt
Copy link
Author

rscnt commented Jan 31, 2016

@mbrookes, @oliviertassinari

The TimePicker now adopts a behaviour similar to the DatePicker one.

Tests have been added to prove the fix, although they don't cover all scenarios, it show at least that the change is working 😅

@mbrookes mbrookes added PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Jan 31, 2016
@mbrookes
Copy link
Member

Gonna leave @oliviertassinari for the final review, but have to say, awesome work!

@oliviertassinari
Copy link
Member

@rscnt Wow, thanks for the tests! Could you update the examples of the doc? I would be better to remove the warnings from the console (linked to the deprecated methods)

@@ -80,6 +82,11 @@ const TimePicker = React.createClass({
textFieldStyle: React.PropTypes.object,

/**
* Sets the time for the Time Picker programmatically
Copy link
Member

Choose a reason for hiding this comment

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

missing dot at the end of the sentence.

@rscnt
Copy link
Author

rscnt commented Jan 31, 2016

@oliviertassinari docs have been updated, commentaries have been applied and mistakes have been fixed 😄

super(props);
this.state = {value24: new Date(), value12: new Date()};
this.handleChangeTimePicker24 = this.handleChangeTimePicker24.bind(this);
this.handleChangeTimePicker12 = this.handleChangeTimePicker12.bind(this);
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for using bind over the arrow function property?

@rscnt
Copy link
Author

rscnt commented Jan 31, 2016

@oliviertassinari warnings added and TimePicker/ComplexExample is now using arrow syntax.

@oliviertassinari
Copy link
Member

@rscnt Thanks! I will have a closer look at this PR, but that look good so far. I have seen some minor issue, like using let where const would work or adding a _ for method, but I wouldn't worry too much about it.
By the way, before we merge, you will have to squash down the commits. (make the history cleaner).

@rscnt
Copy link
Author

rscnt commented Feb 1, 2016

@oliviertassinari 'squashed' 👍

@@ -3,13 +3,17 @@ import TimePicker from 'material-ui/lib/time-picker/time-picker';

export default class TimePickerExampleComplex extends React.Component {

constructor(props) {
super(props);
this.state = {value24: new Date(), value12: new Date()};
Copy link
Member

Choose a reason for hiding this comment

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

Could we have only one state for this example with a default value null as before.
It would be something like:

this.state = {
  value: null,
};

Copy link
Author

Choose a reason for hiding this comment

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

👍

@oliviertassinari
Copy link
Member

@rscnt We are almost there :).

@oliviertassinari oliviertassinari added PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI and removed PR: Needs Review labels Feb 1, 2016
@rscnt rscnt force-pushed the master branch 2 times, most recently from 1dcbd2f to e180bc3 Compare February 11, 2016 21:56
@mbrookes
Copy link
Member

Hah, I was using this PR to test error output on gpr, and the errors went away. 😆

@mbrookes mbrookes added PR: Needs Review and removed PR: needs revision The pull request can't be merged. More details is available on the code review or fails in the CI labels Feb 11, 2016
@@ -204,7 +228,7 @@ const TimePicker = React.createClass({
{...other}
style={textFieldStyle}
ref="input"
value={time === emptyTime ? null : this.formatTime(time)}
value={time === emptyTime ? null : DateTime.formatTime(time, this.props.format, this.props.pedantic)}
Copy link
Member

Choose a reason for hiding this comment

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

What about DateTime.formatTime(time, format, pedantic)?

Copy link
Author

Choose a reason for hiding this comment

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

👍

@oliviertassinari
Copy link
Member

@rscnt Thanks!
Sorry, that's not ready to be merged 😁. I have more feedbacks and we have two conflicts with the master branch (wording and WindowsListener).

@rscnt rscnt force-pushed the master branch 2 times, most recently from 6c5798a to 2b41865 Compare February 12, 2016 19:39
@@ -165,4 +223,12 @@ export default {
return ~~(this.monthDiff(d1, d2) / 12);
},

isEqualTime(d1, d2) {
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for keeping this method? That's no longer used.

Copy link
Author

Choose a reason for hiding this comment

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

👍

@rscnt
Copy link
Author

rscnt commented Feb 14, 2016

@oliviertassinari removed.

ref="picker24hr"
format="24hr"
hintText="24hr Format"
<TimePicker format="ampm" hintText="12hr Format"
Copy link
Member

Choose a reason for hiding this comment

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

Could you follow this coding style?

<TimePicker
  format="ampm"
  hintText="12hr Format"

@oliviertassinari
Copy link
Member

@rscnt Thanks! I have done a final review of this PR, aside from my two comments and the Travis fail. I think that we can merge. Good job 🎉.

src/utils/date-time.js
  159:11  error  `isAM` is never modified, use `const` instead        prefer-const
  161:11  error  `additional` is never modified, use `const` instead  prefer-const

@alitaheri
Copy link
Member

This looks awesome 😍 can't wait to see it merged 👍

@rscnt rscnt force-pushed the master branch 2 times, most recently from 59f76b9 to b6e0271 Compare February 15, 2016 16:43
- TimePicker#getValue is now deprecated.
- TimePicker#setValue is now deprecated.
- Added value prop.
- defaultTime is only used if value is not defined on props.
- Added tests for TimePicker initialization behavior.
- Adding  utils/DateTime#formatTime

Fixes mui#3094

Signed-off-by: rscnt <[email protected]>
@rscnt
Copy link
Author

rscnt commented Feb 15, 2016

@oliviertassinari sorry, linting issues have been fixed.

oliviertassinari added a commit that referenced this pull request Feb 15, 2016
[TimePicker] Update time state on new defaultTime prop.
@oliviertassinari oliviertassinari merged commit 7df55c9 into mui:master Feb 15, 2016
@oliviertassinari
Copy link
Member

@rscnt Thanks that's a great feature 🚀.

@zannager zannager added component: time picker This is the name of the generic UI component, not the React module! component: pickers This is the name of the generic UI component, not the React module! labels Mar 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module! component: time picker This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TimePicker] state.time doesn't updates on new defaultTime prop.
6 participants