Skip to content

Commit 0d82803

Browse files
authored
Merge pull request Expensify#85309 from callstack-internal/perf/waterim/scope-report_attr
perf: Scope REPORT_ATTRIBUTES subscription to per-row level in LHNOptionsList
2 parents dc5b94b + 027e8c7 commit 0d82803

3 files changed

Lines changed: 16 additions & 22 deletions

File tree

src/components/LHNOptionsList/LHNOptionsList.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,9 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
163163
const renderItem = useCallback(
164164
({item, index}: RenderItemProps): ReactElement => {
165165
const reportID = item.reportID;
166-
const itemReportAttributes = reportAttributes?.[reportID];
167166
const itemParentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${item.parentReportID}`];
168167
const itemReportNameValuePairs = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
169168
const itemReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
170-
const itemOneTransactionThreadReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${itemReportAttributes?.oneTransactionThreadReportID}`];
171169
const itemParentReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${item?.parentReportID}`];
172170
const itemParentReportAction = item?.parentReportActionID ? itemParentReportActions?.[item?.parentReportActionID] : undefined;
173171

@@ -197,7 +195,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
197195
canUserPerformWrite,
198196
reportActions,
199197
visibleReportActionsData,
200-
itemOneTransactionThreadReport?.reportID,
198+
reportAttributes?.[reportID]?.oneTransactionThreadReportID,
201199
);
202200

203201
const iouReportIDOfLastAction = getIOUReportIDOfLastAction(item, itemReportNameValuePairs?.private_isArchived, visibleReportActionsData, lastAction);
@@ -226,9 +224,6 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
226224
<OptionRowLHNData
227225
reportID={reportID}
228226
fullReport={item}
229-
reportAttributes={itemReportAttributes}
230-
reportAttributesDerived={reportAttributes}
231-
oneTransactionThreadReport={itemOneTransactionThreadReport}
232227
reportNameValuePairs={itemReportNameValuePairs}
233228
reportActions={itemReportActions}
234229
parentReportAction={itemParentReportAction}
@@ -296,7 +291,6 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
296291
() => [
297292
reportActions,
298293
reports,
299-
reportAttributes,
300294
reportNameValuePairs,
301295
transactionViolations,
302296
policy,
@@ -314,7 +308,6 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
314308
[
315309
reportActions,
316310
reports,
317-
reportAttributes,
318311
reportNameValuePairs,
319312
transactionViolations,
320313
policy,

src/components/LHNOptionsList/OptionRowLHNData.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {deepEqual} from 'fast-equals';
2-
import React, {useMemo, useRef} from 'react';
2+
import React, {useCallback, useMemo, useRef} from 'react';
33
import useReportPreviewSenderID from '@components/ReportActionAvatars/useReportPreviewSenderID';
44
import {useCurrentReportIDState} from '@hooks/useCurrentReportID';
55
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
@@ -12,6 +12,7 @@ import CONST from '@src/CONST';
1212
import {getMovedReportID} from '@src/libs/ModifiedExpenseMessage';
1313
import type {OptionData} from '@src/libs/ReportUtils';
1414
import ONYXKEYS from '@src/ONYXKEYS';
15+
import type {ReportAttributesDerivedValue} from '@src/types/onyx/DerivedValues';
1516
import type {Icon} from '@src/types/onyx/OnyxCommon';
1617
import OptionRowLHN from './OptionRowLHN';
1718
import type {OptionRowLHNDataProps} from './types';
@@ -25,9 +26,6 @@ import type {OptionRowLHNDataProps} from './types';
2526
function OptionRowLHNData({
2627
isOptionFocused = false,
2728
fullReport,
28-
reportAttributes,
29-
reportAttributesDerived,
30-
oneTransactionThreadReport,
3129
reportNameValuePairs,
3230
reportActions,
3331
personalDetails = {},
@@ -53,6 +51,12 @@ function OptionRowLHNData({
5351
const isReportFocused = isOptionFocused && currentReportIDValue === reportID;
5452
const optionItemRef = useRef<OptionData | undefined>(undefined);
5553

54+
const reportAttributesSelector = useCallback((data: ReportAttributesDerivedValue | undefined) => data?.reports?.[reportID], [reportID]);
55+
const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {selector: reportAttributesSelector});
56+
57+
// Look up the one-transaction thread report using the ID from our own attributes.
58+
const [oneTransactionThreadReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(reportAttributes?.oneTransactionThreadReportID)}`);
59+
5660
const [movedFromReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(lastAction, CONST.REPORT.MOVE_TYPE.FROM)}`);
5761
const [movedToReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getMovedReportID(lastAction, CONST.REPORT.MOVE_TYPE.TO)}`);
5862
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
@@ -72,6 +76,13 @@ function OptionRowLHNData({
7276
chatReport: chatReportForIOU,
7377
});
7478

79+
const reportAttributesDerived = useMemo(() => {
80+
if (!reportAttributes) {
81+
return undefined;
82+
}
83+
return {[reportID]: reportAttributes} as ReportAttributesDerivedValue['reports'];
84+
}, [reportID, reportAttributes]);
85+
7586
const optionItem = useMemo(() => {
7687
// Note: ideally we'd have this as a dependent selector in onyx!
7788
const item = SidebarUtils.getOptionData({

src/components/LHNOptionsList/types.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import type {
1818
Transaction,
1919
TransactionViolation,
2020
} from '@src/types/onyx';
21-
import type {ReportAttributes, ReportAttributesDerivedValue} from '@src/types/onyx/DerivedValues';
2221

2322
type OptionMode = ValueOf<typeof CONST.OPTION_MODE>;
2423

@@ -75,9 +74,6 @@ type OptionRowLHNDataProps = {
7574
/** The full data of the report */
7675
fullReport: OnyxEntry<Report>;
7776

78-
/** The transaction thread report associated with the current report, if any */
79-
oneTransactionThreadReport: OnyxEntry<Report>;
80-
8177
/** Array of report name value pairs for this report */
8278
reportNameValuePairs: OnyxEntry<ReportNameValuePairs>;
8379

@@ -128,12 +124,6 @@ type OptionRowLHNDataProps = {
128124
/** Callback to execute when the OptionList lays out */
129125
onLayout?: (event: LayoutChangeEvent) => void;
130126

131-
/** The report attributes for the report */
132-
reportAttributes: OnyxEntry<ReportAttributes>;
133-
134-
/** The derived report attributes for all reports */
135-
reportAttributesDerived?: ReportAttributesDerivedValue['reports'];
136-
137127
/** Whether to show the educational tooltip for the GBR or RBR */
138128
shouldShowRBRorGBRTooltip: boolean;
139129

0 commit comments

Comments
 (0)