-
Notifications
You must be signed in to change notification settings - Fork 3.9k
advanced filters category #46197
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 15 commits into
Expensify:main
from
software-mansion-labs:289Adam289/46038-advanced-filters-category
Aug 1, 2024
Merged
advanced filters category #46197
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0809a25
Add displaying chosen date advanced filters value
Kicu ef5190c
Update search filters type page
Kicu 6e03029
Finalize SearchFiltersTypePage with correct input UI
Kicu d4c91c4
Add status advanced filter for Search
Kicu b8c4643
Improve styling of advanced search filters
Kicu 5525339
Add category advanced filter for Search
289Adam289 0c944e0
Update policyID usage in category page search filters
289Adam289 5df9b97
Apply review sugestions
289Adam289 e354d81
Reduce useOnyx calls
289Adam289 ee9da9f
Improve catgeory filter UI
289Adam289 a35848c
Merge branch 'main' into 289Adam289/46038-advanced-filters-category
289Adam289 a1cd0dd
Fix merge problems
289Adam289 5550dc4
Remove redundant styles
289Adam289 53c0802
Enhance code maintainability and clarity
289Adam289 ee320a8
Fix type error and review sugestions
289Adam289 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import React, {useCallback} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import PressableWithFeedback from '@components/Pressable/PressableWithFeedback'; | ||
| import SelectCircle from '@components/SelectCircle'; | ||
| import TextWithTooltip from '@components/TextWithTooltip'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import CONST from '@src/CONST'; | ||
| import BaseListItem from './BaseListItem'; | ||
| import type {InviteMemberListItemProps, ListItem} from './types'; | ||
|
|
||
| function SelectableListItem<TItem extends ListItem>({ | ||
| item, | ||
| isFocused, | ||
| showTooltip, | ||
| isDisabled, | ||
| canSelectMultiple, | ||
| onSelectRow, | ||
| onCheckboxPress, | ||
| onDismissError, | ||
| onFocus, | ||
| shouldSyncFocus, | ||
| }: InviteMemberListItemProps<TItem>) { | ||
| const styles = useThemeStyles(); | ||
| const handleCheckboxPress = useCallback(() => { | ||
| if (onCheckboxPress) { | ||
| onCheckboxPress(item); | ||
| } else { | ||
| onSelectRow(item); | ||
| } | ||
| }, [item, onCheckboxPress, onSelectRow]); | ||
|
|
||
| return ( | ||
| <BaseListItem | ||
| item={item} | ||
| wrapperStyle={[styles.flex1, styles.justifyContentBetween, styles.sidebarLinkInner, isFocused && styles.sidebarLinkActive]} | ||
| isFocused={isFocused} | ||
| isDisabled={isDisabled} | ||
| showTooltip={showTooltip} | ||
| canSelectMultiple={canSelectMultiple} | ||
| onSelectRow={onSelectRow} | ||
| onDismissError={onDismissError} | ||
| errors={item.errors} | ||
| pendingAction={item.pendingAction} | ||
| keyForList={item.keyForList} | ||
| onFocus={onFocus} | ||
| shouldSyncFocus={shouldSyncFocus} | ||
| > | ||
| <> | ||
| <View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStretch, styles.optionRow]}> | ||
| <View style={[styles.flexRow, styles.alignItemsCenter]}> | ||
| <TextWithTooltip | ||
| shouldShowTooltip={showTooltip} | ||
| text={item.text ?? ''} | ||
| style={[ | ||
| styles.optionDisplayName, | ||
| isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText, | ||
| item.isBold !== false && styles.sidebarLinkTextBold, | ||
| styles.pre, | ||
| item.alternateText ? styles.mb1 : null, | ||
| ]} | ||
| /> | ||
| </View> | ||
| </View> | ||
| {!!item.rightElement && item.rightElement} | ||
| {canSelectMultiple && !item.isDisabled && ( | ||
| <PressableWithFeedback | ||
| onPress={handleCheckboxPress} | ||
| disabled={isDisabled} | ||
| role={CONST.ROLE.BUTTON} | ||
| accessibilityLabel={item.text ?? ''} | ||
| style={[styles.ml2, styles.optionSelectCircle]} | ||
| > | ||
| <SelectCircle | ||
| isChecked={item.isSelected ?? false} | ||
| selectCircleStyles={styles.ml0} | ||
| /> | ||
| </PressableWithFeedback> | ||
| )} | ||
| </> | ||
| </BaseListItem> | ||
| ); | ||
| } | ||
|
|
||
| SelectableListItem.displayName = 'SelectableListItem'; | ||
|
|
||
| export default SelectableListItem; | ||
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 |
|---|---|---|
|
|
@@ -36,6 +36,11 @@ function getFilterDisplayTitle(filters: Partial<SearchAdvancedFiltersForm>, fiel | |
| return dateValue; | ||
| } | ||
|
|
||
| if (fieldName === CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY && filters[fieldName]) { | ||
| const categories = filters[fieldName] ?? []; | ||
| return categories.join(', '); | ||
|
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. You did not sort the categories before showing which caused #48496 |
||
| } | ||
|
|
||
| // Todo Once all Advanced filters are implemented this line can be cleaned up. See: https://github.com/Expensify/App/issues/45026 | ||
| // @ts-expect-error this property access is temporarily an error, because not every SYNTAX_FILTER_KEYS is handled by form. | ||
| // When all filters are updated here: src/types/form/SearchAdvancedFiltersForm.ts this line comment + type cast can be removed. | ||
|
|
@@ -68,6 +73,11 @@ function AdvancedSearchFilters() { | |
| description: 'common.date' as const, | ||
| route: ROUTES.SEARCH_ADVANCED_FILTERS_DATE, | ||
| }, | ||
| { | ||
| title: getFilterDisplayTitle(searchAdvancedFilters, CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, translate), | ||
| description: 'common.category' as const, | ||
| route: ROUTES.SEARCH_ADVANCED_FILTERS_CATEGORY, | ||
| }, | ||
| ], | ||
| [searchAdvancedFilters, translate], | ||
| ); | ||
|
|
||
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,154 @@ | ||
| import React, {useCallback, useMemo, useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import {useOnyx} from 'react-native-onyx'; | ||
| import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; | ||
| import Button from '@components/Button'; | ||
| import type {FormOnyxValues} from '@components/Form/types'; | ||
| import HeaderWithBackButton from '@components/HeaderWithBackButton'; | ||
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import SelectionList from '@components/SelectionList'; | ||
| import SelectableListItem from '@components/SelectionList/SelectableListItem'; | ||
| import useDebouncedState from '@hooks/useDebouncedState'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import localeCompare from '@libs/LocaleCompare'; | ||
| import type {CategorySection} from '@libs/OptionsListUtils'; | ||
| import type {OptionData} from '@libs/ReportUtils'; | ||
| import Navigation from '@navigation/Navigation'; | ||
| import * as SearchActions from '@userActions/Search'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| function SearchFiltersCategoryPage() { | ||
| const styles = useThemeStyles(); | ||
| const {translate} = useLocalize(); | ||
|
|
||
| const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(''); | ||
| const [noResultsFound, setNoResultsFound] = useState(false); | ||
|
|
||
| const [searchAdvancedFiltersForm] = useOnyx(ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM); | ||
| const currentCategories = searchAdvancedFiltersForm?.category; | ||
| const [newCategories, setNewCategories] = useState<string[]>(currentCategories ?? []); | ||
| const policyID = searchAdvancedFiltersForm?.policyID ?? '-1'; | ||
|
|
||
| const [allPolicyIDCategories] = useOnyx(ONYXKEYS.COLLECTION.POLICY_CATEGORIES); | ||
| const singlePolicyCategories = allPolicyIDCategories?.[`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`]; | ||
|
|
||
| const categoryNames = useMemo(() => { | ||
| let categories: string[] = []; | ||
| if (!singlePolicyCategories) { | ||
| categories = Object.values(allPolicyIDCategories ?? {}) | ||
| .map((policyCategories) => Object.values(policyCategories ?? {}).map((category) => category.name)) | ||
| .flat(); | ||
| } else { | ||
| categories = Object.values(singlePolicyCategories ?? {}).map((value) => value.name); | ||
| } | ||
|
|
||
| return [...new Set(categories)]; | ||
| }, [allPolicyIDCategories, singlePolicyCategories]); | ||
|
|
||
| const sections = useMemo(() => { | ||
| const newSections: CategorySection[] = []; | ||
| const chosenCategories = newCategories | ||
| .filter((category) => category.toLowerCase().includes(debouncedSearchTerm.toLowerCase())) | ||
| .sort((a, b) => localeCompare(a, b)) | ||
| .map((name) => ({ | ||
| text: name, | ||
| keyForList: name, | ||
| isSelected: newCategories?.includes(name) ?? false, | ||
| })); | ||
| const remainingCategories = categoryNames | ||
| .filter((category) => newCategories.includes(category) === false) | ||
| .filter((category) => category.toLowerCase().includes(debouncedSearchTerm.toLowerCase())) | ||
| .sort((a, b) => localeCompare(a, b)) | ||
| .map((name) => ({ | ||
| text: name, | ||
| keyForList: name, | ||
| isSelected: newCategories?.includes(name) ?? false, | ||
| })); | ||
| if (chosenCategories.length === 0 && remainingCategories.length === 0) { | ||
| setNoResultsFound(true); | ||
| } else { | ||
| setNoResultsFound(false); | ||
| } | ||
| newSections.push({ | ||
| title: undefined, | ||
| data: chosenCategories, | ||
| shouldShow: chosenCategories.length > 0, | ||
| }); | ||
| newSections.push({ | ||
| title: translate('common.category'), | ||
| data: remainingCategories, | ||
| shouldShow: remainingCategories.length > 0, | ||
| }); | ||
| return newSections; | ||
| }, [categoryNames, newCategories, translate, debouncedSearchTerm]); | ||
|
|
||
| const updateCategory = useCallback((values: Partial<FormOnyxValues<typeof ONYXKEYS.FORMS.SEARCH_ADVANCED_FILTERS_FORM>>) => { | ||
| SearchActions.updateAdvancedFilters(values); | ||
| }, []); | ||
|
|
||
| const handleConfirmSelection = useCallback(() => { | ||
| updateCategory({ | ||
| category: newCategories.sort((a, b) => localeCompare(a, b)), | ||
| }); | ||
| Navigation.goBack(); | ||
| }, [newCategories, updateCategory]); | ||
|
|
||
| const updateNewCategories = useCallback( | ||
| (item: Partial<OptionData>) => { | ||
| if (!item.text) { | ||
| return; | ||
| } | ||
| if (item.isSelected) { | ||
| setNewCategories(newCategories?.filter((category) => category !== item.text)); | ||
| } else { | ||
| setNewCategories([...(newCategories ?? []), item.text]); | ||
| } | ||
| }, | ||
| [newCategories], | ||
| ); | ||
|
|
||
| const footerContent = useMemo( | ||
| () => ( | ||
| <Button | ||
| success | ||
| text={translate('common.save')} | ||
| pressOnEnter | ||
| onPress={handleConfirmSelection} | ||
| large | ||
| /> | ||
| ), | ||
| [translate, handleConfirmSelection], | ||
| ); | ||
| return ( | ||
| <ScreenWrapper | ||
| testID={SearchFiltersCategoryPage.displayName} | ||
| shouldShowOfflineIndicatorInWideScreen | ||
| offlineIndicatorStyle={styles.mtAuto} | ||
| > | ||
| <FullPageNotFoundView shouldShow={false}> | ||
| <HeaderWithBackButton title={translate('common.category')} /> | ||
| <View style={[styles.flex1]}> | ||
| <SelectionList | ||
|
luacmartins marked this conversation as resolved.
|
||
| sections={sections} | ||
| textInputValue={searchTerm} | ||
| onChangeText={setSearchTerm} | ||
| textInputLabel={translate('common.search')} | ||
| onSelectRow={updateNewCategories} | ||
| headerMessage={noResultsFound ? translate('common.noResultsFound') : undefined} | ||
| footerContent={footerContent} | ||
| shouldStopPropagation | ||
| showLoadingPlaceholder={!noResultsFound} | ||
| shouldShowTooltips | ||
| canSelectMultiple | ||
| ListItem={SelectableListItem} | ||
| /> | ||
| </View> | ||
| </FullPageNotFoundView> | ||
| </ScreenWrapper> | ||
| ); | ||
| } | ||
|
|
||
| SearchFiltersCategoryPage.displayName = 'SearchFiltersCategoryPage'; | ||
|
|
||
| export default SearchFiltersCategoryPage; | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.