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

Feat: New Date Picker Design #15343

Merged
merged 94 commits into from
Mar 20, 2023
Merged

Conversation

ArekChr
Copy link
Contributor

@ArekChr ArekChr commented Feb 22, 2023

Details

This Pull Request introduces the new implementation of DatePicker. At this moment, it is implemented only in Date of Birth screen.

  • Form (forward ref) has been fixed for CalendarPicker ref forwarding
  • OptionsSelection (forward keyboardType) has been updated to change the keyboard type in the selection text input
  • BaseTextInput has been updated by adding a right generic icon to display the calendar icon in the DOB input

Fixed Issues

$ #14322
PROPOSAL: #14322 (comment)

Tests

  • Verify that no errors appear in the JS console
  1. Enter the Date of Birth page
  2. Click on the input
  3. Change the month using the arrows
  4. Click the year
  5. After navigating to new screen select another year
  6. It should go back to screen with calendar open and new year in the picker
  7. Select the date

Offline tests

No need to test offline

QA Steps

  • Verify that no errors appear in the JS console
  1. Enter the Date of Birth page
  2. Click on the input
  3. Change the month using the arrows
  4. Click the year
  5. After navigating to new screen select another year
  6. It should go back to screen with calendar open and new year in the picker
  7. Select the date

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android / native
    • Android / Chrome
    • iOS / native
    • iOS / Safari
    • MacOS / Chrome / Safari
    • MacOS / Desktop
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I verified the translation was requested/reviewed in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

WEB-CHROME.mov
Mobile Web - Chrome ​ ​
ANDROID-CHROME.mov
Mobile Web - Safari ​ ​
IOS-SAFARI.mov
Desktop ​ ​
DESKTOP.mov
iOS
IOS.mov
Android
ANDROID.mov

@MelvinBot
Copy link

Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers!

@ArekChr
Copy link
Contributor Author

ArekChr commented Feb 22, 2023

#15208

Copy link
Contributor Author

@ArekChr ArekChr left a comment

Choose a reason for hiding this comment

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

Overall looks good. I left some minor comments, good job 🙌

src/components/CalendarPicker/index.js Outdated Show resolved Hide resolved
src/components/NewDatePicker/index.native.js Outdated Show resolved Hide resolved
src/stories/Form.stories.js Outdated Show resolved Hide resolved
@ArekChr ArekChr marked this pull request as ready for review March 2, 2023 12:06
@ArekChr ArekChr requested a review from a team as a code owner March 2, 2023 12:06
@melvin-bot melvin-bot bot requested review from Beamanator and mananjadhav and removed request for a team March 2, 2023 12:06
@MelvinBot
Copy link

@Beamanator @mananjadhav One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@mountiny mountiny requested review from mountiny and s77rt March 2, 2023 14:34
@TMisiukiewicz
Copy link
Contributor

also tagging @shawnborton for design review

@shawnborton shawnborton self-requested a review March 2, 2023 14:58
@shawnborton
Copy link
Contributor

shawnborton commented Mar 2, 2023

Looking good! A couple of minor items to address:

Let's use a calendar icon to the right of the date input field. You can use this svg here:
calendar.svg.zip

Screenshot 2023-03-02 at 10 01 32 AM

For the arrows, maybe we should give them a hover color? Perhaps even just using our textSupporting color would be enough.

For the year picker screen, I don't think we need to have the "Please select a year" text - I think it's pretty obvious what you need to do on that screen so that text doesn't really offer much, it just takes up space.
Screenshot 2023-03-02 at 10 03 22 AM

@shawnborton
Copy link
Contributor

Also, on the year screen, should we auto focus the search input? cc @trjExpensify not sure if we have a rule of them there.

Also, I notice that the list options stretch full width so the border goes to the edge of the screen. I think we want to fix this so that the borders line up within the left edge of the text. cc @cristipaval - did we fix this globally yet?
image

This is what we ideally want:
image

Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

@TMisiukiewicz @ArekChr Love that we got tests here already

There is one thing I would like to raise which is I think not a great UX. The Month section arrows are positioned to the right from the month text and hence if you change the month the position of the arrows moves too. This means you cannot quickly skip through them as you wont be able to click on the arrows quickly. you can see it in the web video here https://user-images.githubusercontent.com/24796318/222424665-7e5caae7-0d5a-4696-afbb-df53806ff1eb.mov

should we put the arrows on the left? or something else @shawnborton @Beamanator

src/components/CalendarPicker/ArrowIcon.js Outdated Show resolved Hide resolved
src/components/CalendarPicker/calendarPickerPropTypes.js Outdated Show resolved Hide resolved
src/components/CalendarPicker/calendarPickerPropTypes.js Outdated Show resolved Hide resolved
src/components/CalendarPicker/calendarPickerPropTypes.js Outdated Show resolved Hide resolved
src/components/NewDatePicker/index.native.js Outdated Show resolved Hide resolved
src/components/NewDatePicker/index.native.js Outdated Show resolved Hide resolved
src/components/NewDatePicker/index.native.js Outdated Show resolved Hide resolved
src/pages/YearPickerPage.js Show resolved Hide resolved
@shawnborton
Copy link
Contributor

I agree with that @mountiny and I actually think @JmillsExpensify designed an updated version of this at some point where the year is on the left side so it matches the formatting we do (YYYY-MM-DD). So let's do this:
image

Which I think solves that problem?

@mountiny
Copy link
Contributor

mountiny commented Mar 2, 2023

@shawnborton yep, love that, thanks!

@trjExpensify
Copy link
Contributor

Also, on the year screen, should we auto focus the search input? cc @trjExpensify not sure if we have a rule of them there.

Yep, agreed we should! Another instance of this particular list view page in production is the currency page in the request money flow.

@TMisiukiewicz TMisiukiewicz force-pushed the feat/new-date-picker-design branch from f1c85b7 to 03c62d2 Compare March 3, 2023 11:20
Copy link
Contributor

@s77rt s77rt left a comment

Choose a reason for hiding this comment

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

There is a lot to be improved here, first initial tests shows the date picker working well but I have few things to note for now:

  1. Arrows keep changing positions, making it hard to fast month switch.
  2. When a date is selected and you open the calendar, it will always point to last date, it should point to the current selected date.
  3. Clicking on year (while field is empty) will yield a form error.
  4. Can't clear date.
  5. backTo param accepts any value, not that I found a bug in that, just worth mentioning maybe we should use a whitelist to be extra safe
  6. The calendar (on web) is always rendered, it's just invisible (opacity is 0), so we can't use it with any other field? Is the date picker supposed to be rendered in it's separated page? does not seem to make sense.

src/components/CalendarPicker/calendarPickerPropTypes.js Outdated Show resolved Hide resolved
src/components/CalendarPicker/calendarPickerPropTypes.js Outdated Show resolved Hide resolved
src/components/CalendarPicker/ArrowIcon.js Outdated Show resolved Hide resolved
src/components/CalendarPicker/generateMonthMatrix.js Outdated Show resolved Hide resolved
src/components/CalendarPicker/index.js Outdated Show resolved Hide resolved
src/components/NewDatePicker/index.js Outdated Show resolved Hide resolved
src/components/NewDatePicker/index.native.js Outdated Show resolved Hide resolved
@mountiny
Copy link
Contributor

mountiny commented Mar 6, 2023

Can't clear date.

I think for now we decided to go without an option to clear, we can see later if the user experience will be bad, essentially the dates should not be optional I believe.

@s77rt great review 🙌

@Beamanator
Copy link
Contributor

I'm planning to hold off reviewing till more of the outstanding comments get resolved 👍 Or if they're already addressed, can you please resolve them @ArekChr ? 🙏

@ArekChr
Copy link
Contributor Author

ArekChr commented Mar 6, 2023

@Beamanator Yes, I will finish probably tomorrow

@mountiny mountiny requested a review from s77rt March 7, 2023 16:19
Copy link
Contributor

@mountiny mountiny left a comment

Choose a reason for hiding this comment

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

Let's ship this 🎉

@mountiny mountiny dismissed Beamanator’s stale review March 20, 2023 16:31

comments were addressed

@mountiny
Copy link
Contributor

I think we got approvals of Carlo, s77rt and Alex's comments were addressed so I am going to ship this :shiny:

@mountiny mountiny merged commit bb8dff1 into Expensify:main Mar 20, 2023
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 1.2.88-0 🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 1.2.88-0 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@tienifr
Copy link
Contributor

tienifr commented Mar 23, 2023

@mountiny @luacmartins This issue seems to be a regression caused by this PR.

I just made a quick proposal to fix it

Proposal

Please re-state the problem that we are trying to solve in this issue.

Place holder date format is incorrect in Spainese

What is the root cause of that problem?

In this PR, we are setting the placeholder in DateOfBirthPage as a constant (YYYY-MM-DD)

placeholder={this.props.placeholder || CONST.DATE.MOMENT_FORMAT_STRING}

What changes do you think we should make in order to solve the problem?

In Expensify/App/src/components/NewDatePicker/index.js
We should use withLocalize to wrap the component

withLocalize(React.forwardRef((props, ref) => (
    /* eslint-disable-next-line react/jsx-props-no-spreading */
    <NewDatePicker {...props} innerRef={ref} />
)));

don't forget to import new things and update the propsType

import withLocalize, {withLocalizePropTypes} from '../withLocalize';

const propTypes = {
    ...withLocalizePropTypes,
    ...datePickerPropTypes,
};

and then update the placeholder
placeholder={this.props.placeholder || this.props.translate('common.dateFormat')}

What alternative solutions did you explore? (Optional)

We also can pass the translate function from the parent component instead of using withLocalize

Result

Screen Shot 2023-03-23 at 17 55 42

@mountiny
Copy link
Contributor

Nice, exported the issue, do you want to post the proposal there too

@tienifr
Copy link
Contributor

tienifr commented Mar 23, 2023

@mountiny I just posted a proposal

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 1.2.88-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 failure ❌
🕸 web 🕸 success ✅

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/AndrewGable in version: 1.2.88-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Comment on lines +88 to +101
<OptionsSelector
textInputLabel={this.props.translate('yearPickerPage.selectYear')}
onChangeText={this.filterYearList}
keyboardType={CONST.KEYBOARD_TYPE.NUMBER_PAD}
maxLength={4}
value={this.state.inputText}
sections={[{data: this.state.yearOptions, indexOffset: 0}]}
onSelectRow={option => this.updateSelectedYear(option.value)}
initiallyFocusedOptionKey={this.currentYear.toString()}
hideSectionHeaders
optionHoveredStyle={styles.hoveredComponentBG}
shouldHaveOptionSeparator
contentContainerStyles={[styles.ph5]}
/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here we added a Search option but failed to handle no results case for the search.

Which lead to this issue

import getButtonState from '../../libs/getButtonState';
import * as StyleUtils from '../../styles/StyleUtils';

class CalendarPicker extends React.PureComponent {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a huge amount of comment history in this PR, so apologies if I missed something, but imo this CalendarPicker component should not have been separated from the NewDatePicker. Doing so actually makes things a bit more complicated.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. It would have been good to get some wider input before introducing large changes like this.

Copy link
Contributor

@mountiny mountiny Jun 12, 2023

Choose a reason for hiding this comment

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

It was separated to two components as initially we had a logic which was hiding and opening the date picker once user focused into the date input. So it was clearer from developer perspective that way I would say.

Down the road we have decided to remove this logic and the calendar is permanently shown now so it should be easier to keep it all in one component now

Copy link
Contributor

Choose a reason for hiding this comment

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

Made an issue to track the improvements here if you want to follow along

There was a bunch of follow up PRs to this component since this PR got merged so I am sure we could use some clean up and refactoring as well.

} from '../TextInput/baseTextInputPropTypes';
import CONST from '../../CONST';

const propTypes = {
Copy link
Contributor

Choose a reason for hiding this comment

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

These prop types are not imported anywhere except for src/components/NewDatePicker/index.js. So they should not have been moved to their own file and instead should be in the same file as the component they're relevant to. This also means that we would no longer need src/components/NewDatePicker to be a directory, and could just have src/components/NewDatePicker.js.

this.showPicker = this.showPicker.bind(this);
this.hidePicker = this.hidePicker.bind(this);

this.opacity = new Animated.Value(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to normalize using Reanimated as the default animation library for the sake of both performance and simplicity. This could've been a bit simpler by just using default Reanimated LayoutAnimations:

import Animated, {FadeIn, FadeOut} from 'react-native-reanimated';

...
...

<Animated.View
    onMouseDown={(e) => {
        // To prevent focus stealing
        e.preventDefault();
    }}
    style={[styles.datePickerPopover, styles.border]}
    entering={FadeIn}
    exiting={FadeOut}
>
    <CalendarPicker />
</Animated.View>

and I think that's it!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think thats a great suggestion

super(props);

this.monthNames = moment.localeData(props.preferredLocale).months();
this.daysOfWeek = moment.localeData(props.preferredLocale).weekdays();
Copy link
Member

Choose a reason for hiding this comment

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

This caused a regression.

Text wasn't changing when switched to a different locale through another device/tab

Comment on lines +94 to +95
const hasAvailableDatesNextMonth = moment(this.props.maxDate).endOf('month').startOf('day') > moment(this.state.currentDateView).add(1, 'M');
const hasAvailableDatesPrevMonth = moment(this.props.minDate).startOf('day') < moment(this.state.currentDateView).subtract(1, 'M').endOf('month');
Copy link
Contributor

Choose a reason for hiding this comment

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

This comparison was not accurate. More details about the root cause: #28622 (comment)

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.