Skip to content

R4: Add contextual Category rules section to category details RHP - #96591

Merged
JS00001 merged 17 commits into
Expensify:mainfrom
Krishna2323:krishna2323/issue-92742
Jul 30, 2026
Merged

JS00001 merged 17 commits into
Expensify:mainfrom
Krishna2323:krishna2323/issue-92742

Conversation

@Krishna2323

@Krishna2323 Krishna2323 commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixed Issues

$ #92742
PROPOSAL:

Tests

  1. Enable the RULES_REVAMP beta and open a workspace with categories + rules enabled.
  2. Go to Workspace → Categories, open a category that has a flag-for-review and/or require-fields rule.
  3. Scroll below Delete and verify the Category rules section lists those rules as tappable rows with a bolt icon and chevron.
  4. Tap a rule row and verify it opens the same Rules edit screen; save and confirm the summary updates on the category RHP and on the Rules page.
  5. On a category with no rules, verify only Create new rule is shown.
  6. Tap Create new rule, pick Flag for review or Require fields, and verify the current category is already selected.
  7. Create the rule, then verify it appears in Category rules and on the Rules page.
  • Verify that no errors appear in the JS console

Offline tests

  • Same as tests

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)
    • 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
    • MacOS: Desktop
  • 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 verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • 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 shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • 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)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • 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)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • 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.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • 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_hybrid.mp4
Android: mWeb Chrome
android_mWeb.mp4
iOS: Native
ios_hybrid.mp4
iOS: mWeb Safari
ios_mWeb.mp4
MacOS: Chrome / Safari
web_chrome.mp4

Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@melvin-bot

melvin-bot Bot commented Jul 21, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

Krishna2323 and others added 4 commits July 22, 2026 22:58
Resolve conflicts in Rules Revamp utils/pages while keeping category pre-scope (initialCategoryName) and contextual Category rules helpers.

Co-authored-by: Cursor <cursoragent@cursor.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@Krishna2323
Krishna2323 marked this pull request as ready for review July 22, 2026 18:47
@Krishna2323
Krishna2323 requested review from a team as code owners July 22, 2026 18:47
@melvin-bot
melvin-bot Bot requested review from situchan and removed request for a team July 22, 2026 18:47
@melvin-bot

melvin-bot Bot commented Jul 22, 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]

@melvin-bot
melvin-bot Bot requested review from trjExpensify and removed request for a team July 22, 2026 18:47

@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: 20a1801455

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

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

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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

Let us know when there's screen recordings to look at. Let's have @Expensify/design take a look too.

(CC: @JmillsExpensify, though I know you're OOO for a bit so didn't assign you).

@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

@dubielzyk-expensify

dubielzyk-expensify commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Tests well to me 👍 I wonder if we actually need to tweak the design cause I didn't anticipate the long strings feeling so unusable:

CleanShot 2026-07-23 at 10 07 21@2x

Given it links to the edit screen, yes you can technically see the rule there, but it's a bit harder through that UI.

In the mock I did have it as non bold, so I wonder if we should align with that and let it go to multiple lines:

CleanShot 2026-07-23 at 10 11 13@2x

@dubielzyk-expensify

Copy link
Copy Markdown
Contributor

I really like how we fill the category on New rule. I think it's probably fine to show all the rules, but just knowing that technically you can't create a Card rule with a category. That being said I think it's still nicer to show all the actions for education purposes since it would likely be worse to hide it.

CleanShot 2026-07-23 at 10 12 15@2x

@dubielzyk-expensify
dubielzyk-expensify self-requested a review July 23, 2026 00:13
@trjExpensify

Copy link
Copy Markdown
Contributor

I like wrapping to two lines, and then if for some reason it's still truncated, hover to show the full string?

@dubielzyk-expensify

Copy link
Copy Markdown
Contributor

Yeah dig it. I think we could even afford 3 lines, but lets start with 2 and then alt text on hover 👍

@shawnborton

Copy link
Copy Markdown
Contributor

In the mock I did have it as non bold, so I wonder if we should align with that and let it go to multiple lines:

Agree with that.

That being said I think it's still nicer to show all the actions for education purposes since it would likely be worse to hide it.

Also agree with that. Probably fine not to touch the agent rule flow for now, but it might be nice to think of how we would prefill the edit tab of that flow (but I can't think of any good ideas myself).

@dubielzyk-expensify

Copy link
Copy Markdown
Contributor

but it might be nice to think of how we would prefill the edit tab of that flow (but I can't think of any good ideas myself).

Yeah I was thinking we'd land on the edit tab with a "For X category limit spend" or something, but it all has some drawbacks so I agree that it's better to just do as a follow-up.

Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@Krishna2323

Copy link
Copy Markdown
Contributor Author

@JS00001 could you please run translations script?

Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@Krishna2323

Copy link
Copy Markdown
Contributor Author

This still happens on category rule edit pages

@situchan fixed.

@melvin-bot
melvin-bot Bot requested review from JS00001 and luacmartins July 29, 2026 19:58
@MelvinBot

Copy link
Copy Markdown
Contributor

Regression scan — 🤖 no regressions to existing flows; 1 edge case in the new feature

I reviewed the diff across three areas (the CategorySettingsPage refactor, the shared rule create/edit page bases, and the routing/navigation config). The existing Workspace → Rules flows are behaviorally unchanged — every new branch is gated on isCategoryScopedFlow / initialCategoryName / isCategoryLocked, all of which are falsy in the normal flow, so routes, drafts, and back-navigation stay identical.

I did find one thing worth fixing before merge — it's in the new category-scoped feature (not a regression of prior behavior):

Post-save return ignores the quick-settings (Settings → Categories) flow

The contextual "Category rules" section and its Create new rule button render in both the workspace flow and the quick-settings flow, and the new dynamic routes list DYNAMIC_SETTINGS_CATEGORY_SETTINGS in their entryScreens — so a category-scoped rule can be created from Settings → Categories. But the post-save goBack fallback is hardcoded to the workspace category path:

The rest of CategorySettingsPage carefully branches on isQuickSettingsFlow (e.g. it picks SETTINGS_CATEGORY_EDIT vs WORKSPACE_CATEGORY_EDIT), but this new goBack destination doesn't.

Failure scenario: create a flag-for-review/require-fields rule from Settings → Categories → <category>, save, then refresh or deeplink the save. goBack falls back to the workspace category page instead of the settings category page you came from. In normal in-app navigation the fallback usually isn't hit (the stack pops), so impact is limited to refresh/deeplink — but it's the same class of bug the surrounding code already guards against.

Suggested fix: thread the flow through the save handlers and pick a settings-scoped route when isQuickSettingsFlow (mirroring the SETTINGS_CATEGORY_EDIT vs WORKSPACE_CATEGORY_EDIT pattern), rather than always returning getWorkspaceCategorySettingsRoute.

What I checked and cleared (no regression)
  • CategorySettingsPage split — for both revamp and non-revamp users, no menu item is dropped or duplicated; the legacy !isRulesRevampEnabled block preserves the same items/order/routes/pendingActions; the new "Category rules" header is guarded by contextualRules.length > 0 || canWriteRules so it never renders empty. arePolicyRulesEnabled(policy, policyCategories) gating is unchanged (now stored in categoryRulesEnabled).
  • Route helper signatures (RULES_*_NEW/EDIT, RULES_FLAG_FOR_REVIEW_RULE_AMOUNT/_EDIT, RULES_NEW, RULES_MERCHANT_NEW) — all appended params are optional; getOptionalCategoryNameQuery/getOptionalIsCategoryLockedQuery return '' when omitted, so existing call sites produce byte-identical URLs. No caller passes a positional arg into the wrong new slot.
  • RulesNewPage array refactor — the workspace RULES_NEW flow (no categoryName) still renders all five options in the same order with the same onPress routes and sentryLabels. Its only caller passes no categoryName, so options are never wrongly hidden.
  • Rule page bases — normal-flow backToRoute, draft init (setDraft…({})), canEditCategory (= canWriteRules when unlocked), and the save-navigation branch all resolve to prior behavior when the new props are falsy. useDynamicBackPath is called unconditionally at top level → no hook-order issue.
  • MerchantRulePageBase edit-init restructure preserves edit-mode population and the unmount clearDraftMerchantRule(); the create draft is set at most once via a ref.
  • New DYNAMIC_CATEGORY_ screens* are registered consistently across SCREENS.ts, types.ts, ModalStackNavigators, WORKSPACE_TO_RHP, and config.ts.
  • getCategoryContextualRules guards against undefined policy/category and returns [] cleanly.

This was a static review (no runtime repro of the goBack edge case). Reply @MelvinBot implement this to draft the quick-settings fix, or @MelvinBot <feedback> to refine.

@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: 3eec4e1229

ℹ️ 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 thread src/ROUTES.ts Resolved
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@JS00001
JS00001 merged commit 48c8baa into Expensify:main Jul 30, 2026
35 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

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

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/JS00001 in version: 9.4.47-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

Help site review — no docs PR created

I reviewed the changes in this PR against the help site articles under docs/articles, and no help site changes are required at this time.

Why: The entire "Category rules" contextual section this PR adds to the category details RHP (the summary rows, the bolt icon, and the Create new rule entry) is gated behind the RULES_REVAMP beta — it only renders when isBetaEnabled(CONST.BETAS.RULES_REVAMP) is true, and the pre-existing legacy category rule entry points are preserved for everyone else. All the new user-facing strings (createNewRule, contextualFlagForReview) are used exclusively inside that beta-gated code path.

The help site documents current, generally-available behavior. Because this UX is beta-only and not yet GA, documenting it now would misrepresent what most admins actually see. The existing guidance still accurately reflects current behavior for non-beta users:

Follow-up when RULES_REVAMP goes GA: Both "How to configure Category Rules" sections above will need to be revised to describe the new flow — that rule creation is centralized on the Rules page, that a category's applicable rules now surface as tappable summary rows in the category details RHP with a Create new rule entry, and that editing a rule from the category opens the same shared rule object as the Rules page. That update should ride along with the beta's GA rollout, not before it.

@Krishna2323, since there's no help site PR to link (the feature is still beta-gated), there's nothing to mark Ready for review yet. If you'd rather I go ahead and draft the doc updates now so they're queued for the GA rollout, reply with @MelvinBot draft the docs updates anyway and I'll create the draft PR.

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #97560 was identified to be related to this PR.

@mitarachim

Copy link
Copy Markdown

Deploy Blocker #97561 was identified to be related to this PR.

@jponikarchuk

Copy link
Copy Markdown

Deploy Blocker #97563 was identified to be related to this PR.

@OSBotify

OSBotify commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.4.47-7 🚀

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

Bundle Size Analysis (Sentry):

@Krishna2323 Krishna2323 changed the title Add contextual Category rules section to category details RHP R4: Add contextual Category rules section to category details RHP Aug 3, 2026
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.