Skip to content

Commit aaa856e

Browse files
committed
provide stable selectors for useSidebarOrderedReports
1 parent 470b8ba commit aaa856e

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/hooks/useSidebarOrderedReports.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {deepEqual} from 'fast-equals';
22
import React, {createContext, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
3-
import type {OnyxEntry} from 'react-native-onyx';
3+
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
44
import Log from '@libs/Log';
55
import {getPolicyEmployeeListByIdWithoutCurrentUser} from '@libs/PolicyUtils';
6+
import {reportAttributesSelector} from '@libs/ReportUtils';
67
import SidebarUtils from '@libs/SidebarUtils';
78
import CONST from '@src/CONST';
89
import ONYXKEYS from '@src/ONYXKEYS';
@@ -43,6 +44,8 @@ const policySelector = (policy: OnyxEntry<OnyxTypes.Policy>): PartialPolicyForSi
4344
employeeList: policy.employeeList,
4445
}) as PartialPolicyForSidebar;
4546

47+
const policiesSelector = (policies: OnyxCollection<OnyxTypes.Policy>) => mapOnyxCollectionItems(policies, policySelector);
48+
4649
function SidebarOrderedReportsContextProvider({
4750
children,
4851
/**
@@ -57,13 +60,13 @@ function SidebarOrderedReportsContextProvider({
5760
}: SidebarOrderedReportsContextProviderProps) {
5861
const [priorityMode = CONST.PRIORITY_MODE.DEFAULT] = useOnyx(ONYXKEYS.NVP_PRIORITY_MODE, {canBeMissing: true});
5962
const [chatReports, {sourceValue: reportUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: true});
60-
const [policies, {sourceValue: policiesUpdates}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: (c) => mapOnyxCollectionItems(c, policySelector), canBeMissing: true});
63+
const [policies, {sourceValue: policiesUpdates}] = useOnyx(ONYXKEYS.COLLECTION.POLICY, {selector: policiesSelector, canBeMissing: true});
6164
const [transactions, {sourceValue: transactionsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: true});
6265
const [transactionViolations, {sourceValue: transactionViolationsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS, {canBeMissing: true});
6366
const [reportNameValuePairs, {sourceValue: reportNameValuePairsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS, {canBeMissing: true});
6467
const [, {sourceValue: reportsDraftsUpdates}] = useOnyx(ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT, {canBeMissing: true});
6568
const [betas] = useOnyx(ONYXKEYS.BETAS, {canBeMissing: true});
66-
const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {selector: (value) => value?.reports, canBeMissing: true});
69+
const [reportAttributes] = useOnyx(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, {selector: reportAttributesSelector, canBeMissing: true});
6770
const [currentReportsToDisplay, setCurrentReportsToDisplay] = useState<ReportsToDisplayInLHN>({});
6871

6972
const {shouldUseNarrowLayout} = useResponsiveLayout();

src/libs/ReportUtils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11252,6 +11252,10 @@ function getReportStatusTranslation(stateNum?: number, statusNum?: number): stri
1125211252
return '';
1125311253
}
1125411254

11255+
function reportAttributesSelector(reportAttributes: OnyxEntry<ReportAttributesDerivedValue>) {
11256+
return reportAttributes?.reports;
11257+
}
11258+
1125511259
export {
1125611260
areAllRequestsBeingSmartScanned,
1125711261
buildOptimisticAddCommentReportAction,
@@ -11631,6 +11635,7 @@ export {
1163111635
isWorkspaceTaskReport,
1163211636
isWorkspaceThread,
1163311637
getReportStatusTranslation,
11638+
reportAttributesSelector,
1163411639
};
1163511640

1163611641
export type {

0 commit comments

Comments
 (0)