Skip to content

Derive the invite Approver row from the real approval workflows - #100327

Merged
MonilBhavsar merged 12 commits into
mainfrom
claude-approverRowDerivedFromWorkflows
Oct 9, 2026
Merged

MonilBhavsar merged 12 commits into
mainfrom
claude-approverRowDerivedFromWorkflows

Conversation

@MelvinBot

@MelvinBot MelvinBot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

The Approver row on the workspace invite confirmation page was gated on the stored policy.approvalMode flag:

const shouldShowApproverRow = isControl && policy?.approvalMode === CONST.POLICY.APPROVAL_MODE.ADVANCED && policy?.areWorkflowsEnabled;

approvalMode === ADVANCED was being used as a proxy for "this workspace has a custom approval workflow", but that flag is written optimistically by many code paths and drifts from the real workflow structure. It pointed the wrong way in both reported scenarios:

  • Row missing on a Control workspace that does have a custom workflow. With the MULTIPLE_APPROVERS beta on, creating a workflow writes only to the RULE collection and never sets approvalMode = ADVANCED, so the gate failed.
  • Row appearing on a workspace that has no custom workflow. After upgrading Collect → Control through the Workflows flow, approvalMode is ADVANCED and areWorkflowsEnabled is already true, so the gate passed even though no workflow was created.

This change stops trusting the stored flag. It derives whether a custom workflow exists the same way the Workflows tab already does:

  • The workflow derivation that lived inline in WorkflowsApprovalsTab moved, unchanged, into a new shared useApprovalWorkflows hook. It takes the policy and returns approvalWorkflows, filteredApprovalWorkflows, availableMembers, usedApproverEmails, isAdvanceApproval, rulesCollection, and personalDetails.
  • WorkflowsApprovalsTab now reads everything from the hook. Its behavior is unchanged.
  • WorkspaceInviteMessageComponent shows the Approver row when isAdvanceApproval && policy.areWorkflowsEnabled. It also reuses the hook's rulesCollection for the "+N more" fast-edit save instead of keeping its own RULE subscription.

Because both pages now use the same hook, they can no longer disagree about whether a workspace has a custom workflow.

AI Tests run locally (on 5bce7a5fc2)

Check Result
npm run typecheck ✅ passed
npm run react-compiler-compliance-check check <changed files> ✅ passed
Jest: tests/unit/useApprovalWorkflowsTest.tsx (4 cases covering both reported scenarios) ✅ passed
Jest: tests/unit/WorkflowUtilsTest.ts ✅ passed (127/127 across both suites)

Not run locally: ESLint (ran out of memory in the automated environment) and the full npm test suite. CI covers both.

Fixed Issues

$ #99749
PROPOSAL: #99749 (comment)

Tests

Preconditions: Use an expensifail account.

  1. Create a Control workspace (or upgrade to Control in Overview).
  2. Add a few members.
  3. Go to Workflows > Add approval workflow, and create a workflow with a submitter and approver.
  4. Go to Members > Invite member > select a member, and proceed to the confirmation page.
  5. Verify the Approver row appears.
  6. Create a Collect workspace.
  7. Go to Workflows > Add approval workflow > upgrade the workspace to Control, then go back without creating a workflow.
  8. Go to Members > Invite member > select a member, and proceed to the confirmation page.
  9. Verify the Approver row does not appear.
  • Verify that no errors appear in the JS console

Offline tests

// TODO: The human co-author must fill out the offline behavior they verified.

QA Steps

Preconditions: Use an expensifail account.

  1. Go to staging.new.expensify.com
  2. Create a Control workspace (or upgrade to Control in Overview).
  3. Add a few members.
  4. Go to Workflows > Add approval workflow, and create a workflow with a submitter and approver.
  5. Go to Members > Invite member > select a member, and proceed to the confirmation page.
  6. Verify the Approver row appears.
  7. Create a Collect workspace.
  8. Go to Workflows > Add approval workflow > upgrade the workspace to Control, then go back without creating a workflow.
  9. Go to Members > Invite member > select a member, and proceed to the confirmation page.
  10. Verify the Approver row does not appear.
  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

The invite confirmation page gated the Approver row on policy.approvalMode ===
ADVANCED, a flag written optimistically by several paths that drifts from the
real workflow structure. Reuse the Workflows tab derivation through a shared
useApprovalWorkflows hook so both read the same source of truth.

Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
@codecov

codecov Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/hooks/useApprovalWorkflows.ts 100.00% <100.00%> (ø)
...kspace/members/WorkspaceInviteMessageComponent.tsx 89.78% <100.00%> (+0.15%) ⬆️
...workspace/workflows/tabs/WorkflowsApprovalsTab.tsx 86.01% <100.00%> (-0.75%) ⬇️
... and 736 files with indirect coverage changes

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Android test steps verification results: ✅ pass

On standalone Android NewDot, the invite confirmation Approver row appeared only when a real custom approval workflow existed (Control workspace with a submitter/approver workflow) and stayed hidden on a workspace upgraded to Control through the workflow flow with no workflow created — even though its policy.approvalMode had been set to ADVANCED. Workflows > Approvals rendered correctly in both workspaces and no JS runtime errors were observed.

WS Collect Workflows page after upgrade, showing only the default Everyone to Mel workflow

Step Status
VERIFY 1 — Control workspace with a custom approval workflow (submitter melvinbottestuser+wsm1, approver melvinbottestuser+wsm2): Members > Invite member > select member > confirmation page shows the Approver rowWorkspace "WS Control" was upgraded to Control (Overview > Plan type = Control), 2 members invited, and a custom approval workflow created via Workflows > Add approval workflow. On the invite confirmation page for a new invitee, the accessibility snapshot listed an "Approver, Mel" button between the Role and Message rows, and a visibility assertion on that label passed.
WS Control invite 'Confirm details' page showing Members, Role and an Approver row set to Mel
✅
VERIFY 2 — Collect workspace upgraded to Control through Workflows > Add approval workflow, then backed out without creating a workflow: confirmation page does NOT show the Approver rowOn Collect workspace "WS Collect", Workflows > Add approval workflow routed straight to the "Unlock this feature / Advanced Approvals" upgrade page; after Upgrade ("You've successfully upgraded WS Collect to the Control plan!") the flow resumed at the submitter picker and the tester backed out without creating a workflow. On the subsequent invite confirmation page, the snapshot listed only Members, Role, Message and Privacy — no Approver node — and a find for "Approver" matched no element. JS logs confirm this workspace's policy had approvalMode: ADVANCED at that moment, so the row is correctly derived from workflows rather than the flag — this is exactly the drift case the PR targets.
WS Collect invite 'Confirm details' page showing only Members and Role rows, with no Approver row
✅
VERIFY 3 — Workflows > Approvals renders correctly in both workspaces (custom workflow listed in workspace 1, only the default in workspace 2)WS Control: Approvals renders the default workflow (Expenses from Everyone → Approver Mel) plus the custom workflow (Expenses from melvinbottestuser+wsm1 → Approver melvinbottestuser+wsm2), each with an Edit button, followed by "Add approval workflow". WS Collect (post-upgrade): Approvals renders only the default workflow (Everyone → Mel) plus "Add approval workflow". No error banners or blank sections in either.
WS Control Workflows page with default workflow and the custom wsm1 to wsm2 workflow listed
WS Collect Workflows page after upgrade, showing only the default Everyone to Mel workflow
✅
VERIFY 4 — No JS console/runtime errors during the flowsGrepping the JS log stream for [error], TypeError, ReferenceError, unhandled promise rejections, "Invariant Violation", "Cannot read" and "is not a function" returned no matches, and no native FATAL EXCEPTION / redbox was raised. Only pre-existing warn-level noise appeared: repeated [warn] [getStateFromPath.ts][DynamicRoute] None of the ... dynamic suffix candidate(s) passed entryScreens validation and [warn] ActivityIndicator has been shown for longer than expected — neither is specific to the invite/approvals screens.
✅

Setup deviation worth noting on VERIFY 2: after upgrading workspace 1 to Control, the account was on the Control plan, so the newly created workspace 2 was auto-provisioned as Control rather than Collect. It was downgraded to Collect via Overview > Plan type first, then the VERIFY 2 flow ran exactly as documented.


view run

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Web test steps verification results: ⚠️ partial

VERIFY 1–3 all pass on dev NewDot web: the invite confirmation Approver row now tracks the real approval workflows (shown only when a custom workflow exists), and both Workflows > Approvals lists render correctly. VERIFY 4 could not be executed — console capture is out of scope for the web driver, though no error UI, blank screens, or failed interactions were observed.

Collect WS Workflows page: only the default Expenses from Everyone workflow listed under Approvals

Step Status
VERIFY 1 — Control workspace with a real custom approval workflow shows the Approver row on the invite confirmation pageCreated a workspace, upgraded Overview > Plan type from Collect to Control, invited bob.melvintest@example.com and carol.melvintest@example.com as members, then Workflows > Add approval workflow with submitter bob → approver carol. Members > Invite member > dave.melvintest@example.com > Next produced a Confirm details page whose interactive tree contains "Members", "Role, Member" and "Approver, melvinbottestuser+…". A visibility assertion on that Approver button passed. Bonus data point: before the custom workflow existed, the same Control workspace's confirmation page had NO Approver row — Control plan alone does not surface it.
Control workspace with a custom bob to carol approval workflow: invite Confirm details page shows Members, Role and Approver rows
Same Control workspace before any custom workflow existed: Confirm details shows only Members, Role and Message - no Approver row
✅
VERIFY 2 — Collect workspace upgraded to Control through Workflows > Add approval workflow, then backed out without creating a workflow, does NOT show the Approver rowCreated "Collect WS" (it defaulted to Control because the account already had a Control subscription, so it was downgraded via Overview > Plan type > Collect > Downgrade workspace, confirmed "Plan type, Collect"). Then Workflows > Add approval workflow > Upgrade > "Got it, thanks", which lands on the "Expenses from" step; pressed Back without creating a workflow. Overview then reads "Plan type, Control", so the workspace is upgraded but has no custom workflow. Members > Invite member > erin.melvintest@example.com > Next produced Confirm details with only Members, Role, Message, Privacy, Invite. Assertions: a find for the text "Approver" matched no element, and a visibility check on the Approver label did not match.
Collect WS upgraded to Control via the workflow flow, no custom workflow: invite Confirm details shows Members and Role only, no Approver row
✅
VERIFY 3 — Workflows > Approvals renders correctly in both workspacesWorkspace 1 (Control, custom workflow): Approvals lists the default workflow ("Expenses from Everyone" → Approver melvinbottestuser+…) plus the custom workflow ("Expenses from bob.melvintest@example.com" → Approver carol.melvintest@example.com), each with an Edit button, then "Add approval workflow" — two Expenses from / Approver / Edit triplets in the tree. Workspace 2 ("Collect WS", upgraded, no custom workflow): Approvals lists only the default workflow plus "Add approval workflow" — one triplet. No layout breakage or error state in either.
Workspace 1 Workflows page: default workflow plus custom bob to carol workflow listed under Approvals
Collect WS Workflows page: only the default Expenses from Everyone workflow listed under Approvals
✅
VERIFY 4 — No JS console errors during the flowsNot verifiable with the available tooling — not an observed defect. Browser console/runtime log capture is out of scope for the web driver (the logs operation returns UNSUPPORTED_OPERATION on web). Indirect signal only: every step of both flows completed normally, with no error banners, red screens, blank routes, or stuck states across roughly 60 interactions.
❌

One environment note: new workspaces created after the first upgrade default to the Control plan on this account, so workspace 2 had to be explicitly downgraded to Collect before running the VERIFY 2 flow. Separately, a "Pre-built agents for you" promo and a "Stay ahead of the deadline" modal intercepted clicks and had to be dismissed — neither is related to this PR.


view run

@situchan

situchan commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@codex review

@situchan

situchan commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 507492caf2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

const {isBetaEnabled} = usePermissions();
const {login: currentUserLogin = ''} = useCurrentUserPersonalDetails();
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const [rulesCollection] = useOnyx(ONYXKEYS.COLLECTION.RULE, {selector: (rules: OnyxCollection<Rule>) => filterRulesForPolicy(rules, policyID)});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Load workflow rules before deriving beta workflows

When a MULTIPLE_APPROVERS user enters the invite flow directly with a cold Rule collection, this hook treats the empty collection as authoritative and falls back to employeeList, even though beta workflow creation writes the configuration only to Rule records. The Members flow only calls openWorkspaceMembersPage() (WorkspaceMembersPage.tsx), while those records are fetched by openPolicyWorkflowsPage() on the Workflows page, so visiting Members first can incorrectly hide the Approver row and submit the invite without the chosen submitsTo; fetch the policy's workflow rules here or defer the derived result until they are loaded.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid — fixed in a938794.

Confirmed the mechanism: openPolicyWorkflowsPage is called only from WorkspaceWorkflowsPage.tsx:70 and WorkspaceWorkflowsPageRevamp.tsx:76, and with an empty rules map buildApproverChainFromRules falls back to employeeList.submitsTo — which the beta path never writes. So Members-first really did read an unfetched collection as "no custom workflow".

Went with the fetch rather than deferring: the collection is never fetched at all on that path, so deferring would hide the row indefinitely, and blocking submit would break enabledWhenOffline on the form. The invite component now fires the same read when the beta is on (WorkspaceInviteMessageComponent.tsx:121-130), and the hook's doc block now states the requirement for any future caller.

Comment thread src/hooks/useApprovalWorkflows.ts Outdated
? convertApprovalWorkflowRulesToWorkflows(params)
: convertPolicyEmployeesToApprovalWorkflows(params);

const isAdvanceApproval = (approvalWorkflows.length > 1 || (approvalWorkflows.at(0)?.approvers ?? []).length > 1) && isControlPolicy(policy);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Treat a customized default workflow as advanced

When the only workflow customizes the default approver, or uses an approval limit with overLimitForwardsTo, it still has one workflow containing one unconditional approver, so this cardinality check returns false. These are explicitly recognized as custom workflows by hasCustomApprovalWorkflow() in PolicyUtils.ts, and previously their ADVANCED mode displayed the invite Approver row; this change therefore hides that row and prevents the inviter from selecting a submitsTo for new members in those configurations.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Half right — fixed the half that reproduces, in a938794.

overLimitForwardsTo — valid. calculateApprovers walks only forwardsTo, so an over-limit approver leaves the chain at length 1 and the cardinality check returned false. Meanwhile Workflow.ts:175 writes approvalMode = ADVANCED for exactly that config, so the old gate did show the row. The hook now also treats an approver with overLimitForwardsTo as advanced, with a regression test.

Changed default approver — not a regression. When only policy.approver moves off the owner, every member still submits to the new default approver, so Workflow.ts:174-176 computes hasMultipleWorkflows = false and hasForwardsToChain = false and writes BASIC. The old approvalMode === ADVANCED gate hid the row there too, so behavior is unchanged. hasCustomApprovalWorkflow() returning true for that case is a difference between that helper and the invite gate that predates this PR — it feeds only the getting-started checklist at useGettingStartedItems.ts:337.

Note the plain forwardsTo case you grouped with these was already handled: it extends the chain, so approvers.length > 1 catches it.

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Code review — the refactor is sound, but one issue is worth fixing before merge.

The derivation can transiently read false on cold load, which hides the row and silently drops the approver. Under the MULTIPLE_APPROVERS beta the result depends on the RULE collection, and useApprovalWorkflows.ts:46 gets undefined for it on the first render(s) before Onyx hydrates. With no rules, WorkflowUtils.ts:1380-1381 falls back to employeeList.submitsTo — and this PR's own premise is that the beta path never writes submitsTo, so the fallback yields only the default workflow and isAdvanceApproval is false. The row is hidden, then pops in once rules load. Worse, WorkspaceInviteMessageComponent.tsx:206 passes shouldShowApproverRow ? validatedApprover : undefined, so tapping Invite inside that window sends no approver at all. The old policy.approvalMode check couldn't do this — that field arrives with the policy the page already needs. Suggested fix: return the rules status (or an isLoading) from the hook and hold the row / block submit until loaded, the way the page already does with isLoadingOnyxValue at line 132.

The new unit test doesn't cover the primary reported scenario. All three cases in useApprovalWorkflowsTest.tsx run with ONYXKEYS.BETAS unset, so isBetaEnabled(MULTIPLE_APPROVERS) is false and only convertPolicyEmployeesToApprovalWorkflows is exercised. Reported bug #1 — row missing on a Control workspace that does have a custom workflow — is specific to the rules path. Please add a case that sets BETAS to include MULTIPLE_APPROVERS, seeds ONYXKEYS.COLLECTION.RULE with a custom approval-workflow rule, and asserts isAdvanceApproval === true while approvalMode is BASIC.

Smaller items and verification notes

firstApprover is dead code. Neither call site passes it. It clearly exists for WorkspaceWorkflowsApprovalsEditPage.tsx:79-90, which still hand-rolls the identical beta branch. Converting that page here would be the better call — it's the third copy that can disagree, so leaving it out undercuts the "the two can no longer disagree" goal. Otherwise drop the param.

Duplicate Onyx subscriptions. Both call sites already subscribe to the keys the hook subscribes to again: WorkflowsApprovalsTab.tsx:121 and :137-138, and WorkspaceInviteMessageComponent.tsx:94. The tab needs rulesCollection and personalDetails elsewhere, so consider having the hook accept or return them so one subscription serves both. The tab's policyRulesSelector useCallback is also now a duplicate of the hook's inline selector — and since this PR is already removing the neighbouring useMemo per the React Compiler rule in CLAUDE.md, that useCallback is a natural thing to drop in the same pass.

Two other call sites still disagree by design. WorkspaceMembersPage.tsx:155 and WorkspaceMemberDetailsPage.tsx:160 call convertPolicyEmployeesToApprovalWorkflows unconditionally, ignoring the beta. Pre-existing, not a blocker — but the hook currently unifies 2 of 5 call sites, so a follow-up issue is worth filing.

Nit: useApprovalWorkflows.ts:7-8 imports twice from the same module; combine as import type ApprovalWorkflow, {Member} from '@src/types/onyx/ApprovalWorkflow';.

Verified locally, no issue: dropping the useMemo is correct per the React Compiler rule in CLAUDE.md, and npm run react-compiler-compliance-check check passes on all three changed files under both compilers — so the inline useOnyx selector at line 46 is compiler-memoized and stable, and there's no re-subscription churn. I also confirmed disabling approvals resets submitsTo to the owner and deletes the policy's rules (Policy.ts:962-981, :1097-1105), so an approvals-off workspace can't derive isAdvanceApproval === true — that path is safe.

I could not run the Jest suite in this sandbox, so I'm taking the reported 3/3 and 197/197 results at face value; CI covers them.

Separately, the Tests, Offline tests, and QA Steps sections are still // TODO placeholders and the author checklist is unchecked, so this can't be merged as-is regardless of the code.


view run

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Web regression hunt: ⚠️ one new regression found

Regression — the invite page and the Workflows tab now disagree in the non-beta path, which is the exact drift this PR set out to remove. WorkflowsApprovalsTab.tsx:217-224 still filters the displayed list down to the default workflow whenever the MULTIPLE_APPROVERS beta is off and approvalMode isn't ADVANCED/DYNAMICEXTERNAL. isAdvanceApproval is computed from the unfiltered list at useApprovalWorkflows.ts:60, and the invite page applies no equivalent filter. So on a beta-off Control workspace with approvalMode: BASIC and drifted submitsTo values, Workflows > Approvals shows only the default workflow while Members > Invite member > Next shows an Approver row — and picking an approver there writes a workflow the tab won't display. Before this PR both surfaces were gated on approvalMode === ADVANCED, so they agreed. Fix: derive isAdvanceApproval from the filtered list (move that filteredApprovalWorkflows expression into the hook and return it), so both consumers read the same set. Scenario 1 from the issue is beta-on, where the filter is a no-op, so this doesn't weaken the fix.

Not a regression — the multi-level default chain. Testing showed the Approver row appears on a Control workspace whose default workflow has two approvers and no custom workflow. The old gate did the same: Workflow.ts:174-180 sets approvalMode = ADVANCED when hasForwardsToChain is true. Behavior is unchanged; no action needed.

Everything else held up. Create / edit / delete of a custom workflow, the Approvals off→on round-trip, the invite row tracking a workflow deletion, and the Collect-workspace negative case all behaved correctly on the refactored tab.

No Approver row on Collect-plan workspace invite confirmation

Step Status
VERIFY 1 — Workflows > Approvals: create, edit and delete a custom workflow on a Control workspaceCreated a Control workspace with 3 members plus owner. Added a custom workflow (member1test → member2test) alongside the default, edited it to change the approver to member3test — the list updated correctly and the default workflow was untouched. Deleted the custom workflow via the confirmation dialog; the list fell back cleanly to the default workflow only, with no error or blank state.
Custom workflow added alongside default
Custom workflow approver changed to member3test
Clean fallback to default-only workflow after delete
✅
VERIFY 2 — Approvals toggle round-trip with a custom workflow presentToggled Approvals OFF (confirmed through the "Disabling approvals will erase all existing approval workflows" dialog) — the section collapsed cleanly with no error. Toggled it back ON — the list rendered with only the default workflow, which is expected since disabling erases custom workflows, and no stale or duplicate rows appeared.
Approvals section collapsed after toggling off
Approvals re-enabled, single default workflow, no duplicates
✅
VERIFY 3 — Invite Approver row tracks workflow deletionWith a custom workflow present, Members > Invite member > Next showed the Approver row. After deleting that workflow in Workflows > Approvals, the same path showed no Approver row.
Approver row present with custom workflow
Approver row absent after custom workflow deleted
✅
VERIFY 4 — Multi-level default chain with no custom workflowEdited only the default workflow to add a second approver (first: owner, second: member1test), leaving no separate custom workflow. Members > Invite member > Next did show the Approver row. Confirmed against the code afterwards: the pre-PR gate behaved identically here, because a forwardsTo chain on the default approver forces approvalMode = ADVANCED. Unchanged behavior.
Default workflow with First and Second approver, no custom workflow
Approver row present despite no separate custom workflow
✅
VERIFY 5 — Collect workspace never upgraded shows no Approver rowCreated a second workspace and downgraded its plan type to Collect. Members > Invite member > Next showed no Approver row, as expected for a non-Control workspace.
No Approver row on Collect-plan workspace invite confirmation
✅
VERIFY 6 — Approver row on a hard reload of the invite confirmation pageNot executed. A hard browser reload drops client auth in this session type and can hit a magic-code wall the tester cannot clear, so the web driver forbids it. In-app navigation reuses already-hydrated Onyx state and would not reproduce a genuine first-mount load, so this could not be substituted. The cold-load concern raised in the earlier review therefore remains unverified — worth a manual check.
❌

Still open from my earlier review: the cold-load path, where the RULE collection is undefined on first render and the derivation falls back to employeeList, which the beta path never writes. VERIFY 6 was the test for it and could not run.


view run

@situchan

situchan commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot address #100327 (comment), #100327 (comment), #100327 (comment), #100327 (comment) only if they're valid and not edge cases.

- Derive `isAdvanceApproval` from the filtered workflow list, so the invite
  page and the Workflows tab can no longer disagree about whether a workspace
  has a custom workflow.
- Treat an over-limit "Approves to" approver as a custom workflow. It hangs
  off `overLimitForwardsTo` rather than extending the approver chain, so
  counting workflows and approvers alone missed it and hid the row for a
  config the old `approvalMode` gate showed.
- Fetch the workspace's approval-workflow rules from the invite flow when the
  MULTIPLE_APPROVERS beta is on. Only the Workflows page fetched them, so
  reaching Members first derived the row from a collection that was never
  loaded and invited without the chosen approver.
- Drop the unused `firstApprover` parameter and the duplicate RULE and
  PERSONAL_DETAILS_LIST subscriptions in the Workflows tab.
- Cover the beta/rules path and the over-limit approver in the unit tests.

Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Addressed in a938794 — four of the items were valid, three I skipped.

Item Verdict What changed
Cold RULE collection under the beta (also my review item 1) Valid Invite flow now fetches the workflow rules when the beta is on
Over-limit "Approves to" approver Valid overLimitForwardsTo now counts as a custom workflow
Invite page vs Workflows tab disagree Valid isAdvanceApproval derived from the filtered list both surfaces share
Tests missed the beta/rules path Valid Test suite is now 6 cases, covering the real reported scenario
Changed default approver (same codex comment) Not a regression The old gate hid the row there too — see the thread
Duplicate Onyx subscriptions Valid, low Folded in while touching the tab
Two-line type import nit Skipped Matches the surrounding files; not worth the churn

The one that would have shipped a real bug: under MULTIPLE_APPROVERS, workflows live only in the RULE collection, and that collection is fetched only by openPolicyWorkflowsPage, called from the Workflows page alone. Coming in through Members meant deriving the row from a collection that was never loaded, so the row stayed hidden and the invite went out without the chosen approver. Codex caught the missing fetch; my earlier review had only spotted the narrower first-render race.

What each fix looks like

Rules fetch. The invite component fires the same read the Workflows page does when the beta is on (WorkspaceInviteMessageComponent.tsx:121-130). I fetched rather than deferred: the collection is never fetched at all on that path, so deferring would hide the row indefinitely, and gating the submit button would break enabledWhenOffline on the form. The hook's doc block now states the requirement for future callers.

Over-limit approver. calculateApprovers walks only forwardsTo, so an over-limit approver leaves the chain at length 1 — while Workflow.ts:175 writes approvalMode = ADVANCED for that same config. The old gate showed the row; the cardinality check hid it. Now useApprovalWorkflows.ts:88-92 treats it as advanced.

Surfaces agreeing. The filteredApprovalWorkflows expression moved out of the tab and into useApprovalWorkflows.ts:78-86; isAdvanceApproval is computed from it and the tab consumes it. Both scenarios from the linked issue still behave correctly: beta-on makes the filter a no-op, and a freshly upgraded workspace has only the default workflow either way.

Cleanup. Dropped the unused firstApprover parameter, plus the tab's duplicate RULE and PERSONAL_DETAILS_LIST subscriptions and its policyRulesSelector useCallback — the hook returns those now.

Verification
Check Result
npm run typecheck ✅ passed
ESLint on the four changed files ✅ passed
cspell on the four changed files ✅ no issues
react-compiler-compliance-check check on all three source files ✅ passed, both compilers
tests/unit/useApprovalWorkflowsTest.tsx ✅ 6/6 (was 3)
WorkflowUtilsTest, WorkflowTest, ApprovalWorkflowSectionTest ✅ 137/137
WorkspaceInviteMessageApproverPageTest, PolicyMemberTest ✅ 54/54

The old first test asserted that a beta-off Control workspace with approvalMode: BASIC and drifted submitsTo reports an advanced approval. That is precisely the disagreement being fixed, so it was replaced by the real reported scenario — beta on, workflow in the RULE collection, approvalMode stale at BASIC — plus a case asserting the beta-off drift is now ignored, matching what the Workflows tab displays.

Browser verification did not run. The prestarted web session was dead before the first command — a fresh unauthenticated browser process had replaced the signed-in one, so agent-device snapshot returned 0 nodes and screenshots came back blank. I confirmed that myself after the tester reported it. The three flows worth a manual look: the Members-first invite under the beta, the over-limit approver on a default-only workflow, and a beta-off Control workspace with approvalMode: BASIC.

The Tests, Offline tests, and QA Steps sections are still // TODO placeholders, so this still needs a human pass before it can merge.


view run

Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
@MelvinBot

MelvinBot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed and pushed in 37b65d4 — the Oxfmt check failure was a missing npm run fmt on the two files this PR added.

CI reported a formatting diff in:

Both are whitespace and import ordering only. No logic changed. Oxfmt check now passes, along with ESLint, typecheck, all 8 test jobs, Storybook, spellcheck, and React Compiler.

The other originally-failing check, checklist, also passes now. Check independent approval still fails, which is expected on a PR that hasn't been reviewed yet.

Local verification
Check Result
npm run fmt (oxfmt 0.55.0, matches the pin) ✅ stable / idempotent
npm run lint -- <changed files> ✅ passed
npm run typecheck ✅ passed
Jest tests/unit/useApprovalWorkflowsTest.tsx ✅ 6/6 passed
npm run react-compiler-compliance-check check ✅ passed

⚠️ The browser walk-through is still outstanding. I tried to close the gap your PR description flags, but the web session went to a blank page (0 DOM nodes) before the drive started — the dev server compiled cleanly and returned HTTP 200, so this was a session-side failure, not a problem with your code. None of the three test steps were exercised. The two reported flows still need a manual pass, or a re-run once the session is healthy.


view run · view recording

@situchan

situchan commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 37b65d4ddd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +121 to +130
// Under the `MULTIPLE_APPROVERS` beta the approval workflows live in the `RULE` collection, which is only
// fetched by the Workflows page. Reaching the invite flow through Members would otherwise derive the Approver
// row from a collection that was never loaded, hiding the row and inviting without the chosen approver.
const isMultipleApproversBetaEnabled = isBetaEnabled(CONST.BETAS.MULTIPLE_APPROVERS);
useEffect(() => {
if (!isMultipleApproversBetaEnabled || !policyID) {
return;
}
openPolicyWorkflowsPage(policyID);
}, [isMultipleApproversBetaEnabled, policyID]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot this is edge case. remove it.

Comment thread src/hooks/useApprovalWorkflows.ts Outdated
Comment on lines +89 to +91
// An "Approves to" user set above an approval limit is a custom workflow too, but it hangs off
// `overLimitForwardsTo` instead of extending the approver chain, so counting approvers alone misses it.
const hasOverLimitApprover = filteredApprovalWorkflows.some((workflow) => workflow.approvers.some((approver) => !!approver.overLimitForwardsTo));

@situchan situchan Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MelvinBot Is this logic really needed? I don't see this in WorkflowsApprovalsTab.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes — without it the invite page regresses against main, and the tab genuinely never needed it.

overLimitForwardsTo is the only custom-workflow shape that doesn't add a workflow or extend the approver chain, so the cardinality check alone returns false for it. But Workflow.ts:176-180 folds overLimitForwardsTo into hasForwardsToChain and writes approvalMode = ADVANCED for exactly that config (same at :245-246). So main's approvalMode === ADVANCED gate does show the Approver row there; dropping line 91 would hide it.

Why the tab never needed it: isAdvanceApproval is used in exactly one place there — WorkflowsApprovalsTab.tsx:132, feeding the mode written when the approvals toggle is switched back on at :326. Turning approvals off already clears overLimitForwardsTo (Policy.ts:973-975), so by the time that value is read the field is empty and the extra check can't fire. The tab was correct for its narrower use; the invite page gates a visible row, so it needs the full definition.

Sharing the hook doesn't change the tab's behaviour in any reachable state for the same reason. And if the field somehow survives with approvalMode = OPTIONAL, the tab now writes ADVANCED — which is what the workflow editor writes for that config anyway, so it's the more consistent value, not a regression.

Reachability and coverage

Not a phantom state — it has dedicated UI: WorkspaceWorkflowsApprovalsApprovalLimitPage.tsx and WorkspaceWorkflowsApprovalsOverLimitApproverPage.tsx. Set an approval limit and an over-limit approver on the default workflow's single approver and you land in it.

Covered by useApprovalWorkflowsTest.tsx:151.

Plain forwardsTo needs no special case — it extends the chain, so approvers.length > 1 already catches it.

Happy to drop it if you'd rather keep the hook a literal copy of the tab's old expression and accept that the row stops appearing for approval-limit workspaces — just say the word and I'll remove line 91 and its test.


view run

@MelvinBot

Copy link
Copy Markdown
Contributor Author

🤖 Re-reviewed at 37b65d4. My four earlier points are all addressed. Three new regression risks came in with the fix, one of which I'd block on.

1. openPolicyWorkflowsPage now fires on mount of four unrelated screens, with no gating. WorkspaceInviteMessageComponent.tsx:125-130 fires the read whenever the beta is on, without checking isControlPolicy(policy) or areWorkflowsEnabled — but isAdvanceApproval can only ever be true when both hold, so on Collect, Submit and workflows-off workspaces the request can't change the outcome. And this component isn't only the Members invite page: it also backs Expensify Card → Issue new card and Company cards → Assign card. Both card flows now hit OpenPolicyWorkflowsPage too. Each call also flips policy.isLoading true→false (Policy.ts:3834-3843), re-rendering everything bound to the policy, and it re-fires on every remount — including navigating to the Approver sub-page and back. Please gate the effect on isControlPolicy(policy) && policy?.areWorkflowsEnabled.

2. The approver can still be silently dropped while that read is in flight. The effect doesn't block anything, so until the rules land shouldShowApproverRow is false and line 219 sends undefined instead of validatedApprover. On a cold invite the window is a full round trip, and a user who taps Invite inside it invites with no approver. The hook's own doc comment flags this hazard; nothing acts on it. The page already has a loading gate at line 145 — fold the rules result into it.

3. The Workflows tab's Approvals toggle now writes a different approvalMode, which the PR description doesn't mention. isAdvanceApproval moved from the unfiltered approvalWorkflows to filteredApprovalWorkflows, plus a new hasOverLimitApprover term, and that value feeds updateApprovalMode → the toggle at line 326.

Concrete case where it flips, and why it's probably fine but still needs QA

Control workspace, policy.approver !== policy.owner, approvals currently off. Disabling approvals rewrote every submitsTo to owner (Policy.ts:962-981), but defaultApprover resolves to policy.approver, so no group is marked default and WorkflowUtils.ts:284-292 unshifts a synthetic default — approvalWorkflows.length === 2. Old code: isAdvanceApproval === true → re-enabling Approvals wrote ADVANCED. New code: the filter keeps only the default → length 1 → writes BASIC.

BASIC looks like the more correct value (the old ADVANCED was an artifact of the synthetic default), so I'd call this a latent fix rather than a break. But it's outside the linked issue's scope, no test asserts what the toggle writes — every new test checks isAdvanceApproval in isolation — and the QA steps don't cover the Workflows tab toggle. The hasOverLimitApprover term widens it the other way: a Control workspace whose only custom routing is overLimitForwardsTo now writes ADVANCED where it wrote BASIC. Both directions deserve a QA line.

Coverage gap: neither card flow is covered by a test or by the QA steps, and both now run the new derivation and the new fetch. The Tests, Offline tests and QA Steps sections are still // TODO.

Checked and clean
  • hasOverLimitApprover works on both paths — overLimitForwardsTo is populated by calculateApprovers and by buildApproverChainFromRules, so it isn't dead in the beta branch.
  • Returning rulesCollection and personalDetails from the hook removes the duplicate subscriptions cleanly, and the hook's selector is byte-identical to the tab's old policyRulesSelector.
  • Dropping usePermissions from the tab is safe — its only isBetaEnabled use was the filteredApprovalWorkflows block that moved into the hook.
  • usePermissions reads BetasContext, provided app-wide from App.tsx:103, so no missing-provider risk in the card flows. The test file correctly wraps in OnyxListItemProvider.
  • The policy.isLoading flip does not trigger a full-screen loader: AccessOrNotFoundWrapper.tsx:199 additionally requires isPolicyEmpty.
  • npm run react-compiler-compliance-check check passes on all three changed files under both compilers.

I could not verify any of this in a browser this run — the web test environment failed to come up, so everything above is from static analysis. Jest is also blocked in this sandbox, so I'm taking the reported test results at face value.


view run

@MelvinBot

Copy link
Copy Markdown
Contributor Author

No code fix is needed — all 34 real checks pass. The only genuine failure was Oxfmt check, which I already fixed in 37b65d4 (currently the PR head).

The two checks still red both require a human, not a code change:

Check Why it's red
checklist (PR Reviewer Checklist) The job log ends with No PR Reviewer Checklist was found — a reviewer needs to post the checklist comment
Check independent approval Needs an independent approving review

Everything else is green: ESLint, typecheck, all 8 test jobs, Oxfmt, Storybook, spellcheck, React Compiler, Bun tests, knip, unused styles, and all native builds. Nothing is pending.

What the earlier Oxfmt fix changed

npm run fmt reformatted the two files this PR adds:

Whitespace and import ordering only — no logic changed.


⚠️ Still outstanding: the browser walk-through of the three test steps in the PR description has never run. The web session failed on my previous attempt, and browser control was unavailable on this run, so I could not verify the two reported Approver-row flows. That still needs a manual pass before merge.


view run

@MelvinBot

Copy link
Copy Markdown
Contributor Author

⏱️ Ran out of time before I could finish. This usually means the task was too complex or I got stuck exploring. Please try again with a more specific request or post in #melvinbot-ai.

Run details

@situchan

situchan commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot pull main and fix conflict

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Merged main into claude-approverRowDerivedFromWorkflows and resolved the conflict — the PR is mergeable again (9fdd377).

The conflict: one line in src/pages/workspace/workflows/tabs/WorkflowsApprovalsTab.tsx:105. This PR dropped localeCompare from the useLocalize() destructure (it moved into the new useApprovalWorkflows hook), while main added formatPhoneNumber there for the new phone-number-aware workflow search. Resolved by keeping both intents:

const {translate, formatPhoneNumber} = useLocalize();

main's other changes to that file (the shouldHideDynamicExternalWorkflowPeople gate around the workflows list and the pushSearchableName search helper) merged cleanly and are untouched.

Verification
Check Result
npm run typecheck ✅ passed (all 5 projects)
npm run lint on the 4 changed files ✅ passed
npm run spell-changed ✅ 0 issues
npm run react-compiler-compliance-check check <changed files> ✅ passed
Jest: useApprovalWorkflowsTest, WorkflowUtilsTest, ApprovalWorkflowSectionTest ✅ 113/113 passed
Jest: tests/ui/WorkspaceInviteMessageApproverPageTest ✅ 5/5 passed

localeCompare and formatPhoneNumber are both confirmed used/unused correctly in the merged file — localeCompare has no remaining references there (the hook owns it), and formatPhoneNumber is used by main's search helper.

Not run locally: the full npm test suite, the Storybook smoke test (no stories or shared components changed), and oxfmt --check (blocked in this environment — the one edited line matches the surrounding single-line style). CI covers all three.

The Tests / Offline tests / QA Steps sections are still the human co-author's TODO, and per the author checklist the manual flows should be re-run now that main was merged.

@MelvinBot

MelvinBot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor Author

No code fix is needed — all 34 real checks pass on 9fdd377. The single red check needs a human, not a commit.

Check Status Why
Check independent approval ❌ fail The Verify peer review step failed because the PR has zero approving reviews — every review on it so far is COMMENTED. It goes green once an independent reviewer approves.

Everything else is green after the main merge: all 8 Jest jobs, ESLint, typecheck, Oxfmt, spellcheck, React Compiler, Bun tests, Storybook, knip, unused styles, baseline-perf-tests / branch-perf-tests, and both native builds. Nothing is pending or failing.

Why the earlier failures are gone

The failures from 2026-09-04 were resolved before this run:

  • Oxfmt check — fixed in 37b65d4 (formatting only).
  • checklist (PR Reviewer Checklist) — now reports skipping rather than fail.

The merge commit 9fdd377 re-ran the full suite from scratch and the Jest, perf, and build jobs all completed successfully.


⚠️ Still outstanding, unrelated to CI: the Tests, Offline tests, and QA Steps sections of the PR body are still // TODO, and the browser walk-through of the two reported Approver-row flows has never been completed. Both need a manual pass before this merges.


view run · no recording available

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5bce7a5fc2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

? convertApprovalWorkflowRulesToWorkflows(params)
: convertPolicyEmployeesToApprovalWorkflows(params);

const isAdvanceApproval = (approvalWorkflows.length > 1 || (approvalWorkflows?.at(0)?.approvers ?? []).length > 1) && isControlPolicy(policy);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Derive advanced state from the active workflows

For a non-beta Control workspace whose employeeList still contains a non-default submitsTo while approvalMode is BASIC, this counts the hidden legacy workflow and exposes the invite Approver picker. The same hook filters that workflow out at lines 74–80, and getManagerAccountEmail() deliberately ignores employeeList.submitsTo for BASIC policies (src/libs/PolicyUtils/index.ts:1907–1919), so the selected approver is sent with the invite but the member's reports will still route to the default approver. Compute this flag from filteredApprovalWorkflows (or otherwise require the active mode) so the invite surface agrees with effective routing.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consequence is real but the premise state isn't reachable, so I don't think this needs a change.

The getManagerAccountEmail citation is accurate — PolicyUtils/index.ts#L1907-L1910 does return defaultApprover for BASIC/OPTIONAL and ignore submitsTo. But "employeeList still contains a non-default submitsTo while approvalMode is BASIC" is asserted without a path, and every writer that sets BASIC rules it out at the moment it writes:

  • Workflow.ts#L183 / #L189 — updateApprovalWorkflow writes BASIC only when hasMultipleWorkflows is false, i.e. no employee has a submitsTo other than the effective default approver, over the full merged list. #L251 has the same guard for remove.
  • The Approvals re-enable writes BASIC only after disabling flattened every chain to the owner (Policy.ts#L981-L1000).
  • CSV import promotes to ADVANCED whenever it sends a submitsTo on a Control policy (Member.ts#L1067).
  • addMembersToWorkspace only writes a non-default submitsTo when the Approver row was shown, which already requires isAdvanceApproval — circular.

Toggling Workflows off is also rejected by the backend when a custom workflow exists, which closes the other route into a non-ADVANCED mode with chains intact.

The suggested fix isn't clearly safer either: routing goes through getApprovalWorkflow, which defaults a missing approvalMode to ADVANCED (PolicyUtils/index.ts#L1680), while the filter tests the raw field for === ADVANCED. For a policy with approvalMode undefined and real chains, computing the flag from filteredApprovalWorkflows would hide a row that does match effective routing — and since the Workflows tab shares isAdvanceApproval, it would also undo the revert that keeps the tab identical to main.

Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
@MelvinBot
MelvinBot requested a review from a team as a code owner October 6, 2026 16:46
@melvin-bot
melvin-bot Bot requested review from situchan and removed request for a team October 6, 2026 16:46
@melvin-bot

melvin-bot Bot commented Oct 6, 2026

Copy link
Copy Markdown

@situchan Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@situchan

situchan commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot

The Approver row now shows on DEW workspaces with "Hide People Table Columns" on.

const shouldShowApproverRow = isAdvanceApproval && !!policy?.areWorkflowsEnabled;

isAdvanceApproval ignores dynamicExternalWorkflowHidePeople, so the row shows where #98491 hides workflows (and #100728 says to keep it hidden).

  1. Control workspace, Dynamic External Workflow with "Hide People Table Columns" on, members with 2+ different approvers
  2. Members > Invite > pick a user > continue

Expected: No Approver row (as on main)
Actual: Approver row shows and the chosen approver is sent with the invite

Fix:

const shouldShowApproverRow = isAdvanceApproval && !!policy?.areWorkflowsEnabled && !shouldHideDynamicExternalWorkflowPeople(policy);

…eople

Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

Fixed. The Approver row is now hidden when a Dynamic External Workflow has "Hide People Table Columns" on. This matches main and Approver row is hidden on the workspace invite confirmation page for Dynamic External Workflow policies.

WorkspaceInviteMessageComponent.tsx:133 now uses your suggested condition:

const shouldShowApproverRow = isAdvanceApproval && !!policy?.areWorkflowsEnabled && !shouldHideDynamicExternalWorkflowPeople(policy);

sendInvitation only sends the approver when this flag is true, so the hidden row also stops the approver from being sent.

Typecheck and the React Compiler check pass. The WorkspaceInviteMessageApproverPageTest, WorkspaceInviteMessageFastEditSaveTest, and useApprovalWorkflowsTest suites pass (12 tests). I didn't test it in the browser, because the test account can't set up a Dynamic External Workflow.

@situchan

situchan commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@MonilBhavsar ready for final review

@situchan

situchan commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot will this PR fix #100728 as well?

@MelvinBot

Copy link
Copy Markdown
Contributor Author

Mostly yes. This PR removes the approvalMode === ADVANCED check, so Dynamic External Workflow workspaces no longer fall through. It also adds the shouldHideDynamicExternalWorkflowPeople guard that Approver row is hidden on the workspace invite confirmation page for Dynamic External Workflow policies asks for (WorkspaceInviteMessageComponent.tsx:132-133).

One gap: the row appears only when the workspace has a custom workflow (useApprovalWorkflows.ts:76). A dynamic external workspace where every member submits to the default approver, with no forwarding, still hides the row. If #100728 needs the row on every such workspace, add || hasDynamicExternalWorkflow(policy) to the gate.

Details

Comment thread src/hooks/useApprovalWorkflows.ts Resolved
Comment thread tests/unit/useApprovalWorkflowsTest.tsx Resolved
@situchan

situchan commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

@MelvinBot apply suggested changes

Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
@MelvinBot

Copy link
Copy Markdown
Contributor Author

I applied all three of MonilBhavsar's suggestions in 5c8aa37. The changes only touch comments:

I didn't change any code, including the optional hasDynamicExternalWorkflow change from my earlier comment. I couldn't run prettier or lint locally, so CI will check them.

@MonilBhavsar

Copy link
Copy Markdown
Contributor

@situchan Melvin's/author checklist is empty too

@situchan

situchan commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

@situchan Melvin's/author checklist is empty too

I think it's fine as per #98353, #98642

Discussion: https://expensify.slack.com/archives/C02NK2DQWUX/p1786550513486419?thread_ts=1786111493.247829&cid=C02NK2DQWUX

@MonilBhavsar MonilBhavsar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@MonilBhavsar
MonilBhavsar merged commit 52c3170 into main Oct 9, 2026
45 of 46 checks passed
@MonilBhavsar
MonilBhavsar deleted the claude-approverRowDerivedFromWorkflows branch October 9, 2026 16:08
@OSBotify

OSBotify commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🚧 MonilBhavsar has triggered a test Expensify/App build. You can view the workflow run here.

@OSBotify OSBotify mentioned this pull request Oct 9, 2026
74 tasks done
@OSBotify

OSBotify commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 9.5.7-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor Author

No help site update needed. This bug fix makes the Approver row on the invite confirmation page appear only when the workspace has a custom approval workflow, and no article under docs/articles describes that row or when it shows.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/mountiny in version: 9.5.7-3 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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

Labels

Melvin-Test-Android Melvin-Test-Web Triggers Melvin to run the testing steps of the PR on web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants