Skip to content

Commit

Permalink
Merge pull request #47558 from callstack-internal/hur/fix-46115
Browse files Browse the repository at this point in the history
fix: right operand of in is not an object
  • Loading branch information
marcochavezf authored Aug 20, 2024
2 parents 1a8e6c4 + 1ea6781 commit ea13761
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/libs/EmojiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function getDynamicSpacing(emojiCount: number, suffix: number): EmojiSpacer[] {
function addSpacesToEmojiCategories(emojis: PickerEmojis): EmojiPickerList {
let updatedEmojis: EmojiPickerList = [];
emojis.forEach((emoji, index) => {
if (emoji && 'header' in emoji) {
if (emoji && typeof emoji === 'object' && 'header' in emoji) {
updatedEmojis = updatedEmojis.concat(getDynamicSpacing(updatedEmojis.length, index), [emoji], getDynamicSpacing(1, index));
return;
}
Expand Down
19 changes: 10 additions & 9 deletions src/libs/ModifiedExpenseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
const setFragments: string[] = [];
const changeFragments: string[] = [];

const isReportActionOriginalMessageAnObject = reportActionOriginalMessage && typeof reportActionOriginalMessage === 'object';
const hasModifiedAmount =
reportActionOriginalMessage &&
isReportActionOriginalMessageAnObject &&
'oldAmount' in reportActionOriginalMessage &&
'oldCurrency' in reportActionOriginalMessage &&
'amount' in reportActionOriginalMessage &&
'currency' in reportActionOriginalMessage;

const hasModifiedMerchant = reportActionOriginalMessage && 'oldMerchant' in reportActionOriginalMessage && 'merchant' in reportActionOriginalMessage;
const hasModifiedMerchant = isReportActionOriginalMessageAnObject && 'oldMerchant' in reportActionOriginalMessage && 'merchant' in reportActionOriginalMessage;

if (hasModifiedAmount) {
const oldCurrency = reportActionOriginalMessage?.oldCurrency;
Expand All @@ -149,7 +150,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
buildMessageFragmentForValue(amount, oldAmount, Localize.translateLocal('iou.amount'), false, setFragments, removalFragments, changeFragments);
}

const hasModifiedComment = reportActionOriginalMessage && 'oldComment' in reportActionOriginalMessage && 'newComment' in reportActionOriginalMessage;
const hasModifiedComment = isReportActionOriginalMessageAnObject && 'oldComment' in reportActionOriginalMessage && 'newComment' in reportActionOriginalMessage;
if (hasModifiedComment) {
buildMessageFragmentForValue(
reportActionOriginalMessage?.newComment ?? '',
Expand Down Expand Up @@ -188,7 +189,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
);
}

const hasModifiedCategory = reportActionOriginalMessage && 'oldCategory' in reportActionOriginalMessage && 'category' in reportActionOriginalMessage;
const hasModifiedCategory = isReportActionOriginalMessageAnObject && 'oldCategory' in reportActionOriginalMessage && 'category' in reportActionOriginalMessage;
if (hasModifiedCategory) {
buildMessageFragmentForValue(
reportActionOriginalMessage?.category ?? '',
Expand All @@ -201,7 +202,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
);
}

const hasModifiedTag = reportActionOriginalMessage && 'oldTag' in reportActionOriginalMessage && 'tag' in reportActionOriginalMessage;
const hasModifiedTag = isReportActionOriginalMessageAnObject && 'oldTag' in reportActionOriginalMessage && 'tag' in reportActionOriginalMessage;
if (hasModifiedTag) {
const policyTags = allPolicyTags?.[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`] ?? {};
const transactionTag = reportActionOriginalMessage?.tag ?? '';
Expand Down Expand Up @@ -232,7 +233,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
});
}

const hasModifiedTaxAmount = reportActionOriginalMessage && 'oldTaxAmount' in reportActionOriginalMessage && 'taxAmount' in reportActionOriginalMessage;
const hasModifiedTaxAmount = isReportActionOriginalMessageAnObject && 'oldTaxAmount' in reportActionOriginalMessage && 'taxAmount' in reportActionOriginalMessage;
if (hasModifiedTaxAmount) {
const currency = reportActionOriginalMessage?.currency;

Expand All @@ -242,7 +243,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
buildMessageFragmentForValue(taxAmount, oldTaxAmount, Localize.translateLocal('iou.taxAmount'), false, setFragments, removalFragments, changeFragments);
}

const hasModifiedTaxRate = reportActionOriginalMessage && 'oldTaxRate' in reportActionOriginalMessage && 'taxRate' in reportActionOriginalMessage;
const hasModifiedTaxRate = isReportActionOriginalMessageAnObject && 'oldTaxRate' in reportActionOriginalMessage && 'taxRate' in reportActionOriginalMessage;
if (hasModifiedTaxRate) {
buildMessageFragmentForValue(
reportActionOriginalMessage?.taxRate ?? '',
Expand All @@ -255,7 +256,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
);
}

const hasModifiedBillable = reportActionOriginalMessage && 'oldBillable' in reportActionOriginalMessage && 'billable' in reportActionOriginalMessage;
const hasModifiedBillable = isReportActionOriginalMessageAnObject && 'oldBillable' in reportActionOriginalMessage && 'billable' in reportActionOriginalMessage;
if (hasModifiedBillable) {
buildMessageFragmentForValue(
reportActionOriginalMessage?.billable ?? '',
Expand All @@ -268,7 +269,7 @@ function getForReportAction(reportID: string | undefined, reportAction: OnyxEntr
);
}

const hasModifiedReimbursable = reportActionOriginalMessage && 'oldReimbursable' in reportActionOriginalMessage && 'reimbursable' in reportActionOriginalMessage;
const hasModifiedReimbursable = isReportActionOriginalMessageAnObject && 'oldReimbursable' in reportActionOriginalMessage && 'reimbursable' in reportActionOriginalMessage;
if (hasModifiedReimbursable) {
buildMessageFragmentForValue(
getBooleanLiteralMessage(reportActionOriginalMessage?.reimbursable, Localize.translateLocal('iou.reimbursable'), Localize.translateLocal('iou.nonReimbursable')),
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function getWhisperedTo(reportAction: OnyxInputOrEntry<ReportAction>): number[]
return [];
}

if (!Array.isArray(message) && typeof message === 'object' && 'whisperedTo' in message) {
if (message !== null && !Array.isArray(message) && typeof message === 'object' && 'whisperedTo' in message) {
return message?.whisperedTo ?? [];
}

Expand Down
10 changes: 6 additions & 4 deletions src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ function ReportActionItem({
);

const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(action);
const prevActionResolution = usePrevious(isActionableWhisper && originalMessage && 'resolution' in originalMessage ? originalMessage?.resolution : null);
const isOriginalMessageAnObject = originalMessage && typeof originalMessage === 'object';
const hasResolutionInOriginalMessage = isOriginalMessageAnObject && 'resolution' in originalMessage;
const prevActionResolution = usePrevious(isActionableWhisper && hasResolutionInOriginalMessage ? originalMessage?.resolution : null);

// IOUDetails only exists when we are sending money
const isSendingMoney =
Expand Down Expand Up @@ -375,10 +377,10 @@ function ReportActionItem({
return;
}

if (prevActionResolution !== (originalMessage && 'resolution' in originalMessage ? originalMessage.resolution : null)) {
if (prevActionResolution !== (hasResolutionInOriginalMessage ? originalMessage.resolution : null)) {
reportScrollManager.scrollToIndex(index);
}
}, [index, originalMessage, prevActionResolution, reportScrollManager, isActionableWhisper]);
}, [index, originalMessage, prevActionResolution, reportScrollManager, isActionableWhisper, hasResolutionInOriginalMessage]);

const toggleReaction = useCallback(
(emoji: Emoji) => {
Expand Down Expand Up @@ -860,7 +862,7 @@ function ReportActionItem({
}

// If action is actionable whisper and resolved by user, then we don't want to render anything
if (isActionableWhisper && (originalMessage && 'resolution' in originalMessage ? originalMessage.resolution : null)) {
if (isActionableWhisper && (hasResolutionInOriginalMessage ? originalMessage.resolution : null)) {
return null;
}

Expand Down

0 comments on commit ea13761

Please sign in to comment.