Skip to content

Commit bcdb515

Browse files
authored
Merge pull request Expensify#87849 from software-mansion-labs/perf/raise-billing-grace-period-use-onyx-followup
[No QA] perf: Raise BillingGracePeriodEnds subscriptions out of list items v2
2 parents 0df6b7a + e6d2a1b commit bcdb515

4 files changed

Lines changed: 48 additions & 56 deletions

File tree

src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, {useMemo} from 'react';
22
import type {ColorValue} from 'react-native';
33
import {View} from 'react-native';
4-
import type {OnyxEntry} from 'react-native-onyx';
54
import Checkbox from '@components/Checkbox';
65
import {useDelegateNoAccessActions, useDelegateNoAccessState} from '@components/DelegateNoAccessModalProvider';
76
import Icon from '@components/Icon';
@@ -19,13 +18,13 @@ import {handleActionButtonPress} from '@userActions/Search';
1918
import CONST from '@src/CONST';
2019
import ONYXKEYS from '@src/ONYXKEYS';
2120
import {isActionLoadingSelector} from '@src/selectors/ReportMetaData';
22-
import type {LastPaymentMethod, Policy, Report} from '@src/types/onyx';
21+
import type {Policy, Report} from '@src/types/onyx';
2322
import ActionCell from './ActionCell';
2423
import TotalCell from './TotalCell';
25-
import type {TransactionReportGroupListItemType} from './types';
24+
import type {SearchListActionProps, TransactionReportGroupListItemType} from './types';
2625
import UserInfoAndActionButtonRow from './UserInfoAndActionButtonRow';
2726

28-
type ReportListItemHeaderProps<TItem extends ListItem> = {
27+
type ReportListItemHeaderProps<TItem extends ListItem> = SearchListActionProps & {
2928
/** The report currently being looked at */
3029
report: TransactionReportGroupListItemType;
3130

@@ -58,12 +57,6 @@ type ReportListItemHeaderProps<TItem extends ListItem> = {
5857

5958
/** Whether the item is hovered */
6059
isHovered?: boolean;
61-
62-
/** The last payment method used per policy */
63-
lastPaymentMethod?: OnyxEntry<LastPaymentMethod>;
64-
65-
/** The user's personal policy ID */
66-
personalPolicyID?: string;
6760
};
6861

6962
type FirstRowReportHeaderProps<TItem extends ListItem> = {
@@ -210,13 +203,14 @@ function ReportListItemHeader<TItem extends ListItem>({
210203
isHovered,
211204
lastPaymentMethod,
212205
personalPolicyID,
206+
userBillingGracePeriodEnds,
207+
ownerBillingGracePeriodEnd,
213208
}: ReportListItemHeaderProps<TItem>) {
214209
const StyleUtils = useStyleUtils();
215210
const styles = useThemeStyles();
216211
const theme = useTheme();
217212
const {currentSearchHash, currentSearchKey, currentSearchResults: snapshot} = useSearchStateContext();
218213
const {isLargeScreenWidth, shouldUseNarrowLayout} = useResponsiveLayout();
219-
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
220214
const thereIsFromAndTo = !!reportItem?.from && !!reportItem?.to;
221215
const showUserInfo = (reportItem.type === CONST.REPORT.TYPE.IOU && thereIsFromAndTo) || (reportItem.type === CONST.REPORT.TYPE.EXPENSE && !!reportItem?.from);
222216
const snapshotReport = useMemo(() => {
@@ -227,7 +221,6 @@ function ReportListItemHeader<TItem extends ListItem>({
227221
}, [snapshot, reportItem.policyID]);
228222
const {isDelegateAccessRestricted} = useDelegateNoAccessState();
229223
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
230-
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
231224
const avatarBorderColor =
232225
StyleUtils.getItemBackgroundColorStyle(!!reportItem.isSelected, !!isFocused || !!isHovered, !!isDisabled, theme.activeComponentBG, theme.hoverComponentBG)?.backgroundColor ??
233226
theme.highlightBG;

src/components/Search/SearchList/ListItem/TransactionGroupListItem.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ function TransactionGroupListItem<TItem extends ListItem>({
8080
personalPolicyID,
8181
isFirstItem,
8282
isLastItem,
83+
userBillingGracePeriodEnds,
84+
ownerBillingGracePeriodEnd,
8385
}: TransactionGroupListItemProps<TItem>) {
8486
const groupItem = item as unknown as TransactionGroupListItemType;
8587

@@ -452,6 +454,8 @@ function TransactionGroupListItem<TItem extends ListItem>({
452454
personalPolicyID={personalPolicyID}
453455
onDownArrowClick={onExpandIconPress}
454456
isExpanded={isExpanded}
457+
userBillingGracePeriodEnds={userBillingGracePeriodEnds}
458+
ownerBillingGracePeriodEnd={ownerBillingGracePeriodEnd}
455459
/>
456460
);
457461
}

src/components/Search/SearchList/ListItem/TransactionListItem.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ function TransactionListItem<TItem extends ListItem>({
5656
lastPaymentMethod,
5757
personalPolicyID,
5858
isLastItem,
59+
userBillingGracePeriodEnds,
60+
ownerBillingGracePeriodEnd,
5961
}: TransactionListItemProps<TItem>) {
6062
const transactionItem = item as unknown as TransactionListItemType;
6163
const styles = useThemeStyles();
@@ -66,13 +68,11 @@ function TransactionListItem<TItem extends ListItem>({
6668
const {currentSearchHash, currentSearchKey, currentSearchResults} = useSearchStateContext();
6769
const snapshotReport = (currentSearchResults?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${transactionItem.reportID}`] ?? {}) as Report;
6870

69-
const [userBillingGracePeriodEnds] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_USER_BILLING_GRACE_PERIOD_END);
7071
const [isActionLoading] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${transactionItem.reportID}`, {selector: isActionLoadingSelector});
7172

7273
// Use active policy (user's current workspace) as fallback for self DM tracking expenses
7374
// This matches MoneyRequestView's approach via usePolicyForMovingExpenses()
7475
const [activePolicyID] = useOnyx(ONYXKEYS.NVP_ACTIVE_POLICY_ID);
75-
const [ownerBillingGracePeriodEnd] = useOnyx(ONYXKEYS.NVP_PRIVATE_OWNER_BILLING_GRACE_PERIOD_END);
7676

7777
// Use report's policyID as fallback when transaction doesn't have policyID directly
7878
// Use active policy as final fallback for SelfDM (tracking expenses)

src/components/Search/SearchList/ListItem/types.ts

Lines changed: 37 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ import type {
3535
} from '@src/types/onyx/SearchResults';
3636
import type Transaction from '@src/types/onyx/Transaction';
3737

38+
type SearchListActionProps = {
39+
/** The last payment method used per policy */
40+
lastPaymentMethod?: OnyxEntry<LastPaymentMethod>;
41+
/** The user's personal policy ID */
42+
personalPolicyID?: string;
43+
/** Billing grace period end dates for workspace owners (shared across all list items) */
44+
userBillingGracePeriodEnds?: OnyxCollection<BillingGraceEndPeriod>;
45+
/** The workspace owner's billing grace period end date */
46+
ownerBillingGracePeriodEnd?: OnyxEntry<number>;
47+
};
48+
3849
type ChatListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {
3950
queryJSONHash?: number;
4051

@@ -54,25 +65,14 @@ type ChatListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {
5465
userBillingFundID: number | undefined;
5566
};
5667

57-
type ExpenseReportListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {
58-
/** The visible columns for the report */
59-
columns?: SearchColumnType[];
60-
61-
/** Whether the item's action is loading */
62-
isLoading?: boolean;
63-
64-
/** The last payment method used per policy */
65-
lastPaymentMethod?: OnyxEntry<LastPaymentMethod>;
66-
67-
/** The user's personal policy ID */
68-
personalPolicyID?: string;
69-
70-
/** Billing grace period end dates for workspace owners (shared across all list items) */
71-
userBillingGracePeriodEnds?: OnyxCollection<BillingGraceEndPeriod>;
68+
type ExpenseReportListItemProps<TItem extends ListItem> = ListItemProps<TItem> &
69+
SearchListActionProps & {
70+
/** The visible columns for the report */
71+
columns?: SearchColumnType[];
7272

73-
/** The workspace owner's billing grace period end date */
74-
ownerBillingGracePeriodEnd?: OnyxEntry<number>;
75-
};
73+
/** Whether the item's action is loading */
74+
isLoading?: boolean;
75+
};
7676

7777
type TransactionListItemType = ListItem &
7878
Transaction & {
@@ -417,31 +417,25 @@ type TransactionQuarterGroupListItemType = TransactionGroupListItemType & {group
417417
sortKey: number;
418418
};
419419

420-
type TransactionListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {
421-
/** Whether the item's action is loading */
422-
isLoading?: boolean;
423-
columns?: SearchColumnType[];
424-
violations?: Record<string, TransactionViolations | undefined> | undefined;
425-
customCardNames?: Record<number, string>;
426-
/** The last payment method used per policy */
427-
lastPaymentMethod?: OnyxEntry<LastPaymentMethod>;
428-
/** The user's personal policy ID */
429-
personalPolicyID?: string;
430-
};
420+
type TransactionListItemProps<TItem extends ListItem> = ListItemProps<TItem> &
421+
SearchListActionProps & {
422+
/** Whether the item's action is loading */
423+
isLoading?: boolean;
424+
columns?: SearchColumnType[];
425+
violations?: Record<string, TransactionViolations | undefined> | undefined;
426+
customCardNames?: Record<number, string>;
427+
};
431428

432-
type TransactionGroupListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {
433-
groupBy?: SearchGroupBy;
434-
searchType?: SearchDataTypes;
435-
policies?: OnyxCollection<Policy>;
436-
accountID?: number;
437-
columns?: SearchColumnType[];
438-
newTransactionID?: string;
439-
violations?: Record<string, TransactionViolations | undefined> | undefined;
440-
/** The last payment method used per policy */
441-
lastPaymentMethod?: OnyxEntry<LastPaymentMethod>;
442-
/** The user's personal policy ID */
443-
personalPolicyID?: string;
444-
};
429+
type TransactionGroupListItemProps<TItem extends ListItem> = ListItemProps<TItem> &
430+
SearchListActionProps & {
431+
groupBy?: SearchGroupBy;
432+
searchType?: SearchDataTypes;
433+
policies?: OnyxCollection<Policy>;
434+
accountID?: number;
435+
columns?: SearchColumnType[];
436+
newTransactionID?: string;
437+
violations?: Record<string, TransactionViolations | undefined> | undefined;
438+
};
445439

446440
type TransactionGroupListExpandedProps<TItem extends ListItem> = Pick<
447441
TransactionGroupListItemProps<TItem>,
@@ -467,6 +461,7 @@ type UnreportedExpenseListItemType = Transaction & {
467461
};
468462

469463
export type {
464+
SearchListActionProps,
470465
ChatListItemProps,
471466
ExpenseReportListItemProps,
472467
TransactionReportGroupListItemType,

0 commit comments

Comments
 (0)