Repository navigation
feat: [Insights] [Release 1] Top Categories - Add group-by:category #80333
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
Changes from all commits
58e977f
4571bbb
e42a41a
c219475
97836f0
17395a0
acd4da8
805a346
ec18923
e37af71
d229390
678b5a9
09d6496
8eeb3a8
a0a07b7
4d35ab1
e870ee5
d28536b
7d470dc
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 |
|---|---|---|
|
|
@@ -72,6 +72,10 @@ function SearchContextProvider({children}: ChildrenProps) { | |
| const [searchContextData, setSearchContextData] = useState(defaultSearchContextData); | ||
| const areTransactionsEmpty = useRef(true); | ||
|
|
||
| // Use a ref to access searchContextData in callbacks without causing callback reference changes | ||
| const searchContextDataRef = useRef(searchContextData); | ||
|
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. Note: iOS Selection Mode Bug Fix (Pre-existing)Bug: Selection mode on iOS would immediately turn off after long-press on group-by views. Root Cause: Fix: Used a ref to read |
||
| searchContextDataRef.current = searchContextData; | ||
|
|
||
| const [snapshotSearchResults] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${searchContextData.currentSearchHash}`, {canBeMissing: true}); | ||
| const {todoSearchResultsData} = useTodos(); | ||
|
|
||
|
|
@@ -196,11 +200,13 @@ function SearchContextProvider({children}: ChildrenProps) { | |
| return; | ||
| } | ||
|
|
||
| if (searchHashOrClearIDsFlag === searchContextData.currentSearchHash) { | ||
| const data = searchContextDataRef.current; | ||
|
|
||
| if (searchHashOrClearIDsFlag === data.currentSearchHash) { | ||
| return; | ||
| } | ||
|
|
||
| if (searchContextData.selectedReports.length === 0 && isEmptyObject(searchContextData.selectedTransactions) && !searchContextData.shouldTurnOffSelectionMode) { | ||
| if (data.selectedReports.length === 0 && isEmptyObject(data.selectedTransactions) && !data.shouldTurnOffSelectionMode) { | ||
| return; | ||
| } | ||
| setSearchContextData((prevState) => ({ | ||
|
|
@@ -214,13 +220,7 @@ function SearchContextProvider({children}: ChildrenProps) { | |
| shouldShowSelectAllMatchingItems(false); | ||
| selectAllMatchingItems(false); | ||
| }, | ||
| [ | ||
| searchContextData.currentSearchHash, | ||
| searchContextData.selectedReports.length, | ||
| searchContextData.selectedTransactions, | ||
| searchContextData.shouldTurnOffSelectionMode, | ||
| setSelectedTransactions, | ||
| ], | ||
| [setSelectedTransactions], | ||
| ); | ||
|
|
||
| const removeTransaction: SearchContextProps['removeTransaction'] = useCallback( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,7 @@ import { | |
| isSearchResultsEmpty as isSearchResultsEmptyUtil, | ||
| isTaskListItemType, | ||
| isTransactionCardGroupListItemType, | ||
| isTransactionCategoryGroupListItemType, | ||
| isTransactionGroupListItemType, | ||
| isTransactionListItemType, | ||
| isTransactionMemberGroupListItemType, | ||
|
|
@@ -213,6 +214,7 @@ function Search({ | |
| onDEWModalOpen, | ||
| }: SearchProps) { | ||
| const {type, status, sortBy, sortOrder, hash, similarSearchHash, groupBy} = queryJSON; | ||
|
|
||
| const {isOffline} = useNetwork(); | ||
| const prevIsOffline = usePrevious(isOffline); | ||
| const {shouldUseNarrowLayout} = useResponsiveLayout(); | ||
|
|
@@ -770,6 +772,7 @@ function Search({ | |
| } | ||
|
|
||
| const currentTransactions = itemTransactions ?? item.transactions; | ||
|
|
||
| // Handle empty reports - treat the report itself as selectable | ||
| if (currentTransactions.length === 0 && isTransactionReportGroupListItemType(item)) { | ||
| const reportKey = item.keyForList; | ||
|
|
@@ -799,6 +802,7 @@ function Search({ | |
| updateSelectAllMatchingItemsState(updatedTransactions); | ||
| return; | ||
| } | ||
|
|
||
| if (currentTransactions.some((transaction) => selectedTransactions[transaction.keyForList]?.isSelected)) { | ||
| const reducedSelectedTransactions: SelectedTransactions = {...selectedTransactions}; | ||
|
|
||
|
|
@@ -887,6 +891,20 @@ function Search({ | |
| return; | ||
| } | ||
|
|
||
| if (isTransactionCategoryGroupListItemType(item)) { | ||
| const categoryValue = item.category === '' ? CONST.SEARCH.CATEGORY_EMPTY_VALUE : item.category; | ||
| const newFlatFilters = queryJSON.flatFilters.filter((filter) => filter.key !== CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY); | ||
| newFlatFilters.push({key: CONST.SEARCH.SYNTAX_FILTER_KEYS.CATEGORY, filters: [{operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO, value: categoryValue}]}); | ||
| const newQueryJSON: SearchQueryJSON = {...queryJSON, groupBy: undefined, flatFilters: newFlatFilters}; | ||
| const newQuery = buildSearchQueryString(newQueryJSON); | ||
| const newQueryJSONWithHash = buildSearchQueryJSON(newQuery); | ||
| if (!newQueryJSONWithHash) { | ||
| return; | ||
| } | ||
| handleSearch({queryJSON: newQueryJSONWithHash, searchKey, offset: 0, shouldCalculateTotals: false, isLoading: false}); | ||
| return; | ||
| } | ||
|
Comment on lines
+894
to
+906
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. NAB: This is getting repetitve. Maybe we can do this in a follow up? Use
|
||
|
|
||
| let reportID = item.reportID; | ||
| if (isTransactionItem && item?.reportAction?.childReportID) { | ||
| const isFromSelfDM = item.reportID === CONST.REPORT.UNREPORTED_REPORT_ID; | ||
|
|
@@ -1184,7 +1202,7 @@ function Search({ | |
| clearSelectedTransactions(); | ||
| const newQuery = buildSearchQueryString({...queryJSON, sortBy: column, sortOrder: order}); | ||
| onSortPressedCallback?.(); | ||
| // We want to explicitly clear stale rawQuery since it’s only used for manually typed-in queries. | ||
| // We want to explicitly clear stale rawQuery since it's only used for manually typed-in queries. | ||
| navigation.setParams({q: newQuery, rawQuery: undefined}); | ||
| }; | ||
|
|
||
|
|
||
|
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. NAB:follow-up: All of these ListItemHeader components are very similar. I would like to see us refactor these to use a BaseListItemHeader component. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
| import Checkbox from '@components/Checkbox'; | ||
| import type {SearchColumnType} from '@components/Search/types'; | ||
| import type {ListItem, TransactionCategoryGroupListItemType} from '@components/SelectionListWithSections/types'; | ||
| import TextWithTooltip from '@components/TextWithTooltip'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
| import useStyleUtils from '@hooks/useStyleUtils'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
| import CONST from '@src/CONST'; | ||
| import ExpandCollapseArrowButton from './ExpandCollapseArrowButton'; | ||
| import TextCell from './TextCell'; | ||
| import TotalCell from './TotalCell'; | ||
|
|
||
| type CategoryListItemHeaderProps<TItem extends ListItem> = { | ||
| /** The category currently being looked at */ | ||
| category: TransactionCategoryGroupListItemType; | ||
|
|
||
| /** Callback to fire when a checkbox is pressed */ | ||
| onCheckboxPress?: (item: TItem) => void; | ||
|
|
||
| /** Whether this section items disabled for selection */ | ||
| isDisabled?: boolean | null; | ||
|
|
||
| /** Whether selecting multiple transactions at once is allowed */ | ||
| canSelectMultiple: boolean | undefined; | ||
|
|
||
| /** Whether all transactions are selected */ | ||
| isSelectAllChecked?: boolean; | ||
|
|
||
| /** Whether only some transactions are selected */ | ||
| isIndeterminate?: boolean; | ||
|
|
||
| /** Callback for when the down arrow is clicked */ | ||
| onDownArrowClick?: () => void; | ||
|
|
||
| /** Whether the down arrow is expanded */ | ||
| isExpanded?: boolean; | ||
|
|
||
| /** The visible columns for the header */ | ||
| columns?: SearchColumnType[]; | ||
| }; | ||
|
|
||
| function CategoryListItemHeader<TItem extends ListItem>({ | ||
| category: categoryItem, | ||
| onCheckboxPress, | ||
| isDisabled, | ||
| canSelectMultiple, | ||
| isSelectAllChecked, | ||
| isIndeterminate, | ||
| isExpanded, | ||
| onDownArrowClick, | ||
| columns, | ||
| }: CategoryListItemHeaderProps<TItem>) { | ||
| const styles = useThemeStyles(); | ||
| const StyleUtils = useStyleUtils(); | ||
| const {isLargeScreenWidth} = useResponsiveLayout(); | ||
| const {translate} = useLocalize(); | ||
| // formattedCategory is pre-decoded in SearchUIUtils, just translate empty values | ||
| const rawCategory = categoryItem.formattedCategory ?? categoryItem.category; | ||
| const categoryName = !rawCategory || rawCategory === CONST.SEARCH.CATEGORY_EMPTY_VALUE ? translate('reportLayout.uncategorized') : rawCategory; | ||
|
|
||
| const columnComponents = { | ||
| [CONST.SEARCH.TABLE_COLUMNS.GROUP_CATEGORY]: ( | ||
| <View | ||
| key={CONST.SEARCH.TABLE_COLUMNS.GROUP_CATEGORY} | ||
| style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.CATEGORY)} | ||
| > | ||
| <View style={[styles.gap1, styles.flexShrink1]}> | ||
| <TextWithTooltip | ||
| text={categoryName} | ||
| style={[styles.optionDisplayName, styles.sidebarLinkTextBold, styles.pre, styles.fontWeightNormal]} | ||
| /> | ||
| </View> | ||
| </View> | ||
| ), | ||
| [CONST.SEARCH.TABLE_COLUMNS.GROUP_EXPENSES]: ( | ||
| <View | ||
| key={CONST.SEARCH.TABLE_COLUMNS.GROUP_EXPENSES} | ||
| style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.EXPENSES)} | ||
| > | ||
| <TextCell text={String(categoryItem.count)} /> | ||
| </View> | ||
| ), | ||
| [CONST.SEARCH.TABLE_COLUMNS.GROUP_TOTAL]: ( | ||
| <View | ||
| key={CONST.SEARCH.TABLE_COLUMNS.GROUP_TOTAL} | ||
| style={StyleUtils.getReportTableColumnStyles(CONST.SEARCH.TABLE_COLUMNS.TOTAL, false, false, false, false, false, false, false, true)} | ||
| > | ||
| <TotalCell | ||
| total={categoryItem.total} | ||
| currency={categoryItem.currency} | ||
| /> | ||
| </View> | ||
| ), | ||
| }; | ||
|
|
||
| return ( | ||
| <View> | ||
| <View style={[styles.pv1Half, styles.pl3, styles.flexRow, styles.alignItemsCenter, isLargeScreenWidth ? styles.gap3 : styles.justifyContentStart]}> | ||
| <View style={[styles.flexRow, styles.alignItemsCenter, styles.mnh40, styles.flex1, styles.gap3]}> | ||
| {!!canSelectMultiple && ( | ||
| <Checkbox | ||
| onPress={() => onCheckboxPress?.(categoryItem as unknown as TItem)} | ||
| isChecked={isSelectAllChecked} | ||
| isIndeterminate={isIndeterminate} | ||
| disabled={!!isDisabled || categoryItem.isDisabledCheckbox} | ||
| accessibilityLabel={translate('common.select')} | ||
| style={isLargeScreenWidth && styles.mr1} | ||
| /> | ||
| )} | ||
| {!isLargeScreenWidth && ( | ||
| <View style={[styles.flexRow, styles.flex1, styles.gap3]}> | ||
| <View style={[styles.gap1, styles.flexShrink1]}> | ||
| <TextWithTooltip | ||
| text={categoryName} | ||
| style={[styles.optionDisplayName, styles.sidebarLinkTextBold, styles.pre, styles.fontWeightNormal]} | ||
| /> | ||
| </View> | ||
| </View> | ||
| )} | ||
| {isLargeScreenWidth && columns?.map((column) => columnComponents[column as keyof typeof columnComponents])} | ||
| </View> | ||
| {!isLargeScreenWidth && ( | ||
| <View style={[styles.flexShrink0, styles.ml2, styles.mr3, styles.gap1]}> | ||
| <TotalCell | ||
| total={categoryItem.total} | ||
| currency={categoryItem.currency} | ||
| /> | ||
| {!!onDownArrowClick && ( | ||
| <ExpandCollapseArrowButton | ||
| isExpanded={isExpanded} | ||
| onPress={onDownArrowClick} | ||
| /> | ||
| )} | ||
| </View> | ||
| )} | ||
| </View> | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
| export default CategoryListItemHeader; |
Uh oh!
There was an error while loading. Please reload this page.