-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Fix: Add sections within Group By filters #83428
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
Julesssss
merged 7 commits into
Expensify:main
from
marufsharifi:bugfix/group-by-filter-section-structure
Mar 16, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7dea7fb
fix(group-by): add sections within Group By filters
marufsharifi fcc7d0f
Merge branch 'main' into bugfix/group-by-filter-section-structure
marufsharifi 64463cc
Add 16px spacing between Group by filter sections
marufsharifi f7f4c59
Merge branch 'main' into bugfix/group-by-filter-section-structure
marufsharifi 935c505
Update Group by filters to use dividers
marufsharifi 4162027
Merge branch 'main' into bugfix/group-by-filter-section-structure
marufsharifi 7c1c389
Simplify Group by option builder
marufsharifi 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| import React, {useCallback, useMemo, useState} from 'react'; | ||
| import {View} from 'react-native'; | ||
| import Button from '@components/Button'; | ||
| import type {SearchGroupBy} from '@components/Search/types'; | ||
| import SingleSelectListItem from '@components/SelectionList/ListItem/SingleSelectListItem'; | ||
| import SelectionListWithSections from '@components/SelectionList/SelectionListWithSections'; | ||
| import type {ListItem} from '@components/SelectionList/types'; | ||
| import Text from '@components/Text'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
| import type {GroupBySection} from '@libs/SearchUIUtils'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| type GroupByPopupItem = { | ||
| text: string; | ||
| value: SearchGroupBy; | ||
| }; | ||
|
|
||
| type GroupByPopupProps = { | ||
| /** The label to show when in an overlay on mobile */ | ||
| label?: string; | ||
|
|
||
| /** The grouped options to show in the list */ | ||
| sections: GroupBySection[]; | ||
|
|
||
| /** The currently selected item */ | ||
| value: GroupByPopupItem | null; | ||
|
|
||
| /** Function to call to close the overlay when changes are applied */ | ||
| closeOverlay: () => void; | ||
|
|
||
| /** Function to call when changes are applied */ | ||
| onChange: (item: GroupByPopupItem | null) => void; | ||
| }; | ||
|
|
||
| function GroupByPopup({label, value, sections, closeOverlay, onChange}: GroupByPopupProps) { | ||
| const {translate} = useLocalize(); | ||
| const styles = useThemeStyles(); | ||
| // eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth | ||
| const {isSmallScreenWidth} = useResponsiveLayout(); | ||
| const {windowHeight} = useWindowDimensions(); | ||
| const [selectedItem, setSelectedItem] = useState(value); | ||
|
|
||
| const allSelectableItems = useMemo(() => sections.flatMap((section) => section.options), [sections]); | ||
|
|
||
| const listSections = useMemo( | ||
| () => | ||
| sections.map((section) => ({ | ||
| sectionIndex: section.sectionIndex, | ||
| ...(section.sectionIndex > 0 ? {customHeader: <View style={styles.dividerLine} />} : {}), | ||
| data: section.options.map<ListItem<SearchGroupBy>>((item) => ({ | ||
| text: item.text, | ||
| keyForList: item.value, | ||
| isSelected: item.value === selectedItem?.value, | ||
| })), | ||
| })), | ||
| [sections, selectedItem?.value, styles.dividerLine], | ||
| ); | ||
|
|
||
| const optionsCount = Math.max( | ||
| 1, | ||
| listSections.reduce((count, section) => count + section.data.length + (section.data.length > 0 && !!section.customHeader ? 1 : 0), 0), | ||
| ); | ||
|
|
||
| const updateSelectedItem = useCallback( | ||
| (item: ListItem) => { | ||
| const newItem = allSelectableItems.find((option) => option.value === item.keyForList) ?? null; | ||
| setSelectedItem(newItem); | ||
| }, | ||
| [allSelectableItems], | ||
| ); | ||
|
|
||
| const applyChanges = useCallback(() => { | ||
| onChange(selectedItem); | ||
| closeOverlay(); | ||
| }, [closeOverlay, onChange, selectedItem]); | ||
|
|
||
| const resetChanges = useCallback(() => { | ||
| onChange(null); | ||
| closeOverlay(); | ||
| }, [closeOverlay, onChange]); | ||
|
|
||
| return ( | ||
| <View style={[!isSmallScreenWidth && styles.pv4, styles.gap2]}> | ||
| {isSmallScreenWidth && !!label && <Text style={[styles.textLabel, styles.textSupporting, styles.ph5, styles.pv1]}>{label}</Text>} | ||
|
|
||
| <View style={[styles.getSelectionListPopoverHeight(optionsCount, windowHeight, false)]}> | ||
| <SelectionListWithSections | ||
| sections={listSections} | ||
| shouldSingleExecuteRowSelect | ||
| ListItem={SingleSelectListItem} | ||
| onSelectRow={updateSelectedItem} | ||
| /> | ||
| </View> | ||
|
|
||
| <View style={[styles.flexRow, styles.gap2, styles.ph5]}> | ||
| <Button | ||
| medium | ||
| style={[styles.flex1]} | ||
| text={translate('common.reset')} | ||
| onPress={resetChanges} | ||
| sentryLabel={CONST.SENTRY_LABEL.SEARCH.FILTER_POPUP_RESET_SINGLE_SELECT} | ||
| /> | ||
| <Button | ||
| success | ||
| medium | ||
| style={[styles.flex1]} | ||
| text={translate('common.apply')} | ||
| onPress={applyChanges} | ||
| sentryLabel={CONST.SENTRY_LABEL.SEARCH.FILTER_POPUP_APPLY_SINGLE_SELECT} | ||
| /> | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default GroupByPopup; |
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.
Uh oh!
There was an error while loading. Please reload this page.