-
Notifications
You must be signed in to change notification settings - Fork 3.4k
remove remaining inline selectors #72546
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
base: main
Are you sure you want to change the base?
remove remaining inline selectors #72546
Conversation
|
@dukenv0307 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] |
|
3 more places App/src/hooks/usePersonalPolicy.ts Line 19 in d057ac4
|
| } | ||
| }); | ||
|
|
||
| const transactionViolationSelector = (violations: OnyxCollection<TransactionViolations>) => { |
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.
let's use useCallback
| * `true` means the onboarding flow is loading | ||
| * `false` means the onboarding flow is not loading | ||
| */ | ||
| function isOnboardingLoadingSelector(onboarding: OnyxValue<typeof ONYXKEYS.NVP_ONBOARDING>): boolean | undefined { |
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.
why don't we move it to selectors folder?
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.
Good call, I missed the fact that it's not there
|
Updated ✅ |
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.
@TMisiukiewicz Can you please upgrade eslint-config-expensify to include the no-inline-useOnyx-selector rule we added in Expensify/eslint-config-expensify#160, now that the ESLint 9 upgrade is complete?
|
|
|
@roryabraham amazing! Bumped version to 2.0.92 |
2e64e20 to
6133146
Compare
|
@TMisiukiewicz Can you please fix the eslint check? |
|
Let's see if it works now |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppScreen.Recording.2025-10-18.at.17.56.34.movAndroid: mWeb ChromeScreen.Recording.2025-10-18.at.17.54.55.moviOS: HybridAppScreen.Recording.2025-10-18.at.17.56.44.moviOS: mWeb SafariScreen.Recording.2025-10-18.at.17.55.11.movMacOS: Chrome / SafariScreen.Recording.2025-10-18.at.17.54.29.movMacOS: DesktopScreen.Recording.2025-10-18.at.17.59.34.mov |
|
Looks good, but we have a conflict |
|
resolved |
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.
All yours @roryabraham !
| import BaseListItem from './BaseListItem'; | ||
| import type {ListItem, UserListItemProps} from './types'; | ||
|
|
||
| const reportExistsSelector = (report: OnyxEntry<Report>) => !!report; |
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.
NAB but maybe it's cleaner architecturally and will naturally lead to more reuse if all pure selectors (i.e: no dependencies on component props or state) are declared in the @selectors directory/namespace.
| (policies: OnyxCollection<Policy>) => { | ||
| return Object.values(policies ?? {}).some((policy) => isPaidGroupPolicy(policy) && isPolicyAdmin(policy, currentUserPersonalDetails.login)); | ||
| }, | ||
| [currentUserPersonalDetails.login], |
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.
The leaves me wondering if we could improve selector composition further and promote reuse. Because this selector "is the current user an admin of a paid policy" is not specific only to this component, and should not be.
I think you could compose this into a custom hook:
function useIsCurrentUserPolicyAdmin() {
// NAB TODO: add a selector for just `currentUserLogin`?
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const isUserPaidPolicyAdminSelector = useCallback(
(policies: OnyxCollection<Policy>) => Object.values(policies ?? {}).some((policy) => isPaidGroupPolicy(policy) && isPolicyAdmin(policy, currentUserPersonalDetails.login)),
[currentUserPersonalDetails.login],
);
const [isCurrentUserPolicyAdmin = false] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {
canBeMissing: true,
selector: isUserPaidPolicyAdminSelector,
});
return isCurrentUserPolicyAdmin;
}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.
Also, maybe it should be using session instead of currentUserPersonalDetails?
| @@ -1,9 +1,9 @@ | |||
| import {createPoliciesSelector} from '@selectors/Policy'; | |||
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.
I find it odd/suspicious that this would be the first import (before react)
| } | ||
| }); | ||
|
|
||
| const transactionViolationSelector = useCallback( |
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.
Hmmm so now I'm wondering - does this selector get re-created every time we import and use this hook? Ideally we want all uses of this hook to result in 1 cached selector, but I don't think that's the case here.
So I feel like there's some piece we're missing to properly compose selectors for reuse....
|
Will get back to this as soon as possible. Still working on some critical stuff |
Explanation of Change
Migrating the remaining inline selectors to stable selectors. They were most likely accidentally missed during migration or created while the migration was ongoing.
Fixed Issues
$ #70272
PROPOSAL:
Tests
Offline tests
n/a
QA Steps
// TODO: These must be filled out, or the issue title must include "[No QA]."
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
android.mov
Android: mWeb Chrome
iOS: Native
ios.mov
iOS: mWeb Safari
ios.web.mov
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov