Skip to content

Fix Changed File ESLint for #11685 #55697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor Author

@srikarparsi srikarparsi Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used undefined here since that is what is done in this example

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see the same pattern where you have linked, can you please cross-check and confirm if you have linked correctly?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see you doing the same for line 121? Is that because reportaction can be undefined but same is not true for report?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that looks good to me. 👍


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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used CONST.DEFAULT_NUMBER_ID here since that is what is done here

: 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
Loading