Skip to content

fix: hide Rules when duplicating a workspace that has Rules turned off - #105852

Merged
deetergp merged 4 commits into
Expensify:mainfrom
vulinh1704:vulinh1704/104231-rules-duplicate
Nov 10, 2026
Merged

deetergp merged 4 commits into
Expensify:mainfrom
vulinh1704:vulinh1704/104231-rules-duplicate

Conversation

@vulinh1704

@vulinh1704 vulinh1704 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Duplicating a Control workspace with Rules turned off showed Rules in two places:

  1. "Select features to copy" listed Rules, already selected. The row only required workspace-level rule values, which a Control workspace can have while Rules is off. It now also requires arePolicyRulesEnabled(policy, policyCategories), the same check the workspace menu uses.
  2. Rules flashed in the new workspace's menu, even when Rules wasn't selected. When categories are copied, the DuplicatePolicy response merges a stray {areRulesEnabled: true} into the new policy after the full policy merge. successData is applied after the response, so it now sets areRulesEnabled to whether Rules was copied (parts.expenses), which change 1 allows only when the source has Rules on.

The backend still sends the stray true, so on another device, or after reconnecting if the duplicate was made offline, Rules can show until the policy reloads (same as on main).

Unit tests: WorkspaceDuplicateSelectFeaturesFormTest covers the form change (with Rules hidden, Expense defaults is still selected and sent with codingRules: true), and PolicyTest covers the stray true.

Fixed Issues

$ #104231
PROPOSAL: #104231 (comment)

Tests

Where these ran: steps 2–5 on all five platforms (videos below), each with a Control source that has Rules turned off but still has workspace-level rule values. Steps 6–9, the offline tests, the JS console check and the deep link checks ran on web (Windows Chrome, dev build, staging API).

Source with Rules turned off (the issue):

  1. Use a Control workspace with Categories turned on. In More features, turn Rules on. Set any rule, for example Rules > General > "Flag receipt line items" > Alcohol. Then turn Rules off in More features.
  2. Go to Workspaces, open the three-dot menu of that workspace, choose Duplicate workspace, enter a name and press Next.
  3. Verify Rules is not listed on "Select features to copy".
  4. Keep Categories selected and press Continue.
  5. Open the new workspace. Verify Rules never appears in its menu, not even for a moment while it loads.
  6. Reload the page. Verify Rules is still not in the menu and is off in More features.

Source with Rules turned on:

  1. Turn Rules back on in the source workspace and duplicate it again.
  2. Verify Rules is listed and selected on "Select features to copy". Press Continue.
  3. Open the new workspace. Verify Rules is in the menu right away, and Rules > General > "Flag receipt line items" includes Alcohol.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline, for example with Account > Troubleshoot > Force offline.
  2. Duplicate the source from Tests step 1 (Rules turned off), following Tests steps 2–4.
  3. Verify Rules isn't listed on "Select features to copy" and doesn't appear in the new workspace's menu.
  4. Go back online and wait for the duplicate request to complete. Rules can show in the new workspace's menu for a moment, because ReconnectApp returns the duplicate's update with the stray true again (main shows the same when Rules is deselected). Verify Rules goes away once the policy loads. Then reload and verify Rules is not in the menu and is off in More features.

QA Steps

Same as tests.

  • 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) (N/A: no inputs or error messages change)
    • 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) (on web, with Force 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). (Tests 2–6 on web, dev build against the staging API; no long loading states)
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on: (see the note at the top of Tests)
    • 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) (none during the duplicate flow; the errors at page load also appear on main and come from browser extensions, the Group-IB script, the dev API proxy and React dev warnings)
  • I verified any copy / text that was added to the app 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) (N/A: no copy added)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers (N/A: no new pattern)
  • 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) (the duplicate flow is the only caller of both changes; I checked the new workspace's menu, More features and Rules pages)
  • If new assets were added or existing ones were modified, I verified that: (N/A: no assets added or changed)
    • 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. (N/A: no messaging code changed)
  • 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) (N/A: no generic component changed)
  • 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. (N/A: no component with a story changed)
  • 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: (N/A: no layout or style changes)
    • 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.
  • If the PR adds or modifies the UI: (N/A: no element is added or changed. An existing row is no longer shown when the source has Rules off.)
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • 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. (N/A: main hasn't been merged into this branch since the review)

Screenshots/Videos

Android: Native

Android 16 emulator, dev build (waits sped up): "Select features to copy" has no Rules row, the new workspace's menu has no Rules, and Rules is off in More features.

after-android-native.mp4
Android: mWeb Chrome

Chrome on the same emulator: "Select features to copy" has no Rules row, the new workspace's menu has no Rules, and Rules is off in More features.

after-android-mweb-chrome.mp4
iOS: Native

iPhone 18 Pro simulator, dev build (sped up): "Select features to copy" has no Rules row, and the new workspace's menu has no Rules.

after-ios-native.mp4
iOS: mWeb Safari

Safari in the same simulator (sped up): "Select features to copy" has no Rules row, and the new workspace's menu has no Rules.

after-ios-safari.mp4
MacOS: Chrome / Safari

Before (main, Chrome): Rules is listed and selected on "Select features to copy", and Rules shows for a moment in the new workspace's menu.

before-macos-chrome.mp4

After (Chrome): "Select features to copy" has no Rules row, and the new workspace's menu has no Rules.

after-macos-chrome.mp4

After (Safari): "Select features to copy" has no Rules row, and the new workspace's menu has no Rules.

after-macos-safari.mp4

After (Windows Chrome, an extra check with a source that has Rules turned off and an expense default): Rules isn't listed and Expense defaults is, the new workspace's menu has no Rules, also after a reload, and Rules is off in More features.

after-windows-chrome-expense-defaults.mp4

…ponse turns it on

The DuplicatePolicy response can merge a stray areRulesEnabled: true into the
new policy after the full policy merge when categories are copied from a
Control workspace. successData is applied after the response onyxData, so set
the final value there.
…Rules turned off

A Control workspace keeps some rule settings (prohibited expenses, category
GL codes...) while Rules is turned off, so the Rules row was listed and
preselected for such a workspace. Only offer it when arePolicyRulesEnabled is
true for the source.
@vulinh1704
vulinh1704 requested review from a team as code owners November 4, 2026 02:15
@melvin-bot
melvin-bot Bot requested review from abzokhattab and removed request for a team November 4, 2026 02:15
@melvin-bot

melvin-bot Bot commented Nov 4, 2026

Copy link
Copy Markdown

@abzokhattab 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]

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T02:34:43.213392Z 8f4fd79 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@melvin-bot
melvin-bot Bot requested review from heyjennahay and removed request for a team November 4, 2026 02:15
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@vulinh1704

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

exfy-clabot Bot added a commit to Expensify/CLA that referenced this pull request Nov 4, 2026

@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: 8f4fd798cb

ℹ️ 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".

: undefined,
rules && rules.length > 0 && !isCollect
// A Control workspace keeps its rule settings while Rules is turned off, so only offer to copy them when Rules is on.
rules && rules.length > 0 && !isCollect && arePolicyRulesEnabled(policy, policyCategories)

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 Preserve choices when the Rules row disappears

When the source's areRulesEnabled flips from true to false while this form is open (for example, another admin turns Rules off and the Pusher update lands), this new predicate removes the Rules row while its settings remain. That changes items.length, so the existing effect at lines 344–350 resets selectedItems to every remaining item and silently reselects unrelated features the user had already deselected; Continue then copies those features. Reconcile only the no-longer-visible item while preserving the other choices instead of reinitializing the entire selection.

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.

Good catch, fixed in 556e2f5. The reset came from the existing effect that selected every row again whenever the number of rows changed, so main already did this, for example when another admin turned Travel off or merchant rules loaded after the selection was changed. The effect now keeps the admin's choices: rows that go away are dropped, and rows that show up are selected, like every row when the form opens, so rows that load late still start selected. I added unit tests for Rules being turned off and on while the form is open.

…es away

The form selected every row again whenever the number of rows changed, so a
row the admin had deselected came back selected when another row showed up or
went away while the form was open, for example when Rules is turned off or on
for the source. Keep the admin's choices, drop rows that go away and select
rows that show up, like every row when the form opens.
@abzokhattab

Copy link
Copy Markdown
Contributor

can you please make the Explanation of Change more concise ... also do we need all of the 4 tests mentioned in Tests
section ? @vulinh1704

@vulinh1704

Copy link
Copy Markdown
Contributor Author

@abzokhattab Thanks, I shortened the Explanation. For the tests, I kept the issue's case and the one with Rules turned on (now steps 1–9), and removed the rest:

  • The Expense defaults test repeated the first test's checks, plus one that a unit test in WorkspaceDuplicateSelectFeaturesFormTest already covers: with Rules hidden, Expense defaults stays selected and is sent with codingRules: true.
  • The Collect test and step 10 (deselecting Rules) ended the same way as the first test: Rules isn't copied and never shows in the new workspace.

@vulinh1704

Copy link
Copy Markdown
Contributor Author

@abzokhattab friendly bump: the Explanation is shortened and the Tests are trimmed to the two cases, as you asked. Checks are green. Let me know if anything else is needed, thanks!

@abzokhattab

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • 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 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.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
Android: mWeb Chrome
iOS: HybridApp
Screen.Recording.2026-11-07.at.19.27.11.mov
iOS: mWeb Safari
Screen.Recording.2026-11-07.at.19.28.41.mov
MacOS: Chrome / Safari
Screen.Recording.2026-11-07.at.19.12.05.mov

setSelectedItems(items.map((i) => i.value));
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [items.length]);
const previousItemValues = previousItemValuesRef.current;

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.

I dont get why this change is needed. it doesnt look like a part of the bug we are fixing

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.

can you please revert the change in the useffect

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.

You're right, it isn't part of this bug. I'd added it for an edge case from the Codex review (selection reset when a row appears while the form is open). Reverted in 68c4622: the effect is back to the original, and its two tests are removed.

The reviewer asked to keep the useEffect as it was, since it is not part of
this bug. This takes out the change from 556e2f5 and its two tests.
@vulinh1704

Copy link
Copy Markdown
Contributor Author

@abzokhattab Updated. I reverted the useEffect change and removed that paragraph from the description. The related tests still pass locally.

@abzokhattab abzokhattab 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.

LGTM .. thank you

@melvin-bot
melvin-bot Bot requested a review from deetergp November 7, 2026 23:45
@abzokhattab

Copy link
Copy Markdown
Contributor

ready for your review @deetergp

@deetergp
deetergp merged commit 90e341e into Expensify:main Nov 10, 2026
39 of 42 checks passed
@OSBotify

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

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/deetergp in version: 9.5.36-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No FullStory changes needed — this PR only fixes disabled Rules incorrectly appearing during workspace duplication; it adds no new features, screens, or sensitive content.


view run

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed — this PR fixes workspace duplication to respect disabled Rules, restoring expected behavior without adding a feature or making existing article guidance incorrect.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/yuwenmemon in version: 9.5.36-0 🚀

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants