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

Migrated to new lifecycle method for datepiceker #10309

Merged
merged 6 commits into from Jul 19, 2018

Conversation

Rohanhacker
Copy link
Contributor

@Rohanhacker Rohanhacker commented Apr 29, 2018

…picker

First of all, thank you for your contribution! :-)

Please makes sure that these checkboxes are checked before submitting your PR, thank you!

  • Make sure that you propose PR to right branch: bugfix for master, feature for latest active branch feature-x.x.
  • Make sure that you follow antd's code convention.
  • Run npm run lint and fix those errors before submitting in order to keep consistent code style.
  • Rebase before creating a PR to keep commit history clear.
  • Add some descriptions and refer relative issues for you PR.

Extra checklist:

if isBugFix :

no
elif isNewFeature :

#9792

@Rohanhacker Rohanhacker changed the title changed componentWillReceiveprops to getDerivedStateFromProps in date… Migrated to new lifecycle method for datepicekr Apr 29, 2018
@Rohanhacker Rohanhacker changed the title Migrated to new lifecycle method for datepicekr Migrated to new lifecycle method for datepiceker Apr 29, 2018
@ant-design-bot
Copy link
Contributor

ant-design-bot commented Apr 29, 2018

Deploy preview for ant-design ready!

Built with commit 1b76799

https://deploy-preview-10309--ant-design.netlify.com

@yesmeck
Copy link
Member

yesmeck commented May 2, 2018

We need use https://github.com/reactjs/react-lifecycles-compat

@Rohanhacker
Copy link
Contributor Author

@yesmeck ok Will update

@codecov
Copy link

codecov bot commented May 2, 2018

Codecov Report

Merging #10309 into master will decrease coverage by 0.01%.
The diff coverage is 95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10309      +/-   ##
==========================================
- Coverage   91.76%   91.75%   -0.02%     
==========================================
  Files         199      199              
  Lines        5005     5011       +6     
  Branches     1402     1402              
==========================================
+ Hits         4593     4598       +5     
- Misses        407      408       +1     
  Partials        5        5
Impacted Files Coverage Δ
components/date-picker/createPicker.tsx 96.82% <100%> (+0.1%) ⬆️
components/date-picker/WeekPicker.tsx 80.39% <100%> (+0.8%) ⬆️
components/date-picker/RangePicker.tsx 95.1% <90%> (-0.64%) ⬇️
components/select/index.tsx 100% <0%> (ø) ⬆️
components/drawer/index.tsx 85.41% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2cacfe7...1b76799. Read the comment docs.

@picodoth
Copy link
Contributor

picodoth commented Jun 2, 2018

@Rohanhacker can you resolve conflict? Thanks!

@Rohanhacker
Copy link
Contributor Author

sure

if ('open' in nextProps) {
state = {
...state,
open: nextProps.open,
Copy link
Contributor

Choose a reason for hiding this comment

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

gDSFP is not a drop in replacement for cWRP, this implementation will reset state.open on every parent rerender under React 16.4.

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

Choose a reason for hiding this comment

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

@whtsky thanks, I didn't know. I'll add condition to check whether 'value' & 'open' is changed or not

showDate: getShowDateFromValue(value) || prevState.showDate,
};
}
if (('open' in nextProps) && prevState.open !== nextProps.open) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this doesn't solve the problem: state.open still got reset to props.open whenever getDerivedStateFromProps is called.

One possible solution is to store previous props.open & props.value in state and compare them in gDSFP, then update state if they didn't match with nextProps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@whtsky that's what I am doing no ? previous values of 'open' and 'value' are stored in state and I am comparing them in gDSFP ??

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, sorry. Didn’t realize value & open won’t be modified if passed in props.

static defaultProps = {
prefixCls: 'ant-calendar',
allowClear: true,
showToday: false,
};

static getDerivedStateFromProps(nextProps: any, prevState: any) {
let state = null;
if (('value' in nextProps) && !isEqual(nextProps.value,prevState.value)) {
Copy link
Member

Choose a reason for hiding this comment

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

Why need to compare nextProps.value and prevState.value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yesmeck so that it only change state when the value of 'value' changes, otherwise it'll reset value of 'value' every time the parent rerenders as @whtsky commented

Copy link
Member

Choose a reason for hiding this comment

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

Is it ok to reset value of value on every time the parent rerenders? Like we did in componentWillReceiveProps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup we did reset it every time in componentWillReceiveProps so I suppose its okay to do so ?
Ok I'll change it

@yesmeck
Copy link
Member

yesmeck commented Jun 8, 2018

CI failed.

@Rohanhacker
Copy link
Contributor Author

@yesmeck done but it seems like there is some typing error. Should do I have to update @types/react for fixing this?

@yesmeck
Copy link
Member

yesmeck commented Jun 11, 2018

@Rohanhacker Yes, please.

@Rohanhacker
Copy link
Contributor Author

@yesmeck the lint is failing on upstream/master. Can you please check

@yesmeck
Copy link
Member

yesmeck commented Jul 16, 2018

It's passing now.

@Rohanhacker
Copy link
Contributor Author

@yesmeck Can you review and merge ? All tests are passing now

@yesmeck
Copy link
Member

yesmeck commented Jul 18, 2018

@Rohanhacker Checking.

package.json Outdated
"@types/react": "^16.4.6",
"@types/react-dom": "^16.0.6",
"@types/react": "^16.0.0",
"@types/react-dom": "^16.0.0",
Copy link
Member

Choose a reason for hiding this comment

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

?

Copy link
Member

Choose a reason for hiding this comment

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

We're using ^16.0.0 on master.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

some tests were failing when I upgraded to 16.4.6 so had to downgrade

@yesmeck yesmeck merged commit 12b9997 into ant-design:master Jul 19, 2018
@yesmeck yesmeck mentioned this pull request Aug 2, 2018
54 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants