Repository navigation
Add rules engine types and merchant rule AST helpers #100389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
dbaf171
Add rules engine types and merchant rule AST helpers
Krishna2323 9d523ff
Fix knip and jest typecheck findings
Krishna2323 94f6362
Keep expense default rules when approvals are disabled
Krishna2323 18b1291
Read and write merchant rules through the rules engine
Krishna2323 e65b234
Copy and import merchant rules through the rules collection
Krishna2323 0edfd62
Update tests for the rules engine migration
Krishna2323 135b8e3
Merge upstream/main, keeping the rules engine storage under the new c…
Krishna2323 87009d5
Fix tests missed by the rules engine migration
Krishna2323 2acfff5
Assert merchant rule optimistic state with the request paused
Krishna2323 836b5b6
Match existing patterns for the rules collection reads and fetch trig…
Krishna2323 6048090
Reduce rules collection reads to what each consumer uses
Krishna2323 30420f2
Derive merchant rule condition text from the filter tree
Krishna2323 efb92da
Merge branch 'main' into krishna2323/issue-100300
Krishna2323 76a721a
fix ESLint and tests.
Krishna2323 7e1a7a5
Merge main into krishna2323/issue-100300
Krishna2323 cbf5092
Refuse to open a merchant rule the editor would overwrite
Krishna2323 4fbbe46
Resolve merchant rule tax defaults against the live rate
Krishna2323 227835e
Fetch rules where the merchant rule count is consumed, and throttle G…
Krishna2323 780e516
Use getByTestId for the guard test's presence assertion
Krishna2323 9cd0ae4
Drop the GetRules freshness window
Krishna2323 a41f492
Fetch the rules collection through a prefetch hook
Krishna2323 04cc8f1
Render the merchant rule guard test inside a navigator
Krishna2323 413e7c1
Add hasRulesDataBeenFetched to the Onyx export safe keys bucket
Krishna2323 15a9a44
merge main and resolve conflicts.
Krishna2323 eee1393
Write merchant rules through SetPolicyCodingRule instead of SetRule
Krishna2323 440446a
Merge main, keep new rules_ collection reads/writes over legacy revam…
Krishna2323 6c90b49
Fix CI: repair merge fallout in PolicyUtils and a stale test call
Krishna2323 f24b9f1
Merge upstream/main into krishna2323/issue-100300
Krishna2323 bd27131
One-index rule triggers and actions in tests and docs
Krishna2323 a6809e7
Merge upstream/main into krishna2323/issue-100300
Krishna2323 08b1366
Address review: fix editor deep link, unify rule normalization
Krishna2323 4b4b7a6
Address review: extract RuleUtils, flatten rule triggers and actions
Krishna2323 2fca025
Say when the legacy write path goes away
Krishna2323 a9350e3
Address review: fix deep link race, consolidate rule helpers
Krishna2323 f32eb5c
Address review: say why the rules refetch bypasses the prefetch guard
Krishna2323 9ef372d
Fix ExportOnyxState buckets after the rules flag rename
Krishna2323 21e33c7
Merge upstream/main into krishna2323/issue-100300
Krishna2323 375b4ca
Merge branch 'main' into krishna2323/issue-100300
Krishna2323 5475dc2
Order expense default rule summaries by editor field order
Krishna2323 aca0005
Merge branch 'main' into krishna2323/issue-100300
Krishna2323 a683cef
fix CI check.
Krishna2323 51ab5ec
Merge branch 'main' into krishna2323/issue-100300
Krishna2323 65899a2
Fix the rules fetch lifecycle and let unsupported rules be deleted
Krishna2323 b0e37ce
Bound the rules in-flight flag and hold the editor while rules load
Krishna2323 8034769
Refetch rules on the Rules page after a cache clear
Krishna2323 163064e
Merge branch 'main' into krishna2323/issue-100300
Krishna2323 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import {getRules, resetRulesFetchState} from '@libs/actions/Policy/Rules'; | ||
|
|
||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue'; | ||
|
|
||
| import {useEffect} from 'react'; | ||
|
|
||
| import useNetwork from './useNetwork'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| /** | ||
| * Fetches the `rules_` collection for a screen that reads it without opening a workspace. | ||
| * | ||
| * Merchant rules used to arrive on the policy, so anything holding a policy could read them. They now | ||
| * live in their own collection that only `GetRules` populates, which leaves screens reached from the | ||
| * workspaces list or from Home reading an empty collection. Where that collection decides whether an | ||
| * option is offered at all, an empty read silently drops the rules rather than showing a stale count. | ||
| * | ||
| * `GetRules` takes no parameters and its response SETs the whole collection, so this fetches once per | ||
| * session rather than on every mount. The shared guards live here so callers cannot drift apart. | ||
| * | ||
| * Returns whether the collection is still on its way, which a screen that decides something from a rule's | ||
| * absence has to wait for. Onyx hydrates the collection as empty long before the response lands, so without | ||
| * this a deep linked screen reads "no such rule" for a rule that exists. | ||
| */ | ||
| function useRulesPrefetch(enabled = true): {areRulesLoading: boolean} { | ||
| // Reconnecting is the only signal that a fetch which never settled is not still on its way. | ||
| const {isOffline} = useNetwork({onReconnect: resetRulesFetchState}); | ||
| const [hasBeenFetched, hasBeenFetchedResult] = useOnyx(ONYXKEYS.RAM_ONLY_HAS_RULES_DATA_BEEN_FETCHED); | ||
| const [isLoadingRules] = useOnyx(ONYXKEYS.RAM_ONLY_IS_LOADING_RULES); | ||
| const isFlagLoading = isLoadingOnyxValue(hasBeenFetchedResult); | ||
| const isFetchNeeded = enabled && !isFlagLoading && !isOffline && !hasBeenFetched && !isLoadingRules; | ||
|
|
||
| useEffect(() => { | ||
| if (!isFetchNeeded) { | ||
| return; | ||
| } | ||
| getRules(); | ||
| }, [isFetchNeeded]); | ||
|
|
||
| // `isFetchNeeded` and `isFlagLoading` cover the renders before the effect has run, which are the ones a | ||
| // guard reading the collection would otherwise resolve against nothing. Offline there is nothing to wait for. | ||
| return {areRulesLoading: enabled && !isOffline && (isFlagLoading || isFetchNeeded || !!isLoadingRules)}; | ||
| } | ||
|
|
||
| export default useRulesPrefetch; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.