Repository navigation
fix: hide Rules when duplicating a workspace that has Rules turned off - #105852
Conversation
…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.
|
@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] |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
|
can you please make the Explanation of Change more concise ... also do we need all of the 4 tests mentioned in Tests |
|
@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:
|
|
@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! |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppScreen.Recording.2026-11-07.at.19.27.11.moviOS: mWeb SafariScreen.Recording.2026-11-07.at.19.28.41.movMacOS: Chrome / SafariScreen.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; |
There was a problem hiding this comment.
I dont get why this change is needed. it doesnt look like a part of the bug we are fixing
There was a problem hiding this comment.
can you please revert the change in the useffect
There was a problem hiding this comment.
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.
|
@abzokhattab Updated. I reverted the |
|
ready for your review @deetergp |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚧 deetergp 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/deetergp in version: 9.5.36-0 🚀
|
|
No FullStory changes needed — this PR only fixes disabled Rules incorrectly appearing during workspace duplication; it adds no new features, screens, or sensitive content. |
|
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. |
|
🚀 Deployed to production by https://github.com/yuwenmemon in version: 9.5.36-0 🚀
Bundle Size Analysis (Sentry): |
Explanation of Change
Duplicating a Control workspace with Rules turned off showed Rules in two places:
arePolicyRulesEnabled(policy, policyCategories), the same check the workspace menu uses.DuplicatePolicyresponse merges a stray{areRulesEnabled: true}into the new policy after the full policy merge.successDatais applied after the response, so it now setsareRulesEnabledto 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 onmain).Unit tests:
WorkspaceDuplicateSelectFeaturesFormTestcovers the form change (with Rules hidden, Expense defaults is still selected and sent withcodingRules: true), andPolicyTestcovers the straytrue.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):
Source with Rules turned on:
Offline tests
ReconnectAppreturns the duplicate's update with the straytrueagain (mainshows 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.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionmainand come from browser extensions, the Group-IB script, the dev API proxy and React dev warnings)Avatar, I verified the components usingAvatarare 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)npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases) (N/A: no generic component changed)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. (N/A:mainhasn'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