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

[HOLD App#22901] Fix/address page state navigation #29053

Closed
wants to merge 10,000 commits into from

Conversation

ygshbht
Copy link
Contributor

@ygshbht ygshbht commented Oct 7, 2023

Details

Fixed Issues

$ #23725
PROPOSAL: #23725 (comment)

Tests

  1. Go to Settings > Profile > Personal details > Home address > State
  2. Click back button of device
  3. Notice it Properly navigates to Home address screen
  • Verify that no errors appear in the JS console

Offline tests

Same as tests

QA Steps

Same as tests

  • Verify that no errors appear in the JS console

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 the left part of a conditional rendering a React component is a boolean and NOT a string, e.g. myBool && <MyComponent />.
    • 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 grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is 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
    • If we are not using the full Onyx data that we loaded, I've added the proper selector in order to ensure the component only re-renders when the data it is using changes
      • 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 code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • 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 the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • 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.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.

Screenshots/Videos

Web
output_web.mp4
Mobile Web - Chrome
output_android.chrome.mp4
Mobile Web - Safari
output_ios.safari.mp4
Desktop
output_desktop.mp4
iOS
output_ios.mp4
Android
trimmed_output_android.mp4

@ygshbht ygshbht requested a review from a team as a code owner October 7, 2023 13:51
@melvin-bot melvin-bot bot removed the request for review from a team October 7, 2023 13:51
@melvin-bot
Copy link

melvin-bot bot commented Oct 7, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Oct 7, 2023

@parasharrajat Please 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]

@melvin-bot melvin-bot bot requested a review from parasharrajat October 7, 2023 13:51
@ygshbht
Copy link
Contributor Author

ygshbht commented Oct 7, 2023

@parasharrajat I have made the changes. Will soon add the screenshots and complete the checklist.

I'd like to hightlight a minor issue:

Regarding CountryPicker (not related to StatePicker/ this PR), I see behavior (attached below) where after modifying state value, there's form error on validation when you change country. This issue was slighlty diferent before the first PR. I couldn't figure what was the difference. I am leaning towards labelling it unintentional. Do you think this needs fixing? Also, if you just touch the input and change the country, the error was there before the change as well as after it. The first part of video shows behaviour on country-selector branch and the second part on the main branch (main branch before country picker update)

2023-09-26_16-04-04_output_trimmed.mp4

@parasharrajat
Copy link
Member

parasharrajat commented Oct 7, 2023

@ygshbht I really didn't understand from your comment what is the issue. Before and after look same.

Are you saying that after changing the country the state picker that was filled shows an error? I think this is because the form input remains dirty even after we clear it on the setting country. We should reset its state when changed programmatically.

Let me test it first.

@@ -164,6 +174,8 @@ function AdditionalDetailsStep({walletAdditionalDetails, translate, currentUserP
);
}

const state = getStateFromRoute(route);
Copy link
Member

Choose a reason for hiding this comment

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

let's use useRoute hook instead.

@ygshbht
Copy link
Contributor Author

ygshbht commented Oct 8, 2023

Are you saying that after changing the country the state picker that was filled shows an error? I think this is because the form input remains dirty even after we clear it on the setting country. We should reset its state when changed programmatically.

Yes. Because the state field has been touched, the error ("this field is required") is shown after you change the country and set state to empty string

@parasharrajat
Copy link
Member

@ygshbht Did you handle #28743 as well?

@ygshbht
Copy link
Contributor Author

ygshbht commented Oct 11, 2023

@parasharrajat Yes, it should be fixed now. If you see any issue, please let me know

@parasharrajat
Copy link
Member

@ygshbht I have been tracking https://github.com/Expensify/App/pull/27836/files PR which seems to implement a similar picker but in a generic way. I am hoping that we can reuse that component in our PR. Unfortunately, there is a bug in that PR thus we reverted that PR. But It is hoped to be remerged soon. Do you think we can wait on that and reuse logic?

@ygshbht
Copy link
Contributor Author

ygshbht commented Oct 13, 2023

@parasharrajat, I'm not sure. Upon reviewing the files, it seems that the change is a replacement for the Picker component, and not CountryPicker or StatePicker. While more general components could be advantageous, it might stray a bit from the scope of this task; however, I trust your judgment on what's best.

@parasharrajat
Copy link
Member

Thanks for the response. I will analyze the code myself and try to outline the possible changes. I agree let's do this only when it is a quick change.

@parasharrajat
Copy link
Member

Okay, so ValuePicker on that PR is using the Old pattern which we are migrating away so we are good.

I think I will report a new issue to migrate those to the new pattern as well. But it gave me an idea. Can we use a similar valueSelector component that replaces both CountrySelector and StateSelector? Maybe we can control the type via props.

Can you analyze this? @ygshbht

@ygshbht
Copy link
Contributor Author

ygshbht commented Oct 16, 2023

@parasharrajat CountryPicker and StatePicker are very similar indeed. I suppose, if whole components can't be repalced with a single component, a good chuck of their code can be. Some differences that i initially see which might be not very straightforwrad to tackle include these in CountrySelectionPage and StateSelectionPage
image
image

@parasharrajat
Copy link
Member

parasharrajat commented Oct 18, 2023

Apologies for the delay. Your comment makes sense. I will get this finalized tomorrow.

@ygshbht
Copy link
Contributor Author

ygshbht commented Oct 25, 2023

bump @parasharrajat

params?: Record<string, any>;
};

export default function getStateFromRoute(route: RouteProps, stateParamName = 'state'): string {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have to create a separate hook? I think the logic can be moved in useGeographicalStateFromRoute itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that was being used at mulitple places before i created useGeographicalStateFromRoute. Have removed it

@ygshbht
Copy link
Contributor Author

ygshbht commented Oct 27, 2023

@parasharrajat Updated. I've also removed StateSelector logic of getting param from URL in various files and also fixed autocomplete bug for state if you want to test

@parasharrajat
Copy link
Member

@ygshbht Can you please merge main again? We has a major refactor on main.

@ygshbht
Copy link
Contributor Author

ygshbht commented Oct 29, 2023

@parasharrajat Done

src/ROUTES.ts Outdated
route += `&label=${encodeURIComponent(label)}`;
}
if (stateParamName) {
route += `&stateParamName=${encodeURIComponent(stateParamName)}`;
Copy link
Member

Choose a reason for hiding this comment

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

what is the purpose of this?

Copy link
Contributor Author

@ygshbht ygshbht Oct 31, 2023

Choose a reason for hiding this comment

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

To distinguish state values for cases when there are more than one state selectors in one page e.g Company step in Reimbursement flow.

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 we can hold this on changes done here #22901 as I believe we will not have two state pickers on one page ever

forwardedRef: PropTypes.func,

/** Label of state in the url */
paramName: PropTypes.string,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
paramName: PropTypes.string,
queryParam: PropTypes.string,

inputID: PropTypes.string.isRequired,

/** React ref being forwarded to the MenuItemWithTopDescription */
forwardedRef: PropTypes.func,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
forwardedRef: PropTypes.func,
forwardedRef: refPropType,

Please import it.

label: PropTypes.string,

/** whether to use state from url, for cases when url value is passed from parent */
useStateFromUrl: PropTypes.bool,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
useStateFromUrl: PropTypes.bool,
shouldUseStateFromUrl: PropTypes.bool,

Comment on lines 2 to 3
// eslint-disable-next-line you-dont-need-lodash-underscore/get
import lodashGet from 'lodash/get';
Copy link
Member

Choose a reason for hiding this comment

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

We can remove the lodash from this code. I don't see any need for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure? Its being used at two places. The code will be longer without it but I'll remove it if you think that's causing any issues

Copy link
Member

Choose a reason for hiding this comment

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

We can use optional chaining from TS instead of lodash. We are trying to get away from it.

src/hooks/useGeographicalStateFromRoute.ts Outdated Show resolved Hide resolved
@parasharrajat
Copy link
Member

Somehow, I forgot to submit the review 2 days back.

@parasharrajat
Copy link
Member

Can you please also merge main into this?

@parasharrajat
Copy link
Member

@mountiny Can you please cross-verify the approach as well?

* @param {string} paramValue - The value of the query parameter to append or update.
* @returns {string} The updated URL with the appended or updated query parameter.
*/
function appendParam(url, paramName, paramValue) {
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 we should update our navigate function to accept params. It is duplicate work when react-navigation already handles that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the Navigation.navigate and Navigation.goBack functions? Can you please provide a little example of the change you want here?

Copy link
Member

Choose a reason for hiding this comment

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

Technically, this change is out of the scope of this PR. I was just putting the idea.

We can, for now, move this function to a lib for generic use.

@ygshbht
Copy link
Contributor Author

ygshbht commented Oct 31, 2023

@parasharrajat Merged and updated. Please let me know your thoughts on the remaining changes

@ygshbht
Copy link
Contributor Author

ygshbht commented Nov 1, 2023

@parasharrajat Done

grgia and others added 24 commits February 15, 2024 08:09
…migration

[TS migration] Migrate 'DistanceEReceipt.js' component to TypeScript
[FIX]: "PO boxes and mail drop addresses are not allowed" appears twice in Address
[FIX]: "Company type" appears twice in the selection list
…sReportMessageAttachmentTest

[No QA] [TS migration] Migrate 'isReportMessageAttachmentTest.js' test to TypeScript
…ify-icons

fix: cretae seperated logo for icons
…le-levels-tags

Allow for multiple levels of tags on workspace
…y-native-attachment-carousel

Simplify native attachment gallery paging context and improve code
Conversation scrolling to the beginning of the chat.
…-for-e2e-failures

[NoQA] post slack update about failed e2e pipeline to new slack room
Update report description max length to 500
…mistic-flag

Ensure isOptimisticReport is set and fix issues with optimistic reports getting deleted on reconnect
…olations/36481-billable-field

Move violation message below billable field
@ygshbht
Copy link
Contributor Author

ygshbht commented Feb 18, 2024

@parasharrajat I merged fix/address-page-state-navigation into main and then merged main back into fix/address-page-state-navigation. But as you see Github shows a lot of commits. You think i need to create a new PR or can this be fixed somehow?

@ygshbht ygshbht mentioned this pull request Feb 18, 2024
58 tasks
@mountiny
Copy link
Contributor

@ygshbht yes please, can you create a fresh PR this might be the best path forwards

@ygshbht
Copy link
Contributor Author

ygshbht commented Feb 19, 2024

Yep, it is here

@mountiny
Copy link
Contributor

Lets close this in favour of #36770 then thank you

@mountiny mountiny closed this Feb 19, 2024
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.