Refactor new date picker#21792
Conversation
…n, poc for year picker modal
|
Hey there @ArekChr , We have some bugs :
Screen.Recording.2023-07-03.at.2.45.41.PM.mov
Screen.Recording.2023-07-03.at.11.59.24.AM.movScreen.Recording.2023-07-03.at.11.59.54.AM.mov
|
There was a problem hiding this comment.
@ArekChr I believe we implemented something different for a similar case , specifically the AvatarCropModal , we utilized the modal to display a new screen. It appears that the modal possesses the necessary animations and props to handle this scenario as well. I'm uncertain about the optimal approach we should adopt, but for the sake of consistency, I think it's best to adhere to a single approach.
There was a problem hiding this comment.
Great idea! What you proposed works flawlessly, with the only difference being that the modal has a backdrop, that the YearPickerPage did not have previously. But this matches the AvatarCropModal and brings more design consistency, so I think it's a even bigger win
Screen.Recording.2023-07-06.at.14.53.57.mov
|
thanks for the reviews and testing so far. great job, lets egt this done on Monday 🎉 |
| import {radioListItemPropTypes} from '../../SelectionListRadio/selectionListRadioPropTypes'; | ||
|
|
||
| const propTypes = { | ||
| ...withLocalizePropTypes, |
There was a problem hiding this comment.
| ...withLocalizePropTypes, |
Since this is a functional component we should use localize hook :
const {translate} = useLocalize();There was a problem hiding this comment.
I wasn't aware, thanks for this!
|
|
||
| const propTypes = { | ||
| ...withLocalizePropTypes, | ||
| ...withCurrentUserPersonalDetailsPropTypes, |
There was a problem hiding this comment.
| ...withCurrentUserPersonalDetailsPropTypes, |
Not needed.
| }; | ||
|
|
||
| function YearPickerModal(props) { | ||
| const headerMessage = props.textInputValue.trim() && !props.years.length ? props.translate('common.noResultsFound') : ''; |
There was a problem hiding this comment.
I think we should handle the search (filtering) inside this component something similar to :
const [searchText, setSearchText] = useState('');
const {sections, headerMessage} = useMemo(
() => {
const yearsList = searchText === '' ? props.years : _.filter(props.years, (year) => year.text.includes(searchText));
return {
headerMessage: !yearsList.length ? translate('common.noResultsFound') : '',
sections: [{data: yearsList, indexOffset: 0}],
}
},
[props.years, searchText],
)This will avoids unnecessary renders of calendar when we filter the list. It will also resets the search and fix this bug :
Screen.Recording.2023-07-09.at.8.34.52.PM.mov
There was a problem hiding this comment.
Cool, I like this approach. But that does not reset the search alone, because the modal is never unmounted, it just becomes invisible. So I also added an effect to clear the search text when it closes
| textInputValue: '', | ||
| yearsFiltered: this.years, |
There was a problem hiding this comment.
As suggested , let's move filtering logic to YearPickerModal.
| yearsFiltered: this.years, | ||
| }; | ||
|
|
||
| this.filterYears = this.filterYears.bind(this); |
There was a problem hiding this comment.
| this.filterYears = this.filterYears.bind(this); |
Same
| ))} | ||
| <YearPickerModal | ||
| isVisible={this.state.isYearPickerVisible} | ||
| years={this.state.yearsFiltered} |
There was a problem hiding this comment.
| years={this.state.yearsFiltered} | |
| years={this.years} |
we only need to pass initial years array.
| textInputValue={this.state.textInputValue} | ||
| onChangeText={this.filterYears} |
There was a problem hiding this comment.
| textInputValue={this.state.textInputValue} | |
| onChangeText={this.filterYears} |
As suggested , Not needed.
| }; | ||
|
|
||
| const defaultProps = { | ||
| ...withCurrentUserPersonalDetailsDefaultProps, |
There was a problem hiding this comment.
| ...withCurrentUserPersonalDetailsDefaultProps, |
unused.
| @@ -0,0 +1,84 @@ | |||
| import React from 'react'; | |||
| import PropTypes from 'prop-types'; | |||
| import {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '../../withCurrentUserPersonalDetails'; | |||
There was a problem hiding this comment.
| import {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '../../withCurrentUserPersonalDetails'; |
unused.
|
@fedirjh Sent fixes to all your latest comments! :) |
|
I see that some unit tests failed and I'm working on it 👍🏻 |
|
Fixed 👌🏻 |
fedirjh
left a comment
There was a problem hiding this comment.
Code looks good to me. Left one small comment.
| textInputLabel={translate('yearPickerPage.selectYear')} | ||
| textInputValue={searchText} | ||
| textInputMaxLength={4} | ||
| onChangeText={setSearchText} |
There was a problem hiding this comment.
| onChangeText={setSearchText} | |
| onChangeText={(text) => setSearchText(text.replace(CONST.REGEX.NON_NUMERIC, '').trim())} |
This will prevent searching for non num characters
Reviewer Checklist
Screenshots/VideosWebScreen.Recording.2023-07-10.at.3.34.56.PM.movMobile Web - ChromeScreen.Recording.2023-07-10.at.3.33.59.PM.movMobile Web - SafariScreen.Recording.2023-07-10.at.3.09.31.PM.movDesktopDesktop.moviOSScreen.Recording.2023-07-10.at.2.24.08.PM.movAndroidScreen.Recording.2023-07-10.at.3.32.34.PM.mov |
|
@fedirjh Great job on the review and thanks @thiagobrez for acting fast! |
mountiny
left a comment
There was a problem hiding this comment.
Thanks everyone, great job on this one 🎉
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/mountiny in version: 1.3.39-0 🚀
|
|
Awesome work! Love the simplification. |
|
🚀 Deployed to production by https://github.com/francoisl in version: 1.3.39-11 🚀
|
|
Coming from #19073: This refactor (page > modal) caused modal overlay regression again which was fixed during navigation refactor, though it's minor UI inconsistency. |
| this.props.onSelected(this.getSelectedDateString()); | ||
| }, | ||
| ); | ||
| this.setState((prev) => ({currentDateView: moment(prev.currentDateView).subtract(1, 'months').toDate()})); |
There was a problem hiding this comment.
✋ Coming from #33006
The refactor for moveToPrevMonth and moveToNextMonth doesn't update the year.
| <Modal | ||
| type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED} | ||
| isVisible={props.isVisible} | ||
| onClose={props.onClose} |
There was a problem hiding this comment.
We should include shouldHandleNavigationBack props to handle physical back button on mWeb. More details in:
#52383 (comment)
There was a problem hiding this comment.
@hungvu193 shouldHandleNavigationBack was not present when this PR was implemented. It was added in #38693.

Details
This pull request introduces significant improvements to the Date Picker component by refactoring the codebase and implementing logic changes. The main objectives are to enhance reusability by removing navigation.
Fixed Issues
$ #20630
PROPOSAL: #20630 (comment)
Tests
Offline tests
No offline tests needed.
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Web
web.mov
Mobile Web - Chrome
mobile.chrome.mov
Mobile Web - Safari
mobile.safari.mov
Desktop
desktop.mov
iOS
ios.mov
Android
android.mov