Skip to content
Merged
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
15 changes: 13 additions & 2 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy, PolicyTagLists, Report, ReportAction} from '@src/types/onyx';
import {getDecodedCategoryName} from './CategoryUtils';
import {getDecodedCategoryName, isCategoryMissing} from './CategoryUtils';
import {convertToDisplayString} from './CurrencyUtils';
import DateUtils from './DateUtils';
import {getEnvironmentURL} from './Environment/Environment';
Expand Down Expand Up @@ -62,7 +62,18 @@ function buildMessageFragmentForValue(
shouldConvertToLowercase = true,
) {
const newValueToDisplay = valueInQuotes ? `"${newValue}"` : newValue;
const oldValueToDisplay = valueInQuotes ? `"${oldValue}"` : oldValue;

// 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').toLowerCase()) && isCategoryMissing(oldValue)) {

Copy link
Copy Markdown
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 the reason to use includes here instead of direct equality check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The categoryLabel can be appended with other text if it is derived based on AI etc.

let categoryLabel = translateLocal('common.category').toLowerCase();
// Add attribution suffix based on source
if (reportActionOriginalMessage?.source === CONST.CATEGORY_SOURCE.AI) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
categoryLabel += ` ${translateLocal('iou.basedOnAI')}`;
} else if (reportActionOriginalMessage?.source === CONST.CATEGORY_SOURCE.MCC) {
// eslint-disable-next-line @typescript-eslint/no-deprecated
const policy = getPolicy(policyID);
const isAdmin = isPolicyAdmin(policy, currentUserLogin);
// For admins, create a hyperlink to the workspace rules page
if (isAdmin && policy?.id) {
const rulesLink = `${environmentURL}/${ROUTES.WORKSPACE_RULES.getRoute(policy.id)}`;
// eslint-disable-next-line @typescript-eslint/no-deprecated
categoryLabel += ` ${translateLocal('iou.basedOnMCC', {rulesLink})}`;
} else {
// eslint-disable-next-line @typescript-eslint/no-deprecated
categoryLabel += ` ${translateLocal('iou.basedOnMCC', {rulesLink: ''})}`;
}
}

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
const isOldValuePartialMerchant = valueName === translateLocal('common.merchant') && oldValue === CONST.TRANSACTION.PARTIAL_TRANSACTION_MERCHANT;
Expand Down
Loading