Skip to content

[Rules Engine Release 1] Use the new SetRule and DeleteRule commands - #102106

Merged
JS00001 merged 10 commits into
Expensify:mainfrom
Krishna2323:krishna2323/rules-engine-setrule
Oct 8, 2026
Merged

JS00001 merged 10 commits into
Expensify:mainfrom
Krishna2323:krishna2323/rules-engine-setrule

Conversation

@Krishna2323

@Krishna2323 Krishna2323 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixed Issues

$ #102275
$ #100300
PROPOSAL:

Tests

  • Same as QA steps

  • Verify that no errors appear in the JS console

Offline tests

  1. Turn off your network and open Rules. Verify the page loads and does not
    hang on a loading spinner.
  2. Still offline, create a merchant rule. Verify it appears greyed out as
    pending.
  3. Reconnect. Verify the rule saves and the pending style clears.

QA Steps

Setup: on https://staging.new.expensify.com, use a Control workspace with
Rules, Taxes and Approvals enabled. Create two merchant rules and one approval
workflow.

  1. Deep link to a rule. Open a merchant rule, copy the browser URL, then
    paste it into a brand new tab and load it. Verify the rule's editor opens.
    It may briefly show a loading spinner, but it must never show
    "Hmm... it's not here".
  2. Deep link to a rule that doesn't exist. Take that same URL and change a
    few characters in the rule ID. Verify it now does show the not-found page.
  3. Rules survive approval changes. Delete one merchant rule, refresh the
    page, and verify every approval workflow is still there. Then edit an
    approval workflow, refresh, and verify the remaining merchant rules are
    still there.
  4. Create, edit and delete. Create a merchant rule, refresh, verify it is
    there. Edit it, refresh, verify the edit stuck and no duplicate appeared.
    Delete it, refresh, verify it stays deleted.
  5. Rule count outside the workspace. From Home and from the Workspaces
    list, verify the workspace's Rules row shows the correct number of merchant
    rules without opening the workspace first.
  • 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: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
web_chrome.mp4

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

Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@Krishna2323 Krishna2323 changed the title Krishna2323/rules engine setrule [Rules Engine Release 1] Support the GetRules command and rules_ collection Sep 26, 2026
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@codecov

codecov Bot commented Sep 26, 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/libs/API/types.ts 100.00% <ø> (ø)
src/libs/ExpenseDefaultRuleUtils.ts 97.93% <ø> (ø)
...space/rules/MerchantRules/MerchantRulePageBase.tsx 62.99% <100.00%> (ø)
...s/workspace/rules/tabs/useRulesTableBulkActions.ts 60.82% <ø> (ø)
src/libs/actions/Policy/Rules.ts 74.10% <90.90%> (-5.49%) ⬇️
... and 9 files with indirect coverage changes

@Krishna2323
Krishna2323 marked this pull request as ready for review September 26, 2026 21:42
@Krishna2323
Krishna2323 requested review from a team as code owners September 26, 2026 21:42
@melvin-bot

melvin-bot Bot commented Sep 26, 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]

@JS00001

JS00001 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

@Krishna2323 based on the title of this PR, whats the difference between this and #100389? The issue linked here was created as reference for the already existing PR

Signed-off-by: krishna2323 <belivethatkg@gmail.com>
@Krishna2323 Krishna2323 changed the title [Rules Engine Release 1] Support the GetRules command and rules_ collection [Rules Engine Release 1] Use the new SetRule and DeleteRule commands Sep 28, 2026
@Krishna2323

Copy link
Copy Markdown
Contributor Author

Sorry, my mistake, I confused myself with the sub-issues. This PR originally had the SetRule/DeleteRule work (#102275), but I misread the split and stripped it back out, which made it look like a duplicate of #100389.

To clarify the split: #100389 is the read side (#102273, GetRules and the new rules_ collection), while this PR is the write side (#102275, SetRule/DeleteRule replacing SetPolicyCodingRule). I've restored that work here.

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

JS00001 commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Ah nice, thanks!

@JS00001 JS00001 changed the title [Rules Engine Release 1] Use the new SetRule and DeleteRule commands [Hold https://github.com/Expensify/App/pull/102106] [Rules Engine Release 1] Use the new SetRule and DeleteRule commands Sep 28, 2026
@luacmartins
luacmartins self-requested a review September 28, 2026 17:37
@JS00001 JS00001 changed the title [Hold https://github.com/Expensify/App/pull/102106] [Rules Engine Release 1] Use the new SetRule and DeleteRule commands [Hold https://github.com/Expensify/App/pull/100389] [Rules Engine Release 1] Use the new SetRule and DeleteRule commands Sep 29, 2026
@JS00001
JS00001 self-requested a review September 29, 2026 14:38
…ngine-setrule

# Conflicts:
#	src/libs/actions/Policy/Rules.ts
#	tests/unit/WorkflowUtilsTest.ts
@luacmartins

Copy link
Copy Markdown
Contributor

The holding PR is merged. We can resume work here

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

The code looks good, but I think that we want SetRule to be broader/not as scoped to merchant rules. This way, we can easily use it in the future for other rules

Comment thread src/libs/API/parameters/SetRuleParams.ts
Comment thread src/libs/actions/Policy/Rules.ts Outdated
Comment thread src/libs/actions/Policy/Rules.ts Outdated
Comment thread src/libs/actions/Policy/Rules.ts Outdated
@situchan

situchan commented Oct 6, 2026

Copy link
Copy Markdown
Contributor
  1. Rule count outside the workspace. From Home and from the Workspaces
    list, verify the workspace's Rules row shows the correct number of merchant
    rules without opening the workspace first.

I am not sure about this test step.
I don't see workspace's rules row in home and workspaces list.

@situchan

situchan commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Tests well.

@situchan

situchan commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

One leftover setMerchantRule:

// Fetch once on mount and whenever policyID changes. setMerchantRule already updates Onyx, so refetching

@melvin-bot
melvin-bot Bot requested a review from JS00001 October 7, 2026 11:16

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

Nice! Let's hold on the minimum version PR getting to production. Its merged, but will take 2 days to deploy

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

@JS00001 JS00001 changed the title [hold https://github.com/Expensify/App/issues/102274] [Rules Engine Release 1] Use the new SetRule and DeleteRule commands [Rules Engine Release 1] Use the new SetRule and DeleteRule commands Oct 8, 2026
@JS00001

JS00001 commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

:shipit: Great work!

@JS00001
JS00001 merged commit 7d5f627 into Expensify:main Oct 8, 2026
38 of 40 checks passed
@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

OSBotify commented Oct 8, 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.

@OSBotify OSBotify mentioned this pull request Oct 8, 2026
90 tasks done
@OSBotify

OSBotify commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

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

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

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed. This PR switches merchant rule saves and deletes to the new SetRule and DeleteRule API commands without changing any UI, label, or workflow, so no article sentence is now incorrect.


view run

@IuliiaHerets

Copy link
Copy Markdown

Hi @Krishna2323. Could you please clarify where exactly the Rules count should be displayed in the Home or Workspaces list? Is the Duplicate/Copy Workspace flow an acceptable place to verify it?
All steps passed successfully except for it

Captura de pantalla 2026-10-08 a la(s) 8 03 39 p m

сс @luacmartins @JS00001 @situchan

@jponikarchuk

Copy link
Copy Markdown

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

@OSBotify

OSBotify commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/puneetlath in version: 9.5.6-6 🚀

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.

8 participants