Skip to content

Commit 50d0332

Browse files
authored
Merge pull request #90876 from parasharrajat/onyx/session-21
[No QA] Update remaining functions to remove use of `getUserAccountID`
2 parents f6d388a + 5b4455f commit 50d0332

15 files changed

Lines changed: 289 additions & 103 deletions

File tree

src/hooks/useSidebarOrderedReports.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function SidebarOrderedReportsContextProvider({
8686
const [currentReportsToDisplay, setCurrentReportsToDisplay] = useState<ReportsToDisplayInLHN>({});
8787
const {shouldUseNarrowLayout} = useResponsiveLayout();
8888
const {isOffline} = useNetwork();
89-
const {accountID} = useCurrentUserPersonalDetails();
89+
const {accountID, login: currentUserLogin} = useCurrentUserPersonalDetails();
9090
const {currentReportID: currentReportIDValue} = useCurrentReportIDState();
9191
const derivedCurrentReportID = currentReportIDForTests ?? currentReportIDValue;
9292
const prevDerivedCurrentReportID = usePrevious(derivedCurrentReportID);
@@ -213,21 +213,25 @@ function SidebarOrderedReportsContextProvider({
213213
draftComments: reportsDrafts,
214214
transactions,
215215
isOffline,
216+
currentUserLogin: currentUserLogin ?? '',
217+
currentUserAccountID: accountID,
216218
});
217219
} else {
218220
Log.info('[useSidebarOrderedReports] building reportsToDisplay from scratch');
219-
reportsToDisplay = SidebarUtils.getReportsToDisplayInLHN(
220-
derivedCurrentReportID,
221-
chatReports,
221+
reportsToDisplay = SidebarUtils.getReportsToDisplayInLHN({
222+
currentReportId: derivedCurrentReportID,
223+
reports: chatReports,
222224
betas,
223225
priorityMode,
224-
reportsDrafts,
226+
draftComments: reportsDrafts,
225227
transactionViolations,
226228
transactions,
227229
isOffline,
230+
currentUserLogin: currentUserLogin ?? '',
231+
currentUserAccountID: accountID,
228232
reportNameValuePairs,
229233
reportAttributes,
230-
);
234+
});
231235
}
232236

233237
return reportsToDisplay;
@@ -245,6 +249,8 @@ function SidebarOrderedReportsContextProvider({
245249
reportsDrafts,
246250
isOffline,
247251
clearCacheDummyCounter,
252+
currentUserLogin,
253+
accountID,
248254
]);
249255

250256
// Derive a stable boolean map indicating which reports have drafts.

src/libs/DebugUtils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,8 @@ function getReasonForShowingRowInLHN({
14161416
isInFocusMode = false,
14171417
betas = undefined,
14181418
draftComment,
1419+
currentUserLogin,
1420+
currentUserAccountID,
14191421
}: {
14201422
report: OnyxEntry<Report>;
14211423
chatReport: OnyxEntry<Report>;
@@ -1425,6 +1427,8 @@ function getReasonForShowingRowInLHN({
14251427
isInFocusMode?: boolean;
14261428
betas?: OnyxEntry<Beta[]>;
14271429
draftComment: string | undefined;
1430+
currentUserLogin?: string;
1431+
currentUserAccountID?: number;
14281432
}): TranslationPaths | null {
14291433
if (!report) {
14301434
return null;
@@ -1442,6 +1446,8 @@ function getReasonForShowingRowInLHN({
14421446
includeSelfDM: true,
14431447
isReportArchived,
14441448
draftComment,
1449+
currentUserLogin,
1450+
currentUserAccountID,
14451451
});
14461452

14471453
if (!([CONST.REPORT_IN_LHN_REASONS.HAS_ADD_WORKSPACE_ROOM_ERRORS, CONST.REPORT_IN_LHN_REASONS.HAS_IOU_VIOLATIONS] as Array<typeof reason>).includes(reason) && hasRBR) {

src/libs/OptionsListUtils/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,6 +2090,7 @@ function isValidReport(option: SearchOption<Report>, policy: OnyxEntry<Policy>,
20902090
isRestrictedToPreferredPolicy,
20912091
preferredPolicyID,
20922092
currentUserAccountID,
2093+
currentUserLogin,
20932094
shouldAlwaysIncludeDM,
20942095
isTimeRequest = false,
20952096
} = config;
@@ -2109,6 +2110,8 @@ function isValidReport(option: SearchOption<Report>, policy: OnyxEntry<Policy>,
21092110
includeDomainEmail,
21102111
isReportArchived: option.private_isArchived,
21112112
draftComment,
2113+
currentUserLogin,
2114+
currentUserAccountID,
21122115
});
21132116

21142117
if (!shouldBeInOptionList) {
@@ -2493,6 +2496,7 @@ function getValidOptions(
24932496
includeDomainEmail,
24942497
loginsToExclude: loginsToExcludeFromSuggestions,
24952498
currentUserAccountID,
2499+
currentUserLogin: currentUserEmail,
24962500
},
24972501
draftComment,
24982502
chatReport,

src/libs/OptionsListUtils/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ type IsValidReportsConfig = Pick<
193193
| 'isTimeRequest'
194194
> & {
195195
currentUserAccountID: number;
196+
currentUserLogin: string;
196197
};
197198

198199
type GetOptionsConfig = {

src/libs/ReportUtils.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ import {isEmptyObject, isEmptyValueObject} from '@src/types/utils/EmptyObject';
8686
import type {EmptyObject} from '@src/types/utils/EmptyObject';
8787
import type IconAsset from '@src/types/utils/IconAsset';
8888
import {getBankAccountFromID} from './actions/BankAccounts';
89-
import {getUserAccountID} from './actions/IOU';
9089
import {unholdRequest} from './actions/IOU/Hold';
9190
import {
9291
createDraftTransaction,
@@ -4322,8 +4321,14 @@ function getReasonAndReportActionThatRequiresAttention(
43224321
* @param option (report or optionItem)
43234322
* @param parentReportAction (the report action the current report is a thread of)
43244323
*/
4325-
function requiresAttentionFromCurrentUser(optionOrReport: OnyxEntry<Report> | OptionData, parentReportAction?: OnyxEntry<ReportAction>, isReportArchived = false) {
4326-
return !!getReasonAndReportActionThatRequiresAttention(optionOrReport, getCurrentUserEmail() ?? '', getUserAccountID(), parentReportAction, isReportArchived);
4324+
function requiresAttentionFromCurrentUser(
4325+
optionOrReport: OnyxEntry<Report> | OptionData,
4326+
currentUserLogin: string,
4327+
currentUserAccountID: number,
4328+
parentReportAction?: OnyxEntry<ReportAction>,
4329+
isReportArchived = false,
4330+
) {
4331+
return !!getReasonAndReportActionThatRequiresAttention(optionOrReport, currentUserLogin, currentUserAccountID, parentReportAction, isReportArchived);
43274332
}
43284333

43294334
/**
@@ -9490,6 +9495,8 @@ type ShouldReportBeInOptionListParams = {
94909495
doesReportHaveViolations: boolean;
94919496
includeSelfDM?: boolean;
94929497
login?: string;
9498+
currentUserLogin?: string;
9499+
currentUserAccountID?: number;
94939500
includeDomainEmail?: boolean;
94949501
isReportArchived: boolean | undefined;
94959502
draftComment: string | undefined;
@@ -9508,6 +9515,8 @@ function reasonForReportToBeInOptionList({
95089515
draftComment,
95099516
includeSelfDM = false,
95109517
login,
9518+
currentUserLogin,
9519+
currentUserAccountID,
95119520
includeDomainEmail = false,
95129521
isReportArchived,
95139522
requiresAttention,
@@ -9591,7 +9600,7 @@ function reasonForReportToBeInOptionList({
95919600
return CONST.REPORT_IN_LHN_REASONS.HAS_DRAFT_COMMENT;
95929601
}
95939602

9594-
if (requiresAttention ?? requiresAttentionFromCurrentUser(report, undefined, isReportArchived)) {
9603+
if (requiresAttention ?? requiresAttentionFromCurrentUser(report, currentUserLogin ?? '', currentUserAccountID ?? CONST.DEFAULT_NUMBER_ID, undefined, isReportArchived)) {
95959604
return CONST.REPORT_IN_LHN_REASONS.HAS_GBR;
95969605
}
95979606

src/libs/SidebarUtils.ts

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ type ShouldDisplayReportInLHNParams = {
274274
isOffline: boolean;
275275
isReportArchived?: boolean;
276276
reportAttributes?: ReportAttributesDerivedValue['reports'];
277+
currentUserLogin: string;
278+
currentUserAccountID: number;
277279
};
278280

279281
function shouldDisplayReportInLHN({
@@ -288,6 +290,8 @@ function shouldDisplayReportInLHN({
288290
isOffline,
289291
isReportArchived,
290292
reportAttributes,
293+
currentUserAccountID,
294+
currentUserLogin,
291295
}: ShouldDisplayReportInLHNParams) {
292296
if (!report) {
293297
return {shouldDisplay: false};
@@ -345,23 +349,40 @@ function shouldDisplayReportInLHN({
345349
includeSelfDM: true,
346350
isReportArchived,
347351
requiresAttention,
352+
currentUserLogin,
353+
currentUserAccountID,
348354
});
349355

350356
return {shouldDisplay};
351357
}
352358

353-
function getReportsToDisplayInLHN(
354-
currentReportId: string | undefined,
355-
reports: OnyxCollection<Report>,
356-
betas: OnyxEntry<Beta[]>,
357-
priorityMode: OnyxEntry<PriorityMode>,
358-
draftComments: OnyxCollection<string>,
359-
transactionViolations: OnyxCollection<TransactionViolation[]>,
360-
transactions: OnyxCollection<Transaction>,
361-
isOffline: boolean,
362-
reportNameValuePairs?: OnyxCollection<ReportNameValuePairs>,
363-
reportAttributes?: ReportAttributesDerivedValue['reports'],
364-
) {
359+
function getReportsToDisplayInLHN({
360+
currentReportId,
361+
reports,
362+
betas,
363+
priorityMode,
364+
draftComments,
365+
transactionViolations,
366+
transactions,
367+
isOffline,
368+
currentUserLogin,
369+
currentUserAccountID,
370+
reportNameValuePairs,
371+
reportAttributes,
372+
}: {
373+
currentReportId: string | undefined;
374+
reports: OnyxCollection<Report>;
375+
betas: OnyxEntry<Beta[]>;
376+
priorityMode: OnyxEntry<PriorityMode>;
377+
draftComments: OnyxCollection<string>;
378+
transactionViolations: OnyxCollection<TransactionViolation[]>;
379+
transactions: OnyxCollection<Transaction>;
380+
isOffline: boolean;
381+
currentUserLogin: string;
382+
currentUserAccountID: number;
383+
reportNameValuePairs?: OnyxCollection<ReportNameValuePairs>;
384+
reportAttributes?: ReportAttributesDerivedValue['reports'];
385+
}) {
365386
const isInFocusMode = priorityMode === CONST.PRIORITY_MODE.GSD;
366387
const allReportsDictValues = reports ?? {};
367388
const reportsToDisplay: ReportsToDisplayInLHN = {};
@@ -385,6 +406,8 @@ function getReportsToDisplayInLHN(
385406
isOffline,
386407
isReportArchived: isArchivedReport(reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`]),
387408
reportAttributes,
409+
currentUserLogin,
410+
currentUserAccountID,
388411
});
389412

390413
if (shouldDisplay) {
@@ -410,6 +433,8 @@ type UpdateReportsToDisplayInLHNProps = {
410433
draftComments: OnyxCollection<string>;
411434
transactions: OnyxCollection<Transaction>;
412435
isOffline: boolean;
436+
currentUserLogin: string;
437+
currentUserAccountID: number;
413438
};
414439

415440
function updateReportsToDisplayInLHN({
@@ -425,6 +450,8 @@ function updateReportsToDisplayInLHN({
425450
draftComments,
426451
transactions,
427452
isOffline,
453+
currentUserLogin,
454+
currentUserAccountID,
428455
}: UpdateReportsToDisplayInLHNProps) {
429456
// Use a lazy copy to avoid creating a new object reference when no entries actually change.
430457
let displayedReportsCopy: ReportsToDisplayInLHN | undefined;
@@ -460,6 +487,8 @@ function updateReportsToDisplayInLHN({
460487
isOffline,
461488
isReportArchived: isArchivedReport(reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report.reportID}`] ?? {}),
462489
reportAttributes,
490+
currentUserLogin,
491+
currentUserAccountID,
463492
});
464493

465494
if (shouldDisplay) {

src/libs/UnreadIndicatorUpdater/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,20 @@ import * as ReportUtils from '@libs/ReportUtils';
88
import Navigation, {navigationRef} from '@navigation/Navigation';
99
import CONST from '@src/CONST';
1010
import ONYXKEYS from '@src/ONYXKEYS';
11-
import type {Report, ReportActions, ReportNameValuePairs} from '@src/types/onyx';
11+
import type {Report, ReportActions, ReportNameValuePairs, Session} from '@src/types/onyx';
1212
import updateUnread from './updateUnread';
1313

1414
let allReports: OnyxCollection<Report> = {};
15+
let currentUserAccountID: number = CONST.DEFAULT_NUMBER_ID;
16+
let currentUserLogin = '';
17+
18+
Onyx.connectWithoutView({
19+
key: ONYXKEYS.SESSION,
20+
callback: (value: Session | undefined) => {
21+
currentUserAccountID = value?.accountID ?? CONST.DEFAULT_NUMBER_ID;
22+
currentUserLogin = value?.email ?? '';
23+
},
24+
});
1525

1626
let allReportNameValuePairs: OnyxCollection<ReportNameValuePairs> = {};
1727
// This subscription is used to update the unread indicators count which is not linked to UI and it does not update any UI state.
@@ -62,6 +72,8 @@ function getUnreadReportsForUnreadIndicator(reports: OnyxCollection<Report>, cur
6272
excludeEmptyChats: false,
6373
isReportArchived,
6474
draftComment,
75+
currentUserLogin,
76+
currentUserAccountID,
6577
}) &&
6678
/**
6779
* Chats with hidden preference remain invisible in the LHN and are not considered "unread."

src/libs/actions/IOU/MoneyRequestBuilder.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import type ReportAction from '@src/types/onyx/ReportAction';
6666
import type {OnyxData} from '@src/types/onyx/Request';
6767
import type {Receipt, TransactionChanges, TransactionCustomUnit, WaypointCollection} from '@src/types/onyx/Transaction';
6868
import {isEmptyObject} from '@src/types/utils/EmptyObject';
69-
import {getAllPersonalDetails, getAllReportActionsFromIOU, getAllReportNameValuePairs, getAllReports, getCurrentUserPersonalDetails, getUserAccountID} from './index';
69+
import {getAllPersonalDetails, getAllReportActionsFromIOU, getAllReportNameValuePairs, getAllReports, getCurrentUserPersonalDetails} from './index';
7070
import type {ReplaceReceipt} from './Receipt';
7171
import {getSearchOnyxUpdate} from './SearchUpdate';
7272
import type {StartSplitBilActionParams} from './Split';
@@ -261,6 +261,7 @@ type BuildOnyxDataForTestDriveIOUParams = {
261261
iouOptimisticParams: MoneyRequestOptimisticParams['iou'];
262262
chatOptimisticParams: MoneyRequestOptimisticParams['chat'];
263263
testDriveCommentReportActionID?: string;
264+
currentUserAccountIDParam: number;
264265
};
265266

266267
function buildMinimalTransactionForFormula(
@@ -323,8 +324,6 @@ function getReceiptError(
323324
function buildOnyxDataForTestDriveIOU(
324325
testDriveIOUParams: BuildOnyxDataForTestDriveIOUParams,
325326
): OnyxData<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.TRANSACTION_DRAFT> {
326-
const deprecatedUserAccountID = getUserAccountID();
327-
const deprecatedCurrentUserPersonalDetails = getCurrentUserPersonalDetails();
328327
const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT>> = [];
329328
const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT>> = [];
330329
const failureData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.REPORT_ACTIONS | typeof ONYXKEYS.COLLECTION.REPORT | typeof ONYXKEYS.COLLECTION.TRANSACTION_DRAFT>> = [];
@@ -340,11 +339,11 @@ function buildOnyxDataForTestDriveIOU(
340339
transactionID: testDriveIOUParams.transaction.transactionID,
341340
reportActionID: testDriveIOUParams.iouOptimisticParams.action.reportActionID,
342341
});
343-
const text = translateLocal('testDrive.employeeInviteMessage', getAllPersonalDetails()?.[deprecatedUserAccountID]?.firstName ?? '');
342+
const text = translateLocal('testDrive.employeeInviteMessage', getAllPersonalDetails()?.[testDriveIOUParams.currentUserAccountIDParam]?.firstName ?? '');
344343
// delegateAccountIDParam: will be threaded in PR 15; buildOptimisticAddCommentReportAction falls back to module-level Onyx.connect value (https://github.com/Expensify/App/issues/66425)
345344
const textComment = buildOptimisticAddCommentReportAction({
346345
text,
347-
actorAccountID: deprecatedUserAccountID,
346+
actorAccountID: testDriveIOUParams.currentUserAccountIDParam,
348347
reportActionID: testDriveIOUParams.testDriveCommentReportActionID,
349348
delegateAccountIDParam: undefined,
350349
});
@@ -364,7 +363,7 @@ function buildOnyxDataForTestDriveIOU(
364363
value: {
365364
...{lastActionType: CONST.REPORT.ACTIONS.TYPE.MARKED_REIMBURSED, statusNum: CONST.REPORT.STATUS_NUM.REIMBURSED},
366365
hasOutstandingChildRequest: false,
367-
lastActorAccountID: deprecatedCurrentUserPersonalDetails?.accountID,
366+
lastActorAccountID: testDriveIOUParams.currentUserAccountIDParam,
368367
},
369368
},
370369
{
@@ -618,6 +617,7 @@ function buildOnyxDataForMoneyRequest(moneyRequestParams: BuildOnyxDataForMoneyR
618617
iouOptimisticParams: iou,
619618
chatOptimisticParams: chat,
620619
testDriveCommentReportActionID,
620+
currentUserAccountIDParam,
621621
});
622622
onyxData.optimisticData?.push(...testDriveOptimisticData);
623623
onyxData.successData?.push(...testDriveSuccessData);

src/libs/actions/IOU/SearchUpdate.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type * as OnyxTypes from '@src/types/onyx';
1111
import type {Participant} from '@src/types/onyx/IOU';
1212
import type {OnyxData} from '@src/types/onyx/Request';
1313
import type {SearchResultDataType} from '@src/types/onyx/SearchResults';
14-
import {getCurrentUserPersonalDetails, getUserAccountID} from './index';
14+
import {getCurrentUserPersonalDetails} from './index';
1515

1616
type ExpenseReportStatusPredicate = (expenseReport: OnyxEntry<OnyxTypes.Report>, transactionReportID?: string) => boolean;
1717

@@ -44,6 +44,7 @@ function shouldOptimisticallyUpdateSearch(
4444
currentSearchQueryJSON: Readonly<SearchQueryJSON>,
4545
iouReport: OnyxEntry<OnyxTypes.Report>,
4646
isInvoice: boolean | undefined,
47+
currentUserAccountID: number,
4748
transaction?: OnyxEntry<OnyxTypes.Transaction>,
4849
) {
4950
if (
@@ -76,7 +77,7 @@ function shouldOptimisticallyUpdateSearch(
7677
return false;
7778
}
7879

79-
const suggestedSearches = getSuggestedSearches(getUserAccountID());
80+
const suggestedSearches = getSuggestedSearches(currentUserAccountID);
8081
const submitQueryJSON = suggestedSearches[CONST.SEARCH.SEARCH_KEYS.SUBMIT].searchQueryJSON;
8182
const approveQueryJSON = suggestedSearches[CONST.SEARCH.SEARCH_KEYS.APPROVE].searchQueryJSON;
8283
const unapprovedCashSimilarSearchHash = suggestedSearches[CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CASH].similarSearchHash;
@@ -125,7 +126,7 @@ function getSearchOnyxUpdate({
125126
return;
126127
}
127128

128-
if (shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, isInvoice, transaction)) {
129+
if (shouldOptimisticallyUpdateSearch(currentSearchQueryJSON, iouReport, isInvoice, fromAccountID, transaction)) {
129130
const isOptimisticToAccountData = isOptimisticPersonalDetail(toAccountID);
130131
const successData = [];
131132
if (isOptimisticToAccountData) {

0 commit comments

Comments
 (0)