Skip to content

Commit

Permalink
Merge pull request #55697 from Expensify/srikar-someESLint
Browse files Browse the repository at this point in the history
 Fix Changed File ESLint for #11685
  • Loading branch information
techievivek authored Jan 24, 2025
2 parents 2c846db + c8df75f commit aa849f1
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 219 deletions.
36 changes: 17 additions & 19 deletions src/components/LHNOptionsList/LHNOptionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import usePrevious from '@hooks/usePrevious';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as DraftCommentUtils from '@libs/DraftCommentUtils';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {isValidDraftComment} from '@libs/DraftCommentUtils';
import {getIOUReportIDOfLastAction, getLastMessageTextForReport} from '@libs/OptionsListUtils';
import {getOriginalMessage, getSortedReportActionsForDisplay, isMoneyRequestAction} from '@libs/ReportActionsUtils';
import {canUserPerformWriteAction} from '@libs/ReportUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -118,11 +118,11 @@ function LHNOptionsList({style, contentContainerStyles, data, onSelectRow, optio
const renderItem = useCallback(
({item: reportID}: RenderItemProps): ReactElement => {
const itemFullReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`];
const itemParentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${itemFullReport?.parentReportID ?? '-1'}`];
const itemParentReport = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${itemFullReport?.parentReportID}`];
const itemReportNameValuePairs = reportNameValuePairs?.[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`];
const itemReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`];
const itemParentReportActions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${itemFullReport?.parentReportID}`];
const itemParentReportAction = itemParentReportActions?.[itemFullReport?.parentReportActionID ?? '-1'];
const itemParentReportAction = itemFullReport?.parentReportActionID ? itemParentReportActions?.[itemFullReport?.parentReportActionID] : undefined;

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

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

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

const canUserPerformWriteAction = ReportUtils.canUserPerformWriteAction(itemFullReport);
const sortedReportActions = ReportActionsUtils.getSortedReportActionsForDisplay(itemReportActions, canUserPerformWriteAction);
const canUserPerformWrite = canUserPerformWriteAction(itemFullReport);
const sortedReportActions = getSortedReportActionsForDisplay(itemReportActions, canUserPerformWrite);
const lastReportAction = sortedReportActions.at(0);

// Get the transaction for the last report action
let lastReportActionTransactionID = '';

if (ReportActionsUtils.isMoneyRequestAction(lastReportAction)) {
lastReportActionTransactionID = ReportActionsUtils.getOriginalMessage(lastReportAction)?.IOUTransactionID ?? '-1';
}
const lastReportActionTransactionID = isMoneyRequestAction(lastReportAction)
? getOriginalMessage(lastReportAction)?.IOUTransactionID ?? CONST.DEFAULT_NUMBER_ID
: CONST.DEFAULT_NUMBER_ID;
const lastReportActionTransaction = transactions?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${lastReportActionTransactionID}`];

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

return (
<OptionRowLHNData
Expand Down
8 changes: 4 additions & 4 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {deepEqual} from 'fast-equals';
import React, {useMemo, useRef} from 'react';
import useCurrentReportID from '@hooks/useCurrentReportID';
import * as ReportUtils from '@libs/ReportUtils';
import SidebarUtils from '@libs/SidebarUtils';
import CONST from '@src/CONST';
import type {OptionData} from '@src/libs/ReportUtils';
import {hasReportViolations, isReportOwner, isSettled, shouldDisplayViolationsRBRInLHN} from '@src/libs/ReportUtils';
import OptionRowLHN from './OptionRowLHN';
import type {OptionRowLHNDataProps} from './types';

Expand Down Expand Up @@ -38,9 +38,9 @@ function OptionRowLHNData({

const optionItemRef = useRef<OptionData>();

const shouldDisplayViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(fullReport, transactionViolations);
const isSettled = ReportUtils.isSettled(fullReport);
const shouldDisplayReportViolations = !isSettled && ReportUtils.isReportOwner(fullReport) && ReportUtils.hasReportViolations(reportID);
const shouldDisplayViolations = shouldDisplayViolationsRBRInLHN(fullReport, transactionViolations);
const isReportSettled = isSettled(fullReport);
const shouldDisplayReportViolations = !isReportSettled && isReportOwner(fullReport) && hasReportViolations(reportID);

const optionItem = useMemo(() => {
// Note: ideally we'd have this as a dependent selector in onyx!
Expand Down
18 changes: 9 additions & 9 deletions src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, {createContext, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import usePrevious from '@hooks/usePrevious';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import type {OptionList} from '@libs/OptionsListUtils';
import * as ReportUtils from '@libs/ReportUtils';
import {createOptionFromReport, createOptionList} from '@libs/OptionsListUtils';
import type {OptionList, SearchOption} from '@libs/OptionsListUtils';
import {isSelfDM} from '@libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetails, Report} from '@src/types/onyx';
import {usePersonalDetails} from './OnyxProvider';
Expand Down Expand Up @@ -62,7 +62,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
return;
}
// Since reports updates can happen in bulk, and some reports depend on other reports, we need to recreate the whole list from scratch.
const newReports = OptionsListUtils.createOptionList(personalDetails, reports).reports;
const newReports = createOptionList(personalDetails, reports).reports;

setOptions((prevOptions) => {
const newOptions = {
Expand Down Expand Up @@ -90,7 +90,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {

const newReportOptions: Array<{
replaceIndex: number;
newReportOption: OptionsListUtils.SearchOption<Report>;
newReportOption: SearchOption<Report>;
}> = [];

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

Object.values(reports ?? {})
.filter((report) => !!Object.keys(report?.participants ?? {}).includes(accountID) || (ReportUtils.isSelfDM(report) && report?.ownerAccountID === Number(accountID)))
.filter((report) => !!Object.keys(report?.participants ?? {}).includes(accountID) || (isSelfDM(report) && report?.ownerAccountID === Number(accountID)))
.forEach((report) => {
if (!report) {
return;
}
const newReportOption = OptionsListUtils.createOptionFromReport(report, personalDetails);
const newReportOption = createOptionFromReport(report, personalDetails);
const replaceIndex = options.reports.findIndex((option) => option.reportID === report.reportID);
newReportOptions.push({
newReportOption,
Expand All @@ -117,7 +117,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
});

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

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

const loadOptions = useCallback(() => {
const optionLists = OptionsListUtils.createOptionList(personalDetails, reports);
const optionLists = createOptionList(personalDetails, reports);
setOptions({
reports: optionLists.reports,
personalDetails: optionLists.personalDetails,
Expand Down
16 changes: 8 additions & 8 deletions src/libs/DebugUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import CONST from '@src/CONST';
import type {TranslationPaths} from '@src/languages/types';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Beta, Policy, Report, ReportAction, ReportActions, ReportNameValuePairs, Transaction, TransactionViolation} from '@src/types/onyx';
import * as ReportActionsUtils from './ReportActionsUtils';
import * as ReportUtils from './ReportUtils';
import {getLinkedTransactionID} from './ReportActionsUtils';
import {getReasonAndReportActionThatRequiresAttention, reasonForReportToBeInOptionList, shouldDisplayViolationsRBRInLHN} from './ReportUtils';
import SidebarUtils from './SidebarUtils';
import * as TransactionUtils from './TransactionUtils';
import {getTransactionID as TransactionUtilsGetTransactionID} from './TransactionUtils';

class NumberError extends SyntaxError {
constructor() {
Expand Down Expand Up @@ -1299,9 +1299,9 @@ function getReasonForShowingRowInLHN(report: OnyxEntry<Report>, hasRBR = false):
return null;
}

const doesReportHaveViolations = ReportUtils.shouldDisplayViolationsRBRInLHN(report, transactionViolations);
const doesReportHaveViolations = shouldDisplayViolationsRBRInLHN(report, transactionViolations);

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

const {reason, reportAction} = ReportUtils.getReasonAndReportActionThatRequiresAttention(report) ?? {};
const {reason, reportAction} = getReasonAndReportActionThatRequiresAttention(report) ?? {};

if (reason) {
return {reason: `debug.reasonGBR.${reason}`, reportAction};
Expand Down Expand Up @@ -1367,12 +1367,12 @@ function getReasonAndReportActionForRBRInLHNRow(report: Report, reportActions: O
}

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

return Number(transactionID) > 0
? transactionID
: Object.values(reportActions ?? {})
.map((reportAction) => ReportActionsUtils.getLinkedTransactionID(reportAction))
.map((reportAction) => getLinkedTransactionID(reportAction))
.find(Boolean);
}

Expand Down
Loading

0 comments on commit aa849f1

Please sign in to comment.