Bug Description
The "Top categories" and "Top merchants" default insight search links use suboptimal sort parameters. They currently sort alphabetically by category/merchant name instead of by total spend descending.
Current behavior
- Top categories search URL contains
sortBy:groupCategory sortOrder:asc — sorts alphabetically by category name
- Top merchants search URL contains
sortBy:groupMerchant sortOrder:asc — sorts alphabetically by merchant name
While this doesn't affect the default chart views (bar chart for categories, pie chart for merchants), switching to view:table reveals the data isn't sorted by total spend descending — which is the expected behavior for "Top X" reports.
Expected behavior
Both should use sortBy:groupTotal sortOrder:desc so that when viewed as a table, categories and merchants are ordered from highest to lowest total spend.
Root cause
In src/libs/SearchUIUtils.ts, the createTopSearchMenuItem function uses a GROUP_BY_TO_SORT_COLUMN mapping that maps groupBy:category to sortBy:groupCategory and groupBy:merchant to sortBy:groupMerchant, both with sortOrder:asc. For "Top X" insight searches, these should always sort by groupTotal descending.
Recommended fix
Modify createTopSearchMenuItem in src/libs/SearchUIUtils.ts to always use sortBy:groupTotal sortOrder:desc instead of the alphabetical sorting from GROUP_BY_TO_SORT_COLUMN.
Issue Owner
Current Issue Owner: @mallenexpensify
Bug Description
The "Top categories" and "Top merchants" default insight search links use suboptimal sort parameters. They currently sort alphabetically by category/merchant name instead of by total spend descending.
Current behavior
sortBy:groupCategory sortOrder:asc— sorts alphabetically by category namesortBy:groupMerchant sortOrder:asc— sorts alphabetically by merchant nameWhile this doesn't affect the default chart views (bar chart for categories, pie chart for merchants), switching to
view:tablereveals the data isn't sorted by total spend descending — which is the expected behavior for "Top X" reports.Expected behavior
Both should use
sortBy:groupTotal sortOrder:descso that when viewed as a table, categories and merchants are ordered from highest to lowest total spend.Root cause
In
src/libs/SearchUIUtils.ts, thecreateTopSearchMenuItemfunction uses aGROUP_BY_TO_SORT_COLUMNmapping that mapsgroupBy:categorytosortBy:groupCategoryandgroupBy:merchanttosortBy:groupMerchant, both withsortOrder:asc. For "Top X" insight searches, these should always sort bygroupTotaldescending.Recommended fix
Modify
createTopSearchMenuIteminsrc/libs/SearchUIUtils.tsto always usesortBy:groupTotal sortOrder:descinstead of the alphabetical sorting fromGROUP_BY_TO_SORT_COLUMN.Issue Owner
Current Issue Owner: @mallenexpensify