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

[TS migration] Migrate SearchPage #34655

Merged
merged 35 commits into from
Mar 11, 2024

Conversation

ruben-rebelo
Copy link
Contributor

Details

[TS migration] Migrate SearchPage to TypeScript

Fixed Issues

$ #25182
PROPOSAL: N/A

Tests

  • Verify that no errors appear in the JS console

Test NewChatPage:

  • Log into an account
  • On the initial screens tap on search button on the drawer menu
  • This screen should work as before together with search, footer and select user functionality

Offline tests

N/A

QA Steps

  • Verify that no errors appear in the JS console

Same as in the Tests section.

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: mWeb Chrome
    • iOS: Native
    • iOS: mWeb 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 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(theme.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 the PR modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label so the design team can review the changes.
  • 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.

Screenshots/Videos

Android: Native android-native
Android: mWeb Chrome android-web
iOS: Native ios-native
iOS: mWeb Safari ios-web
MacOS: Chrome / Safari macos-web
MacOS: Desktop macos-native


type SearchPageProps = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type SearchPageProps = {
type SearchPageOnyxProps = {

src/pages/SearchPage.tsx Outdated Show resolved Hide resolved
SearchPage.displayName = 'SearchPage';
export default withOnyx({

export default withOnyx<SearchPageProps, SearchPageProps>({
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
export default withOnyx<SearchPageProps, SearchPageProps>({
export default withOnyx<SearchPageProps, SearchPageOnyxProps>({

src/pages/SearchPage.tsx Outdated Show resolved Hide resolved
type SearchOptions = {
recentReports: OnyxTypes.Report[];
personalDetails: OnyxTypes.PersonalDetails[];
userToInvite: [];
Copy link
Contributor

Choose a reason for hiding this comment

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

Just an empty array? it doesn't look right for the type, also are you sure it's array at all?

const [searchOptions, setSearchOptions] = useState<SearchOptions>({
recentReports: [],
personalDetails: [],
userToInvite: [],
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure userToInvite is an array?

src/pages/SearchPage.tsx Outdated Show resolved Hide resolved
Comment on lines 32 to 33
/** The report currently being looked at */
reports: OnyxEntry<OnyxTypes.Report>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** The report currently being looked at */
reports: OnyxEntry<OnyxTypes.Report>;
/** All reports shared with the user */
reports: OnyxCollection<OnyxTypes.Report>;

src/pages/SearchPage.tsx Outdated Show resolved Hide resolved
@@ -99,8 +96,6 @@ function SearchPage({betas, personalDetails, reports, isSearchingForReports, nav

/**
* Returns the sections needed for the OptionsSelector
*
* @returns {Array}
*/
const getSections = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add return type for this function

@@ -68,7 +70,7 @@ function SearchPage({betas, personalDetails, reports, isSearchingForReports, nav
recentReports: localRecentReports,
personalDetails: localPersonalDetails,
userToInvite: localUserToInvite,
} = OptionsListUtils.getSearchOptions(reports, personalDetails, searchValue.trim(), betas);
} = OptionsListUtils.getSearchOptions(reports, personalDetails, searchValue.trim(), betas ?? undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
} = OptionsListUtils.getSearchOptions(reports, personalDetails, searchValue.trim(), betas ?? undefined);
} = OptionsListUtils.getSearchOptions(reports, personalDetails, searchValue.trim(), betas ?? []);

Copy link
Contributor

Choose a reason for hiding this comment

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

it would be better to apply this suggestion. :)

@ruben-rebelo ruben-rebelo marked this pull request as ready for review January 31, 2024 15:04
@ruben-rebelo ruben-rebelo requested a review from a team as a code owner January 31, 2024 15:04
@melvin-bot melvin-bot bot requested review from ntdiary and removed request for a team January 31, 2024 15:04
Copy link

melvin-bot bot commented Jan 31, 2024

@ntdiary 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]

@ntdiary
Copy link
Contributor

ntdiary commented Feb 2, 2024

Hi, @ruben-rebelo, sorry for the delay, could you please resolve the conflicts? I can review this PR today. :)

# Conflicts:
#	src/ONYXKEYS.ts
#	src/components/ScreenWrapper.tsx
@ruben-rebelo
Copy link
Contributor Author

Hello @ntdiary, no problem!
I've resolved the conflicts, please have a look!

Copy link
Contributor

@ntdiary ntdiary left a comment

Choose a reason for hiding this comment

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

Hi, the PR looks good. However, I found we have another PR #35058 in progress to remove this file and use the new SearchPage/index.js. Also, considering we have a TODO comment waiting for the OptionsSelector migration, I'm not sure how we should proceed here. Maybe we could wait for PR #35058 to be completed and then migrate SearchPage/index.js?
I've posted a message on slack to get some inputs, and please feel free to let me know If you have a different thought ❤️

@@ -68,7 +70,7 @@ function SearchPage({betas, personalDetails, reports, isSearchingForReports, nav
recentReports: localRecentReports,
personalDetails: localPersonalDetails,
userToInvite: localUserToInvite,
} = OptionsListUtils.getSearchOptions(reports, personalDetails, searchValue.trim(), betas);
} = OptionsListUtils.getSearchOptions(reports, personalDetails, searchValue.trim(), betas ?? undefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be better to apply this suggestion. :)

@ruben-rebelo
Copy link
Contributor Author

Hello @ntdiary, I didn't knew about that PR, Let's keep this on hold until that one is merged than I proceed with the migration from there. Thank you for the information!

# Conflicts:
#	src/pages/SearchPage.tsx
Copy link
Contributor

@ntdiary ntdiary left a comment

Choose a reason for hiding this comment

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

@ruben-rebelo, there's a ts error in WorkspaceMembersPage, and I've also made a few minor ts suggestions. I have tested it locally and they works well. I will fill out the list after they are addressed. :)

@@ -14,7 +14,7 @@ import useTackInputFocus from '@hooks/useTackInputFocus';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as Browser from '@libs/Browser';
import type {RootStackParamList} from '@libs/Navigation/types';
import type {RootStackParamList, SearchNavigatorParamList} from '@libs/Navigation/types';
Copy link
Contributor

@ntdiary ntdiary Feb 28, 2024

Choose a reason for hiding this comment

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

Suggested change
import type {RootStackParamList, SearchNavigatorParamList} from '@libs/Navigation/types';
import type {RootStackParamList} from '@libs/Navigation/types';

SearchPage doesn't pass navigation to ScreenWrapper, so we can revert this change.

@@ -89,7 +89,7 @@ type ScreenWrapperProps = {
*
* This is required because transitionEnd event doesn't trigger in the testing environment.
*/
navigation?: StackNavigationProp<RootStackParamList>;
navigation?: StackNavigationProp<RootStackParamList> | StackNavigationProp<SearchNavigatorParamList>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
navigation?: StackNavigationProp<RootStackParamList> | StackNavigationProp<SearchNavigatorParamList>;
navigation?: StackNavigationProp<RootStackParamList>;

betas: [],
reports: {},
isSearchingForReports: false,
type SearchPageProps = SearchPageOnyxProps & StackScreenProps<SearchNavigatorParamList, typeof SCREENS.SEARCH_ROOT>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type SearchPageProps = SearchPageOnyxProps & StackScreenProps<SearchNavigatorParamList, typeof SCREENS.SEARCH_ROOT>;
type SearchPageProps = SearchPageOnyxProps;

newSections.push({
data: recentReports,
shouldShow: true,
indexOffset,
});
indexOffset += recentReports.length;
indexOffset += recentReports?.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
indexOffset += recentReports?.length;
indexOffset += recentReports.length;

recentReports.length > 0 is true. :)

@@ -202,7 +202,7 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) {
});
});

result = result.sort((value1, value2) => localeCompare(value1.text, value2.text));
result = result.sort((value1, value2) => localeCompare(value1?.text ?? '', value2?.text ?? ''));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
result = result.sort((value1, value2) => localeCompare(value1?.text ?? '', value2?.text ?? ''));
result = result.sort((value1, value2) => localeCompare(value1.text ?? '', value2.text ?? ''));

@@ -462,7 +462,7 @@ function BaseSelectionList<TItem extends ListItem>(
getItemLayout={getItemLayout}
onScroll={onScroll}
onScrollBeginDrag={onScrollBeginDrag}
keyExtractor={(item) => item.keyForList}
keyExtractor={(item) => item.keyForList ?? ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
keyExtractor={(item) => item.keyForList ?? ''}
keyExtractor={(item, index) => item.keyForList ?? `${index}`}

How about falling back to using the index, like React does?

const [isScreenTransitionEnd, setIsScreenTransitionEnd] = useState(false);
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const themeStyles = useThemeStyles();
const personalDetails = usePersonalDetails();

const offlineMessage = isOffline ? [`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] : '';
const offlineMessage = isOffline ? ([`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] as unknown as string) : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const offlineMessage = isOffline ? ([`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] as unknown as string) : '';
const offlineMessage : MaybePhraseKey = isOffline ? [`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] : '';

also change the type of textInputHint to MaybePhraseKey.

# Conflicts:
#	src/components/SelectionList/BaseSelectionList.tsx
#	src/components/SelectionList/RadioListItem.tsx
#	src/components/SelectionList/TableListItem.tsx
#	src/components/SelectionList/UserListItem.tsx
#	src/components/SelectionList/types.ts
@ruben-rebelo
Copy link
Contributor Author

@ntdiary I've updated this PR including your suggestions + merge with main + some ts fixes that appeared after the changes.
Please have a look

Copy link
Contributor

@ntdiary ntdiary left a comment

Choose a reason for hiding this comment

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

@ruben-rebelo, the last minor change, I'm testing it now, and will update the videos later. 😄

src/components/SelectionList/types.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@ntdiary ntdiary left a comment

Choose a reason for hiding this comment

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

LGTM :)

Copy link

melvin-bot bot commented Mar 4, 2024

We did not find an internal engineer to review this PR, trying to assign a random engineer to #25182 as well as to this PR... Please reach out for help on Slack if no one gets assigned!

@yuwenmemon yuwenmemon self-requested a review March 4, 2024 21:02
yuwenmemon
yuwenmemon previously approved these changes Mar 4, 2024
@yuwenmemon
Copy link
Contributor

@ruben-rebelo Conflicts

@ruben-rebelo
Copy link
Contributor Author

@yuwenmemon Conflicts Resolved

@ntdiary
Copy link
Contributor

ntdiary commented Mar 7, 2024

still works well, @yuwenmemon, friendly reminder to merge. :)

@yuwenmemon
Copy link
Contributor

Apologies for the delay! I was sick last week 🤕

@yuwenmemon yuwenmemon merged commit f4c7378 into Expensify:main Mar 11, 2024
14 checks passed
Copy link

melvin-bot bot commented Mar 11, 2024

@yuwenmemon looks like this was merged without a test passing. Please add a note explaining why this was done and remove the Emergency label if this is not an emergency.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by https://github.com/yuwenmemon in version: 1.4.51-0 🚀

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

@OSBotify
Copy link
Contributor

🚀 Deployed to production by https://github.com/luacmartins in version: 1.4.51-3 🚀

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

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.

7 participants