App icon indicating copy to clipboard operation
App copied to clipboard

[$175] Reports - New report defaults to the default workspace instead of the selected workspace

Open applause-bot[bot] opened this issue 1 week ago • 8 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.52-1 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://github.com/Expensify/App/pull/106464 Email or phone of affected tester (no customers): n/a Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Mac 26.5.1 Safari/Chrome, iPhone 13 iOS 26.6 App Component: Money Requests

Action Performed:

  1. Navigate to https://staging.new.expensify.com
  2. Create two workspaces, each with at least two open reports
  3. Navigate to the non-default workspace
  4. Click the + button > Create expense > Manual
  5. Click the Report field.

Expected Result:

The new report should be created in the selected non-default workspace, since expense creation was initiated from that workspace

Actual Result:

Unable to create a new report in a non-default workspace during expense creation. The flow redirects to the default workspace.

Workaround:

Unknown

Platforms:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [x] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/e9fae3b7-bcbd-4fb5-82be-6a5c63343b71

View all open jobs on GitHub

Applause Internal Information Exported by: Chandana Kiran Bug ID: 7320932

Upwork Automation - Do Not Edit

applause-bot[bot] avatar Nov 22 '26 07:11 applause-bot[bot]

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

applause-bot[bot] avatar Nov 22 '26 07:11 applause-bot[bot]

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

Job added to Upwork: https://www.upwork.com/jobs/~022124410898921742791

🤖 Web test steps verification results: ❌ fail

Reproduced from non-default Workspace B’s chat composer + menu: the expense starts in B, but selecting Create report switches it to default Workspace A. No expense was submitted. Expense workspace changed to default Workspace A after selecting Create report

Step Status
Navigate into Workspace B without changing the defaultWorkspace A remained the default; B’s expense chat contained two open report cards.
✅
Open + → Create expense → ManualUsed B’s chat composer menu, not the global sidebar button. The form initially showed Workspace B.
✅
Report picker preserves Workspace B contextExisting reports belonged to B, but Create report displayed Workspace A.
Workspace B expense with B reports but Create report targeting default Workspace A
❌
Selecting Create report retains Workspace BThe form switched to Workspace A. Persisted report ownership was not independently verified.
Expense workspace changed to default Workspace A after selecting Create report
❌

Proposal

What is the root cause of that problem?

The Report picker discards the expense’s workspace when the selected report belongs to the current user and the expense is not per diem. This causes Create report to fall back to the saved default workspace—even though the expense and existing-report options correctly identify the non-default workspace.

Code evidence and alternative explanations

The initial-context-loss hypothesis does not explain this reproduction: the manual form and existing-report options retained B until Create report was selected. The frontend fallback explains the observed switch without requiring a backend redirect.

Scope: Verified on development web through the chat composer. The global sidebar + entry point was not verified; it should not be conflated with this flow. No introducing PR was established.

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

Preserve the explicit workspace-chat destination when creating a new report for a non-global expense. Do not discard it solely because the selected report belongs to the current user.

Keep global-create defaults, editing behavior, per-diem handling, other-owner handling, and workspace restrictions intact.

Regression coverage

With A default and B non-default, each containing two open reports:

  • Start a manual expense from B’s chat.
  • Verify existing reports and Create report target B.
  • Verify creation sends B’s policy ID.
  • Cover both dropdown and full-page pickers.
  • Retest global creation, per diem, other-owner expenses, and restricted workspaces.

What alternative solutions did you explore? (Optional)

Changing the saved default workspace would mask the bug rather than preserve the expense’s existing workspace context.

Related issue: Consolidate the default-workspace eligibility rule across report and expense flows concerns overlapping fallback logic, but is not a confirmed duplicate.


Next Steps for Contributor+ team: To accept: @MelvinBot implement this to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run · view recording

MelvinBot avatar Nov 22 '26 07:11 MelvinBot

Proposal

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

When I create an expense from a non-default workspace and pick Create report in the Report field, the new report goes to my default workspace instead of the workspace I started the expense in.

What is the root cause of that problem?

The report picker decides where Create report goes with usePolicyForMovingExpenses. It passes targetExpensePolicyID as the preferred workspace:

https://github.com/Expensify/App/blob/5de42f69e315de80aee82d2fdf01b283034ea8b6/src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts#L196-L210

targetExpensePolicyID is only set when the expense belongs to another user or is per diem. For my own regular expense it is always undefined, even when I'm creating the expense inside a specific workspace chat (transactionPolicyID, the workspace of the chat I started in, is already computed on L196 but not used here).

With no expensePolicyID, usePolicyForMovingExpenses falls back to the active/default workspace:

https://github.com/Expensify/App/blob/5de42f69e315de80aee82d2fdf01b283034ea8b6/src/hooks/usePolicyForMovingExpenses.ts#L127-L143

So policyForMovingExpenses is the default workspace, and createReportForPolicy builds the optimistic report on that policy (https://github.com/Expensify/App/blob/5de42f69e315de80aee82d2fdf01b283034ea8b6/src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts#L261-L276). Then handleRegularReportSelection moves the draft expense onto that new report, so the expense also switches to the default workspace. The list already uses the chat's workspace when creating an expense (selectedPolicyID, https://github.com/Expensify/App/blob/5de42f69e315de80aee82d2fdf01b283034ea8b6/src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts#L311-L316), which is why the existing reports shown are from the right workspace but Create report isn't.

The comment there says "fall back to undefined to let the default workspace apply". That makes sense when moving an existing expense, but not when the expense is being created from a chosen workspace chat.

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

In useReportPickerActions, when we're creating an expense (action === CREATE) and its participant is a workspace chat, pass that workspace (transactionPolicyID) to usePolicyForMovingExpenses as the preferred policy. Keep the current behavior for editing/moving existing expenses (still default workspace) and for other users' and per diem expenses.

usePolicyForMovingExpenses already checks that the preferred policy is valid (member, can create expenses, group policy, not pending delete, time tracking for time requests). If it isn't valid, it still falls back to the default workspace, so we don't add a new edge case.

The empty-report confirmation and the restricted-action check already use policyForMovingExpenses, so they follow the right workspace automatically.

What specific scenarios should we test?

  • Two workspaces, A default. From workspace B's chat: + > Create expense > Manual > Report > Create report. The report and the expense stay in B (web, iOS, Mac).
  • The same from workspace A still creates in A.
  • Editing an existing expense's report and choosing Create report keeps the current behavior.
  • Per diem, time and managed-card expenses are unchanged.
  • If I start in a workspace where I can't create expenses, it falls back to the default workspace as it does today.
  • Add a unit test in tests/ui/components/IOURequestStepReportNewReportTest.tsx covering a non-default workspace chat.

What alternative solutions did you explore? (Optional)

Using reportOrDraftReport?.policyID (the same source as selectedPolicyID) as the preferred policy for the create flow, so the list and Create report always use the same workspace.

Contributor details

Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~01be5d412b545fdf18

akzkid avatar Nov 22 '26 07:11 akzkid

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 22 '26 07:11 melvin-bot[bot]

Proposal

What is the root cause of that problem?

In src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts (lines 196–210), targetExpensePolicyID determines which workspace Create report targets (both for creating the report in createReportForPolicy at lines 261–279 and for displaying the workspace subtitle on the Create report row via transactionPolicyID: targetExpensePolicyID at line 328 → IOURequestEditReportCommon.tsx:169).

Currently, line 201 only populates targetExpensePolicyID when ownerAccountID !== session?.accountID || isPerDiemTransaction, otherwise setting it to undefined:

  1. When a workspace has no open reports yet, selectedReport is undefined, so ownerAccountID is undefined and ownerAccountID !== session?.accountID accidentally evaluates to true, preserving transactionPolicyID.
  2. When the non-default workspace has open reports (as in the repro steps), selectedReport resolves to an open report owned by the current user (ownerAccountID === session?.accountID), so line 201 flips to false and discards the originating workspace (targetExpensePolicyID = undefined).
  3. Passing undefined to usePolicyForMovingExpenses (src/hooks/usePolicyForMovingExpenses.ts:135–142) skips the preferred validExpensePolicyID branch and falls back to activePolicy (the user's default workspace). Meanwhile, selectedPolicyID at line 315 explicitly preserves reportOrDraftReport?.policyID ?? transactionPolicyID when !isEditing && !isFromGlobalCreate, which is why the picker lists Workspace B's existing reports while Create report targets default Workspace A and moves the draft expense there.

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

In src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts:

  1. Preserve the originating workspace during non-global expense creation:
    • Extend the targetExpensePolicyID condition at line 201 to also apply when creating a non-global expense (isCreateReport && !isFromGlobalCreate), resolving selectedReport?.policyID ?? reportOrDraftReport?.policyID ?? transactionPolicyID (aligned with selectedPolicyID at line 315 so both the existing-report list and Create report always use the same originating workspace, including when reportIDFromRoute is a generated ID or a workspace chat/report).
    • Keep !isFromGlobalCreate in the guard so Global Create (+ sidebar button, where selectedPolicyID is intentionally undefined to list reports across all workspaces and allow default/workspace-picker resolution via shouldSelectPolicy) is unaffected.
    • Keep isEditing, per-diem, time, managed-card, and other-owner flows untouched.
    • Because targetExpensePolicyID feeds both usePolicyForMovingExpenses (line 208) and listProps.transactionPolicyID (line 328 → IOURequestEditReportCommon.tsx:169), both the Create report row subtitle, restriction check (createReport), empty-report confirmation, and createReportForPolicy automatically target the originating non-default workspace across both the anchored dropdown and full-page report picker.
  2. Add regression unit tests in tests/ui/components/IOURequestStepReportNewReportTest.tsx:
    • With Workspace A as default (activePolicyID) and Workspace B non-default (both containing open reports), open the Report picker while creating a manual expense in Workspace B's chat (isFromGlobalCreate: false) and assert that Create report displays and creates the new report on Workspace B (policyID: B) rather than Workspace A.
    • Verify Global Create (isFromGlobalCreate: true) and editing an existing expense (action: EDIT) preserve their existing fallback behavior.

What alternative solutions did you explore? (Optional)

  • Passing transactionPolicyID for all action === CREATE flows without checking !isFromGlobalCreate: Rejected because in Global Create (isFromGlobalCreate: true), selectedPolicyID is intentionally undefined so the picker spans all workspaces and Create report respects the default workspace / shouldSelectPolicy workspace selector flow.
  • Passing selectedPolicyID directly into usePolicyForMovingExpenses: Rejected because for editing another user's expense (isEditing === true and ownerAccountID !== session?.accountID), selectedPolicyID is undefined, whereas targetExpensePolicyID must still preserve selectedReport?.policyID ?? transactionPolicyID.

danlopes18-ctrl avatar Nov 22 '26 08:11 danlopes18-ctrl

Contributor details: Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0179cdc82689f205c7

Proposal

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

When initiating expense creation from a non-default workspace (Workspace B) with existing open reports and tapping on the Report field, selecting Create report creates the new report in the default workspace (Workspace A) instead of retaining the selected originating workspace (Workspace B).

What is the root cause of that problem?

In src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts (lines 196–210 & 315–328):

  1. The Report picker correctly filters existing reports to Workspace B because line 315 preserves the originating policy:
selectedPolicyID = !isEditing && !isFromGlobalCreate ? (reportOrDraftReport?.policyID ?? transactionPolicyID) : undefined;
  1. However, line 201 calculates targetExpensePolicyID:
const targetExpensePolicyID = ownerAccountID !== session?.accountID || isPerDiemTransaction ? (selectedReport?.policyID ?? transactionPolicyID) : undefined;

For a user's own manual expense in a non-default workspace with open reports, selectedReport resolves to the user's existing open report (ownerAccountID === session?.accountID), so ownerAccountID !== session?.accountID is false. Consequently, targetExpensePolicyID is set to undefined.

  1. targetExpensePolicyID is passed into usePolicyForMovingExpenses (line 208) and listProps.transactionPolicyID (line 328): When targetExpensePolicyID is undefined, usePolicyForMovingExpenses falls back to activePolicy (the user's saved default workspace, Workspace A).
  2. Therefore, the Create report action (and its subtitle) targets Workspace A instead of the active workspace (Workspace B) where expense creation was initiated.

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

In src/pages/iou/request/step/IOURequestStepReport/hooks/useReportPickerActions.ts:

Update targetExpensePolicyID (line 201) to preserve the originating policy during non-global expense creation (!isFromGlobalCreate && !isEditing / isCreateReport):

const originatingPolicyID = selectedReport?.policyID ?? reportOrDraftReport?.policyID ?? transactionPolicyID;
const targetExpensePolicyID =
    (!isFromGlobalCreate && !isEditing) || ownerAccountID !== session?.accountID || isPerDiemTransaction
        ? originatingPolicyID
        : undefined;

This guarantees that:

  • Non-global expense creation initiated from a specific workspace chat or report retains that workspace for Create report.
  • Global Create (isFromGlobalCreate === true, via + in global LHN) continues to pass undefined, allowing standard default workspace resolution (shouldSelectPolicy).
  • Other-owner expenses and per-diem transactions continue to work as expected.
  • Both usePolicyForMovingExpenses and listProps.transactionPolicyID receive the consistent originating policyID.

What alternative solutions did you explore? (Optional)

  • Unconditionally setting targetExpensePolicyID = originatingPolicyID: Suboptimal because global create (isFromGlobalCreate) intentionally needs undefined to allow workspace selection. Checking !isFromGlobalCreate ensures global create flows remain intact.

TassioSales avatar Nov 22 '26 20:11 TassioSales