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

fix: Calendar select can't switch #15338

Merged
merged 11 commits into from Mar 12, 2019
Merged

fix: Calendar select can't switch #15338

merged 11 commits into from Mar 12, 2019

Conversation

orzyyyy
Copy link
Contributor

@orzyyyy orzyyyy commented Mar 12, 2019

First of all, thank you for your contribution! 😄

New feature please send pull request to feature branch, and rest to master branch.
Pull request will be merged after one of collaborators approve.
Please makes sure that these form are filled before submitting your pull request, thank you!

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / document update
  • Component style update
  • TypeScript definition update
  • Refactoring
  • Code style optimization
  • Branch merge
  • Other (about what?)

👻 What's the background?

  1. Describe the source of requirement, like related issue link.

    To close Calendar select cannot switch #15334

  2. Describe the problem and the scenario.

💡 Solution

  1. How to fix the problem, and list final API implementation and usage sample if that is an new feature.

  2. GIF or snapshot should be provided if includes UI/interactive modification.

📝 Changelog description

Describe changes from user side, and list all potential break changes or other risks.

Fix Calendar can't switch.

修复 Calendar 无法切换类型的问题。

☑️ Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

@netlify
Copy link

netlify bot commented Mar 12, 2019

Deploy preview for ant-design ready!

Built with commit d53e003

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

@afc163
Copy link
Member

afc163 commented Mar 12, 2019

We should add some test cases..

@netlify
Copy link

netlify bot commented Mar 12, 2019

Deploy preview for ant-design ready!

Built with commit 5c1c4e7

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

@codecov
Copy link

codecov bot commented Mar 12, 2019

Codecov Report

Merging #15338 into master will increase coverage by 0.07%.
The diff coverage is 33.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15338      +/-   ##
==========================================
+ Coverage   94.11%   94.18%   +0.07%     
==========================================
  Files         250      250              
  Lines        6643     6642       -1     
  Branches     1907     1906       -1     
==========================================
+ Hits         6252     6256       +4     
+ Misses        390      385       -5     
  Partials        1        1
Impacted Files Coverage Δ
components/calendar/Header.tsx 82.27% <100%> (ø) ⬆️
components/calendar/index.tsx 91.2% <20%> (+2.07%) ⬆️
components/_util/wave.tsx 87.5% <0%> (+2.88%) ⬆️

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 43b13f6...222c744. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 12, 2019

Codecov Report

Merging #15338 into master will increase coverage by 0.16%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #15338      +/-   ##
==========================================
+ Coverage   94.11%   94.27%   +0.16%     
==========================================
  Files         250      250              
  Lines        6643     6640       -3     
  Branches     1907     1938      +31     
==========================================
+ Hits         6252     6260       +8     
+ Misses        390      379      -11     
  Partials        1        1
Impacted Files Coverage Δ
components/calendar/Header.tsx 87.34% <100%> (+5.06%) ⬆️
components/calendar/index.tsx 96.62% <100%> (+7.49%) ⬆️

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 43b13f6...5c1c4e7. Read the comment docs.

@afc163
Copy link
Member

afc163 commented Mar 12, 2019

所以,问题是出在哪里了?

@orzyyyy
Copy link
Contributor Author

orzyyyy commented Mar 12, 2019

getDerivedStateFromProps 里判断 props 里有 mode 就更新 state, 然后 defaultProps.mode 始终都是 month,也就是 Header 的 onChange 始终没法改变外部的 mode

实际上去掉这个 defaultProps 就完了,其它改动是因为 type 老是变来变去,实在头疼就改了

测试用例在补,不要慌

@afc163
Copy link
Member

afc163 commented Mar 12, 2019

话说这个组件用的人真少,居然都没人报 bug。

@orzyyyy
Copy link
Contributor Author

orzyyyy commented Mar 12, 2019

何不弄个问卷,或者直接在文档网页上弄个点击统计

不但方便路人看热闹,自己还能看到哪些组件该重点维护

这组件出问题我还是在写测试用例的时候发现的

@afc163
Copy link
Member

afc163 commented Mar 12, 2019

image

@zombieJ
Copy link
Member

zombieJ commented Mar 12, 2019

话说这个组件用的人真少,居然都没人报 bug。

3.1.4.x 是好的:https://codesandbox.io/s/m9ol1o05nj

感觉迁移 lifecycle j经常遇到这类问题,合之前需要多点点 😄

ref: 4601144

@zombieJ
Copy link
Member

zombieJ commented Mar 12, 2019

- const mode = type === 'date' ? 'month' : 'year';
- if (this.state.mode !== mode) {
-     this.setState({ mode });	
-     this.onPanelChange(this.state.value, mode);	
- }

+ setType = (mode: CalendarMode) => {
+   this.setState({ mode });
+   this.onPanelChange(this.state.value, mode);
+ }

感觉 type 也没什么用了,全部统一掉吧:

  • mode => type
  • setType => setMode
  • onHeaderTypeChange => onHeaderModeChange

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

Successfully merging this pull request may close these issues.

Calendar select cannot switch
4 participants