-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Remove active policy onyx connect ref from ReportUtils #79174
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
Changes from all commits
f0b9277
179fd30
fa30e34
a8b00e6
65f1cc2
9c2c931
99ce009
4792031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import useOnyx from './useOnyx'; | ||
| import usePolicy from './usePolicy'; | ||
|
|
||
| export default function useActivePolicy() { | ||
| const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: false}); | ||
| return usePolicy(activePolicyID); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1203,12 +1203,6 @@ Onyx.connectWithoutView({ | |
| }, | ||
| }); | ||
|
|
||
| let activePolicyID: OnyxEntry<string>; | ||
| Onyx.connectWithoutView({ | ||
| key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, | ||
| callback: (value) => (activePolicyID = value), | ||
| }); | ||
|
|
||
| let reportAttributesDerivedValue: ReportAttributesDerivedValue['reports']; | ||
| Onyx.connectWithoutView({ | ||
| key: ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, | ||
|
|
@@ -11172,6 +11166,7 @@ function createDraftTransactionAndNavigateToParticipantSelector( | |
| actionName: IOUAction, | ||
| reportActionID: string | undefined, | ||
| introSelected: OnyxEntry<IntroSelected>, | ||
| activePolicy: OnyxEntry<Policy>, | ||
| isRestrictedToPreferredPolicy = false, | ||
| preferredPolicyID?: string, | ||
| ): void { | ||
|
|
@@ -11215,23 +11210,20 @@ function createDraftTransactionAndNavigateToParticipantSelector( | |
| const filteredPolicies = Object.values(allPolicies ?? {}).filter((policy) => shouldShowPolicy(policy, false, currentUserEmail)); | ||
|
|
||
| if (actionName === CONST.IOU.ACTION.CATEGORIZE) { | ||
| // This will be fixed as part of https://github.com/Expensify/Expensify/issues/507850 | ||
| // eslint-disable-next-line @typescript-eslint/no-deprecated | ||
| const activePolicy = getPolicy(activePolicyID); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @roryabraham We pass active policy to use in here
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because getPolicy also be deprecated now, so in this PR we pass activePolicy to remove getPolicy call |
||
| if (activePolicy && shouldRestrictUserBillableActions(activePolicy.id)) { | ||
| Navigation.navigate(ROUTES.RESTRICTED_ACTION.getRoute(activePolicy.id)); | ||
| return; | ||
| } | ||
|
|
||
| if (shouldShowPolicy(activePolicy, false, currentUserEmail)) { | ||
| const policyExpenseReportID = getPolicyExpenseChat(currentUserAccountID, activePolicyID)?.reportID; | ||
| if (activePolicy && shouldShowPolicy(activePolicy, false, currentUserEmail)) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @roryabraham we also need the whole activePolicy for |
||
| const policyExpenseReportID = getPolicyExpenseChat(currentUserAccountID, activePolicy.id)?.reportID; | ||
| setMoneyRequestParticipants(transactionID, [ | ||
| { | ||
| selected: true, | ||
| accountID: 0, | ||
| isPolicyExpenseChat: true, | ||
| reportID: policyExpenseReportID, | ||
| policyID: activePolicyID, | ||
| policyID: activePolicy.id, | ||
| searchText: activePolicy?.name, | ||
| }, | ||
| ]); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import RoomHeaderAvatars from '@components/RoomHeaderAvatars'; | |
| import ScreenWrapper from '@components/ScreenWrapper'; | ||
| import ScrollView from '@components/ScrollView'; | ||
| import {useSearchContext} from '@components/Search/SearchContext'; | ||
| import useActivePolicy from '@hooks/useActivePolicy'; | ||
| import useAncestors from '@hooks/useAncestors'; | ||
| import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; | ||
| import useDeleteTransactions from '@hooks/useDeleteTransactions'; | ||
|
|
@@ -155,6 +156,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail | |
| const {translate, localeCompare, formatPhoneNumber} = useLocalize(); | ||
| const {isOffline} = useNetwork(); | ||
| const {isRestrictedToPreferredPolicy, preferredPolicyID} = usePreferredPolicy(); | ||
| const activePolicy = useActivePolicy(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here - only ID needed. |
||
| const styles = useThemeStyles(); | ||
| const expensifyIcons = useMemoizedLazyExpensifyIcons(['Users', 'Gear', 'Send', 'Folder', 'UserPlus', 'Pencil', 'Checkmark', 'Building', 'Exit', 'Bug', 'Camera', 'Trashcan']); | ||
| const backTo = route.params.backTo; | ||
|
|
@@ -440,6 +442,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail | |
| CONST.IOU.ACTION.SUBMIT, | ||
| actionableWhisperReportActionID, | ||
| introSelected, | ||
| activePolicy, | ||
| isRestrictedToPreferredPolicy, | ||
| preferredPolicyID, | ||
| ); | ||
|
|
@@ -453,7 +456,14 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail | |
| isAnonymousAction: false, | ||
| shouldShowRightIcon: true, | ||
| action: () => { | ||
| createDraftTransactionAndNavigateToParticipantSelector(iouTransactionID, actionReportID, CONST.IOU.ACTION.CATEGORIZE, actionableWhisperReportActionID, introSelected); | ||
| createDraftTransactionAndNavigateToParticipantSelector( | ||
| iouTransactionID, | ||
| actionReportID, | ||
| CONST.IOU.ACTION.CATEGORIZE, | ||
| actionableWhisperReportActionID, | ||
| introSelected, | ||
| activePolicy, | ||
| ); | ||
| }, | ||
| }); | ||
| items.push({ | ||
|
|
@@ -463,7 +473,14 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail | |
| isAnonymousAction: false, | ||
| shouldShowRightIcon: true, | ||
| action: () => { | ||
| createDraftTransactionAndNavigateToParticipantSelector(iouTransactionID, actionReportID, CONST.IOU.ACTION.SHARE, actionableWhisperReportActionID, introSelected); | ||
| createDraftTransactionAndNavigateToParticipantSelector( | ||
| iouTransactionID, | ||
| actionReportID, | ||
| CONST.IOU.ACTION.SHARE, | ||
| actionableWhisperReportActionID, | ||
| introSelected, | ||
| activePolicy, | ||
| ); | ||
| }, | ||
| }); | ||
| } | ||
|
|
@@ -584,6 +601,7 @@ function ReportDetailsPage({policy, report, route, reportMetadata}: ReportDetail | |
| isRestrictedToPreferredPolicy, | ||
| preferredPolicyID, | ||
| introSelected, | ||
| activePolicy, | ||
| parentReport, | ||
| ]); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,7 @@ import {ShowContextMenuContext} from '@components/ShowContextMenuContext'; | |
| import Text from '@components/Text'; | ||
| import TextLink from '@components/TextLink'; | ||
| import UnreadActionIndicator from '@components/UnreadActionIndicator'; | ||
| import useActivePolicy from '@hooks/useActivePolicy'; | ||
| import useConfirmModal from '@hooks/useConfirmModal'; | ||
| import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; | ||
| import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; | ||
|
|
@@ -358,6 +359,7 @@ type PureReportActionItemProps = { | |
| actionName: IOUAction, | ||
| reportActionID: string, | ||
| introSelected: OnyxEntry<OnyxTypes.IntroSelected>, | ||
| activePolicy: OnyxEntry<OnyxTypes.Policy>, | ||
| isRestrictedToPreferredPolicy?: boolean, | ||
| preferredPolicyID?: string, | ||
| ) => void; | ||
|
|
@@ -517,6 +519,7 @@ function PureReportActionItem({ | |
| const [isEmojiPickerActive, setIsEmojiPickerActive] = useState<boolean | undefined>(); | ||
| const [isPaymentMethodPopoverActive, setIsPaymentMethodPopoverActive] = useState<boolean | undefined>(); | ||
| const {isRestrictedToPreferredPolicy, preferredPolicyID} = usePreferredPolicy(); | ||
| const activePolicy = useActivePolicy(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again it seems like we might need only the ID, so we should provide a selector to |
||
| const shouldRenderViewBasedOnAction = useTableReportViewActionRenderConditionals(action); | ||
| const [isHidden, setIsHidden] = useState(false); | ||
| const [moderationDecision, setModerationDecision] = useState<OnyxTypes.DecisionName>(CONST.MODERATION.MODERATOR_DECISION_APPROVED); | ||
|
|
@@ -877,6 +880,7 @@ function PureReportActionItem({ | |
| CONST.IOU.ACTION.SUBMIT, | ||
| action.reportActionID, | ||
| introSelected, | ||
| activePolicy, | ||
| isRestrictedToPreferredPolicy, | ||
| preferredPolicyID, | ||
| ); | ||
|
|
@@ -890,14 +894,28 @@ function PureReportActionItem({ | |
| text: 'actionableMentionTrackExpense.categorize', | ||
| key: `${action.reportActionID}-actionableMentionTrackExpense-categorize`, | ||
| onPress: () => { | ||
| createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportActionReportID, CONST.IOU.ACTION.CATEGORIZE, action.reportActionID, introSelected); | ||
| createDraftTransactionAndNavigateToParticipantSelector( | ||
| transactionID, | ||
| reportActionReportID, | ||
| CONST.IOU.ACTION.CATEGORIZE, | ||
| action.reportActionID, | ||
| introSelected, | ||
| activePolicy, | ||
| ); | ||
| }, | ||
| }, | ||
| { | ||
| text: 'actionableMentionTrackExpense.share', | ||
| key: `${action.reportActionID}-actionableMentionTrackExpense-share`, | ||
| onPress: () => { | ||
| createDraftTransactionAndNavigateToParticipantSelector(transactionID, reportActionReportID, CONST.IOU.ACTION.SHARE, action.reportActionID, introSelected); | ||
| createDraftTransactionAndNavigateToParticipantSelector( | ||
| transactionID, | ||
| reportActionReportID, | ||
| CONST.IOU.ACTION.SHARE, | ||
| action.reportActionID, | ||
| introSelected, | ||
| activePolicy, | ||
| ); | ||
| }, | ||
| }, | ||
| ); | ||
|
|
@@ -1037,6 +1055,7 @@ function PureReportActionItem({ | |
| isOriginalReportArchived, | ||
| resolveActionableMentionWhisper, | ||
| introSelected, | ||
| activePolicy, | ||
| report, | ||
| originalReport, | ||
| ]); | ||
|
|
||
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.
Per the guideline Avoid Broad Object Dependencies:
since only the ID is needed, the param to this should be
activePolicyIDrather thanactivePolicy