Skip to content

[$250] Spend - Default sort is descending #91935

Open

Description

@applause-bot

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 9.3.84-0
Reproducible in staging?: Yes
Reproducible in production?: No
If this was caught during regression testing, add the test name, ID and link from BrowserStack: #91710
Email or phone of affected tester (no customers): applausetester+05272026_1@applause.expensifail.com
Issue reported by: Applause Internal Team
Bug source: Pull Request QA execution
Device used: Windows 11/ Chrome
App Component: Other

Action Performed:

  1. Open the staging.new.expensify.com website.
  2. Create new report
  3. Add two expenses to the report and force the second one of them to have a violation
  4. Go to Spend -> Reports
  5. Open the created report
  6. Change sort to Total

Expected Result:

Verify you have the default sort (Date/ASC) set. RBR pre-sort is gone.

Actual Result:

Default sort for Date is set to DESC. RBR pre-sort is still at the top

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome Safari

Screenshots/Videos

bandicam.2026-05-28.09-08-42-638.1.mp4

View all open jobs on GitHub

Applause Internal Information
Exported by: Julia Ponikarchuk
Bug ID: 7164951

Activity

  1. applause-bot commented on May 28, 2026

    @applause-bot
    Author

    While Applause doesn't embed attachments for this bug, here are the links for quick view:
    https://platform.applause.com/services/links/v1/external/297f145c1eeb20e9d3e55802cae6333624c7b62935f10115ecdb0c62624c9de0

  2. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 28, 2026
  3. MelvinBot commented on May 28, 2026

    @MelvinBot
    Contributor

    Proposal

    What is the root cause of that problem?

    The sort toggle logic in SortableHeaderText.tsx:60 always defaults to DESC when clicking a column that isn't currently active:

    const nextSortOrder = isActive && sortOrder === DESC ? ASC : DESC;

    When isActive is false (i.e., switching to a different column), the ternary short-circuits to DESC regardless. So the flow is:

    1. Report opens with Date/ASC (correct initial state at MoneyRequestReportTransactionList.tsx:285-288)
    2. User clicks Total → isActive=false → sort becomes Total/DESC
    3. User clicks Date again → isActive=false → sort becomes Date/DESC (bug: should be ASC)

    What changes do you think we should make in order to solve the problem?

    Modify the nextSortOrder logic in SortableHeaderText.tsx:60 so that when switching to a non-active column, the default sort order is ASC instead of DESC. The toggle behavior (clicking an already-active column flips the order) should remain unchanged.

    What alternative solutions did you explore? (Optional)

    An alternative would be to handle this in the onSortPress callback of MoneyRequestReportTransactionList.tsx:741 by overriding the sort order when the column changes. However, fixing it in SortableHeaderText is cleaner since it's the shared component responsible for computing the next sort order and the same issue would affect any consumer. Note that this change would also affect the Search table headers that use the same component — this is likely the correct behavior there too (defaulting to ASC when first clicking a column), but should be verified during QA.


    Next Steps for Contributor+ team: Reply with @MelvinBot implement this to create a draft PR, @MelvinBot <your feedback> to refine this analysis, or explain why you are rejecting Melvin's proposal.

  4. added
    ExternalAdded to denote the issue can be worked on by a contributor
    on May 28, 2026
  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on May 28, 2026
  6. yusufdeveloper2903 commented on May 28, 2026

    @yusufdeveloper2903
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2026-08-26 09:34:11 UTC.

    Proposal

    What is the root cause of that problem?

    The report transaction table declares its own default sort as Date/ASC, and gates the RBR pre-sort on exactly that pair:

    const [sortConfig, setSortConfig] = useState<SortedTransactions>({
    sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE,
    sortOrder: CONST.SEARCH.SORT_ORDER.ASC,
    });
    const {sortBy, sortOrder} = sortConfig;
    const isDefaultSort = sortBy === CONST.SEARCH.TABLE_COLUMNS.DATE && sortOrder === CONST.SEARCH.SORT_ORDER.ASC;

    The RBR set is null for any other pair, which is what switches violation-first ordering off:

    const rbrTransactionIDs = useMemo(() => {
    if (!isDefaultSort || !allTransactionViolations) {
    return null;
    }

    But the direction a header click produces is not decided here. It is decided by the shared SortableHeaderText, which anchors the first click of any inactive column to DESC:

    const nextSortOrder = isActive && sortOrder === CONST.SEARCH.SORT_ORDER.DESC ? CONST.SEARCH.SORT_ORDER.ASC : CONST.SEARCH.SORT_ORDER.DESC;
    return (
    <View style={containerStyle}>
    <PressableWithFeedback
    onPress={() => onPress(nextSortOrder)}

    SortableTableHeader forwards that order verbatim, and this table's onSortPress writes it into state without translating it to the view's own default:

    onSortPress={(selectedSortBy, selectedSortOrder) => {
    if (!isSortableColumnName(selectedSortBy)) {
    return;
    }
    setSortConfig((prevState) => ({...prevState, sortBy: selectedSortBy, sortOrder: selectedSortOrder}));
    }}

    So after Date → Amount → Date the table lands on Date/DESC, isDefaultSort stays false, and the flagged expense stops floating to the top.

    I measured the emitted order rather than inferring it. Rendering the real MoneyRequestReportTableHeader in Jest with Amount active and pressing Date emits ['date', 'desc'], and driving PR #91710's steps 5 → 7 → 8 through the same onSortPress body fails on current main with:

    -   "isDefaultSort": true,     -   "sortOrder": "asc",
    +   "isDefaultSort": false,    +   "sortOrder": "desc",
    

    When it became wrong

    The DESC anchor is correct for the component's other consumer: Search's own Date sort is DESC.

    const newQueryJSON: SearchQueryJSON = {...queryJSON, groupBy: undefined, sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE, sortOrder: CONST.SEARCH.SORT_ORDER.DESC, flatFilters: newFlatFilters};

    The two defaults diverged on 2025-03-24, when this table's initial order was changed from DESC to ASC in #58903:

    const [sortedData, setSortedData] = useState<SortedTransactions>({
    transactions,
    sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE,
    sortOrder: CONST.SEARCH.SORT_ORDER.ASC,
    });

    That made the shared anchor wrong for this view immediately, but with no visible effect until the isDefaultSort gate gave the lost default a consequence.

    Why the listed steps do not reproduce it

    @rojiphil the OP's step list stops at "Change sort to Total". PR #91710's test plan has an eighth step — "Switch back to Date/ASC and verify RBR-flagged item is back on the top" — and the Applause export dropped it. Following the six listed steps, nothing is wrong.

    The second reason it is easy to miss: the Date sort value is created, which is written date-only.

    const created = currentDate ?? format(new Date(), 'yyyy-MM-dd');

    App/src/libs/ReportUtils.ts

    Lines 14103 to 14105 in 9e84742

    switch (key) {
    case CONST.SEARCH.TABLE_COLUMNS.DATE:
    return getTransactionCreated(transaction);

    Two expenses created on the same day compare equal, and Array.prototype.sort is stable, so ASC and DESC render the same rows in the same order — only the arrow flips. Expenses on different days separate cleanly.

    On the second sentence of the Actual Result ("RBR pre-sort is still at the top"): with Amount active, isDefaultSort is false and rbrTransactionIDs is null — my run asserts that — so nothing pins the flagged row there. If it is still on top, it also wins the amount comparison. That is not a second defect, and a tie-break in the comparator cannot change the sort direction the title is about.

    Nothing catches it: SortableHeaderText and SortableTableHeader have no test anywhere in tests/, and the only unit test for this component replicates one effect in isolation instead of rendering the header.

    /**
    * This hook replicates the active transaction IDs logic from MoneyRequestReportTransactionList
    * to allow isolated testing of the useEffect behavior.
    */
    function useActiveTransactionIDsEffect(visualOrderTransactionIDs: string[]) {

    What changes do you think we should make in order to solve the problem?

    First, a correction to my own earlier proposal. I suggested a defaultSortOrder prop on SortableHeaderText. That is wrong: the prop is per table, not per column, so passing ASC would also flip the first click of Amount, Merchant, Description, Category and Tag in this same table. That is a behaviour change well beyond this bug.

    The default belongs to the view, so the translation belongs in the view. Hoist the pair this file already spells out twice into one constant, and reuse it in the handler:

    +const DEFAULT_SORT_CONFIG: SortedTransactions = {
    +    sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE,
    +    sortOrder: CONST.SEARCH.SORT_ORDER.ASC,
    +};
    -    const [sortConfig, setSortConfig] = useState<SortedTransactions>({sortBy: DATE, sortOrder: ASC});
    -    const isDefaultSort = sortBy === CONST.SEARCH.TABLE_COLUMNS.DATE && sortOrder === CONST.SEARCH.SORT_ORDER.ASC;
    +    const [sortConfig, setSortConfig] = useState<SortedTransactions>(DEFAULT_SORT_CONFIG);
    +    const isDefaultSort = sortBy === DEFAULT_SORT_CONFIG.sortBy && sortOrder === DEFAULT_SORT_CONFIG.sortOrder;
    -setSortConfig((prevState) => ({...prevState, sortBy: selectedSortBy, sortOrder: selectedSortOrder}));
    +const isReturningToDefaultColumn = selectedSortBy !== sortBy && selectedSortBy === DEFAULT_SORT_CONFIG.sortBy;
    +setSortConfig((prevState) => ({...prevState, sortBy: selectedSortBy, sortOrder: isReturningToDefaultColumn ? DEFAULT_SORT_CONFIG.sortOrder : selectedSortOrder}));

    Only the third hunk changes behaviour. I hoist rather than add a fourth DATE/ASC literal because the drift between the two places that spell the default out and the one that did not is the bug.

    Regression safety:

    • Search is untouched. Same column, opposite default, and Search writes the emitted order into the URL query, so changing the shared header would re-rank saved and shared search links:
      const onSortPress = useCallback(
      (column: SearchSortBy, order: SortOrder) => {
      clearSelectedTransactions();
      const newQuery = buildSearchQueryString({
      ...queryJSON,
      sortBy: column,
      sortOrder: order,
      });
      onSortPressedCallback?.();
      navigation.setParams({q: newQuery, rawQuery: undefined});
      },
      [clearSelectedTransactions, queryJSON, onSortPressedCallback, navigation],
    • setSortConfig has exactly one call site, the handler above.
    • Toggling the active Date column is unaffected: selectedSortBy !== sortBy is false, so repeat clicks still flip ASC↔DESC. Switching to any non-default column still lands on DESC.
    • No offline or optimistic path is involved: sortConfig is local useState, with no API call and no failureData.
    • The grouped layout derives from sortedTransactions, so it inherits the corrected order with no extra change.

    One limitation I want to be straight about: a user who deliberately sets Date/DESC, switches to Amount and comes back to Date gets ASC, not the DESC they last chose. The view has one default and this makes it reachable in one click; a second click still gives DESC.

    Tests, all of which I ran:

    1. Steps 5 → 7 → 8: open, click Amount, click Date, expect date/asc and isDefaultSort true. Fails on current main with the output above, passes with the fix.
    2. Date → Date still toggles DESC then ASC. Passes on main and with the fix.
    3. Merchant and Amount still land on DESC. Passes on main and with the fix.
    4. MoneyRequestReportTransactionListActiveTransactionIDsTest, MoneyRequestReportViewTest, MoneyRequestReportGroupHeaderTest — 15 tests, green with the fix applied.

    I did not render the whole transaction list in Jest. Test 1 drives the real MoneyRequestReportTableHeader → SortableTableHeader → SortableHeaderText chain and reproduces the onSortPress body verbatim.

    What alternative solutions did you explore? (Optional)

    • Flip the ternary to ASC. Rejected: Search's Date default is DESC, so this makes the shared header wrong for its other consumer, and Search's order is encoded in the URL.
    • A defaultSortOrder prop, my earlier proposal. Rejected above: per table rather than per column, so it changes five other columns in this table.
    • A deterministic tie-break in the comparator. Worth doing on its own, but it only makes equal rows stable; it cannot make Date land on ASC, so it does not address the reported default sort.
  7. MobileMage commented on May 28, 2026

    @MobileMage
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    In the money request report view (Spend → Reports → open a report), the initial default sort is Date/ASC so that RBR-flagged transactions are surfaced at the top. After clicking the Total column header to change sort, then clicking the Date column header again, Date sorts in DESC order instead of returning to the expected Date/ASC default. This contradicts step 8 of the test plan from the linked PR #91710 ("Switch back to Date/ASC and verify RBR-flagged item is back on the top") because clicking Date no longer restores the table's documented default ordering.

    What is the root cause of that problem?

    The READ side — MoneyRequestReportTransactionList — initialises sortConfig with {sortBy: DATE, sortOrder: ASC} and treats that combination as the "default sort" guard that triggers the RBR pre-sort path. The WRITE side — clicks coming up from SortableHeaderText — computes the next order with logic that does not know about this table's ASC default:

    const nextSortOrder = isActive && sortOrder === CONST.SEARCH.SORT_ORDER.DESC ? CONST.SEARCH.SORT_ORDER.ASC : CONST.SEARCH.SORT_ORDER.DESC;
    return (
    <View style={containerStyle}>
    <PressableWithFeedback
    onPress={() => onPress(nextSortOrder)}

    Line 60 reads const nextSortOrder = isActive && sortOrder === DESC ? ASC : DESC. When the user clicks a column that is not currently active (isActive is false because sortBy === 'total' after step 6, and Date is being re-clicked in step 7), the expression short-circuits to the falsy branch and returns DESC. The press handler in MoneyRequestReportTransactionList then writes that order straight into state without translating it to the table's per-column default:

    onSortPress={(selectedSortBy, selectedSortOrder) => {
    if (!isSortableColumnName(selectedSortBy)) {
    return;
    }
    setSortConfig((prevState) => ({...prevState, sortBy: selectedSortBy, sortOrder: selectedSortOrder}));
    }}

    The full chain is therefore: user clicks Total → SortableHeaderText emits ('total', DESC) → state becomes {sortBy: 'total', sortOrder: 'DESC'} (correct behaviour for non-default columns) → user clicks Date → SortableHeaderText sees isActive=false for Date and emits ('date', DESC) → state becomes {sortBy: 'date', sortOrder: 'DESC'}. Because isDefaultSort on line 291 only fires when sortOrder === ASC, the RBR pre-sort path in rbrTransactionIDs (lines 297-311) is also bypassed, so the RBR-flagged transaction no longer floats to the top either. The behaviour in SortableHeaderText is the right global default for the main Search screen, which uses DESC as its defaultSortOrder in SearchUIUtils (line 646), but it is wrong for this specific table whose default is Date/ASC. The mismatch was latent before PR #91710 — the new test plan added the Total → Date round-trip step, which is why staging surfaces it but production (which still ran the old test plan) does not.

    What changes do you think we should make in order to solve the problem?

    Fix it locally inside MoneyRequestReportTransactionList's onSortPress handler so the global SortableHeaderText keeps its existing behaviour for Search (which legitimately defaults to DESC). When the user clicks a column that is not the currently active sort column (i.e. selectedSortBy !== sortBy), use the table's per-column default: ASC when selectedSortBy === CONST.SEARCH.TABLE_COLUMNS.DATE, otherwise the incoming selectedSortOrder (DESC). When the user clicks the already-active column, honour selectedSortOrder so toggling Date between ASC and DESC still works.

    onSortPress={(selectedSortBy, selectedSortOrder) => {
    if (!isSortableColumnName(selectedSortBy)) {
    return;
    }
    setSortConfig((prevState) => ({...prevState, sortBy: selectedSortBy, sortOrder: selectedSortOrder}));
    }}

    Concretely, inside the existing onSortPress callback after the isSortableColumnName guard, compute const nextOrder = selectedSortBy !== sortBy && selectedSortBy === CONST.SEARCH.TABLE_COLUMNS.DATE ? CONST.SEARCH.SORT_ORDER.ASC : selectedSortOrder and pass that as sortOrder into setSortConfig. This restores the original Date/ASC default on switch-back, which in turn re-arms isDefaultSort on line 291 and re-enables the RBR pre-sort that PR #91710 wanted to validate. The change is scoped to a single handler and a single column, does not modify any shared helper or other Search consumers, and preserves the column-toggle behaviour for repeated clicks on Date (DESC ↔ ASC) because the selectedSortBy !== sortBy check is false on a re-click of the active column.

    What alternative solutions did you explore? (Optional)

    Adding a per-column default-order map to SortableHeaderText (so the global component computes ASC for Date and DESC for everything else) was considered but rejected — it would change behaviour for the main Search screen and every other consumer of SortableTableHeader, where DESC is the intentional default (defaultSortOrder = DESC in SearchUIUtils.ts). Keeping the fix local to the one table that has an ASC default avoids any cross-screen regressions.

  8. melvin-bot commented on May 28, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @rojiphil (External)

  9. changed the title [-]Spend - Default sort is descending[/-] [+][$250] Spend - Default sort is descending[/+] on May 28, 2026
  10. melvin-bot commented on May 28, 2026

    @melvin-bot
  11. github-actions commented on May 28, 2026

    @github-actions
    Contributor

    ⚠️ @yusufdeveloper2903 Thanks for your proposal. Please update it to follow the proposal template, as proposals are only reviewed if they follow that format (note the mandatory sections).

  12. github-actions commented on May 28, 2026

    @github-actions
    Contributor

    ⚠️ @MobileMage Your proposal is a duplicate of an already existing proposal and has been automatically withdrawn to prevent spam. Please review the existing proposals before submitting a new one.

  13. 192 remaining items

  14. jeffrey-graham commented on Nov 6, 2026

    @jeffrey-graham
  15. melvin-bot commented on Nov 6, 2026

    @melvin-bot
  16. melvin-bot commented on Nov 6, 2026

    @melvin-bot

    @rojiphil Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  17. bonnhatnguyen commented on Nov 7, 2026

    @bonnhatnguyen

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    In Spend > Reports, when opening an expense report:

    1. The transaction table initializes its sort order to Date (ASC) (useMoneyRequestReportSortedTransactions.ts:103-106). However, if the user clicks another column header (such as Total) and then clicks Date again, the Date column sorts in descending (DESC) order instead of returning to its default ascending (ASC) order.
    2. When transactions are grouped by Category or Tag (useMoneyRequestReportGroupedTransactions.ts), clicking a column header updates the sort direction arrow, but groupTransactionsByCategory / groupTransactionsByTag (src/libs/ReportLayoutUtils.ts:62-116) always re-sorts the groups alphabetically (A → Z), so when each group contains a single expense (as in the QA reproduction), the visible row order never changes.

    What is the root cause of that problem?

    1. SortableHeaderText hardcodes DESC for any inactive column (src/components/Search/SortableHeaderText.tsx:84 & src/components/MoneyRequestReportView/useMoneyRequestReportSortedTransactions.ts:110-115):
      In src/components/Search/SortableHeaderText.tsx:84:

      const nextSortOrder = isActive && sortOrder === CONST.SEARCH.SORT_ORDER.DESC ? CONST.SEARCH.SORT_ORDER.ASC : CONST.SEARCH.SORT_ORDER.DESC;

      Whenever a column is not currently active (isActive === false), clicking it always passes CONST.SEARCH.SORT_ORDER.DESC to onPress.
      In src/components/MoneyRequestReportView/useMoneyRequestReportSortedTransactions.ts:103-115:

      const [sortConfig, setSortConfig] = useState<SortConfig>({
          sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE,
          sortOrder: CONST.SEARCH.SORT_ORDER.ASC,
      });
      
      const onSortPress = (selectedSortBy: SearchSortBy, selectedSortOrder: SortOrder) => {
          if (!isSortableColumnName(selectedSortBy)) {
              return;
          }
          setSortConfig((prevState) => ({...prevState, sortBy: selectedSortBy, sortOrder: selectedSortOrder}));
      };

      Because onSortPress stores selectedSortOrder directly without checking whether the user is switching to CONST.SEARCH.TABLE_COLUMNS.DATE from another column, clicking Total (sortBy: TOTAL, sortOrder: DESC) and then clicking Date sets {sortBy: DATE, sortOrder: DESC} instead of restoring the report table's default ASC order for Date.

    2. groupTransactionsByCategory and groupTransactionsByTag unconditionally overwrite transaction sort order with alphabetical group sorting (src/libs/ReportLayoutUtils.ts:81, 113):
      In useMoneyRequestReportGroupedTransactions.ts:256-260, resolvedTransactions (already sorted by useMoneyRequestReportSortedTransactions) are passed into groupTransactionsByCategory / groupTransactionsByTag. Because Map preserves insertion order, groups initially follows the sorted transaction order, but ReportLayoutUtils.ts unconditionally calls return sortGroupedTransactions(result, localeCompare); at the end of both functions, forcing alphabetical category/tag order regardless of the active column sort.

    What changes do you think we should make in order to solve the problem?

    1. Restore CONST.SEARCH.SORT_ORDER.ASC when switching to the DATE column in src/components/MoneyRequestReportView/useMoneyRequestReportSortedTransactions.ts:110-115:
      When selectedSortBy === CONST.SEARCH.TABLE_COLUMNS.DATE and prevState.sortBy !== CONST.SEARCH.TABLE_COLUMNS.DATE, default sortOrder to CONST.SEARCH.SORT_ORDER.ASC (while preserving normal ASC <-> DESC toggling when DATE is already the active column):

      const onSortPress = (selectedSortBy: SearchSortBy, selectedSortOrder: SortOrder) => {
          if (!isSortableColumnName(selectedSortBy)) {
              return;
          }
          setSortConfig((prevState) => {
              const nextSortOrder =
                  selectedSortBy === CONST.SEARCH.TABLE_COLUMNS.DATE && prevState.sortBy !== CONST.SEARCH.TABLE_COLUMNS.DATE
                      ? CONST.SEARCH.SORT_ORDER.ASC
                      : selectedSortOrder;
              return {...prevState, sortBy: selectedSortBy, sortOrder: nextSortOrder};
          });
      };

      (Note: if only the flat-table Date default sort is desired per #101424, this 1-file change in useMoneyRequestReportSortedTransactions.ts completely fixes it without touching shared SortableHeaderText.tsx.)

    2. If grouped views should also respect non-default user column sorts (src/libs/ReportLayoutUtils.ts & useMoneyRequestReportGroupedTransactions.ts):
      Add an optional shouldSortGroupsAlphabetically = true parameter to groupTransactionsByCategory and groupTransactionsByTag in src/libs/ReportLayoutUtils.ts, and pass isDefaultSort (sortBy === CONST.SEARCH.TABLE_COLUMNS.DATE && sortOrder === CONST.SEARCH.SORT_ORDER.ASC) from useMoneyRequestReportGroupedTransactions.ts so groups are alphabetized by default but follow the sorted transaction insertion order when the user actively sorts by a column.

    What alternative solutions did you explore? (Optional)

    • Changing SortableHeaderText.tsx globally to default inactive columns to ASC: SortableHeaderText is shared with the main Search page (SearchTableHeader), where clicking an inactive column is expected to start on DESC. Keeping the DATE -> ASC default inside useMoneyRequestReportSortedTransactions.ts avoids regressions in Search.
  18. melvin-bot commented on Nov 7, 2026

    @melvin-bot

    📣 @ronanchnlps-bit! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  19. Burapa-J commented on Nov 8, 2026

    @Burapa-J

    Withdrawn — I'm withdrawing this proposal so I only hold one job at a time, per the contributor guidelines. Thank you for reviewing.

    Original proposal

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    In Spend > Reports, when opening an expense report that has multiple expenses:

    1. The report transaction table is designed to default to sorting by Date in ascending (ASC) order (Date / ASC).
    2. However, if the user clicks another column header (such as Total) and then clicks Date again, Date sorts in descending (DESC) order instead of restoring its default ascending (ASC) order.
    3. Additionally, because sortConfig inside useMoneyRequestReportSortedTransactions is never reset when report?.reportID changes, switching from a report that was sorted in DESC order to another report while MoneyRequestReportTransactionList stays mounted causes the newly opened report to start with descending (DESC) sort instead of Date / ASC.

    What is the root cause of that problem?

    1. Inactive Column Clicks Always Emit DESC in SortableHeaderText.tsx and Are Stored Unchanged in useMoneyRequestReportSortedTransactions.ts (src/components/Search/SortableHeaderText.tsx:84 & src/components/MoneyRequestReportView/useMoneyRequestReportSortedTransactions.ts:103-115):

      • useMoneyRequestReportSortedTransactions.ts:103-106 initializes the report table's sort configuration to:
        const [sortConfig, setSortConfig] = useState<SortConfig>({
            sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE,
            sortOrder: CONST.SEARCH.SORT_ORDER.ASC,
        });
      • However, SortableHeaderText.tsx:84 computes the next sort order for any column press as:
        const nextSortOrder = isActive && sortOrder === CONST.SEARCH.SORT_ORDER.DESC ? CONST.SEARCH.SORT_ORDER.ASC : CONST.SEARCH.SORT_ORDER.DESC;
        Whenever a column is not currently active (!isActive), SortableHeaderText emits CONST.SEARCH.SORT_ORDER.DESC.
      • When the user clicks Total (sortBy becomes TOTAL) and then clicks Date (isActive is false for Date), SortableHeaderText calls onSortPress(CONST.SEARCH.TABLE_COLUMNS.DATE, CONST.SEARCH.SORT_ORDER.DESC).
      • onSortPress (useMoneyRequestReportSortedTransactions.ts:110-115) blindly stores selectedSortOrder (DESC), overriding the report table's chronological Date / ASC default.
    2. sortConfig Persists Across Report Navigation (src/components/MoneyRequestReportView/useMoneyRequestReportSortedTransactions.ts:103-106):
      useState<SortConfig>({sortBy: DATE, sortOrder: ASC}) only initializes when MoneyRequestReportTransactionList first mounts. If a user sorts a report into DESC order and navigates to another report where the component instance is reused across report?.reportID updates, sortConfig retains the previous report's DESC sort state instead of resetting to {sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE, sortOrder: CONST.SEARCH.SORT_ORDER.ASC}.

    (Note: PR #101497 intentionally removed Red Brick Road violation pre-sorting from useMoneyRequestReportSortedTransactions.ts and confirmed that grouped Category/Tag headers in ReportLayoutUtils.ts remain alphabetically sorted by design, so neither RBR pre-sorting nor sortGroupedTransactions should be altered.)

    What changes do you think we should make in order to solve the problem?

    In src/components/MoneyRequestReportView/useMoneyRequestReportSortedTransactions.ts:

    1. Restore CONST.SEARCH.SORT_ORDER.ASC When Switching Back to CONST.SEARCH.TABLE_COLUMNS.DATE in onSortPress (lines 110-115):
      When switching from another column (prevState.sortBy !== selectedSortBy) to CONST.SEARCH.TABLE_COLUMNS.DATE, set sortOrder to CONST.SEARCH.SORT_ORDER.ASC. When clicking DATE while it is already the active column (prevState.sortBy === selectedSortBy), use selectedSortOrder so it continues toggling cleanly between ASC and DESC:

      const onSortPress = (selectedSortBy: SearchSortBy, selectedSortOrder: SortOrder) => {
          if (!isSortableColumnName(selectedSortBy)) {
              return;
          }
          setSortConfig((prevState) => {
              const isSwitchingToDate =
                  prevState.sortBy !== selectedSortBy && selectedSortBy === CONST.SEARCH.TABLE_COLUMNS.DATE;
              return {
                  sortBy: selectedSortBy,
                  sortOrder: isSwitchingToDate ? CONST.SEARCH.SORT_ORDER.ASC : selectedSortOrder,
              };
          });
      };
    2. Reset sortConfig to Date / ASC When report?.reportID Changes (lines 103-109):
      Track report?.reportID (or key the sort state by report?.reportID) so opening a different report in Spend > Reports always starts on the default {sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE, sortOrder: CONST.SEARCH.SORT_ORDER.ASC} sort.

    What alternative solutions did you explore? (Optional)

    • Changing SortableHeaderText.tsx:84 globally to default inactive columns to ASC: Top-level Search views (Spend > Expenses and Spend > Reports list) intentionally default newly clicked columns to DESC (newest / highest first). Changing SortableHeaderText.tsx globally would regress Search sorting and URL query parameters.
    • Disabling sortGroupedTransactions in src/libs/ReportLayoutUtils.ts or re-adding RBR violation pre-sorting (proposed by several earlier proposals): PR #101497 (fixing #101424) explicitly removed RBR pre-sorting from useMoneyRequestReportSortedTransactions.ts and established that category/tag group headers stay in alphabetical order. Modifying ReportLayoutUtils.ts or re-introducing RBR pre-sort would directly regress #101424.
  20. cocvn157 commented on Nov 8, 2026

    @cocvn157

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    In the Money Request Report view (Reports > Spend / Expense Report table view), after sorting expenses by another column (e.g. Total or Category) and then clicking the Date column header, the table sorts Date in descending (DESC) order instead of restoring its default ascending (ASC) order. Additionally, when expenses are grouped by Category or Tag, clicking column headers to sort does not reorder single-transaction groups because groups are always re-sorted alphabetically (A -> Z).

    What is the root cause of that problem?

    There are three connected issues in MoneyRequestReportView:

    1. Switching back to Date defaults to DESC (SortableHeaderText.tsx & useMoneyRequestReportSortedTransactions.ts):
      useMoneyRequestReportSortedTransactions (src/components/MoneyRequestReportView/useMoneyRequestReportSortedTransactions.ts:103-106) initializes sortConfig to {sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE, sortOrder: CONST.SEARCH.SORT_ORDER.ASC}. However, SortableHeaderText (src/components/Search/SortableHeaderText.tsx:84) always computes nextSortOrder for an inactive column (!isActive) as CONST.SEARCH.SORT_ORDER.DESC:
    const nextSortOrder = isActive && sortOrder === CONST.SEARCH.SORT_ORDER.DESC
        ? CONST.SEARCH.SORT_ORDER.ASC
        : CONST.SEARCH.SORT_ORDER.DESC;

    When the user sorts by another column and then clicks Date, onSortPress (useMoneyRequestReportSortedTransactions.ts:110-115) blindly accepts selectedSortOrder (DESC) instead of starting Date in ASC order to match the table's initial sort order.
    2. Sort state is not reset when switching reports (useMoneyRequestReportSortedTransactions.ts:103-106):
    When report?.reportID changes while MoneyRequestReportTransactionList remains mounted, sortConfig retains the previous report's sortBy/sortOrder.
    3. Grouped mode unconditionally re-sorts groups alphabetically (ReportLayoutUtils.ts:81, 111):
    In groupTransactionsByCategory and groupTransactionsByTag (src/libs/ReportLayoutUtils.ts:57-112), Map insertion order already reflects the sorted transactions passed in from useMoneyRequestReportSortedTransactions, but both functions unconditionally return sortGroupedTransactions(result, localeCompare), which overrides the user's manual column sort with alphabetical A -> Z group ordering.

    What changes do you think we should make in order to solve the problem?

    1. In src/components/MoneyRequestReportView/useMoneyRequestReportSortedTransactions.ts:
      • Track hasUserSorted and reset sortConfig to {sortBy: CONST.SEARCH.TABLE_COLUMNS.DATE, sortOrder: CONST.SEARCH.SORT_ORDER.ASC} (and hasUserSorted to false) in a useEffect when report?.reportID changes.
      • In onSortPress, when switching from another column to CONST.SEARCH.TABLE_COLUMNS.DATE (prevState.sortBy !== selectedSortBy && selectedSortBy === CONST.SEARCH.TABLE_COLUMNS.DATE), set sortOrder to CONST.SEARCH.SORT_ORDER.ASC (while clicking Date when it is already active continues to toggle ASC <-> DESC):
    const onSortPress = (selectedSortBy: SearchSortBy, selectedSortOrder: SortOrder) => {
        if (!isSortableColumnName(selectedSortBy)) {
            return;
        }
        setHasUserSorted(true);
        setSortConfig((prevState) => ({
            ...prevState,
            sortBy: selectedSortBy,
            sortOrder:
                prevState.sortBy !== selectedSortBy && selectedSortBy === CONST.SEARCH.TABLE_COLUMNS.DATE
                    ? CONST.SEARCH.SORT_ORDER.ASC
                    : selectedSortOrder,
        }));
    };
    1. In src/libs/ReportLayoutUtils.ts (groupTransactionsByCategory and groupTransactionsByTag) and src/components/MoneyRequestReportView/useMoneyRequestReportGroupedTransactions.ts:
      • Add an optional shouldSortGroupsAlphabetically = true parameter to groupTransactionsByCategory and groupTransactionsByTag, and pass !hasUserSorted from useMoneyRequestReportGroupedTransactions:
    groupedTransactions =
        currentGroupBy === CONST.REPORT_LAYOUT.GROUP_BY.TAG
            ? groupTransactionsByTag(resolvedTransactions, reportCurrency, localeCompare, !hasUserSorted)
            : groupTransactionsByCategory(resolvedTransactions, reportCurrency, localeCompare, !hasUserSorted);

    This keeps initial grouped loads sorted alphabetically (A -> Z) while preserving the sorted transaction order across groups once the user explicitly clicks a column header to sort.

    What alternative solutions did you explore? (Optional)

    • Changing SortableHeaderText.tsx globally so inactive columns default to ASC: rejected because the main Search page (SearchPage / SearchColumnConfig) intentionally defaults newly selected columns to DESC. Handling the DATE column transition inside useMoneyRequestReportSortedTransactions scopes the behavior to the Money Request Report table without affecting Search.
  21. melvin-bot commented on Nov 8, 2026

    @melvin-bot

    📣 @cocvn157! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  22. melvin-bot commented on Nov 10, 2026

    @melvin-bot

    @rojiphil 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  23. bingg8684 commented on Nov 12, 2026

    @bingg8684
  24. melvin-bot commented on Nov 12, 2026

    @melvin-bot

    📣 @bingg8684! 📣
    Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork.
    Please follow these steps:

    1. Make sure you've read and understood the contributing guidelines.
    2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
    3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
    4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details.
      Screen Shot 2022-11-16 at 4 42 54 PM
      Format:
    Contributor details
    Your Expensify account email: <REPLACE EMAIL HERE>
    Upwork Profile Link: <REPLACE LINK HERE>
    
  25. github-actions commented on Nov 12, 2026

    @github-actions
    Contributor

    ⚠️ @bingg8684 Thanks for your interest. To be considered for this job, please post a proposal following the proposal template (note the mandatory sections). Comments claiming the job without one are not reviewed.

  26. melvin-bot commented on Nov 12, 2026

    @melvin-bot

    @rojiphil 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

  27. KFC-19 commented on Nov 13, 2026

    @KFC-19
  28. github-actions commented on Nov 13, 2026

    @github-actions
    Contributor

    ⚠️ @KFC-19 Thanks for your interest. To be considered for this job, please post a proposal following the proposal template (note the mandatory sections). Comments claiming the job without one are not reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributorHelp WantedApply this label when an issue is open to proposals by contributorsOverdue

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions