From af34658124492fcc0053af7085bc48c4c674f230 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Thu, 27 Nov 2025 09:05:24 +0530 Subject: [PATCH 01/11] use lowercase without quotes for uncategorized --- src/libs/ModifiedExpenseMessage.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 22829175d4ea..16720e653402 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -17,6 +17,7 @@ import {getOriginalMessage, isModifiedExpenseAction} from './ReportActionsUtils' // eslint-disable-next-line import/no-cycle import {buildReportNameFromParticipantNames, getPolicyExpenseChatName, getPolicyName, getReportName, getRootParentReport, isPolicyExpenseChat, isSelfDM} from './ReportUtils'; import {getFormattedAttendees, getTagArrayFromName} from './TransactionUtils'; +import { isCategoryMissing } from './CategoryUtils'; let allPolicyTags: OnyxCollection = {}; Onyx.connect({ @@ -43,9 +44,10 @@ function buildMessageFragmentForValue( removalFragments: string[], changeFragments: string[], shouldConvertToLowercase = true, + noQuotesForOldValue = false, ) { const newValueToDisplay = valueInQuotes ? `"${newValue}"` : newValue; - const oldValueToDisplay = valueInQuotes ? `"${oldValue}"` : oldValue; + const oldValueToDisplay = valueInQuotes && !noQuotesForOldValue ? `"${oldValue}"` : oldValue; const displayValueName = shouldConvertToLowercase ? valueName.toLowerCase() : valueName; // eslint-disable-next-line @typescript-eslint/no-deprecated const isOldValuePartialMerchant = valueName === translateLocal('common.merchant') && oldValue === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; @@ -294,14 +296,19 @@ function getForReportAction({ categoryLabel += ` ${translateLocal('iou.basedOnMCC')}`; } + const wasUncategorized = isCategoryMissing(reportActionOriginalMessage?.oldCategory ?? ''); + const oldCategory = wasUncategorized ? reportActionOriginalMessage?.oldCategory?.toLowerCase() : reportActionOriginalMessage?.oldCategory; + buildMessageFragmentForValue( getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''), - getDecodedCategoryName(reportActionOriginalMessage?.oldCategory ?? ''), + getDecodedCategoryName(oldCategory ?? ''), categoryLabel, true, setFragments, removalFragments, changeFragments, + true, + true, ); } @@ -542,9 +549,14 @@ function getForReportActionTemp({ categoryLabel += ` ${translateLocal('iou.basedOnMCC')}`; } + const wasUncategorized = isCategoryMissing(reportActionOriginalMessage?.oldCategory ?? ''); + + const oldCategory = wasUncategorized ? reportActionOriginalMessage?.oldCategory?.toLowerCase() : reportActionOriginalMessage?.oldCategory; + + buildMessageFragmentForValue( getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''), - getDecodedCategoryName(reportActionOriginalMessage?.oldCategory ?? ''), + getDecodedCategoryName(oldCategory ?? ''), categoryLabel, true, setFragments, From 492666d572cc18b1a7470eddf32b6ee0c916d43d Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Thu, 27 Nov 2025 10:07:54 +0530 Subject: [PATCH 02/11] refactor the old category code --- src/libs/ModifiedExpenseMessage.ts | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 16720e653402..1891434f54ed 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -6,6 +6,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PolicyTagLists, Report, ReportAction} from '@src/types/onyx'; import {getDecodedCategoryName} from './CategoryUtils'; +import {isCategoryMissing} from './CategoryUtils'; import {convertToDisplayString} from './CurrencyUtils'; import DateUtils from './DateUtils'; // eslint-disable-next-line @typescript-eslint/no-deprecated @@ -17,7 +18,6 @@ import {getOriginalMessage, isModifiedExpenseAction} from './ReportActionsUtils' // eslint-disable-next-line import/no-cycle import {buildReportNameFromParticipantNames, getPolicyExpenseChatName, getPolicyName, getReportName, getRootParentReport, isPolicyExpenseChat, isSelfDM} from './ReportUtils'; import {getFormattedAttendees, getTagArrayFromName} from './TransactionUtils'; -import { isCategoryMissing } from './CategoryUtils'; let allPolicyTags: OnyxCollection = {}; Onyx.connect({ @@ -296,12 +296,18 @@ function getForReportAction({ categoryLabel += ` ${translateLocal('iou.basedOnMCC')}`; } - const wasUncategorized = isCategoryMissing(reportActionOriginalMessage?.oldCategory ?? ''); - const oldCategory = wasUncategorized ? reportActionOriginalMessage?.oldCategory?.toLowerCase() : reportActionOriginalMessage?.oldCategory; + let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; + + // If it was uncategorized, display as lowercase without quotes, otherwise use decoded name + if (isCategoryMissing(oldCategory)) { + oldCategory = oldCategory.toLowerCase(); + } else { + oldCategory = getDecodedCategoryName(oldCategory); + } buildMessageFragmentForValue( getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''), - getDecodedCategoryName(oldCategory ?? ''), + oldCategory, categoryLabel, true, setFragments, @@ -549,19 +555,25 @@ function getForReportActionTemp({ categoryLabel += ` ${translateLocal('iou.basedOnMCC')}`; } - const wasUncategorized = isCategoryMissing(reportActionOriginalMessage?.oldCategory ?? ''); - - const oldCategory = wasUncategorized ? reportActionOriginalMessage?.oldCategory?.toLowerCase() : reportActionOriginalMessage?.oldCategory; + let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; + // If it was uncategorized, display as lowercase without quotes, otherwise use decoded name + if (isCategoryMissing(oldCategory)) { + oldCategory = oldCategory.toLowerCase(); + } else { + oldCategory = getDecodedCategoryName(oldCategory); + } buildMessageFragmentForValue( getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''), - getDecodedCategoryName(oldCategory ?? ''), + oldCategory, categoryLabel, true, setFragments, removalFragments, changeFragments, + true, + true, ); } From 596936f8dc938d8f6bb8ee710b13fb9a0209ccdb Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Thu, 27 Nov 2025 10:09:05 +0530 Subject: [PATCH 03/11] prettier --- src/libs/ModifiedExpenseMessage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 1891434f54ed..4478f4c8c900 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -297,7 +297,7 @@ function getForReportAction({ } let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; - + // If it was uncategorized, display as lowercase without quotes, otherwise use decoded name if (isCategoryMissing(oldCategory)) { oldCategory = oldCategory.toLowerCase(); From ed58257fd9450060ce79511eeda48adcbd052c2d Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Thu, 27 Nov 2025 10:14:45 +0530 Subject: [PATCH 04/11] lint --- src/libs/ModifiedExpenseMessage.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 4478f4c8c900..60666f94dceb 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -5,8 +5,7 @@ import type {ValueOf} from 'type-fest'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {PolicyTagLists, Report, ReportAction} from '@src/types/onyx'; -import {getDecodedCategoryName} from './CategoryUtils'; -import {isCategoryMissing} from './CategoryUtils'; +import {getDecodedCategoryName, isCategoryMissing} from './CategoryUtils'; import {convertToDisplayString} from './CurrencyUtils'; import DateUtils from './DateUtils'; // eslint-disable-next-line @typescript-eslint/no-deprecated From 723dc590502800e4776703180d03f3b5757a9416 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Thu, 27 Nov 2025 10:29:12 +0530 Subject: [PATCH 05/11] omit quotes only for uncategorized --- src/libs/ModifiedExpenseMessage.ts | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 60666f94dceb..8cf2f57e663e 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -296,13 +296,9 @@ function getForReportAction({ } let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; + const wasUncategorized = isCategoryMissing(oldCategory); - // If it was uncategorized, display as lowercase without quotes, otherwise use decoded name - if (isCategoryMissing(oldCategory)) { - oldCategory = oldCategory.toLowerCase(); - } else { - oldCategory = getDecodedCategoryName(oldCategory); - } + oldCategory = wasUncategorized ? oldCategory.toLowerCase() : getDecodedCategoryName(oldCategory); buildMessageFragmentForValue( getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''), @@ -313,7 +309,7 @@ function getForReportAction({ removalFragments, changeFragments, true, - true, + wasUncategorized, ); } @@ -555,13 +551,9 @@ function getForReportActionTemp({ } let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; + const wasUncategorized = isCategoryMissing(oldCategory); - // If it was uncategorized, display as lowercase without quotes, otherwise use decoded name - if (isCategoryMissing(oldCategory)) { - oldCategory = oldCategory.toLowerCase(); - } else { - oldCategory = getDecodedCategoryName(oldCategory); - } + oldCategory = wasUncategorized ? oldCategory.toLowerCase() : getDecodedCategoryName(oldCategory); buildMessageFragmentForValue( getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''), @@ -572,7 +564,7 @@ function getForReportActionTemp({ removalFragments, changeFragments, true, - true, + wasUncategorized, ); } From 9ea90539364726032b89b51cf330043dd2c54467 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Fri, 28 Nov 2025 12:18:57 +0530 Subject: [PATCH 06/11] DRY --- src/libs/ModifiedExpenseMessage.ts | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 8cf2f57e663e..96e75cba703d 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -43,10 +43,15 @@ function buildMessageFragmentForValue( removalFragments: string[], changeFragments: string[], shouldConvertToLowercase = true, - noQuotesForOldValue = false, + // wasUncategorized = false, ) { const newValueToDisplay = valueInQuotes ? `"${newValue}"` : newValue; - const oldValueToDisplay = valueInQuotes && !noQuotesForOldValue ? `"${oldValue}"` : oldValue; + // Check if the value is a category + const isCategory = valueName.includes(translateLocal('common.category')); + // Check if the old value is Uncategorized + const wasUncategorized = isCategoryMissing(oldValue); + // If the value is a category, and the old value was Uncategorized, show it in lowercase without quotes + const oldValueToDisplay = isCategory && wasUncategorized ? oldValue.toLowerCase() : valueInQuotes ? `"${oldValue}"` : oldValue; const displayValueName = shouldConvertToLowercase ? valueName.toLowerCase() : valueName; // eslint-disable-next-line @typescript-eslint/no-deprecated const isOldValuePartialMerchant = valueName === translateLocal('common.merchant') && oldValue === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; @@ -295,21 +300,20 @@ function getForReportAction({ categoryLabel += ` ${translateLocal('iou.basedOnMCC')}`; } - let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; - const wasUncategorized = isCategoryMissing(oldCategory); + // let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; + // const wasUncategorized = isCategoryMissing(oldCategory); - oldCategory = wasUncategorized ? oldCategory.toLowerCase() : getDecodedCategoryName(oldCategory); + // oldCategory = wasUncategorized ? oldCategory.toLowerCase() : getDecodedCategoryName(oldCategory); buildMessageFragmentForValue( getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''), - oldCategory, + getDecodedCategoryName(reportActionOriginalMessage?.oldCategory ?? ''), categoryLabel, true, setFragments, removalFragments, changeFragments, true, - wasUncategorized, ); } @@ -550,21 +554,20 @@ function getForReportActionTemp({ categoryLabel += ` ${translateLocal('iou.basedOnMCC')}`; } - let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; - const wasUncategorized = isCategoryMissing(oldCategory); + // let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; + // const wasUncategorized = isCategoryMissing(oldCategory); - oldCategory = wasUncategorized ? oldCategory.toLowerCase() : getDecodedCategoryName(oldCategory); + // oldCategory = wasUncategorized ? oldCategory.toLowerCase() : getDecodedCategoryName(oldCategory); buildMessageFragmentForValue( getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''), - oldCategory, + getDecodedCategoryName(reportActionOriginalMessage?.oldCategory ?? ''), categoryLabel, true, setFragments, removalFragments, changeFragments, true, - wasUncategorized, ); } From 60d2107482a81bb61607604c25fad432f35d8049 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Fri, 28 Nov 2025 12:23:38 +0530 Subject: [PATCH 07/11] cleanup --- src/libs/ModifiedExpenseMessage.ts | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 96e75cba703d..d73357da018e 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -43,15 +43,13 @@ function buildMessageFragmentForValue( removalFragments: string[], changeFragments: string[], shouldConvertToLowercase = true, - // wasUncategorized = false, ) { const newValueToDisplay = valueInQuotes ? `"${newValue}"` : newValue; - // Check if the value is a category - const isCategory = valueName.includes(translateLocal('common.category')); - // Check if the old value is Uncategorized - const wasUncategorized = isCategoryMissing(oldValue); - // If the value is a category, and the old value was Uncategorized, show it in lowercase without quotes - const oldValueToDisplay = isCategory && wasUncategorized ? oldValue.toLowerCase() : valueInQuotes ? `"${oldValue}"` : oldValue; + + // If the valueName is category and the old value was Uncategorized, show it in lowercase without quotes + // eslint-disable-next-line @typescript-eslint/no-deprecated + const oldValueToDisplay = valueName.includes(translateLocal('common.category')) && isCategoryMissing(oldValue) ? oldValue.toLowerCase() : valueInQuotes ? `"${oldValue}"` : oldValue; + const displayValueName = shouldConvertToLowercase ? valueName.toLowerCase() : valueName; // eslint-disable-next-line @typescript-eslint/no-deprecated const isOldValuePartialMerchant = valueName === translateLocal('common.merchant') && oldValue === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; @@ -300,11 +298,6 @@ function getForReportAction({ categoryLabel += ` ${translateLocal('iou.basedOnMCC')}`; } - // let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; - // const wasUncategorized = isCategoryMissing(oldCategory); - - // oldCategory = wasUncategorized ? oldCategory.toLowerCase() : getDecodedCategoryName(oldCategory); - buildMessageFragmentForValue( getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''), getDecodedCategoryName(reportActionOriginalMessage?.oldCategory ?? ''), @@ -554,11 +547,6 @@ function getForReportActionTemp({ categoryLabel += ` ${translateLocal('iou.basedOnMCC')}`; } - // let oldCategory = reportActionOriginalMessage?.oldCategory ?? ''; - // const wasUncategorized = isCategoryMissing(oldCategory); - - // oldCategory = wasUncategorized ? oldCategory.toLowerCase() : getDecodedCategoryName(oldCategory); - buildMessageFragmentForValue( getDecodedCategoryName(reportActionOriginalMessage?.category ?? ''), getDecodedCategoryName(reportActionOriginalMessage?.oldCategory ?? ''), From 4d3c3f84591ad915499e7552223443292d2ca4bf Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Fri, 28 Nov 2025 12:25:12 +0530 Subject: [PATCH 08/11] remove unnecessary default parameter --- src/libs/ModifiedExpenseMessage.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index d73357da018e..39034074b58e 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -49,7 +49,7 @@ function buildMessageFragmentForValue( // If the valueName is category and the old value was Uncategorized, show it in lowercase without quotes // eslint-disable-next-line @typescript-eslint/no-deprecated const oldValueToDisplay = valueName.includes(translateLocal('common.category')) && isCategoryMissing(oldValue) ? oldValue.toLowerCase() : valueInQuotes ? `"${oldValue}"` : oldValue; - + const displayValueName = shouldConvertToLowercase ? valueName.toLowerCase() : valueName; // eslint-disable-next-line @typescript-eslint/no-deprecated const isOldValuePartialMerchant = valueName === translateLocal('common.merchant') && oldValue === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT; @@ -306,7 +306,6 @@ function getForReportAction({ setFragments, removalFragments, changeFragments, - true, ); } @@ -555,7 +554,6 @@ function getForReportActionTemp({ setFragments, removalFragments, changeFragments, - true, ); } From 39a86a90515271bc1062e91ca7eafbd356650396 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Fri, 28 Nov 2025 12:31:52 +0530 Subject: [PATCH 09/11] remove nested ternary as lint complains --- src/libs/ModifiedExpenseMessage.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 39034074b58e..1feda9a93829 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -48,7 +48,14 @@ function buildMessageFragmentForValue( // If the valueName is category and the old value was Uncategorized, show it in lowercase without quotes // eslint-disable-next-line @typescript-eslint/no-deprecated - const oldValueToDisplay = valueName.includes(translateLocal('common.category')) && isCategoryMissing(oldValue) ? oldValue.toLowerCase() : valueInQuotes ? `"${oldValue}"` : oldValue; + let oldValueToDisplay; + if (valueName.includes(translateLocal('common.category')) && isCategoryMissing(oldValue)) { + oldValueToDisplay = oldValue.toLowerCase(); + } else if (valueInQuotes) { + oldValueToDisplay = `"${oldValue}"`; + } else { + oldValueToDisplay = oldValue; + } const displayValueName = shouldConvertToLowercase ? valueName.toLowerCase() : valueName; // eslint-disable-next-line @typescript-eslint/no-deprecated From d3b2dbbbc7d97f021129d3eabfdcbbb3201e5069 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Fri, 28 Nov 2025 12:35:01 +0530 Subject: [PATCH 10/11] move lint override to correct place --- src/libs/ModifiedExpenseMessage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 1feda9a93829..1ab571655efd 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -47,8 +47,8 @@ function buildMessageFragmentForValue( const newValueToDisplay = valueInQuotes ? `"${newValue}"` : newValue; // If the valueName is category and the old value was Uncategorized, show it in lowercase without quotes - // eslint-disable-next-line @typescript-eslint/no-deprecated let oldValueToDisplay; + // eslint-disable-next-line @typescript-eslint/no-deprecated if (valueName.includes(translateLocal('common.category')) && isCategoryMissing(oldValue)) { oldValueToDisplay = oldValue.toLowerCase(); } else if (valueInQuotes) { From 1133f0c1fca7597ba4e6afc738986a5128dda398 Mon Sep 17 00:00:00 2001 From: Krishna Chaitanya Date: Mon, 1 Dec 2025 22:00:04 +0530 Subject: [PATCH 11/11] include the lower case in check --- src/libs/ModifiedExpenseMessage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ModifiedExpenseMessage.ts b/src/libs/ModifiedExpenseMessage.ts index 8c543282144d..680d1c7ed9f4 100644 --- a/src/libs/ModifiedExpenseMessage.ts +++ b/src/libs/ModifiedExpenseMessage.ts @@ -66,7 +66,7 @@ function buildMessageFragmentForValue( // If the valueName is category and the old value was Uncategorized, show it in lowercase without quotes let oldValueToDisplay; // eslint-disable-next-line @typescript-eslint/no-deprecated - if (valueName.includes(translateLocal('common.category')) && isCategoryMissing(oldValue)) { + if (valueName.includes(translateLocal('common.category').toLowerCase()) && isCategoryMissing(oldValue)) { oldValueToDisplay = oldValue.toLowerCase(); } else if (valueInQuotes) { oldValueToDisplay = `"${oldValue}"`;