-
Notifications
You must be signed in to change notification settings - Fork 4k
feat: seed default My expenses saved search for dual-role users and remove obsolete rename tooltip #93541
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
feat: seed default My expenses saved search for dual-role users and remove obsolete rename tooltip #93541
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
daebabb
feat: seed default My expenses saved search for dual-role users and r…
aswin-s 0dc1db1
style: apply prettier formatting
aswin-s dc4eca7
fix: correct dual-role eligibility check and remove stale collapse-tr…
aswin-s bfa4f17
fix: extract isDualRoleUser, fix retry-loop dep, add unit tests
aswin-s db9bef9
fix: resolve CI failures from RENAME_SAVED_SEARCH removal
aswin-s dc6637b
fix: resolve ESLint failures
aswin-s 0eca823
fix: use optional chaining on entry.at(0) to satisfy TypeScript
aswin-s c976f0d
feat: add translations for mySavedSearch key
aswin-s 008446c
fix: move seeding useEffect to SearchTypeMenuWide so re-seeding works…
aswin-s 9d7b8ba
fix: move seeding logic to SearchPage so it runs on narrow (mobile) l…
aswin-s 26f83c5
fix: resolve merge conflict in SearchPage, drop unused CONST import
aswin-s 29ba6de
fix: override pendingAction to null in PolicyTest to prevent random D…
aswin-s 0f4f319
Merge remote-tracking branch 'origin/main' into fix/issue-92780
aswin-s 183fbca
fix: add synchronous ref guard to prevent duplicate seedMyExpensesSea…
aswin-s 68dc40d
fix: skip seeding My Expenses search if query hash already exists
aswin-s 3dd32fd
refactor: extract seeding logic into useSeedMyExpensesSearch hook
aswin-s 891c334
test: add useSeedMyExpensesSearch hook tests
aswin-s 7e64b4a
fix: resolve ESLint errors in seedMyExpensesSearch hook and tests
aswin-s 3197642
Merge remote-tracking branch 'origin/main' into fix/issue-92780
aswin-s c0448c0
refactor: address review feedback on My expenses seed hook
aswin-s ad0bddb
Merge remote-tracking branch 'upstream/main' into fix/issue-92780
aswin-s b288569
fix: use named API import in seedMyExpensesSearch after main migration
aswin-s 6b1e7bc
refactor: extract My expenses seed selector to a module-level factory
aswin-s 0b425c6
Merge remote-tracking branch 'upstream/main' into fix/issue-92780
aswin-s 26c0f72
style: apply oxfmt formatting to seed My expenses hook and tests
aswin-s 6adada5
Merge remote-tracking branch 'origin/main' into fix/issue-92780
aswin-s e81b073
fix: remove deprecated useOnyx dependencies argument
aswin-s 1fea5c0
Merge remote-tracking branch 'origin/main' into fix/issue-92780
aswin-s 819eabd
Add nvp_hasSeededMyExpensesSearch to safe Onyx export keys
aswin-s 1d3a95e
Merge remote-tracking branch 'origin/main' into fix/issue-92780
aswin-s 592f51e
Broaden dual-role eligibility to mirror suggested-search visibility
aswin-s 77534e4
Wait for saved searches to load before seeding My expenses search
aswin-s 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,48 @@ | ||
| import {seedMyExpensesSearch} from '@libs/actions/Search'; | ||
| import {isSubmitterAndApprover} from '@libs/PolicyUtils'; | ||
|
|
||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import {accountIDSelector, emailSelector} from '@src/selectors/Session'; | ||
| import type {Policy} from '@src/types/onyx'; | ||
|
|
||
| import type {OnyxCollection} from 'react-native-onyx'; | ||
|
|
||
| import {useEffect, useMemo, useRef} from 'react'; | ||
|
|
||
| import useLocalize from './useLocalize'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| const createIsSubmitterAndApproverSelector = (currentUserEmail: string | undefined) => (policies: OnyxCollection<Policy>) => isSubmitterAndApprover(policies, currentUserEmail); | ||
|
|
||
| function useSeedMyExpensesSearch() { | ||
| const {translate} = useLocalize(); | ||
| const [hasSeededMyExpensesSearch] = useOnyx(ONYXKEYS.NVP_HAS_SEEDED_MY_EXPENSES_SEARCH); | ||
| const [savedSearches, savedSearchesMetadata] = useOnyx(ONYXKEYS.SAVED_SEARCHES); | ||
| const [currentUserAccountID] = useOnyx(ONYXKEYS.SESSION, {selector: accountIDSelector}); | ||
| const [currentUserEmail] = useOnyx(ONYXKEYS.SESSION, {selector: emailSelector}); | ||
| const isSubmitterAndApproverSelector = useMemo(() => createIsSubmitterAndApproverSelector(currentUserEmail), [currentUserEmail]); | ||
| const [isSubmitterAndApproverUser] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: isSubmitterAndApproverSelector}); | ||
| const hasSeededRef = useRef(false); | ||
|
|
||
| useEffect(() => { | ||
| // Wait for the saved searches to finish loading before seeding. Their value is `undefined` both while loading and when empty, | ||
| // so gating on the load status (instead of the value) prevents seeding over a pre-existing search that has not synced yet. | ||
| if ( | ||
| hasSeededRef.current || | ||
| hasSeededMyExpensesSearch || | ||
| !currentUserAccountID || | ||
| !currentUserEmail || | ||
| isSubmitterAndApproverUser === undefined || | ||
| savedSearchesMetadata.status !== 'loaded' | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| if (isSubmitterAndApproverUser) { | ||
| hasSeededRef.current = true; | ||
| seedMyExpensesSearch(currentUserAccountID, translate('search.mySavedSearch'), savedSearches); | ||
| } | ||
| }, [hasSeededMyExpensesSearch, currentUserAccountID, currentUserEmail, isSubmitterAndApproverUser, translate, savedSearches, savedSearchesMetadata.status]); | ||
| } | ||
|
|
||
| export default useSeedMyExpensesSearch; |
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this to be added on backend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if user explicitly deletes the seeded search, then it won't be reflected on another device or after a fresh login on same device. The 'My Expense' search item will get recreated though user had explicitly deleted it.