Repository navigation
Derive the invite Approver row from the real approval workflows - #100327
Conversation
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 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.
|
|
🤖 Web test steps verification results: 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.
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. |
|
@codex review |
|
@MelvinBot review |
There was a problem hiding this comment.
💡 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)}); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
| ? convertApprovalWorkflowRulesToWorkflows(params) | ||
| : convertPolicyEmployeesToApprovalWorkflows(params); | ||
|
|
||
| const isAdvanceApproval = (approvalWorkflows.length > 1 || (approvalWorkflows.at(0)?.approvers ?? []).length > 1) && isControlPolicy(policy); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
🤖 Code review — the refactor is sound, but one issue is worth fixing before merge. The derivation can transiently read The new unit test doesn't cover the primary reported scenario. All three cases in Smaller items and verification notes
Duplicate Onyx subscriptions. Both call sites already subscribe to the keys the hook subscribes to again: Two other call sites still disagree by design. Nit: Verified locally, no issue: dropping the 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 |
|
🤖 Web regression hunt: 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. 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: 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.
Still open from my earlier review: the cold-load path, where the |
|
@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>
|
🤖 Addressed in a938794 — four of the items were valid, three I skipped.
The one that would have shipped a real bug: under What each fix looks likeRules fetch. The invite component fires the same read the Workflows page does when the beta is on ( Over-limit approver. Surfaces agreeing. The Cleanup. Dropped the unused Verification
The old first test asserted that a beta-off Control workspace with 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 The |
Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
|
Fixed and pushed in CI reported a formatting diff in:
Both are whitespace and import ordering only. No logic changed. The other originally-failing check, Local verification
|
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
| // 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]); |
| // 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)); |
There was a problem hiding this comment.
@MelvinBot Is this logic really needed? I don't see this in WorkflowsApprovalsTab.
There was a problem hiding this comment.
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.
|
🤖 Re-reviewed at 1. 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 3. The Workflows tab's Approvals toggle now writes a different Concrete case where it flips, and why it's probably fine but still needs QAControl workspace,
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 Checked and clean
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. |
|
No code fix is needed — all 34 real checks pass. The only genuine failure was The two checks still red both require a human, not a code change:
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
Whitespace and import ordering only — no logic changed. |
|
⏱️ 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. |
|
@MelvinBot pull main and fix conflict |
|
Merged The conflict: one line in const {translate, formatPhoneNumber} = useLocalize();
Verification
Not run locally: the full The |
|
No code fix is needed — all 34 real checks pass on
Everything else is green after the Why the earlier failures are goneThe failures from 2026-09-04 were resolved before this run:
The merge commit
view run · no recording available |
There was a problem hiding this comment.
💡 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); |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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—updateApprovalWorkflowwritesBASIConly whenhasMultipleWorkflowsis false, i.e. no employee has asubmitsToother than the effective default approver, over the full merged list.#L251has the same guard for remove.- The Approvals re-enable writes
BASIConly after disabling flattened every chain to the owner (Policy.ts#L981-L1000). - CSV import promotes to
ADVANCEDwhenever it sends asubmitsToon a Control policy (Member.ts#L1067). addMembersToWorkspaceonly writes a non-defaultsubmitsTowhen the Approver row was shown, which already requiresisAdvanceApproval— 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>
|
The Approver row now shows on DEW workspaces with "Hide People Table Columns" on.
Expected: No Approver row (as on main) Fix: const shouldShowApproverRow = isAdvanceApproval && !!policy?.areWorkflowsEnabled && !shouldHideDynamicExternalWorkflowPeople(policy); |
…eople Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
|
Fixed. The Approver row is now hidden when a Dynamic External Workflow has "Hide People Table Columns" on. This matches
const shouldShowApproverRow = isAdvanceApproval && !!policy?.areWorkflowsEnabled && !shouldHideDynamicExternalWorkflowPeople(policy);
Typecheck and the React Compiler check pass. The |
|
@MonilBhavsar ready for final review |
|
@MelvinBot will this PR fix #100728 as well? |
|
Mostly yes. This PR removes the One gap: the row appears only when the workspace has a custom workflow ( Details
|
|
@MelvinBot apply suggested changes |
Co-authored-by: Situ Chandra Shil <situchan@users.noreply.github.com>
|
I applied all three of
I didn't change any code, including the optional |
|
@situchan Melvin's/author checklist is empty too |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 MonilBhavsar has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/MonilBhavsar in version: 9.5.7-0 🚀
|
|
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 |
|
🚀 Deployed to production by https://github.com/mountiny in version: 9.5.7-3 🚀
Bundle Size Analysis (Sentry): |



















Explanation of Change
The Approver row on the workspace invite confirmation page was gated on the stored
policy.approvalModeflag:approvalMode === ADVANCEDwas 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:MULTIPLE_APPROVERSbeta on, creating a workflow writes only to theRULEcollection and never setsapprovalMode = ADVANCED, so the gate failed.approvalModeisADVANCEDandareWorkflowsEnabledis 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:
WorkflowsApprovalsTabmoved, unchanged, into a new shareduseApprovalWorkflowshook. It takes thepolicyand returnsapprovalWorkflows,filteredApprovalWorkflows,availableMembers,usedApproverEmails,isAdvanceApproval,rulesCollection, andpersonalDetails.WorkflowsApprovalsTabnow reads everything from the hook. Its behavior is unchanged.WorkspaceInviteMessageComponentshows the Approver row whenisAdvanceApproval && policy.areWorkflowsEnabled. It also reuses the hook'srulesCollectionfor the "+N more" fast-edit save instead of keeping its ownRULEsubscription.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)npm run typechecknpm run react-compiler-compliance-check check <changed files>tests/unit/useApprovalWorkflowsTest.tsx(4 cases covering both reported scenarios)tests/unit/WorkflowUtilsTest.tsNot run locally: ESLint (ran out of memory in the automated environment) and the full
npm testsuite. CI covers both.Fixed Issues
$ #99749
PROPOSAL: #99749 (comment)
Tests
Preconditions: Use an expensifail account.
Offline tests
// TODO: The human co-author must fill out the offline behavior they verified.
QA Steps
Preconditions: Use an expensifail account.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari