Skip to content

Commit aa849f1

Browse files
authored
Merge pull request Expensify#55697 from Expensify/srikar-someESLint
Fix Changed File ESLint for Expensify#11685
2 parents 2c846db + c8df75f commit aa849f1

11 files changed

+252
-219
lines changed

src/components/LHNOptionsList/LHNOptionsList.tsx

+17-19
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import usePrevious from '@hooks/usePrevious';
1616
import useResponsiveLayout from '@hooks/useResponsiveLayout';
1717
import useTheme from '@hooks/useTheme';
1818
import useThemeStyles from '@hooks/useThemeStyles';
19-
import * as DraftCommentUtils from '@libs/DraftCommentUtils';
20-
import * as OptionsListUtils from '@libs/OptionsListUtils';
21-
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
22-
import * as ReportUtils from '@libs/ReportUtils';
19+
import {isValidDraftComment} from '@libs/DraftCommentUtils';
20+
import {getIOUReportIDOfLastAction, getLastMessageTextForReport} from '@libs/OptionsListUtils';
21+
import {getOriginalMessage, getSortedReportActionsForDisplay, isMoneyRequestAction} from '@libs/ReportActionsUtils';
22+
import {canUserPerformWriteAction} from '@libs/ReportUtils';
2323
import variables from '@styles/variables';
2424
import CONST from '@src/CONST';
2525
import ONYXKEYS from '@src/ONYXKEYS';
@@ -118,11 +118,11 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
118118
const renderItem = useCallback(
119119
({item: reportID}: RenderItemProps): ReactElement => {
120120
const itemFullReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
121-
const itemParentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${itemFullReport?.parentReportID ?? '-1'}`];
121+
const itemParentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${itemFullReport?.parentReportID}`];
122122
const itemReportNameValuePairs = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
123123
const itemReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
124124
const itemParentReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${itemFullReport?.parentReportID}`];
125-
const itemParentReportAction = itemParentReportActions?.[itemFullReport?.parentReportActionID ?? '-1'];
125+
const itemParentReportAction = itemFullReport?.parentReportActionID ? itemParentReportActions?.[itemFullReport?.parentReportActionID] : undefined;
126126

127127
let invoiceReceiverPolicyID = '-1';
128128
if (itemFullReport?.invoiceReceiver && 'policyID' in itemFullReport.invoiceReceiver) {
@@ -133,26 +133,24 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
133133
}
134134
const itemInvoiceReceiverPolicy = policy?.[`${ONYXKEYS.COLLECTION.POLICY}${invoiceReceiverPolicyID}`];
135135

136-
const iouReportIDOfLastAction = OptionsListUtils.getIOUReportIDOfLastAction(itemFullReport);
136+
const iouReportIDOfLastAction = getIOUReportIDOfLastAction(itemFullReport);
137137
const itemIouReportReportActions = iouReportIDOfLastAction ? reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReportIDOfLastAction}`] : undefined;
138138

139139
const itemPolicy = policy?.[`${ONYXKEYS.COLLECTION.POLICY}${itemFullReport?.policyID}`];
140-
const transactionID = ReportActionsUtils.isMoneyRequestAction(itemParentReportAction)
141-
? ReportActionsUtils.getOriginalMessage(itemParentReportAction)?.IOUTransactionID ?? '-1'
142-
: '-1';
140+
const transactionID = isMoneyRequestAction(itemParentReportAction)
141+
? getOriginalMessage(itemParentReportAction)?.IOUTransactionID ?? CONST.DEFAULT_NUMBER_ID
142+
: CONST.DEFAULT_NUMBER_ID;
143143
const itemTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionID}`];
144-
const hasDraftComment = DraftCommentUtils.isValidDraftComment(draftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`]);
144+
const hasDraftComment = isValidDraftComment(draftComments?.[`${ONYXKEYS.COLLECTION.REPORT_DRAFT_COMMENT}${reportID}`]);
145145

146-
const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(itemFullReport);
147-
const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(itemReportActions, canUserPerformWriteAction);
146+
const canUserPerformWrite = canUserPerformWriteAction(itemFullReport);
147+
const sortedReportActions = getSortedReportActionsForDisplay(itemReportActions, canUserPerformWrite);
148148
const lastReportAction = sortedReportActions.at(0);
149149

150150
// Get the transaction for the last report action
151-
let lastReportActionTransactionID = '';
152-
153-
if (ReportActionsUtils.isMoneyRequestAction(lastReportAction)) {
154-
lastReportActionTransactionID = ReportActionsUtils.getOriginalMessage(lastReportAction)?.IOUTransactionID ?? '-1';
155-
}
151+
const lastReportActionTransactionID = isMoneyRequestAction(lastReportAction)
152+
? getOriginalMessage(lastReportAction)?.IOUTransactionID ?? CONST.DEFAULT_NUMBER_ID
153+
: CONST.DEFAULT_NUMBER_ID;
156154
const lastReportActionTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${lastReportActionTransactionID}`];
157155

158156
// SidebarUtils.getOptionData in OptionRowLHNData does not get re-evaluated when the linked task report changes, so we have the lastMessageTextFromReport evaluation logic here
@@ -167,7 +165,7 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
167165
}
168166
: null;
169167
}
170-
const lastMessageTextFromReport = OptionsListUtils.getLastMessageTextForReport(itemFullReport, lastActorDetails, itemPolicy);
168+
const lastMessageTextFromReport = getLastMessageTextForReport(itemFullReport, lastActorDetails, itemPolicy);
171169

172170
return (
173171
<OptionRowLHNData

src/components/LHNOptionsList/OptionRowLHNData.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import {deepEqual} from 'fast-equals';
22
import React, {useMemo, useRef} from 'react';
33
import useCurrentReportID from '@hooks/useCurrentReportID';
4-
import * as ReportUtils from '@libs/ReportUtils';
54
import SidebarUtils from '@libs/SidebarUtils';
65
import CONST from '@src/CONST';
76
import type {OptionData} from '@src/libs/ReportUtils';
7+
import {hasReportViolations, isReportOwner, isSettled, shouldDisplayViolationsRBRInLHN} from '@src/libs/ReportUtils';
88
import OptionRowLHN from './OptionRowLHN';
99
import type {OptionRowLHNDataProps} from './types';
1010

@@ -38,9 +38,9 @@ function OptionRowLHNData({
3838

3939
const optionItemRef = useRef<OptionData>();
4040

41-
const shouldDisplayViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(fullReport, transactionViolations);
42-
const isSettled = ReportUtils.isSettled(fullReport);
43-
const shouldDisplayReportViolations = !isSettled && ReportUtils.isReportOwner(fullReport) && ReportUtils.hasReportViolations(reportID);
41+
const shouldDisplayViolations = shouldDisplayViolationsRBRInLHN(fullReport, transactionViolations);
42+
const isReportSettled = isSettled(fullReport);
43+
const shouldDisplayReportViolations = !isReportSettled && isReportOwner(fullReport) && hasReportViolations(reportID);
4444

4545
const optionItem = useMemo(() => {
4646
// Note: ideally we'd have this as a dependent selector in onyx!

src/components/OptionListContextProvider.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, {createContext, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
22
import {useOnyx} from 'react-native-onyx';
33
import usePrevious from '@hooks/usePrevious';
4-
import * as OptionsListUtils from '@libs/OptionsListUtils';
5-
import type {OptionList} from '@libs/OptionsListUtils';
6-
import * as ReportUtils from '@libs/ReportUtils';
4+
import {createOptionFromReport, createOptionList} from '@libs/OptionsListUtils';
5+
import type {OptionList, SearchOption} from '@libs/OptionsListUtils';
6+
import {isSelfDM} from '@libs/ReportUtils';
77
import ONYXKEYS from '@src/ONYXKEYS';
88
import type {PersonalDetails, Report} from '@src/types/onyx';
99
import {usePersonalDetails} from './OnyxProvider';
@@ -62,7 +62,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
6262
return;
6363
}
6464
// Since reports updates can happen in bulk, and some reports depend on other reports, we need to recreate the whole list from scratch.
65-
const newReports = OptionsListUtils.createOptionList(personalDetails, reports).reports;
65+
const newReports = createOptionList(personalDetails, reports).reports;
6666

6767
setOptions((prevOptions) => {
6868
const newOptions = {
@@ -90,7 +90,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
9090

9191
const newReportOptions: Array<{
9292
replaceIndex: number;
93-
newReportOption: OptionsListUtils.SearchOption<Report>;
93+
newReportOption: SearchOption<Report>;
9494
}> = [];
9595

9696
Object.keys(personalDetails).forEach((accountID) => {
@@ -102,12 +102,12 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
102102
}
103103

104104
Object.values(reports ?? {})
105-
.filter((report) => !!Object.keys(report?.participants ?? {}).includes(accountID) || (ReportUtils.isSelfDM(report) && report?.ownerAccountID === Number(accountID)))
105+
.filter((report) => !!Object.keys(report?.participants ?? {}).includes(accountID) || (isSelfDM(report) && report?.ownerAccountID === Number(accountID)))
106106
.forEach((report) => {
107107
if (!report) {
108108
return;
109109
}
110-
const newReportOption = OptionsListUtils.createOptionFromReport(report, personalDetails);
110+
const newReportOption = createOptionFromReport(report, personalDetails);
111111
const replaceIndex = options.reports.findIndex((option) => option.reportID === report.reportID);
112112
newReportOptions.push({
113113
newReportOption,
@@ -117,7 +117,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
117117
});
118118

119119
// since personal details are not a collection, we need to recreate the whole list from scratch
120-
const newPersonalDetailsOptions = OptionsListUtils.createOptionList(personalDetails).personalDetails;
120+
const newPersonalDetailsOptions = createOptionList(personalDetails).personalDetails;
121121

122122
setOptions((prevOptions) => {
123123
const newOptions = {...prevOptions};
@@ -131,7 +131,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
131131
}, [personalDetails]);
132132

133133
const loadOptions = useCallback(() => {
134-
const optionLists = OptionsListUtils.createOptionList(personalDetails, reports);
134+
const optionLists = createOptionList(personalDetails, reports);
135135
setOptions({
136136
reports: optionLists.reports,
137137
personalDetails: optionLists.personalDetails,

src/libs/DebugUtils.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import CONST from '@src/CONST';
99
import type {TranslationPaths} from '@src/languages/types';
1010
import ONYXKEYS from '@src/ONYXKEYS';
1111
import type {Beta, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
12-
import * as ReportActionsUtils from './ReportActionsUtils';
13-
import * as ReportUtils from './ReportUtils';
12+
import {getLinkedTransactionID} from './ReportActionsUtils';
13+
import {getReasonAndReportActionThatRequiresAttention, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils';
1414
import SidebarUtils from './SidebarUtils';
15-
import * as TransactionUtils from './TransactionUtils';
15+
import {getTransactionID as TransactionUtilsGetTransactionID} from './TransactionUtils';
1616

1717
class NumberError extends SyntaxError {
1818
constructor() {
@@ -1299,9 +1299,9 @@ function getReasonForShowingRowInLHN(report: OnyxEntry<Report>, hasRBR = false):
12991299
return null;
13001300
}
13011301

1302-
const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations);
1302+
const doesReportHaveViolations = shouldDisplayViolationsRBRInLHN(report, transactionViolations);
13031303

1304-
const reason = ReportUtils.reasonForReportToBeInOptionList({
1304+
const reason = reasonForReportToBeInOptionList({
13051305
report,
13061306
// We can't pass report.reportID because it will cause reason to always be isFocused
13071307
currentReportId: '-1',
@@ -1339,7 +1339,7 @@ function getReasonAndReportActionForGBRInLHNRow(report: OnyxEntry<Report>): GBRR
13391339
return null;
13401340
}
13411341

1342-
const {reason, reportAction} = ReportUtils.getReasonAndReportActionThatRequiresAttention(report) ?? {};
1342+
const {reason, reportAction} = getReasonAndReportActionThatRequiresAttention(report) ?? {};
13431343

13441344
if (reason) {
13451345
return {reason: `debug.reasonGBR.${reason}`, reportAction};
@@ -1367,12 +1367,12 @@ function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: O
13671367
}
13681368

13691369
function getTransactionID(report: OnyxEntry<Report>, reportActions: OnyxEntry<ReportActions>) {
1370-
const transactionID = TransactionUtils.getTransactionID(report?.reportID);
1370+
const transactionID = TransactionUtilsGetTransactionID(report?.reportID);
13711371

13721372
return Number(transactionID) > 0
13731373
? transactionID
13741374
: Object.values(reportActions ?? {})
1375-
.map((reportAction) => ReportActionsUtils.getLinkedTransactionID(reportAction))
1375+
.map((reportAction) => getLinkedTransactionID(reportAction))
13761376
.find(Boolean);
13771377
}
13781378

0 commit comments

Comments
 (0)