From 6c72ef8f9c3aaf4c312e7fc7b6dd5415e96b52dc Mon Sep 17 00:00:00 2001 From: cdOut <88325488+cdOut@users.noreply.github.com> Date: Wed, 17 Jan 2024 02:23:32 +0100 Subject: [PATCH] remove usage of isNotEmptyObject for in PR related files --- src/libs/ReportUtils.ts | 48 +++++++++++++++++++------------------- src/libs/actions/Policy.ts | 8 +++---- src/libs/actions/Report.ts | 14 +++++------ 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 01e41465f99a..9f833ea5b661 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -23,7 +23,7 @@ import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/Rep import type {Receipt, WaypointCollection} from '@src/types/onyx/Transaction'; import type DeepValueOf from '@src/types/utils/DeepValueOf'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; -import {isEmptyObject, isNotEmptyObject} from '@src/types/utils/EmptyObject'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; import type IconAsset from '@src/types/utils/IconAsset'; import * as CurrencyUtils from './CurrencyUtils'; import DateUtils from './DateUtils'; @@ -479,7 +479,7 @@ function getRootParentReport(report: OnyxEntry | undefined | EmptyObject const parentReport = getReport(report?.parentReportID); // Runs recursion to iterate a parent report - return getRootParentReport(isNotEmptyObject(parentReport) ? parentReport : null); + return getRootParentReport(!isEmptyObject(parentReport) ? parentReport : null); } function getPolicy(policyID: string): Policy | EmptyObject { @@ -566,11 +566,11 @@ function isTaskReport(report: OnyxEntry): boolean { * In this case, we have added the key to the report itself */ function isCanceledTaskReport(report: OnyxEntry | EmptyObject = {}, parentReportAction: OnyxEntry | EmptyObject = {}): boolean { - if (isNotEmptyObject(parentReportAction) && (parentReportAction?.message?.[0]?.isDeletedParentAction ?? false)) { + if (!isEmptyObject(parentReportAction) && (parentReportAction?.message?.[0]?.isDeletedParentAction ?? false)) { return true; } - if (isNotEmptyObject(report) && report?.isDeletedParentAction) { + if (!isEmptyObject(report) && report?.isDeletedParentAction) { return true; } @@ -1034,7 +1034,7 @@ function isExpenseRequest(report: OnyxEntry): boolean { if (isThread(report)) { const parentReportAction = ReportActionsUtils.getParentReportAction(report); const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; - return isExpenseReport(parentReport) && isNotEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction); + return isExpenseReport(parentReport) && !isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction); } return false; } @@ -1047,7 +1047,7 @@ function isIOURequest(report: OnyxEntry): boolean { if (isThread(report)) { const parentReportAction = ReportActionsUtils.getParentReportAction(report); const parentReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`] ?? null; - return isIOUReport(parentReport) && isNotEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction); + return isIOUReport(parentReport) && !isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction); } return false; } @@ -1115,7 +1115,7 @@ function canDeleteReportAction(reportAction: OnyxEntry, reportID: // For now, users cannot delete split actions const isSplitAction = reportAction?.originalMessage?.type === CONST.IOU.REPORT_ACTION_TYPE.SPLIT; - if (isSplitAction || isSettled(String(reportAction?.originalMessage?.IOUReportID)) || (isNotEmptyObject(report) && isReportApproved(report))) { + if (isSplitAction || isSettled(String(reportAction?.originalMessage?.IOUReportID)) || (!isEmptyObject(report) && isReportApproved(report))) { return false; } @@ -1134,7 +1134,7 @@ function canDeleteReportAction(reportAction: OnyxEntry, reportID: } const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; - const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN && isNotEmptyObject(report) && !isDM(report); + const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN && !isEmptyObject(report) && !isDM(report); return isActionOwner || isAdmin; } @@ -1611,7 +1611,7 @@ function getLastVisibleMessage(reportID: string | undefined, actionsToMerge: Rep const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(reportID ?? '', actionsToMerge); // For Chat Report with deleted parent actions, let us fetch the correct message - if (ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && isNotEmptyObject(report) && isChatReport(report)) { + if (ReportActionsUtils.isDeletedParentAction(lastVisibleAction) && !isEmptyObject(report) && isChatReport(report)) { const lastMessageText = getDeletedParentActionMessageForChatReport(lastVisibleAction); return { lastMessageText, @@ -1832,7 +1832,7 @@ function getTransactionDetails(transaction: OnyxEntry, createdDateF const report = getReport(transaction?.reportID); return { created: TransactionUtils.getCreated(transaction, createdDateFormat), - amount: TransactionUtils.getAmount(transaction, isNotEmptyObject(report) && isExpenseReport(report)), + amount: TransactionUtils.getAmount(transaction, !isEmptyObject(report) && isExpenseReport(report)), currency: TransactionUtils.getCurrency(transaction), comment: TransactionUtils.getDescription(transaction), merchant: TransactionUtils.getMerchant(transaction), @@ -2023,7 +2023,7 @@ function getTransactionReportName(reportAction: OnyxEntry): string } const transaction = TransactionUtils.getLinkedTransaction(reportAction); - if (!isNotEmptyObject(transaction)) { + if (!!isEmptyObject(transaction)) { // Transaction data might be empty on app's first load, if so we fallback to Request return Localize.translateLocal('iou.request'); } @@ -2064,14 +2064,14 @@ function getReportPreviewMessage( return reportActionMessage; } - if (isNotEmptyObject(reportAction) && !isIOUReport(report) && reportAction && ReportActionsUtils.isSplitBillAction(reportAction)) { + if (!isEmptyObject(reportAction) && !isIOUReport(report) && reportAction && ReportActionsUtils.isSplitBillAction(reportAction)) { // This covers group chats where the last action is a split bill action const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction); if (isEmptyObject(linkedTransaction)) { return reportActionMessage; } - if (isNotEmptyObject(linkedTransaction)) { + if (!isEmptyObject(linkedTransaction)) { if (TransactionUtils.isReceiptBeingScanned(linkedTransaction)) { return Localize.translateLocal('iou.receiptScanning'); } @@ -2099,10 +2099,10 @@ function getReportPreviewMessage( }); } - if (isNotEmptyObject(reportAction) && shouldConsiderReceiptBeingScanned && reportAction && ReportActionsUtils.isMoneyRequestAction(reportAction)) { + if (!isEmptyObject(reportAction) && shouldConsiderReceiptBeingScanned && reportAction && ReportActionsUtils.isMoneyRequestAction(reportAction)) { const linkedTransaction = TransactionUtils.getLinkedTransaction(reportAction); - if (isNotEmptyObject(linkedTransaction) && TransactionUtils.hasReceipt(linkedTransaction) && TransactionUtils.isReceiptBeingScanned(linkedTransaction)) { + if (!isEmptyObject(linkedTransaction) && TransactionUtils.hasReceipt(linkedTransaction) && TransactionUtils.isReceiptBeingScanned(linkedTransaction)) { return Localize.translateLocal('iou.receiptScanning'); } } @@ -2208,11 +2208,11 @@ function getReportName(report: OnyxEntry, policy: OnyxEntry = nu let formattedName: string | undefined; const parentReportAction = ReportActionsUtils.getParentReportAction(report); if (isChatThread(report)) { - if (isNotEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) { + if (!isEmptyObject(parentReportAction) && ReportActionsUtils.isTransactionThread(parentReportAction)) { return getTransactionReportName(parentReportAction); } - const isAttachment = ReportActionsUtils.isReportActionAttachment(isNotEmptyObject(parentReportAction) ? parentReportAction : null); + const isAttachment = ReportActionsUtils.isReportActionAttachment(!isEmptyObject(parentReportAction) ? parentReportAction : null); const parentReportActionMessage = (parentReportAction?.message?.[0]?.text ?? '').replace(/(\r\n|\n|\r)/gm, ' '); if (isAttachment && parentReportActionMessage) { return `[${Localize.translateLocal('common.attachment')}]`; @@ -2477,11 +2477,11 @@ function updateOptimisticParentReportAction(parentReportAction: OnyxEntry, policies: OnyxCollection, currentReportId: string): boolean { const currentReport = getReport(currentReportId); - const parentReport = getParentReport(isNotEmptyObject(currentReport) ? currentReport : null); + const parentReport = getParentReport(!isEmptyObject(currentReport) ? currentReport : null); const reportActions = ReportActionsUtils.getAllReportActions(report?.reportID ?? ''); const isChildReportHasComment = Object.values(reportActions ?? {})?.some((reportAction) => (reportAction?.childVisibleActionCount ?? 0) > 0); return parentReport?.reportID !== report?.reportID && !isChildReportHasComment; @@ -3592,7 +3592,7 @@ function canFlagReportAction(reportAction: OnyxEntry, reportID: st reportAction?.actionName === CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT && !ReportActionsUtils.isDeletedAction(reportAction) && !ReportActionsUtils.isCreatedTaskReportAction(reportAction) && - isNotEmptyObject(report) && + !isEmptyObject(report) && report && isAllowedToComment(report), ); @@ -4215,7 +4215,7 @@ function getIOUReportActionDisplayMessage(reportAction: OnyxEntry) } const transaction = TransactionUtils.getTransaction(originalMessage.IOUTransactionID ?? ''); - const transactionDetails = getTransactionDetails(isNotEmptyObject(transaction) ? transaction : null); + const transactionDetails = getTransactionDetails(!isEmptyObject(transaction) ? transaction : null); const formattedAmount = CurrencyUtils.convertToDisplayString(transactionDetails?.amount ?? 0, transactionDetails?.currency); const isRequestSettled = isSettled(originalMessage.IOUReportID); const isApproved = isReportApproved(iouReport); diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 35ce0bb81fd5..743804410ba6 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -22,7 +22,7 @@ import ONYXKEYS from '@src/ONYXKEYS'; import type {PersonalDetailsList, Policy, PolicyMember, PolicyTags, RecentlyUsedCategories, RecentlyUsedTags, ReimbursementAccount, Report, ReportAction, Transaction} from '@src/types/onyx'; import type {Errors} from '@src/types/onyx/OnyxCommon'; import type {CustomUnit} from '@src/types/onyx/Policy'; -import {isEmptyObject, isNotEmptyObject} from '@src/types/utils/EmptyObject'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; type AnnounceRoomMembersOnyxData = { onyxOptimisticData: OnyxUpdate[]; @@ -430,7 +430,7 @@ function removeMembers(accountIDs: number[], policyID: string) { // If the policy has primaryLoginsInvited, then it displays informative messages on the members page about which primary logins were added by secondary logins. // If we delete all these logins then we should clear the informative messages since they are no longer relevant. - if (isNotEmptyObject(policy?.primaryLoginsInvited ?? {})) { + if (!isEmptyObject(policy?.primaryLoginsInvited ?? {})) { // Take the current policy members and remove them optimistically const policyMemberAccountIDs = Object.keys(allPolicyMembers?.[`${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`] ?? {}).map((accountID) => Number(accountID)); const remainingMemberAccountIDs = policyMemberAccountIDs.filter((accountID) => !accountIDs.includes(accountID)); @@ -641,7 +641,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: Record // Remove the object, when it is a newly created account. value: accountIDs.reduce((accountIDsWithClearedPendingAction, accountID) => { let value = null; - const accountAlreadyExists = isNotEmptyObject(allPersonalDetails?.[accountID]); + const accountAlreadyExists = !isEmptyObject(allPersonalDetails?.[accountID]); if (accountAlreadyExists) { value = {pendingAction: null, errors: null}; @@ -680,7 +680,7 @@ function addMembersToWorkspace(invitedEmailsToAccountIDs: Record welcomeNote: new ExpensiMark().replace(welcomeNote), policyID, }; - if (isNotEmptyObject(membersChats.reportCreationData)) { + if (!isEmptyObject(membersChats.reportCreationData)) { params.reportCreationData = JSON.stringify(membersChats.reportCreationData); } API.write('AddMembersToWorkspace', params, {optimisticData, successData, failureData}); diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 5828dae00322..3c433cf342b2 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -38,7 +38,7 @@ import type Report from '@src/types/onyx/Report'; import type {Message, ReportActionBase, ReportActions} from '@src/types/onyx/ReportAction'; import type ReportAction from '@src/types/onyx/ReportAction'; import type {EmptyObject} from '@src/types/utils/EmptyObject'; -import {isEmptyObject, isNotEmptyObject} from '@src/types/utils/EmptyObject'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; import * as Session from './Session'; import * as Welcome from './Welcome'; @@ -321,7 +321,7 @@ function addActions(reportID: string, text = '', file?: File) { const report = ReportUtils.getReport(reportID); - if (isNotEmptyObject(report) && ReportUtils.getReportNotificationPreference(report) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + if (!isEmptyObject(report) && ReportUtils.getReportNotificationPreference(report) === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { optimisticReport.notificationPreference = CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS; } @@ -422,7 +422,7 @@ function addActions(reportID: string, text = '', file?: File) { // Update optimistic data for parent report action if the report is a child report const optimisticParentReportData = ReportUtils.getOptimisticDataForParentReportAction(reportID, currentTime, CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); - if (isNotEmptyObject(optimisticParentReportData)) { + if (!isEmptyObject(optimisticParentReportData)) { optimisticData.push(optimisticParentReportData); } @@ -572,7 +572,7 @@ function openReport( } // If we are creating a new report, we need to add the optimistic report data and a report action - if (isNotEmptyObject(newReportObject)) { + if (!isEmptyObject(newReportObject)) { // Change the method to set for new reports because it doesn't exist yet, is faster, // and we need the data to be available when we navigate to the chat page optimisticData[0].onyxMethod = Onyx.METHOD.SET; @@ -1190,7 +1190,7 @@ function deleteReportComment(reportID: string, reportAction: ReportAction) { optimisticReport?.lastVisibleActionCreated ?? '', CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE, ); - if (isNotEmptyObject(optimisticParentReportData)) { + if (!isEmptyObject(optimisticParentReportData)) { optimisticData.push(optimisticParentReportData); } } @@ -1390,7 +1390,7 @@ function updateNotificationPreference( report: OnyxEntry | EmptyObject = {}, ) { if (previousValue === newValue) { - if (navigate && isNotEmptyObject(report) && report.reportID) { + if (navigate && !isEmptyObject(report) && report.reportID) { ReportUtils.goBackToDetailsPage(report); } return; @@ -1433,7 +1433,7 @@ function updateNotificationPreference( const parameters: UpdateReportNotificationPreferenceParameters = {reportID, notificationPreference: newValue}; API.write('UpdateReportNotificationPreference', parameters, {optimisticData, failureData}); - if (navigate && isNotEmptyObject(report)) { + if (navigate && !isEmptyObject(report)) { ReportUtils.goBackToDetailsPage(report); } }