-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Search v2.1] Create In filter #46030 #47676
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
Merged
luacmartins
merged 25 commits into
Expensify:main
from
software-mansion-labs:Guccio/46030-InFilter
Aug 30, 2024
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b43f7c0
pulling from, to filters
Guccio163 e2c5d62
in filter, selecting working but duplicates
Guccio163 23f13ce
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 2da8854
ts check
Guccio163 94166fe
updated look, workspaces saving problem
Guccio163 2a5f7e7
fixing adding bug wip
Guccio163 347c8c6
adding solved, but reading from props bugged
Guccio163 412393b
working until first save
Guccio163 a62369f
working version w/o adding from search and naming in allFilters page
Guccio163 4391c6f
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 47f2f0c
workspace chats' alternateText not ready
Guccio163 0c9f99d
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 755cd5f
temporary fix, alternateText doesn't work yet
Guccio163 7b8998e
working, ready for second look
Guccio163 9d45653
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 aa5ee46
stylistic touches
Guccio163 4f03335
PR review 1 changes
Guccio163 2499a0d
fix Navigation.goBack in filters
Guccio163 cecda50
name changes before PR
Guccio163 b7cf074
fix bug1
Guccio163 1aa2256
bug1 fixed 2
Guccio163 80de247
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 27bfd2f
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 97715e9
Merge branch 'main' of github.com:software-mansion-labs/expensify-app…
Guccio163 353f9c3
fixed conflicts with Has filter
Guccio163 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| import React, {useCallback, useEffect, useMemo, useState} from 'react'; | ||
| import {useOnyx} from 'react-native-onyx'; | ||
| import Button from '@components/Button'; | ||
| import {usePersonalDetails} from '@components/OnyxProvider'; | ||
| import {useOptionsList} from '@components/OptionListContextProvider'; | ||
| import SelectionList from '@components/SelectionList'; | ||
| import InviteMemberListItem from '@components/SelectionList/InviteMemberListItem'; | ||
| import useDebouncedState from '@hooks/useDebouncedState'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useScreenWrapperTransitionStatus from '@hooks/useScreenWrapperTransitionStatus'; | ||
| import * as DeviceCapabilities from '@libs/DeviceCapabilities'; | ||
| import * as OptionsListUtils from '@libs/OptionsListUtils'; | ||
| import type {Option} from '@libs/OptionsListUtils'; | ||
| import type {OptionData} from '@libs/ReportUtils'; | ||
| import Navigation from '@navigation/Navigation'; | ||
| import * as Report from '@userActions/Report'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
|
|
||
| const defaultListOptions = { | ||
| recentReports: [], | ||
| personalDetails: [], | ||
| userToInvite: null, | ||
| currentUserOption: null, | ||
| categoryOptions: [], | ||
| tagOptions: [], | ||
| taxRatesOptions: [], | ||
| headerMessage: '', | ||
| }; | ||
|
|
||
| function getSelectedOptionData(option: Option): OptionData { | ||
| return {...option, isSelected: true, reportID: option.reportID ?? '-1'}; | ||
| } | ||
|
|
||
| type SearchFiltersParticipantsSelectorProps = { | ||
| initialReportIDs: string[]; | ||
| onFiltersUpdate: (initialReportIDs: string[]) => void; | ||
| isScreenTransitionEnd: boolean; | ||
| }; | ||
|
|
||
| function SearchFiltersChatsSelector({initialReportIDs, onFiltersUpdate, isScreenTransitionEnd}: SearchFiltersParticipantsSelectorProps) { | ||
| const {translate} = useLocalize(); | ||
| const personalDetails = usePersonalDetails(); | ||
| const {didScreenTransitionEnd} = useScreenWrapperTransitionStatus(); | ||
| const {options, areOptionsInitialized} = useOptionsList({ | ||
| shouldInitialize: didScreenTransitionEnd, | ||
| }); | ||
|
|
||
| const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); | ||
| const [isSearchingForReports] = useOnyx(ONYXKEYS.IS_SEARCHING_FOR_REPORTS, {initWithStoredValues: false}); | ||
| const [selectedReportIDs, setSelectedReportIDs] = useState<string[]>(initialReportIDs); | ||
| const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(''); | ||
| const cleanSearchTerm = useMemo(() => searchTerm.trim().toLowerCase(), [searchTerm]); | ||
|
|
||
| const selectedOptions = useMemo<OptionData[]>(() => { | ||
| return selectedReportIDs.map((id) => { | ||
| const report = getSelectedOptionData(OptionsListUtils.createOptionFromReport({...reports?.[`${ONYXKEYS.COLLECTION.REPORT}${id}`], reportID: id}, personalDetails)); | ||
| const alternateText = OptionsListUtils.getAlternateText(report, {showChatPreviewLine: true}); | ||
| return {...report, alternateText}; | ||
| }); | ||
| }, [personalDetails, reports, selectedReportIDs]); | ||
|
|
||
| const defaultOptions = useMemo(() => { | ||
| if (!areOptionsInitialized || !isScreenTransitionEnd) { | ||
| return defaultListOptions; | ||
| } | ||
| return OptionsListUtils.getSearchOptions(options); | ||
| }, [areOptionsInitialized, isScreenTransitionEnd, options]); | ||
|
|
||
| const chatOptions = useMemo(() => { | ||
| return OptionsListUtils.filterOptions(defaultOptions, cleanSearchTerm, { | ||
| selectedOptions, | ||
| excludeLogins: CONST.EXPENSIFY_EMAILS, | ||
| maxRecentReportsToShow: 0, | ||
| }); | ||
| }, [defaultOptions, cleanSearchTerm, selectedOptions]); | ||
|
|
||
| const {sections, headerMessage} = useMemo(() => { | ||
| const newSections: OptionsListUtils.CategorySection[] = []; | ||
| if (!areOptionsInitialized) { | ||
| return {sections: [], headerMessage: undefined}; | ||
| } | ||
|
|
||
| const formattedResults = OptionsListUtils.formatSectionsFromSearchTerm( | ||
| cleanSearchTerm, | ||
| selectedOptions, | ||
| chatOptions.recentReports, | ||
| chatOptions.personalDetails, | ||
| personalDetails, | ||
| false, | ||
| ); | ||
|
|
||
| newSections.push(formattedResults.section); | ||
|
|
||
| const visibleReportsWhenSearchTermNonEmpty = chatOptions.recentReports.map((report) => (selectedReportIDs.includes(report.reportID) ? getSelectedOptionData(report) : report)); | ||
| const visibleReportsWhenSearchTermEmpty = chatOptions.recentReports.filter((report) => !selectedReportIDs.includes(report.reportID)); | ||
| const reportsFiltered = cleanSearchTerm === '' ? visibleReportsWhenSearchTermEmpty : visibleReportsWhenSearchTermNonEmpty; | ||
|
|
||
| newSections.push({ | ||
| title: undefined, | ||
| data: reportsFiltered, | ||
| shouldShow: chatOptions.recentReports.length > 0, | ||
| }); | ||
|
|
||
| const areResultsFound = didScreenTransitionEnd && formattedResults.section.data.length === 0 && reportsFiltered.length === 0; | ||
| const message = areResultsFound ? translate('common.noResultsFound') : undefined; | ||
|
|
||
| return { | ||
| sections: newSections, | ||
| headerMessage: message, | ||
| }; | ||
| }, [ | ||
| areOptionsInitialized, | ||
| chatOptions.personalDetails, | ||
| chatOptions.recentReports, | ||
| cleanSearchTerm, | ||
| didScreenTransitionEnd, | ||
| personalDetails, | ||
| selectedOptions, | ||
| selectedReportIDs, | ||
| translate, | ||
| ]); | ||
|
|
||
| useEffect(() => { | ||
| Report.searchInServer(debouncedSearchTerm.trim()); | ||
| }, [debouncedSearchTerm]); | ||
|
|
||
| const handleParticipantSelection = useCallback( | ||
| (selectedOption: Option) => { | ||
| const optionReportID = selectedOption.reportID; | ||
| if (!optionReportID) { | ||
| return; | ||
| } | ||
| const foundOptionIndex = selectedReportIDs.findIndex((reportID: string) => { | ||
| return reportID && reportID !== '' && selectedOption.reportID === reportID; | ||
| }); | ||
|
|
||
| if (foundOptionIndex < 0) { | ||
| setSelectedReportIDs([...selectedReportIDs, optionReportID]); | ||
| } else { | ||
| const newSelectedReports = [...selectedReportIDs.slice(0, foundOptionIndex), ...selectedReportIDs.slice(foundOptionIndex + 1)]; | ||
| setSelectedReportIDs(newSelectedReports); | ||
| } | ||
| }, | ||
| [selectedReportIDs], | ||
| ); | ||
|
|
||
| const footerContent = ( | ||
| <Button | ||
| success | ||
| text={translate('common.save')} | ||
| pressOnEnter | ||
| onPress={() => { | ||
| onFiltersUpdate(selectedReportIDs); | ||
| Navigation.goBack(ROUTES.SEARCH_ADVANCED_FILTERS); | ||
| }} | ||
| large | ||
| /> | ||
| ); | ||
|
|
||
| const isLoadingNewOptions = !!isSearchingForReports; | ||
| const showLoadingPlaceholder = !didScreenTransitionEnd || !areOptionsInitialized || !initialReportIDs || !personalDetails; | ||
|
|
||
| return ( | ||
| <SelectionList | ||
| canSelectMultiple | ||
| sections={sections} | ||
| ListItem={InviteMemberListItem} | ||
| textInputLabel={translate('selectionList.nameEmailOrPhoneNumber')} | ||
| headerMessage={headerMessage} | ||
| textInputValue={searchTerm} | ||
| footerContent={footerContent} | ||
| showScrollIndicator | ||
| shouldPreventDefaultFocusOnSelectRow={!DeviceCapabilities.canUseTouchScreen()} | ||
| onChangeText={(value) => { | ||
| setSearchTerm(value); | ||
| }} | ||
| onSelectRow={handleParticipantSelection} | ||
| isLoadingNewOptions={isLoadingNewOptions} | ||
| showLoadingPlaceholder={showLoadingPlaceholder} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| SearchFiltersChatsSelector.displayName = 'SearchFiltersChatsSelector'; | ||
|
|
||
| export default SearchFiltersChatsSelector; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
{bz checklist} coming from #70550, Reset button is not included in footer component here, while its included in other screens we added it in #70869