-
Notifications
You must be signed in to change notification settings - Fork 3.6k
chore: migrate old SelectionList to new SelectionListWithSections in MoneyRe… #82662
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,9 @@ import FormHelpMessage from '@components/FormHelpMessage'; | |
| import MenuItem from '@components/MenuItem'; | ||
| import {usePersonalDetails} from '@components/OnyxListItemProvider'; | ||
| import ReferralProgramCTA from '@components/ReferralProgramCTA'; | ||
| // eslint-disable-next-line no-restricted-imports | ||
| import SelectionList from '@components/SelectionListWithSections'; | ||
| import InviteMemberListItem from '@components/SelectionListWithSections/InviteMemberListItem'; | ||
| import type {SelectionListHandle} from '@components/SelectionListWithSections/types'; | ||
| import InviteMemberListItem from '@components/SelectionList/ListItem/InviteMemberListItem'; | ||
| import SelectionListWithSections from '@components/SelectionList/SelectionListWithSections'; | ||
| import type {Section, SelectionListWithSectionsHandle} from '@components/SelectionList/SelectionListWithSections/types'; | ||
| import useContactImport from '@hooks/useContactImport'; | ||
| import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; | ||
| import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners'; | ||
|
|
@@ -34,8 +33,9 @@ import getPlatform from '@libs/getPlatform'; | |
| import goToSettings from '@libs/goToSettings'; | ||
| import {isMovingTransactionFromTrackExpense} from '@libs/IOUUtils'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import type {Option, Section} from '@libs/OptionsListUtils'; | ||
| import type {Option} from '@libs/OptionsListUtils'; | ||
| import {formatSectionsFromSearchTerm, getHeaderMessage, getParticipantsOption, getPersonalDetailSearchTerms, getPolicyExpenseReportOption, isCurrentUser} from '@libs/OptionsListUtils'; | ||
| import type {OptionWithKey} from '@libs/OptionsListUtils/types'; | ||
| import {getActiveAdminWorkspaces, isPaidGroupPolicy as isPaidGroupPolicyUtil} from '@libs/PolicyUtils'; | ||
| import type {OptionData} from '@libs/ReportUtils'; | ||
| import {isInvoiceRoom} from '@libs/ReportUtils'; | ||
|
|
@@ -127,7 +127,7 @@ function MoneyRequestParticipantsSelector({ | |
| const [loginList] = useOnyx(ONYXKEYS.LOGIN_LIST); | ||
|
|
||
| const [textInputAutoFocus, setTextInputAutoFocus] = useState<boolean>(!isNative); | ||
| const selectionListRef = useRef<SelectionListHandle | null>(null); | ||
| const selectionListRef = useRef<SelectionListWithSectionsHandle | null>(null); | ||
| const offlineMessage: string = isOffline ? `${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}` : ''; | ||
|
|
||
| const isPaidGroupPolicy = useMemo(() => isPaidGroupPolicyUtil(policy), [policy]); | ||
|
|
@@ -279,7 +279,7 @@ function MoneyRequestParticipantsSelector({ | |
| * @returns {Array} | ||
| */ | ||
| const [sections, header] = useMemo(() => { | ||
| const newSections: Section[] = []; | ||
| const newSections: Array<Section<OptionWithKey>> = []; | ||
| if (!areOptionsInitialized || !didScreenTransitionEnd) { | ||
| return [newSections, '']; | ||
| } | ||
|
|
@@ -297,34 +297,42 @@ function MoneyRequestParticipantsSelector({ | |
| ); | ||
| // Just a temporary fix to satisfy the type checker | ||
| // Will be fixed when migrating to use new SelectionListWithSections | ||
| newSections.push({...formatResults.section, title: undefined, shouldShow: true}); | ||
| newSections.push({...formatResults.section, sectionIndex: 0}); | ||
|
|
||
| newSections.push({ | ||
| title: translate('workspace.common.workspace'), | ||
| data: availableOptions.workspaceChats ?? [], | ||
| shouldShow: (availableOptions.workspaceChats ?? []).length > 0, | ||
| }); | ||
|
|
||
| newSections.push({ | ||
| title: translate('workspace.invoices.paymentMethods.personal'), | ||
| data: availableOptions.selfDMChat ? [availableOptions.selfDMChat] : [], | ||
| shouldShow: !!availableOptions.selfDMChat, | ||
| }); | ||
|
|
||
| if (!isWorkspacesOnly) { | ||
| if ((availableOptions.workspaceChats ?? []).length > 0) { | ||
| newSections.push({ | ||
| title: translate('common.recents'), | ||
| data: isPerDiemRequest ? availableOptions.recentReports.filter((report) => report.isPolicyExpenseChat) : availableOptions.recentReports, | ||
| shouldShow: (isPerDiemRequest ? availableOptions.recentReports.filter((report) => report.isPolicyExpenseChat) : availableOptions.recentReports).length > 0, | ||
| title: translate('workspace.common.workspace'), | ||
| data: availableOptions.workspaceChats ?? [], | ||
| sectionIndex: 1, | ||
| }); | ||
| } | ||
|
|
||
| if (availableOptions.selfDMChat) { | ||
| newSections.push({ | ||
| title: translate('common.contacts'), | ||
| data: availableOptions.personalDetails, | ||
| shouldShow: availableOptions.personalDetails.length > 0 && !isPerDiemRequest, | ||
| title: translate('workspace.invoices.paymentMethods.personal'), | ||
| data: availableOptions.selfDMChat ? [availableOptions.selfDMChat] : [], | ||
| sectionIndex: 2, | ||
| }); | ||
| } | ||
|
|
||
| if (!isWorkspacesOnly) { | ||
| if ((isPerDiemRequest ? availableOptions.recentReports.filter((report) => report.isPolicyExpenseChat) : availableOptions.recentReports).length > 0) { | ||
| newSections.push({ | ||
| title: translate('common.recents'), | ||
| data: isPerDiemRequest ? availableOptions.recentReports.filter((report) => report.isPolicyExpenseChat) : availableOptions.recentReports, | ||
| sectionIndex: 3, | ||
| }); | ||
| } | ||
|
|
||
| if (availableOptions.personalDetails.length > 0 && !isPerDiemRequest) { | ||
| newSections.push({ | ||
| title: translate('common.contacts'), | ||
| data: availableOptions.personalDetails, | ||
| sectionIndex: 4, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| if ( | ||
| !isWorkspacesOnly && | ||
| availableOptions.userToInvite && | ||
|
|
@@ -347,11 +355,11 @@ function MoneyRequestParticipantsSelector({ | |
| ? getPolicyExpenseReportOption(participant, currentUserAccountID, personalDetails, reportAttributesDerived) | ||
| : getParticipantsOption(participant, personalDetails); | ||
| }), | ||
| shouldShow: true, | ||
| sectionIndex: 5, | ||
| }); | ||
| } | ||
|
|
||
| let headerMessage = ''; | ||
| let headerMessage; | ||
| if (!showImportContacts) { | ||
| headerMessage = inputHelperText; | ||
| } | ||
|
|
@@ -430,9 +438,9 @@ function MoneyRequestParticipantsSelector({ | |
| return length; | ||
| }, [areOptionsInitialized, sections]); | ||
|
|
||
| const shouldShowListEmptyContent = useMemo(() => optionLength === 0 && !showLoadingPlaceholder, [optionLength, showLoadingPlaceholder]); | ||
| const showListEmptyContent = useMemo(() => optionLength === 0 && !showLoadingPlaceholder, [optionLength, showLoadingPlaceholder]); | ||
|
|
||
| const shouldShowReferralBanner = !isDismissed && iouType !== CONST.IOU.TYPE.INVOICE && !shouldShowListEmptyContent; | ||
| const shouldShowReferralBanner = !isDismissed && iouType !== CONST.IOU.TYPE.INVOICE && !showListEmptyContent; | ||
|
|
||
| const initiateContactImportAndSetState = useCallback(() => { | ||
| setContactPermissionState(RESULTS.GRANTED); | ||
|
|
@@ -561,6 +569,15 @@ function MoneyRequestParticipantsSelector({ | |
| }, | ||
| })); | ||
|
|
||
| const textInputOptions = { | ||
| value: searchTerm, | ||
| label: translate('selectionList.nameEmailOrPhoneNumber'), | ||
| hint: offlineMessage, | ||
| onChangeText: setSearchTerm, | ||
| disableAutoFocus: !textInputAutoFocus, | ||
| headerMessage: header, | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <ContactPermissionModal | ||
|
|
@@ -570,19 +587,19 @@ function MoneyRequestParticipantsSelector({ | |
| setTextInputAutoFocus(true); | ||
| }} | ||
| /> | ||
| <SelectionList | ||
| onConfirm={handleConfirmSelection} | ||
| sections={areOptionsInitialized ? sections : CONST.EMPTY_ARRAY} | ||
| <SelectionListWithSections | ||
| confirmButtonOptions={{ | ||
| onConfirm: handleConfirmSelection, | ||
| }} | ||
| sections={sections} | ||
| ListItem={InviteMemberListItem} | ||
| textInputValue={searchTerm} | ||
| textInputLabel={translate('selectionList.nameEmailOrPhoneNumber')} | ||
| textInputHint={offlineMessage} | ||
| onChangeText={setSearchTerm} | ||
| textInputOptions={textInputOptions} | ||
| shouldPreventDefaultFocusOnSelectRow={!canUseTouchScreen()} | ||
| onSelectRow={onSelectRow} | ||
| shouldSingleExecuteRowSelect | ||
| canShowProductTrainingTooltip={canShowManagerMcTest} | ||
| headerContent={ | ||
| customListHeaderContent={importContactsButtonComponent} | ||
| customHeaderContent={ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Switching this prop to Useful? React with 👍 / 👎.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you test this case @sharabai
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @grgia yep, the comment was useful and I did change the code. |
||
| <ImportContactButton | ||
| showImportContacts={contactState?.showImportUI ?? showImportContacts} | ||
| inputHelperText={inputHelperText} | ||
|
|
@@ -591,14 +608,11 @@ function MoneyRequestParticipantsSelector({ | |
| } | ||
| footerContent={footerContent} | ||
| listEmptyContent={EmptySelectionListContentWithPermission} | ||
| listHeaderContent={importContactsButtonComponent} | ||
| showSectionTitleWithListHeaderContent | ||
| headerMessage={header} | ||
| showLoadingPlaceholder={showLoadingPlaceholder} | ||
| shouldShowTextInput | ||
| canSelectMultiple={isIOUSplit && isAllowedToSplit} | ||
| isLoadingNewOptions={!!isSearchingForReports} | ||
| shouldShowListEmptyContent={shouldShowListEmptyContent} | ||
| textInputAutoFocus={textInputAutoFocus} | ||
| showListEmptyContent={showListEmptyContent} | ||
| ref={selectionListRef} | ||
| onEndReached={onListEndReached} | ||
| /> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sharabai why did this if check change?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grgia the if check is same. It was moved to from inside the object from prop
shouldShowto an outside beforehand if check.Look at this line It's hard to spot it in github diff.