Skip to content

Commit 4f5bde6

Browse files
authored
Merge pull request Expensify#63362 from callstack-internal/fix/lhn-props
fix(perf): directly pass props to lhn items
2 parents 99b20da + c87b1c7 commit 4f5bde6

4 files changed

Lines changed: 49 additions & 14 deletions

File tree

src/components/LHNOptionsList/LHNOptionsList.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import useLHNEstimatedListSize from '@hooks/useLHNEstimatedListSize';
1515
import useLocalize from '@hooks/useLocalize';
1616
import useNetwork from '@hooks/useNetwork';
1717
import usePrevious from '@hooks/usePrevious';
18+
import useRootNavigationState from '@hooks/useRootNavigationState';
1819
import useScrollEventEmitter from '@hooks/useScrollEventEmitter';
1920
import useTheme from '@hooks/useTheme';
2021
import useThemeStyles from '@hooks/useThemeStyles';
@@ -27,6 +28,7 @@ import {canUserPerformWriteAction} from '@libs/ReportUtils';
2728
import isProductTrainingElementDismissed from '@libs/TooltipUtils';
2829
import variables from '@styles/variables';
2930
import CONST from '@src/CONST';
31+
import NAVIGATORS from '@src/NAVIGATORS';
3032
import ONYXKEYS from '@src/ONYXKEYS';
3133
import type {PersonalDetails, Report} from '@src/types/onyx';
3234
import {isEmptyObject} from '@src/types/utils/EmptyObject';
@@ -52,12 +54,16 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
5254
const [transactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: false});
5355
const [draftComments] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: false});
5456
const [transactionViolations] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: false});
57+
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
58+
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
5559
const [dismissedProductTraining, dismissedProductTrainingMetadata] = useOnyx(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {canBeMissing: true});
60+
const [isFullscreenVisible] = useOnyx(ONYXKEYS.FULLSCREEN_VISIBILITY, {canBeMissing: true});
5661

5762
const theme = useTheme();
5863
const styles = useThemeStyles();
5964
const {translate, preferredLocale} = useLocalize();
6065
const estimatedListSize = useLHNEstimatedListSize();
66+
const isReportsSplitNavigatorLast = useRootNavigationState((state) => state?.routes?.at(-1)?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR);
6167
const shouldShowEmptyLHN = data.length === 0;
6268
const estimatedItemSize = optionMode === CONST.OPTION_MODE.COMPACT ? variables.optionRowHeightCompact : variables.optionRowHeight;
6369
const platform = getPlatform();
@@ -233,6 +239,10 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
233239
transactionViolations={transactionViolations}
234240
onLayout={onLayoutItem}
235241
shouldShowRBRorGBRTooltip={shouldShowRBRorGBRTooltip}
242+
activePolicyID={activePolicyID}
243+
onboardingPurpose={introSelected?.choice}
244+
isFullscreenVisible={isFullscreenVisible}
245+
isReportsSplitNavigatorLast={isReportsSplitNavigatorLast}
236246
/>
237247
);
238248
},
@@ -253,6 +263,10 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
253263
onLayoutItem,
254264
isOffline,
255265
firstReportIDWithGBRorRBR,
266+
activePolicyID,
267+
introSelected?.choice,
268+
isFullscreenVisible,
269+
isReportsSplitNavigatorLast,
256270
],
257271
);
258272

src/components/LHNOptionsList/OptionRowLHN.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {useFocusEffect} from '@react-navigation/native';
22
import React, {useCallback, useMemo, useRef, useState} from 'react';
33
import type {GestureResponderEvent, ViewStyle} from 'react-native';
44
import {StyleSheet, View} from 'react-native';
5-
import {useOnyx} from 'react-native-onyx';
65
import DisplayNames from '@components/DisplayNames';
76
import Hoverable from '@components/Hoverable';
87
import Icon from '@components/Icon';
@@ -19,7 +18,6 @@ import Tooltip from '@components/Tooltip';
1918
import EducationalTooltip from '@components/Tooltip/EducationalTooltip';
2019
import useLocalize from '@hooks/useLocalize';
2120
import useResponsiveLayout from '@hooks/useResponsiveLayout';
22-
import useRootNavigationState from '@hooks/useRootNavigationState';
2321
import useStyleUtils from '@hooks/useStyleUtils';
2422
import useTheme from '@hooks/useTheme';
2523
import useThemeStyles from '@hooks/useThemeStyles';
@@ -44,17 +42,20 @@ import FreeTrial from '@pages/settings/Subscription/FreeTrial';
4442
import variables from '@styles/variables';
4543
import Timing from '@userActions/Timing';
4644
import CONST from '@src/CONST';
47-
import NAVIGATORS from '@src/NAVIGATORS';
48-
import ONYXKEYS from '@src/ONYXKEYS';
4945
import {isEmptyObject} from '@src/types/utils/EmptyObject';
5046
import type {OptionRowLHNProps} from './types';
5147

5248
function OptionRowLHN({
5349
reportID,
5450
isFocused = false,
51+
report,
5552
onSelectRow = () => {},
5653
optionItem,
5754
viewMode = 'default',
55+
activePolicyID,
56+
onboardingPurpose,
57+
isFullscreenVisible,
58+
isReportsSplitNavigatorLast,
5859
style,
5960
onLayout = () => {},
6061
hasDraftComment,
@@ -67,18 +68,12 @@ function OptionRowLHN({
6768
const [isScreenFocused, setIsScreenFocused] = useState(false);
6869
const {shouldUseNarrowLayout} = useResponsiveLayout();
6970

70-
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${optionItem?.reportID}`, {canBeMissing: true});
71-
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID, {canBeMissing: true});
72-
const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED, {canBeMissing: true});
73-
const [isFullscreenVisible] = useOnyx(ONYXKEYS.FULLSCREEN_VISIBILITY, {canBeMissing: true});
7471
const session = useSession();
7572
const shouldShowWorkspaceChatTooltip = isPolicyExpenseChat(report) && !isThread(report) && activePolicyID === report?.policyID && session?.accountID === report?.ownerAccountID;
76-
const isOnboardingGuideAssigned = introSelected?.choice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM && !session?.email?.includes('+');
77-
const isChatUsedForOnboarding = isChatUsedForOnboardingReportUtils(report, introSelected?.choice);
73+
const isOnboardingGuideAssigned = onboardingPurpose === CONST.ONBOARDING_CHOICES.MANAGE_TEAM && !session?.email?.includes('+');
74+
const isChatUsedForOnboarding = isChatUsedForOnboardingReportUtils(report, onboardingPurpose);
7875
const shouldShowGetStartedTooltip = isOnboardingGuideAssigned ? isAdminRoom(report) && isChatUsedForOnboarding : isConciergeChatReport(report);
7976

80-
const isReportsSplitNavigatorLast = useRootNavigationState((state) => state?.routes?.at(-1)?.name === NAVIGATORS.REPORTS_SPLIT_NAVIGATOR);
81-
8277
const {tooltipToRender, shouldShowTooltip, shouldTooltipBeLeftAligned} = useMemo(() => {
8378
let tooltip: ProductTrainingTooltipName;
8479
if (shouldShowRBRorGBRTooltip) {

src/components/LHNOptionsList/OptionRowLHNData.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ function OptionRowLHNData({
9090
{...propsToForward}
9191
isFocused={isReportFocused}
9292
optionItem={optionItem}
93+
report={fullReport}
9394
/>
9495
);
9596
}

src/components/LHNOptionsList/types.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
55
import type {ValueOf} from 'type-fest';
66
import type CONST from '@src/CONST';
77
import type {OptionData} from '@src/libs/ReportUtils';
8-
import type {Locale, PersonalDetailsList, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
8+
import type {Locale, OnboardingPurpose, PersonalDetailsList, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
99
import type {ReportAttributes} from '@src/types/onyx/DerivedValues';
1010

1111
type OptionMode = ValueOf<typeof CONST.OPTION_MODE>;
@@ -17,7 +17,7 @@ type CustomLHNOptionsListProps = {
1717
/** Extra styles for the section list container */
1818
contentContainerStyles?: StyleProp<ContentStyle>;
1919

20-
/** Sections for the section list */
20+
/** List of reports */
2121
data: Report[];
2222

2323
/** Callback to fire when a row is selected */
@@ -81,6 +81,17 @@ type OptionRowLHNDataProps = {
8181
/** Array of report actions for this report */
8282
reportActions: OnyxEntry<ReportActions>;
8383

84+
/** The active policy ID */
85+
activePolicyID?: string;
86+
87+
/** The onboarding purpose */
88+
onboardingPurpose?: OnboardingPurpose;
89+
90+
/** Whether the fullscreen is visible */
91+
isFullscreenVisible?: boolean;
92+
93+
isReportsSplitNavigatorLast: boolean;
94+
8495
/**
8596
* Array of report actions for the IOU report related to the last action of this report.
8697
* If the last action is a report action preview, the last message of the report depends on
@@ -115,6 +126,9 @@ type OptionRowLHNProps = {
115126
/** The ID of the report that the option is for */
116127
reportID: string;
117128

129+
/** The report for this option */
130+
report?: Report;
131+
118132
/** Whether this option is currently in focus so we can modify its style */
119133
isFocused?: boolean;
120134

@@ -130,6 +144,17 @@ type OptionRowLHNProps = {
130144
/** The item that should be rendered */
131145
optionItem?: OptionData;
132146

147+
/** The active policy ID */
148+
activePolicyID?: string;
149+
150+
/** The onboarding purpose */
151+
onboardingPurpose?: OnboardingPurpose;
152+
153+
/** Whether the fullscreen is visible */
154+
isFullscreenVisible?: boolean;
155+
156+
isReportsSplitNavigatorLast: boolean;
157+
133158
/** Whether a report contains a draft */
134159
hasDraftComment: boolean;
135160

0 commit comments

Comments
 (0)